-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add tests for
Admin_Settings::admin_enqueue_scripts()
. (#237)
- Loading branch information
Showing
1 changed file
with
101 additions
and
0 deletions.
There are no files selected for viewing
101 changes: 101 additions & 0 deletions
101
tests/phpunit/tests/AdminSettings/AdminSettings_AdminEnqueueScriptsTest.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
<?php | ||
/** | ||
* Class AdminSettings_AdminEnqueueScriptsTest | ||
* | ||
* @package AspireUpdate | ||
*/ | ||
|
||
/** | ||
* Tests for Admin_Settings::admin_enqueue_scripts() | ||
* | ||
* @covers \AspireUpdate\Admin_Settings::admin_enqueue_scripts | ||
*/ | ||
class AdminSettings_AdminEnqueueScriptsTest extends AdminSettings_UnitTestCase { | ||
|
||
/** | ||
* Dequeues assets before each test runs. | ||
* | ||
* @return void | ||
*/ | ||
public function set_up() { | ||
parent::set_up(); | ||
|
||
wp_dequeue_style( 'aspire_update_settings_css' ); | ||
wp_dequeue_script( 'aspire_update_settings_js' ); | ||
} | ||
/** | ||
* Test that the stylesheet is enqueued on the settings screen. | ||
*/ | ||
public function test_should_enqueue_style() { | ||
$admin_settings = new AspireUpdate\Admin_Settings(); | ||
|
||
if ( is_multisite() ) { | ||
$hook = 'index_page_aspireupdate-settings'; | ||
} else { | ||
$hook = 'dashboard_page_aspireupdate-settings'; | ||
} | ||
|
||
$admin_settings->admin_enqueue_scripts( $hook ); | ||
|
||
$this->assertTrue( wp_style_is( 'aspire_update_settings_css' ) ); | ||
} | ||
|
||
/** | ||
* Test that the stylesheet is not enqueued on other screens. | ||
*/ | ||
public function test_should_not_enqueue_style() { | ||
$admin_settings = new AspireUpdate\Admin_Settings(); | ||
|
||
if ( is_multisite() ) { | ||
$hook = 'plugins-network'; | ||
} else { | ||
$hook = 'plugins'; | ||
} | ||
|
||
$admin_settings->admin_enqueue_scripts( $hook ); | ||
|
||
$this->assertFalse( wp_style_is( 'aspire_update_settings_css' ) ); | ||
} | ||
|
||
/** | ||
* Test that the script is enqueued and localized on the settings screen. | ||
*/ | ||
public function test_should_enqueue_and_localize_script() { | ||
$admin_settings = new AspireUpdate\Admin_Settings(); | ||
|
||
if ( is_multisite() ) { | ||
$hook = 'index_page_aspireupdate-settings'; | ||
} else { | ||
$hook = 'dashboard_page_aspireupdate-settings'; | ||
} | ||
|
||
$admin_settings->admin_enqueue_scripts( $hook ); | ||
|
||
$this->assertTrue( | ||
wp_script_is( 'aspire_update_settings_js' ), | ||
'The script is not enqueued.' | ||
); | ||
|
||
$this->assertNotEmpty( | ||
$GLOBALS['wp_scripts']->get_data( 'aspire_update_settings_js', 'data' ), | ||
'The script is not localized.' | ||
); | ||
} | ||
|
||
/** | ||
* Test that the script is not enqueued on other screens. | ||
*/ | ||
public function test_should_not_enqueue_script() { | ||
$admin_settings = new AspireUpdate\Admin_Settings(); | ||
|
||
if ( is_multisite() ) { | ||
$hook = 'plugins-network'; | ||
} else { | ||
$hook = 'plugins'; | ||
} | ||
|
||
$admin_settings->admin_enqueue_scripts( $hook ); | ||
|
||
$this->assertFalse( wp_script_is( 'aspire_update_settings_js' ) ); | ||
} | ||
} |