diff --git a/src/WPDesk/Notice/AjaxHandler.php b/src/WPDesk/Notice/AjaxHandler.php index b17cd553337a55027dbfbf09bda84e6ba59672cb..4ffe395134a3c31ffb8de3dc1f6356e483f72263 100644 --- a/src/WPDesk/Notice/AjaxHandler.php +++ b/src/WPDesk/Notice/AjaxHandler.php @@ -72,7 +72,9 @@ class AjaxHandler implements HookablePluginDependant ); do_action('wpdesk_notice_dismissed_notice', $noticeName); } - die(); + if (defined('DOING_AJAX') && DOING_AJAX) { + die(); + } } } diff --git a/tests/integration/TestAjaxHandler.php b/tests/integration/TestAjaxHandler.php index 80c04723906f962b0b8f8bb7cd4b0ceadd2d6951..08f8fa843d5219f38ef1e741e0b74c2d5ea99a1f 100644 --- a/tests/integration/TestAjaxHandler.php +++ b/tests/integration/TestAjaxHandler.php @@ -1,11 +1,13 @@ <?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 testHooks() @@ -38,4 +40,16 @@ class TestAjaxHandler extends WP_UnitTestCase ); } + 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/TestPermanentDismissinleNotice.php b/tests/integration/TestPermanentDismissinleNotice.php index 82fda69a1a1b8c9a6c050e9daa587bdd47997dd2..2a403359a2b0bc2bc7b5a1ae8dc35576a546f699 100644 --- a/tests/integration/TestPermanentDismissinleNotice.php +++ b/tests/integration/TestPermanentDismissinleNotice.php @@ -5,6 +5,8 @@ use \WPDesk\Notice\PermanentDismissibleNotice; class TestPermanentDismissinleNotice extends WP_UnitTestCase { + const NOTICE_NAME = 'test_notice_name'; + public function testAddAction() { $notice_priority = 11; @@ -19,6 +21,23 @@ class TestPermanentDismissinleNotice extends WP_UnitTestCase $this->assertEquals($notice_priority, has_action('admin_notices', [$notice, 'showNotice'], $notice_priority)); } + public function testUndoDismiss() + { + update_option(PermanentDismissibleNotice::OPTION_NAME_PREFIX . self::NOTICE_NAME, PermanentDismissibleNotice::OPTION_VALUE_DISMISSED); + + $notice = new PermanentDismissibleNotice( + PermanentDismissibleNotice::NOTICE_TYPE_INFO, + 'test', + self::NOTICE_NAME + ); + $notice->undoDismiss(); + + $this->assertEquals( + '', + get_option(PermanentDismissibleNotice::OPTION_NAME_PREFIX . self::NOTICE_NAME, '') + ); + } + public function testShowNotice() { $notice = new PermanentDismissibleNotice(