diff --git a/tests/phpunit/tests/AdminSettings/AdminSettings_AdminEnqueueScriptsTest.php b/tests/phpunit/tests/AdminSettings/AdminSettings_AdminEnqueueScriptsTest.php new file mode 100644 index 0000000..6ea1884 --- /dev/null +++ b/tests/phpunit/tests/AdminSettings/AdminSettings_AdminEnqueueScriptsTest.php @@ -0,0 +1,101 @@ +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' ) ); + } +}