orig_theme_dir = $GLOBALS['wp_theme_directories']; $GLOBALS['wp_theme_directories'] = array( WP_CONTENT_DIR . '/themes', realpath( __DIR__ . '/data/themedir1' ) ); add_filter( 'theme_root', array( $this, 'filter_set_theme_root' ) ); add_filter( 'stylesheet_root', array( $this, 'filter_set_theme_root' ) ); add_filter( 'template_root', array( $this, 'filter_set_theme_root' ) ); wp_clean_themes_cache(); unset( $GLOBALS['wp_themes'] ); // get_block_editor_settings() reads the registered scripts and styles. wp_scripts(); wp_styles(); } public function tear_down() { remove_editor_styles(); remove_theme_support( 'editor-styles' ); $GLOBALS['wp_theme_directories'] = $this->orig_theme_dir; wp_clean_themes_cache(); unset( $GLOBALS['wp_themes'] ); _gutenberg_clean_theme_json_caches(); parent::tear_down(); } public function filter_set_theme_root() { return realpath( __DIR__ . '/data/themedir1' ); } public function test_post_editor_puts_default_editor_styles_first_for_classic_theme_without_editor_styles() { switch_theme( 'default' ); $settings = get_block_editor_settings( array(), new WP_Block_Editor_Context( array( 'post' => self::factory()->post->create_and_get() ) ) ); $this->assertSame( array( 'css' => $settings['defaultEditorStyles'][0]['css'], '__unstableType' => 'theme', 'isGlobalStyles' => false, ), $settings['styles'][0] ); } public function test_post_editor_skips_default_editor_styles_when_classic_theme_has_editor_styles() { switch_theme( 'default' ); add_theme_support( 'editor-styles' ); add_editor_style( 'style.css' ); $settings = get_block_editor_settings( array(), new WP_Block_Editor_Context( array( 'post' => self::factory()->post->create_and_get() ) ) ); $this->assertNotContains( $settings['defaultEditorStyles'][0]['css'], array_column( $settings['styles'], 'css' ) ); } public function test_post_editor_skips_default_editor_styles_for_block_theme() { switch_theme( 'block-theme' ); $settings = get_block_editor_settings( array(), new WP_Block_Editor_Context( array( 'post' => self::factory()->post->create_and_get() ) ) ); $this->assertNotContains( $settings['defaultEditorStyles'][0]['css'], array_column( $settings['styles'], 'css' ) ); } public function test_widgets_editor_skips_default_editor_styles_for_classic_theme_without_editor_styles() { switch_theme( 'default' ); $settings = get_block_editor_settings( array(), new WP_Block_Editor_Context( array( 'name' => 'core/edit-widgets' ) ) ); $this->assertNotContains( $settings['defaultEditorStyles'][0]['css'], array_column( $settings['styles'], 'css' ) ); } public function test_settings_endpoint_skips_default_editor_styles_for_classic_theme_without_editor_styles() { switch_theme( 'default' ); // The /wp-block-editor/v1/settings endpoint uses the post editor's name without a post. $settings = get_block_editor_settings( array(), new WP_Block_Editor_Context( array( 'name' => 'core/edit-post' ) ) ); $this->assertNotContains( $settings['defaultEditorStyles'][0]['css'], array_column( $settings['styles'], 'css' ) ); } }