mirrored from git://develop.git.wordpress.org/
-
Notifications
You must be signed in to change notification settings - Fork 2.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Migrating layout.php to WordPress 6.0 #2518
Closed
ramonjd
wants to merge
5
commits into
WordPress:trunk
from
ramonjd:migrate/block-supports-layout-wordpress-6.0
Closed
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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,160 @@ | ||
<?php | ||
/** | ||
* Block supports tests for the layout. | ||
* | ||
* @package WordPress | ||
* @subpackage Block Supports | ||
* @since 6.0.0 | ||
*/ | ||
|
||
/** | ||
* Tests for block supports related to layout. | ||
* | ||
* @since 6.0.0 | ||
* | ||
* @group block-supports | ||
ramonjd marked this conversation as resolved.
Show resolved
Hide resolved
|
||
*/ | ||
class Test_Block_Supports_Layout extends WP_UnitTestCase { | ||
function set_up() { | ||
parent::set_up(); | ||
$this->theme_root = realpath( DIR_TESTDATA . '/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 ); | ||
|
||
// Set up the new 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' ) ); | ||
|
||
$this->queries = array(); | ||
// Clear caches. | ||
wp_clean_themes_cache(); | ||
unset( $GLOBALS['wp_themes'] ); | ||
} | ||
|
||
function tear_down() { | ||
$GLOBALS['wp_theme_directories'] = $this->orig_theme_dir; | ||
|
||
// Clear up the filters to modify the theme root. | ||
remove_filter( 'theme_root', array( $this, 'filter_set_theme_root' ) ); | ||
remove_filter( 'stylesheet_root', array( $this, 'filter_set_theme_root' ) ); | ||
remove_filter( 'template_root', array( $this, 'filter_set_theme_root' ) ); | ||
|
||
wp_clean_themes_cache(); | ||
unset( $GLOBALS['wp_themes'] ); | ||
parent::tear_down(); | ||
} | ||
|
||
function filter_set_theme_root() { | ||
return $this->theme_root; | ||
} | ||
|
||
/** | ||
* @ticket 55505 | ||
*/ | ||
function test_outer_container_not_restored_for_non_aligned_image_block_with_non_themejson_theme() { | ||
// The "default" theme doesn't have theme.json support. | ||
switch_theme( 'default' ); | ||
$block = array( | ||
'blockName' => 'core/image', | ||
'attrs' => array(), | ||
); | ||
$block_content = '<figure class="wp-block-image size-full"><img src="/my-image.jpg"/></figure>'; | ||
$expected = '<figure class="wp-block-image size-full"><img src="/my-image.jpg"/></figure>'; | ||
|
||
$this->assertSame( $expected, wp_restore_image_outer_container( $block_content, $block ) ); | ||
} | ||
|
||
/** | ||
* @ticket 55505 | ||
*/ | ||
function test_outer_container_restored_for_aligned_image_block_with_non_themejson_theme() { | ||
// The "default" theme doesn't have theme.json support. | ||
switch_theme( 'default' ); | ||
$block = array( | ||
'blockName' => 'core/image', | ||
'attrs' => array(), | ||
); | ||
$block_content = '<figure class="wp-block-image alignright size-full"><img src="/my-image.jpg"/></figure>'; | ||
$expected = '<div class="wp-block-image"><figure class="alignright size-full"><img src="/my-image.jpg"/></figure></div>'; | ||
|
||
$this->assertSame( $expected, wp_restore_image_outer_container( $block_content, $block ) ); | ||
} | ||
|
||
/** | ||
* @ticket 55505 | ||
* | ||
* @dataProvider data_block_image_html_restored_outer_container | ||
* | ||
* @param string $block_image_html The block image HTML passed to `wp_restore_image_outer_container`. | ||
* @param string $expected The expected block image HTML. | ||
*/ | ||
function test_additional_styles_moved_to_restored_outer_container_for_aligned_image_block_with_non_themejson_theme( $block_image_html, $expected ) { | ||
// The "default" theme doesn't have theme.json support. | ||
switch_theme( 'default' ); | ||
$block = array( | ||
'blockName' => 'core/image', | ||
'attrs' => array( | ||
'className' => 'is-style-round my-custom-classname', | ||
), | ||
); | ||
|
||
$this->assertSame( $expected, wp_restore_image_outer_container( $block_image_html, $block ) ); | ||
} | ||
|
||
/** | ||
* Data provider for test_additional_styles_moved_to_restored_outer_container_for_aligned_image_block_with_non_themejson_theme(). | ||
* | ||
* @return array { | ||
* @type array { | ||
* @type string $block_image_html The block image HTML passed to `wp_restore_image_outer_container`. | ||
* @type string $expected The expected block image HTML. | ||
* } | ||
* } | ||
*/ | ||
public function data_block_image_html_restored_outer_container() { | ||
$expected = '<div class="wp-block-image is-style-round my-custom-classname"><figure class="alignright size-full"><img src="/my-image.jpg"/></figure></div>'; | ||
|
||
return array( | ||
array( | ||
'<figure class="wp-block-image alignright size-full is-style-round my-custom-classname"><img src="/my-image.jpg"/></figure>', | ||
$expected, | ||
), | ||
array( | ||
'<figure class="is-style-round my-custom-classname wp-block-image alignright size-full"><img src="/my-image.jpg"/></figure>', | ||
$expected, | ||
), | ||
array( | ||
'<figure class="wp-block-image is-style-round my-custom-classname alignright size-full"><img src="/my-image.jpg"/></figure>', | ||
$expected, | ||
), | ||
array( | ||
'<figure class="is-style-round wp-block-image alignright my-custom-classname size-full"><img src="/my-image.jpg"/></figure>', | ||
$expected, | ||
), | ||
array( | ||
'<figure style="color: red" class=\'is-style-round wp-block-image alignright my-custom-classname size-full\' data-random-tag=">"><img src="/my-image.jpg"/></figure>', | ||
'<div class="wp-block-image is-style-round my-custom-classname"><figure style="color: red" class=\'alignright size-full\' data-random-tag=">"><img src="/my-image.jpg"/></figure></div>', | ||
), | ||
); | ||
} | ||
|
||
/** | ||
* @ticket 55505 | ||
*/ | ||
function test_outer_container_not_restored_for_aligned_image_block_with_themejson_theme() { | ||
switch_theme( 'block-theme' ); | ||
$block = array( | ||
'blockName' => 'core/image', | ||
'attrs' => array( | ||
'className' => 'is-style-round my-custom-classname', | ||
), | ||
); | ||
$block_content = '<figure class="wp-block-image alignright size-full is-style-round my-custom-classname"><img src="/my-image.jpg"/></figure>'; | ||
$expected = '<figure class="wp-block-image alignright size-full is-style-round my-custom-classname"><img src="/my-image.jpg"/></figure>'; | ||
|
||
$this->assertSame( $expected, wp_restore_image_outer_container( $block_content, $block ) ); | ||
} | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@aaronrobertshaw 👀