Skip to content
Snippets Groups Projects
Commit 2d6108cf authored by Dyszczo's avatar Dyszczo
Browse files

Merge branch 'feature/more-tests' into 'master'

Feature/more tests

See merge request !3
parents 1adcc697 7f333b2e
No related branches found
No related tags found
1 merge request!3Feature/more tests
Pipeline #6940 failed
...@@ -72,8 +72,10 @@ class AjaxHandler implements HookablePluginDependant ...@@ -72,8 +72,10 @@ class AjaxHandler implements HookablePluginDependant
); );
do_action('wpdesk_notice_dismissed_notice', $noticeName); do_action('wpdesk_notice_dismissed_notice', $noticeName);
} }
if (defined('DOING_AJAX') && DOING_AJAX) {
die(); die();
} }
}
} }
<?php <?php
use \WPDesk\Notice\AjaxHandler; use \WPDesk\Notice\AjaxHandler;
use \WPDesk\Notice\PermanentDismissibleNotice;
class TestAjaxHandler extends WP_UnitTestCase class TestAjaxHandler extends WP_UnitTestCase
{ {
const ASSETS_URL = 'http://test.com/test/assetes/'; const ASSETS_URL = 'http://test.com/test/assetes/';
const NOTICE_NAME = 'test_notice_name';
const WP_DEFAULT_PRIORITY = 10; const WP_DEFAULT_PRIORITY = 10;
public function testHooks() public function testHooks()
...@@ -38,4 +40,16 @@ class TestAjaxHandler extends WP_UnitTestCase ...@@ -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)
);
}
} }
...@@ -5,6 +5,8 @@ use \WPDesk\Notice\PermanentDismissibleNotice; ...@@ -5,6 +5,8 @@ use \WPDesk\Notice\PermanentDismissibleNotice;
class TestPermanentDismissinleNotice extends WP_UnitTestCase class TestPermanentDismissinleNotice extends WP_UnitTestCase
{ {
const NOTICE_NAME = 'test_notice_name';
public function testAddAction() public function testAddAction()
{ {
$notice_priority = 11; $notice_priority = 11;
...@@ -19,6 +21,23 @@ class TestPermanentDismissinleNotice extends WP_UnitTestCase ...@@ -19,6 +21,23 @@ class TestPermanentDismissinleNotice extends WP_UnitTestCase
$this->assertEquals($notice_priority, has_action('admin_notices', [$notice, 'showNotice'], $notice_priority)); $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() public function testShowNotice()
{ {
$notice = new PermanentDismissibleNotice( $notice = new PermanentDismissibleNotice(
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment