diff --git a/tests/ApbctWP/Localize/TestCtPublicFunctionsLocalize.php b/tests/ApbctWP/Localize/TestCtPublicFunctionsLocalize.php new file mode 100644 index 000000000..dae16de11 --- /dev/null +++ b/tests/ApbctWP/Localize/TestCtPublicFunctionsLocalize.php @@ -0,0 +1,33 @@ +assertArrayHasKey('bot_detector_enabled', $localize_data); + $this->assertArrayNotHasKey('data__bot_detector_enabled', $localize_data); + } +} \ No newline at end of file diff --git a/tests/ApbctWP/Localize/TestCtPublicLocalize.php b/tests/ApbctWP/Localize/TestCtPublicLocalize.php new file mode 100644 index 000000000..ffa1ca500 --- /dev/null +++ b/tests/ApbctWP/Localize/TestCtPublicLocalize.php @@ -0,0 +1,33 @@ +assertArrayHasKey('bot_detector_enabled', $localize_data); + $this->assertArrayNotHasKey('data__bot_detector_enabled', $localize_data); + } +} \ No newline at end of file diff --git a/tests/Inc/TestCleantalkCommon.php b/tests/Inc/TestCleantalkCommon.php new file mode 100644 index 000000000..35e856693 --- /dev/null +++ b/tests/Inc/TestCleantalkCommon.php @@ -0,0 +1,110 @@ +assertTrue($bot_detector_state); + } + + public function testApbctIsBotDetectorDisabledByData() + { + // Arrange + global $apbct; + $apbct->data['bot_detector_enabled'] = 0; + + // Act + $bot_detector_state = apbct__is_bot_detector_enabled(); + + // Assert + $this->assertFalse($bot_detector_state); + } + + public function testApbctIsBotDetectorEnabledByDataTrue() + { + // Arrange + global $apbct; + $apbct->data['bot_detector_enabled'] = 1; + + // Act + $bot_detector_state = apbct__is_bot_detector_enabled(); + + // Assert + $this->assertTrue($bot_detector_state); + } + + public function testApbctIsBotDetectorEnabledByConstant() + { + // Arrange + global $apbct; + $apbct_constant_mock = $this->getMockBuilder(ApbctConstant::class) + ->onlyMethods(['isDefined', 'getValue']) + ->disableOriginalConstructor() + ->getMock(); + + $apbct_constant_mock->method('isDefined') + ->willReturn(true); + + $apbct_constant_mock->method('getValue') + ->willReturn(true); + $apbct->service_constants = new ServiceConstants(); + $apbct->service_constants->bot_detector_enabled = $apbct_constant_mock; + + // Act + $bot_detector_state = apbct__is_bot_detector_enabled(); + + // Assert + $this->assertTrue($bot_detector_state); + } + + public function testApbctIsBotDetectorDisabledByConstant() + { + // Arrange + global $apbct; + $apbct_constant_mock = $this->getMockBuilder(ApbctConstant::class) + ->onlyMethods(['isDefined', 'getValue']) + ->disableOriginalConstructor() + ->getMock(); + + $apbct_constant_mock->method('isDefined') + ->willReturn(true); + + $apbct_constant_mock->method('getValue') + ->willReturn(false); + $apbct->service_constants = new ServiceConstants(); + $apbct->service_constants->bot_detector_enabled = $apbct_constant_mock; + + // Act + $bot_detector_state = apbct__is_bot_detector_enabled(); + + // Assert + $this->assertFalse($bot_detector_state); + } +} diff --git a/tests/Inc/TestCleantalkPublic.php b/tests/Inc/TestCleantalkPublic.php new file mode 100644 index 000000000..9d073b2cd --- /dev/null +++ b/tests/Inc/TestCleantalkPublic.php @@ -0,0 +1,80 @@ +data['bot_detector_enabled'] = 0; + $apbct->settings['data__pixel'] = '3'; + + // Act + apbct_init(); + + // Assert + $this->assertNotNull($apbct->pixel_url); + } + + public function testApbctInitPixelUrlNotLoad() + { + // Arrange + global $apbct; + $apbct->data['bot_detector_enabled'] = 1; + $apbct->settings['data__pixel'] = '3'; + + // Act + apbct_init(); + + // Assert + $this->assertNull($apbct->pixel_url); + } + + public function testApbctHookWpFooterShowPixel() + { + // Arrange + global $apbct; + $apbct->data['bot_detector_enabled'] = 0; + $apbct->settings['data__pixel'] = '3'; + + // Act + ob_start(); + apbct_hook__wp_footer(); + $output = ob_get_clean(); + + // Assert + $this->assertStringContainsString('img alt="Cleantalk Pixel" title="Cleantalk Pixel" id="apbct_pixel" style="display: none;"', $output); + } + + public function testApbctEnqueueAndLocalizePublicScripts() + { + // Arrange + global $apbct; + $apbct->data['bot_detector_enabled'] = 1; + + // Act + apbct_enqueue_and_localize_public_scripts(); + + // Assert + $this->assertTrue(wp_script_is('ct_bot_detector')); + } +} \ No newline at end of file diff --git a/tests/Inc/TestCleantalkSettings.php b/tests/Inc/TestCleantalkSettings.php index c0e04e939..cd552d9f6 100644 --- a/tests/Inc/TestCleantalkSettings.php +++ b/tests/Inc/TestCleantalkSettings.php @@ -1,5 +1,7 @@ data['bot_detector_enabled'] = 1; } + protected function tearDown(): void + { + global $apbct; + unset($apbct); + parent::tearDown(); + } + public function testApbctSettingsSetFieldsBotDetector() { $fields = apbct_settings__set_fields(); diff --git a/tests/Inc/TestCleantalkUpdater.php b/tests/Inc/TestCleantalkUpdater.php new file mode 100644 index 000000000..ec3abe2f3 --- /dev/null +++ b/tests/Inc/TestCleantalkUpdater.php @@ -0,0 +1,37 @@ +settings['data__bot_detector_enabled'] = 1; + + // Act + apbct_update_to_6_76_0(); + $apbct_rebuilt = new State('cleantalk', array('settings', 'data', 'errors', 'remote_calls', 'stats', 'fw_stats')); + + // Assert + $this->assertEquals('1', $apbct_rebuilt->data['bot_detector_enabled']); + } +}