Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 33 additions & 0 deletions tests/ApbctWP/Localize/TestCtPublicFunctionsLocalize.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?php

use Cleantalk\ApbctWP\Localize\CtPublicFunctionsLocalize;
use Cleantalk\ApbctWP\State;

class TestCtPublicFunctionsLocalize extends \PHPUnit\Framework\TestCase
{
protected function setUp(): void
{
parent::setUp();
global $apbct;
$apbct = new State('cleantalk', array('settings', 'data', 'errors', 'remote_calls', 'stats', 'fw_stats'));
}

protected function tearDown(): void
{
global $apbct;
unset($apbct);
parent::tearDown();
}

public function testGetData()
{
// Arrange

// Act
$localize_data = CtPublicFunctionsLocalize::getData();

// Assert
$this->assertArrayHasKey('bot_detector_enabled', $localize_data);
$this->assertArrayNotHasKey('data__bot_detector_enabled', $localize_data);
}
}
33 changes: 33 additions & 0 deletions tests/ApbctWP/Localize/TestCtPublicLocalize.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?php

use Cleantalk\ApbctWP\Localize\CtPublicLocalize;
use Cleantalk\ApbctWP\State;

class TestCtPublicLocalize extends \PHPUnit\Framework\TestCase
{
protected function setUp(): void
{
parent::setUp();
global $apbct;
$apbct = new State('cleantalk', array('settings', 'data', 'errors', 'remote_calls', 'stats', 'fw_stats'));
}

protected function tearDown(): void
{
global $apbct;
unset($apbct);
parent::tearDown();
}

public function testGetData()
{
// Arrange

// Act
$localize_data = CtPublicLocalize::getData();

Comment on lines +8 to +28
// Assert
$this->assertArrayHasKey('bot_detector_enabled', $localize_data);
$this->assertArrayNotHasKey('data__bot_detector_enabled', $localize_data);
}
}
110 changes: 110 additions & 0 deletions tests/Inc/TestCleantalkCommon.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
<?php

namespace Inc;

use Cleantalk\ApbctWP\ApbctConstant;
use Cleantalk\ApbctWP\ServiceConstants;
use Cleantalk\ApbctWP\State;
use PHPUnit\Framework\TestCase;

class TestCleantalkCommon extends TestCase
{
protected function setUp(): void
{
parent::setUp();
global $apbct;
$apbct = new State('cleantalk', array('settings', 'data', 'errors', 'remote_calls', 'stats', 'fw_stats'));
}

protected function tearDown(): void
{
global $apbct;
unset($apbct);
parent::tearDown();
}

public function testApbctIsBotDetectorEnabledByDefault()
{
// Arrange empty

// Act
$bot_detector_state = apbct__is_bot_detector_enabled();

// Assert
$this->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);
}
}
80 changes: 80 additions & 0 deletions tests/Inc/TestCleantalkPublic.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
<?php

namespace Inc;

use Cleantalk\ApbctWP\State;
use PHPUnit\Framework\TestCase;

class TestCleantalkPublic extends TestCase
{
protected function setUp(): void
{
parent::setUp();
global $apbct;
$apbct = new State('cleantalk', array('settings', 'data', 'errors', 'remote_calls', 'stats', 'fw_stats'));
}

protected function tearDown(): void
{
global $apbct;
unset($apbct);
parent::tearDown();
}

public function testApbctInitPixelUrlLoad()
{
// Arrange
global $apbct;
$apbct->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'));
}
}
11 changes: 11 additions & 0 deletions tests/Inc/TestCleantalkSettings.php
Original file line number Diff line number Diff line change
@@ -1,16 +1,27 @@
<?php

namespace Inc;

use Cleantalk\ApbctWP\State;
use PHPUnit\Framework\TestCase;

class TestCleantalkSettings extends TestCase
{
protected function setUp(): void {
parent::setUp(); // TODO: Change the autogenerated stub
require_once(CLEANTALK_PLUGIN_DIR . 'inc/cleantalk-settings.php');
global $apbct;
$apbct = new State('cleantalk', array('settings', 'data', 'errors', 'remote_calls', 'stats', 'fw_stats'));
$apbct->data['bot_detector_enabled'] = 1;
}

protected function tearDown(): void
{
global $apbct;
unset($apbct);
parent::tearDown();
}

public function testApbctSettingsSetFieldsBotDetector()
{
$fields = apbct_settings__set_fields();
Expand Down
37 changes: 37 additions & 0 deletions tests/Inc/TestCleantalkUpdater.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<?php

namespace Inc;

use Cleantalk\ApbctWP\State;
use PHPUnit\Framework\TestCase;

class TestCleantalkUpdater extends TestCase
{
protected function setUp(): void
{
parent::setUp();
global $apbct;
$apbct = new State('cleantalk', array('settings', 'data', 'errors', 'remote_calls', 'stats', 'fw_stats'));
}

protected function tearDown(): void
{
global $apbct;
unset($apbct);
parent::tearDown();
}

public function testApbctUpdateTo_6_76_0()
{
// Arrange
global $apbct;
$apbct->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'));

Comment on lines +30 to +33
// Assert
$this->assertEquals('1', $apbct_rebuilt->data['bot_detector_enabled']);
}
}
Loading