diff --git a/tests/codeception/tests/acceptance/.gitkeep b/tests/codeception/tests/acceptance/.gitkeep new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git a/tests/codeception/tests/integration/TestAjaxHandler.php b/tests/codeception/tests/integration/TestAjaxHandler.php new file mode 100644 index 0000000000000000000000000000000000000000..eebf7cfeb73da974c2b85aea22b17f23b2560988 --- /dev/null +++ b/tests/codeception/tests/integration/TestAjaxHandler.php @@ -0,0 +1,91 @@ +<?php + +namespace codeception\tests\integration; + +use Codeception\TestCase\WPTestCase; +use \WPDesk\Notice\AjaxHandler; +use \WPDesk\Notice\PermanentDismissibleNotice; + +class TestAjaxHandler extends WPTestCase { + + const ASSETS_URL = 'http://test.com/test/assetes/'; + const NOTICE_NAME = 'test_notice_name'; + const WP_DEFAULT_PRIORITY = 10; + + public function setUp() { + parent::setUp(); + } + + public function tearDown() { + parent::tearDown(); + } + + public function testHooksWithAssetsURL() { + $ajaxHandler = new AjaxHandler( self::ASSETS_URL ); + $ajaxHandler->hooks(); + + $this->assertEquals( + self::WP_DEFAULT_PRIORITY, + has_action( 'admin_enqueue_scripts', [ $ajaxHandler, 'enqueueAdminScripts' ] ) + ); + $this->assertEquals( + self::WP_DEFAULT_PRIORITY, + has_action( 'wp_ajax_wpdesk_notice_dismiss', [ $ajaxHandler, 'processAjaxNoticeDismiss' ] ) + ); + } + + public function testHooksWithoutAssetsURL() { + $ajaxHandler = new AjaxHandler(); + $ajaxHandler->hooks(); + + $this->assertEquals( + self::WP_DEFAULT_PRIORITY, + has_action( 'admin_head', [ $ajaxHandler, 'addScriptToAdminHead' ] ) + ); + $this->assertEquals( + self::WP_DEFAULT_PRIORITY, + has_action( 'wp_ajax_wpdesk_notice_dismiss', [ $ajaxHandler, 'processAjaxNoticeDismiss' ] ) + ); + } + + public function testEnqueueAdminScripts() { + $this->markTestSkipped( 'Must be revisited. get_current_screen not working.' ); + $ajaxHandler = new AjaxHandler( self::ASSETS_URL ); + $ajaxHandler->hooks(); + do_action( 'admin_enqueue_scripts' ); + $registeredScripts = wp_scripts()->registered; + + $this->assertArrayHasKey( 'wpdesk_notice', $registeredScripts, 'Script not registered!' ); + $this->assertEquals( + self::ASSETS_URL . 'js/notice.js', + $registeredScripts['wpdesk_notice']->src, + 'Script src is invalid!' + ); + } + + public function testAddScriptToAdminHead() { + $ajaxHandler = new AjaxHandler(); + $ajaxHandler->hooks(); + + $this->expectOutputString( '<script type="text/javascript"> +' . file_get_contents( __DIR__ . '/../../assets/js/notice.js' ) . ' +</script> +' + ); + + $ajaxHandler->addScriptToAdminHead(); + } + + public function testProcessAjaxNoticeDismiss() { + $_POST[ AjaxHandler::POST_FIELD_NOTICE_NAME ] = self::NOTICE_NAME; + + $ajaxHandler = new AjaxHandler( self::ASSETS_URL ); + $ajaxHandler->processAjaxNoticeDismiss(); + + $this->assertEquals( + PermanentDismissibleNotice::OPTION_VALUE_DISMISSED, + get_option( PermanentDismissibleNotice::OPTION_NAME_PREFIX . self::NOTICE_NAME ) + ); + } + +} diff --git a/tests/integration/TestAjaxHandler.php b/tests/integration/TestAjaxHandler.php deleted file mode 100644 index 5d09962599fca95e1d2dcde8b1cb30ea07f10598..0000000000000000000000000000000000000000 --- a/tests/integration/TestAjaxHandler.php +++ /dev/null @@ -1,86 +0,0 @@ -<?php - -use \WPDesk\Notice\AjaxHandler; -use \WPDesk\Notice\PermanentDismissibleNotice; - -class TestAjaxHandler extends WP_UnitTestCase -{ - - const ASSETS_URL = 'http://test.com/test/assetes/'; - const NOTICE_NAME = 'test_notice_name'; - const WP_DEFAULT_PRIORITY = 10; - - public function testHooksWithAssetsURL() - { - $ajaxHandler = new AjaxHandler(self::ASSETS_URL); - $ajaxHandler->hooks(); - - $this->assertEquals( - self::WP_DEFAULT_PRIORITY, - has_action('admin_enqueue_scripts', [$ajaxHandler, 'enqueueAdminScripts']) - ); - $this->assertEquals( - self::WP_DEFAULT_PRIORITY, - has_action('wp_ajax_wpdesk_notice_dismiss', [$ajaxHandler, 'processAjaxNoticeDismiss']) - ); - } - - public function testHooksWithoutAssetsURL() - { - $ajaxHandler = new AjaxHandler(); - $ajaxHandler->hooks(); - - $this->assertEquals( - self::WP_DEFAULT_PRIORITY, - has_action('admin_head', [$ajaxHandler, 'addScriptToAdminHead']) - ); - $this->assertEquals( - self::WP_DEFAULT_PRIORITY, - has_action('wp_ajax_wpdesk_notice_dismiss', [$ajaxHandler, 'processAjaxNoticeDismiss']) - ); - } - - public function testEnqueueAdminScripts() - { - $this->markTestSkipped('Must be revisited. get_current_screen not working.'); - $ajaxHandler = new AjaxHandler(self::ASSETS_URL); - $ajaxHandler->hooks(); - do_action('admin_enqueue_scripts'); - $registeredScripts = wp_scripts()->registered; - - $this->assertArrayHasKey('wpdesk_notice', $registeredScripts, 'Script not registered!'); - $this->assertEquals( - self::ASSETS_URL . 'js/notice.js', - $registeredScripts['wpdesk_notice']->src, - 'Script src is invalid!' - ); - } - - public function testAddScriptToAdminHead() - { - $ajaxHandler = new AjaxHandler(); - $ajaxHandler->hooks(); - - $this->expectOutputString('<script type="text/javascript"> -' . file_get_contents( __DIR__ . '/../../assets/js/notice.js' ) . ' -</script> -' - ); - - $ajaxHandler->addScriptToAdminHead(); - } - - public function testProcessAjaxNoticeDismiss() - { - $_POST[AjaxHandler::POST_FIELD_NOTICE_NAME] = self::NOTICE_NAME; - - $ajaxHandler = new AjaxHandler(self::ASSETS_URL); - $ajaxHandler->processAjaxNoticeDismiss(); - - $this->assertEquals( - PermanentDismissibleNotice::OPTION_VALUE_DISMISSED, - get_option(PermanentDismissibleNotice::OPTION_NAME_PREFIX . self::NOTICE_NAME) - ); - } - -}