From 1bb1fe879f8195a3d995d312cf4d27903364aac2 Mon Sep 17 00:00:00 2001 From: costdev Date: Sat, 30 Nov 2024 10:41:46 +0000 Subject: [PATCH] Add tests for `Themes_Screens::admin_enqueue_scripts()`. --- .../ThemesScreens_AdminEnqueueScriptsTest.php | 88 +++++++++++++++++++ 1 file changed, 88 insertions(+) create mode 100644 tests/phpunit/tests/ThemesScreens/ThemesScreens_AdminEnqueueScriptsTest.php diff --git a/tests/phpunit/tests/ThemesScreens/ThemesScreens_AdminEnqueueScriptsTest.php b/tests/phpunit/tests/ThemesScreens/ThemesScreens_AdminEnqueueScriptsTest.php new file mode 100644 index 0000000..eb79dcd --- /dev/null +++ b/tests/phpunit/tests/ThemesScreens/ThemesScreens_AdminEnqueueScriptsTest.php @@ -0,0 +1,88 @@ +admin_enqueue_scripts( 'theme-install.php' ); + $this->assertTrue( wp_style_is( 'aspire_update_themes_screens_css' ) ); + } + + /** + * Test that the stylesheet is not enqueued on adjacent screens. + * + * @dataProvider data_adjacent_screens + * + * @param string $hook The current screen's hook. + */ + public function test_should_not_enqueue_style_on_adjacent_screens( $hook ) { + if ( is_multisite() ) { + $hook .= '-network'; + } + + $themes_screens = new AspireUpdate\Themes_Screens(); + $themes_screens->admin_enqueue_scripts( $hook ); + $this->assertFalse( wp_style_is( 'aspire_update_themes_screens_css' ) ); + } + + /** + * Data provider. + * + * @return array[] + */ + public function data_adjacent_screens() { + return self::text_array_to_dataprovider( + [ + 'themes', + 'nav-menus', + 'theme-editor', + ] + ); + } + + /** + * Test that the stylesheet is not enqueued when there is no screen. + */ + public function test_should_not_enqueue_style_when_there_is_no_screen() { + $themes_screens = new AspireUpdate\Themes_Screens(); + $themes_screens->admin_enqueue_scripts( '' ); + $this->assertFalse( wp_style_is( 'aspire_update_themes_screens_css' ) ); + } + + /** + * Test that the stylesheet is not enqueued when AP_REMOVE_UI is set to true. + * + * @runInSeparateProcess + * @preserveGlobalState disabled + */ + public function test_should_not_enqueue_style_when_ap_remove_ui_is_true() { + // Prevent the notice from being displayed. + define( 'AP_REMOVE_UI', true ); + + $hook = is_multisite() ? 'theme-install-network' : 'theme-install'; + $themes_screens = new AspireUpdate\Themes_Screens(); + $themes_screens->admin_enqueue_scripts( $hook ); + $this->assertFalse( wp_style_is( 'aspire_update_themes_screens_css' ) ); + } +}