Skip to content
Snippets Groups Projects
Commit 5375cbbc authored by Grzegorz Rola's avatar Grzegorz Rola
Browse files

Tests

parent e9157027
No related branches found
No related tags found
1 merge request!1Tests
Pipeline #6491 passed with warnings
......@@ -3,7 +3,7 @@
>
<testsuites>
<testsuite>
<directory prefix="test-" suffix=".php">./tests/integration</directory>
<directory prefix="Test" suffix=".php">./tests/integration</directory>
</testsuite>
</testsuites>
......
<?php
use \WPDesk\Notice\AjaxHandler;
class TestAjaxHandler extends WP_UnitTestCase
{
const ASSETS_URL = 'http://test.com/test/assetes/';
const WP_DEFAULT_PRIORITY = 10;
public function testHooks()
{
$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 testEnqueueAdminScripts()
{
$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!'
);
}
}
<?php
use \WPDesk\Notice\Notice;
class TestNotice extends WP_UnitTestCase
{
public function testAddAction()
{
$notice_priority = 11;
$notice = new Notice(Notice::NOTICE_TYPE_INFO, 'test', false, $notice_priority);
$this->assertEquals($notice_priority, has_action('admin_notices', [$notice, 'showNotice'], $notice_priority));
}
public function testShowNotice()
{
$notice = new Notice(Notice::NOTICE_TYPE_INFO, 'test');
$this->expectOutputString('<div class="notice notice-info"><p>test</p></div>');
$notice->showNotice();
}
public function testShowNoticeDismissible()
{
$notice = new Notice(Notice::NOTICE_TYPE_INFO, 'test', true);
$this->expectOutputString('<div class="notice notice-info is-dismissible"><p>test</p></div>');
$notice->showNotice();
}
}
<?php
use \WPDesk\Notice\PermanentDismissibleNotice;
class TestPermanentDismissinleNotice extends WP_UnitTestCase
{
public function testAddAction()
{
$notice_priority = 11;
$notice = new PermanentDismissibleNotice(
PermanentDismissibleNotice::NOTICE_TYPE_INFO,
'test',
'test_name',
$notice_priority
);
$this->assertEquals($notice_priority, has_action('admin_notices', [$notice, 'showNotice'], $notice_priority));
}
public function testShowNotice()
{
$notice = new PermanentDismissibleNotice(
PermanentDismissibleNotice::NOTICE_TYPE_INFO,
'test',
'test_name'
);
$this->expectOutputString(
'<div class="notice notice-info is-dismissible"data-notice-name="test_name"><p>test</p></div>'
);
$notice->showNotice();
}
}
......@@ -9,6 +9,8 @@ if ( function_exists( 'xdebug_disable' ) ) {
xdebug_disable();
}
require_once __DIR__ . '/../../vendor/autoload.php';
if ( getenv( 'PLUGIN_PATH' ) !== false ) {
define( 'PLUGIN_PATH', getenv( 'PLUGIN_PATH' ) );
} else {
......@@ -22,6 +24,8 @@ tests_add_filter( 'muplugins_loaded', function () {
update_option( 'active_plugins', $plugins_to_active );
}, 100 );
//new \WPDesk\Notice\AjaxHandler( 'http://test.com/test/vendor/' );
putenv('WP_TESTS_DIR=' . getenv( 'WP_DEVELOP_DIR' ) . '/tests/phpunit');
require_once( getenv( 'WC_DEVELOP_DIR' ) . '/tests/bootstrap.php' );
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment