diff --git a/phpunit/block-supports/position-test.php b/phpunit/block-supports/position-test.php new file mode 100644 index 00000000000000..67bebc0bed5478 --- /dev/null +++ b/phpunit/block-supports/position-test.php @@ -0,0 +1,172 @@ +test_block_name = null; + $this->theme_root = realpath( __DIR__ . '/../data/themedir1' ); + $this->orig_theme_dir = $GLOBALS['wp_theme_directories']; + + // /themes is necessary as theme.php functions assume /themes is the root if there is only one root. + $GLOBALS['wp_theme_directories'] = array( WP_CONTENT_DIR . '/themes', $this->theme_root ); + + 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' ) ); + // Clear caches. + wp_clean_themes_cache(); + unset( $GLOBALS['wp_themes'] ); + } + + public function tear_down() { + $GLOBALS['wp_theme_directories'] = $this->orig_theme_dir; + wp_clean_themes_cache(); + unset( $GLOBALS['wp_themes'] ); + WP_Style_Engine_CSS_Rules_Store_Gutenberg::remove_all_stores(); + unregister_block_type( $this->test_block_name ); + $this->test_block_name = null; + parent::tear_down(); + } + + public function filter_set_theme_root() { + return $this->theme_root; + } + + /** + * Tests that position block support works as expected. + * + * @covers ::gutenberg_render_position_support + * + * @dataProvider data_position_block_support + * + * @param string $theme_name The theme to switch to. + * @param string $block_name The test block name to register. + * @param mixed $position_settings The position block support settings. + * @param mixed $position_style The position styles within the block attributes. + * @param string $expected_wrapper Expected markup for the block wrapper. + * @param string $expected_styles Expected styles enqueued by the style engine. + */ + public function test_position_block_support( $theme_name, $block_name, $position_settings, $position_style, $expected_wrapper, $expected_styles ) { + switch_theme( $theme_name ); + $this->test_block_name = $block_name; + + register_block_type( + $this->test_block_name, + array( + 'api_version' => 2, + 'attributes' => array( + 'style' => array( + 'type' => 'object', + ), + ), + 'supports' => array( + 'position' => $position_settings, + ), + ) + ); + + $block = array( + 'blockName' => 'test/position-rules-are-output', + 'attrs' => array( + 'style' => array( + 'position' => $position_style, + ), + ), + ); + + $actual = gutenberg_render_position_support( '