mirror of
https://github.com/gosticks/wordpress-develop.git
synced 2026-07-01 15:50:09 +00:00
Add Site Editor and PHP changes from Gutenberg 10.1 - 11.9
- First pass at adding the site editor from the Gutenberg plugin to wp-admin/site-editor.php. - Adds miscellaneous PHP changes from Gutenberg 10.1 - 11.9. Follows [52042]. See #54337. Props youknowriad, aristath, hellofromtonya, gziolo. git-svn-id: https://develop.svn.wordpress.org/trunk@52069 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
@@ -307,20 +307,27 @@ function _unhook_block_registration() {
|
||||
remove_action( 'init', 'register_block_core_calendar' );
|
||||
remove_action( 'init', 'register_block_core_categories' );
|
||||
remove_action( 'init', 'register_block_core_file' );
|
||||
remove_action( 'init', 'register_block_core_loginout' );
|
||||
remove_action( 'init', 'register_block_core_latest_comments' );
|
||||
remove_action( 'init', 'register_block_core_latest_posts' );
|
||||
remove_action( 'init', 'register_block_core_legacy_widget' );
|
||||
remove_action( 'init', 'register_block_core_loginout' );
|
||||
remove_action( 'init', 'register_block_core_navigation' );
|
||||
remove_action( 'init', 'register_block_core_navigation_area' );
|
||||
remove_action( 'init', 'register_block_core_navigation_link' );
|
||||
remove_action( 'init', 'register_block_core_navigation_submenu' );
|
||||
remove_action( 'init', 'register_block_core_page_list' );
|
||||
remove_action( 'init', 'register_block_core_pattern' );
|
||||
remove_action( 'init', 'register_block_core_post_author' );
|
||||
remove_action( 'init', 'register_block_core_post_comments' );
|
||||
remove_action( 'init', 'register_block_core_post_content' );
|
||||
remove_action( 'init', 'register_block_core_post_date' );
|
||||
remove_action( 'init', 'register_block_core_post_excerpt' );
|
||||
remove_action( 'init', 'register_block_core_post_featured_image' );
|
||||
remove_action( 'init', 'register_block_core_post_navigation_link' );
|
||||
remove_action( 'init', 'register_block_core_post_template' );
|
||||
remove_action( 'init', 'register_block_core_post_terms' );
|
||||
remove_action( 'init', 'register_block_core_post_title' );
|
||||
remove_action( 'init', 'register_block_core_query' );
|
||||
remove_action( 'init', 'register_block_core_post_template' );
|
||||
remove_action( 'init', 'gutenberg_register_legacy_query_loop_block' );
|
||||
remove_action( 'init', 'register_block_core_query_pagination' );
|
||||
remove_action( 'init', 'register_block_core_query_pagination_next' );
|
||||
remove_action( 'init', 'register_block_core_query_pagination_numbers' );
|
||||
@@ -329,14 +336,14 @@ function _unhook_block_registration() {
|
||||
remove_action( 'init', 'register_block_core_rss' );
|
||||
remove_action( 'init', 'register_block_core_search' );
|
||||
remove_action( 'init', 'register_block_core_shortcode' );
|
||||
remove_action( 'init', 'register_block_core_site_tagline' );
|
||||
remove_action( 'init', 'register_block_core_site_logo' );
|
||||
remove_action( 'init', 'register_block_core_site_tagline' );
|
||||
remove_action( 'init', 'register_block_core_site_title' );
|
||||
remove_action( 'init', 'register_block_core_social_link' );
|
||||
remove_action( 'init', 'register_block_core_social_link' );
|
||||
remove_action( 'init', 'register_block_core_tag_cloud' );
|
||||
remove_action( 'init', 'register_core_block_types_from_metadata' );
|
||||
remove_action( 'init', 'register_block_core_legacy_widget' );
|
||||
remove_action( 'init', 'register_block_core_template_part' );
|
||||
remove_action( 'init', 'register_block_core_term_description' );
|
||||
remove_action( 'init', 'register_core_block_types_from_metadata' );
|
||||
}
|
||||
tests_add_filter( 'init', '_unhook_block_registration', 1000 );
|
||||
|
||||
47
tests/phpunit/tests/block-supports/colors.php
Normal file
47
tests/phpunit/tests/block-supports/colors.php
Normal file
@@ -0,0 +1,47 @@
|
||||
<?php
|
||||
/**
|
||||
* @group block-supports
|
||||
*/
|
||||
class WP_Block_Supports_Colors_Test extends WP_UnitTestCase {
|
||||
|
||||
function test_color_slugs_with_numbers_are_kebab_cased_properly() {
|
||||
register_block_type(
|
||||
'test/color-slug-with-numbers',
|
||||
array(
|
||||
'api_version' => 2,
|
||||
'attributes' => array(
|
||||
'textColor' => array(
|
||||
'type' => 'string',
|
||||
),
|
||||
'backgroundColor' => array(
|
||||
'type' => 'string',
|
||||
),
|
||||
'gradient' => array(
|
||||
'type' => 'string',
|
||||
),
|
||||
),
|
||||
'supports' => array(
|
||||
'color' => array(
|
||||
'text' => true,
|
||||
'background' => true,
|
||||
'gradients' => true,
|
||||
),
|
||||
),
|
||||
)
|
||||
);
|
||||
$registry = WP_Block_Type_Registry::get_instance();
|
||||
$block_type = $registry->get_registered( 'test/color-slug-with-numbers' );
|
||||
|
||||
$block_atts = array(
|
||||
'textColor' => 'fg1',
|
||||
'backgroundColor' => 'bg2',
|
||||
'gradient' => 'gr3',
|
||||
);
|
||||
|
||||
$actual = wp_apply_colors_support( $block_type, $block_atts );
|
||||
$expected = array( 'class' => 'has-text-color has-fg-1-color has-background has-bg-2-background-color has-background has-gr-3-gradient-background' );
|
||||
|
||||
$this->assertSame( $expected, $actual );
|
||||
unregister_block_type( 'test/color-slug-with-numbers' );
|
||||
}
|
||||
}
|
||||
104
tests/phpunit/tests/block-supports/elements.php
Normal file
104
tests/phpunit/tests/block-supports/elements.php
Normal file
@@ -0,0 +1,104 @@
|
||||
<?php
|
||||
/**
|
||||
* @group block-supports
|
||||
*/
|
||||
class WP_Block_Supports_Elements_Test extends WP_UnitTestCase {
|
||||
/**
|
||||
* Given a string containing a class prefixed by "wp-elements-" followed by a unique id,
|
||||
* this function returns a string where the id is one instead of being unique.
|
||||
*
|
||||
* @param string $string String containing unique id classes.
|
||||
* @return string String where the unique id classes were replaced with "wp-elements-1".
|
||||
*/
|
||||
private static function make_unique_id_one( $string ) {
|
||||
return preg_replace( '/wp-elements-.{13}/', 'wp-elements-1', $string );
|
||||
}
|
||||
|
||||
/**
|
||||
* Test wp_render_elements_support() with a simple paragraph and link color preset.
|
||||
*/
|
||||
public function test_simple_paragraph_link_color() {
|
||||
$result = self::make_unique_id_one(
|
||||
wp_render_elements_support(
|
||||
'<p>Hello <a href="http://www.wordpress.org/">WordPress</a>!</p>',
|
||||
array(
|
||||
'blockName' => 'core/paragraph',
|
||||
'attrs' => array(
|
||||
'style' => array(
|
||||
'elements' => array(
|
||||
'link' => array(
|
||||
'color' => array(
|
||||
'text' => 'var:preset|color|subtle-background',
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
)
|
||||
)
|
||||
);
|
||||
$this->assertSame(
|
||||
$result,
|
||||
'<p class="wp-elements-1">Hello <a href="http://www.wordpress.org/">WordPress</a>!</p>'
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test wp_render_elements_support() with a paragraph containing a class.
|
||||
*/
|
||||
public function test_class_paragraph_link_color() {
|
||||
$result = self::make_unique_id_one(
|
||||
wp_render_elements_support(
|
||||
'<p class="has-dark-gray-background-color has-background">Hello <a href="http://www.wordpress.org/">WordPress</a>!</p>',
|
||||
array(
|
||||
'blockName' => 'core/paragraph',
|
||||
'attrs' => array(
|
||||
'style' => array(
|
||||
'elements' => array(
|
||||
'link' => array(
|
||||
'color' => array(
|
||||
'text' => 'red',
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
'backgroundColor' => 'dark-gray',
|
||||
),
|
||||
)
|
||||
)
|
||||
);
|
||||
$this->assertSame(
|
||||
$result,
|
||||
'<p class="wp-elements-1 has-dark-gray-background-color has-background">Hello <a href="http://www.wordpress.org/">WordPress</a>!</p>'
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test wp_render_elements_support() with a paragraph containing a anchor.
|
||||
*/
|
||||
public function test_anchor_paragraph_link_color() {
|
||||
$result = self::make_unique_id_one(
|
||||
wp_render_elements_support(
|
||||
'<p id="anchor">Hello <a href="http://www.wordpress.org/">WordPress</a>!</p>',
|
||||
array(
|
||||
'blockName' => 'core/paragraph',
|
||||
'attrs' => array(
|
||||
'style' => array(
|
||||
'elements' => array(
|
||||
'link' => array(
|
||||
'color' => array(
|
||||
'text' => '#fff000',
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
)
|
||||
)
|
||||
);
|
||||
$this->assertSame(
|
||||
$result,
|
||||
'<p id="anchor" class="wp-elements-1">Hello <a href="http://www.wordpress.org/">WordPress</a>!</p>'
|
||||
);
|
||||
}
|
||||
}
|
||||
138
tests/phpunit/tests/block-supports/spacing.php
Normal file
138
tests/phpunit/tests/block-supports/spacing.php
Normal file
@@ -0,0 +1,138 @@
|
||||
<?php
|
||||
/**
|
||||
* @group block-supports
|
||||
*/
|
||||
class WP_Block_Supports_Spacing_Test extends WP_UnitTestCase {
|
||||
private $sample_block_content = '<div class="wp-block-test-block">Test</div>';
|
||||
private $test_gap_block_value = array();
|
||||
private $test_gap_block_args = array();
|
||||
|
||||
function set_up() {
|
||||
parent::set_up();
|
||||
|
||||
$this->test_gap_block_value = array(
|
||||
'blockName' => 'test/test-block',
|
||||
'attrs' => array(
|
||||
'style' => array(
|
||||
'spacing' => array(
|
||||
'blockGap' => '3em',
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
$this->test_gap_block_args = array(
|
||||
'api_version' => 2,
|
||||
'supports' => array(
|
||||
'spacing' => array(
|
||||
'blockGap' => true,
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
function tear_down() {
|
||||
unregister_block_type( 'test/test-block' );
|
||||
|
||||
parent::tear_down();
|
||||
}
|
||||
|
||||
function test_spacing_gap_block_support_renders_block_inline_style() {
|
||||
register_block_type( 'test/test-block', $this->test_gap_block_args );
|
||||
$render_output = wp_render_spacing_gap_support(
|
||||
$this->sample_block_content,
|
||||
$this->test_gap_block_value
|
||||
);
|
||||
|
||||
$this->assertSame(
|
||||
'<div style="--wp--style--block-gap: 3em" class="wp-block-test-block">Test</div>',
|
||||
$render_output
|
||||
);
|
||||
}
|
||||
|
||||
function test_spacing_gap_block_support_renders_block_inline_style_with_inner_tag() {
|
||||
register_block_type( 'test/test-block', $this->test_gap_block_args );
|
||||
$render_output = wp_render_spacing_gap_support(
|
||||
'<div class="wp-test-block"><p style="color: red;">Test</p></div>',
|
||||
$this->test_gap_block_value
|
||||
);
|
||||
|
||||
$this->assertSame(
|
||||
'<div style="--wp--style--block-gap: 3em" class="wp-test-block"><p style="color: red;">Test</p></div>',
|
||||
$render_output
|
||||
);
|
||||
}
|
||||
|
||||
function test_spacing_gap_block_support_renders_block_inline_style_with_no_other_attributes() {
|
||||
register_block_type( 'test/test-block', $this->test_gap_block_args );
|
||||
$render_output = wp_render_spacing_gap_support(
|
||||
'<div><p>Test</p></div>',
|
||||
$this->test_gap_block_value
|
||||
);
|
||||
|
||||
$this->assertSame(
|
||||
'<div style="--wp--style--block-gap: 3em"><p>Test</p></div>',
|
||||
$render_output
|
||||
);
|
||||
}
|
||||
|
||||
function test_spacing_gap_block_support_renders_appended_block_inline_style() {
|
||||
register_block_type( 'test/test-block', $this->test_gap_block_args );
|
||||
$render_output = wp_render_spacing_gap_support(
|
||||
'<div class="wp-test-block" style="background: green;"><p style="color: red;">Test</p></div>',
|
||||
$this->test_gap_block_value
|
||||
);
|
||||
|
||||
$this->assertSame(
|
||||
'<div class="wp-test-block" style="--wp--style--block-gap: 3em; background: green;"><p style="color: red;">Test</p></div>',
|
||||
$render_output
|
||||
);
|
||||
}
|
||||
|
||||
function test_spacing_gap_block_support_does_not_render_style_when_support_is_false() {
|
||||
$this->test_gap_block_args['supports']['spacing']['blockGap'] = false;
|
||||
|
||||
register_block_type( 'test/test-block', $this->test_gap_block_args );
|
||||
$render_output = wp_render_spacing_gap_support(
|
||||
$this->sample_block_content,
|
||||
$this->test_gap_block_value
|
||||
);
|
||||
|
||||
$this->assertEquals(
|
||||
$this->sample_block_content,
|
||||
$render_output
|
||||
);
|
||||
}
|
||||
|
||||
function test_spacing_gap_block_support_does_not_render_style_when_gap_is_null() {
|
||||
$this->test_gap_block_value['attrs']['style']['spacing']['blockGap'] = null;
|
||||
$this->test_gap_block_args['supports']['spacing']['blockGap'] = true;
|
||||
|
||||
register_block_type( 'test/test-block', $this->test_gap_block_args );
|
||||
$render_output = wp_render_spacing_gap_support(
|
||||
$this->sample_block_content,
|
||||
$this->test_gap_block_value
|
||||
);
|
||||
|
||||
$this->assertEquals(
|
||||
$this->sample_block_content,
|
||||
$render_output
|
||||
);
|
||||
}
|
||||
|
||||
function test_spacing_gap_block_support_does_not_render_style_when_gap_is_illegal_value() {
|
||||
$this->test_gap_block_value['attrs']['style']['spacing']['blockGap'] = '" javascript="alert("hello");';
|
||||
$this->test_gap_block_args['supports']['spacing']['blockGap'] = true;
|
||||
|
||||
register_block_type( 'test/test-block', $this->test_gap_block_args );
|
||||
$render_output = wp_render_spacing_gap_support(
|
||||
$this->sample_block_content,
|
||||
$this->test_gap_block_value
|
||||
);
|
||||
|
||||
$this->assertEquals(
|
||||
$this->sample_block_content,
|
||||
$render_output
|
||||
);
|
||||
}
|
||||
}
|
||||
123
tests/phpunit/tests/block-supports/typography.php
Normal file
123
tests/phpunit/tests/block-supports/typography.php
Normal file
@@ -0,0 +1,123 @@
|
||||
<?php
|
||||
/**
|
||||
* @group block-supports
|
||||
*/
|
||||
class WP_Block_Supports_Typography_Test extends WP_UnitTestCase {
|
||||
|
||||
function test_font_size_slug_with_numbers_is_kebab_cased_properly() {
|
||||
register_block_type(
|
||||
'test/font-size-slug-with-numbers',
|
||||
array(
|
||||
'api_version' => 2,
|
||||
'attributes' => array(
|
||||
'fontSize' => array(
|
||||
'type' => 'string',
|
||||
),
|
||||
),
|
||||
'supports' => array(
|
||||
'typography' => array(
|
||||
'fontSize' => true,
|
||||
),
|
||||
),
|
||||
)
|
||||
);
|
||||
$registry = WP_Block_Type_Registry::get_instance();
|
||||
$block_type = $registry->get_registered( 'test/font-size-slug-with-numbers' );
|
||||
|
||||
$block_atts = array( 'fontSize' => 'h1' );
|
||||
|
||||
$actual = wp_apply_typography_support( $block_type, $block_atts );
|
||||
$expected = array( 'class' => 'has-h-1-font-size' );
|
||||
|
||||
$this->assertSame( $expected, $actual );
|
||||
unregister_block_type( 'test/font-size-slug-with-numbers' );
|
||||
}
|
||||
|
||||
function test_font_family_with_legacy_inline_styles_using_a_value() {
|
||||
$block_name = 'test/font-family-with-inline-styles-using-value';
|
||||
register_block_type(
|
||||
$block_name,
|
||||
array(
|
||||
'api_version' => 2,
|
||||
'attributes' => array(
|
||||
'style' => array(
|
||||
'type' => 'object',
|
||||
),
|
||||
),
|
||||
'supports' => array(
|
||||
'typography' => array(
|
||||
'__experimentalFontFamily' => true,
|
||||
),
|
||||
),
|
||||
)
|
||||
);
|
||||
$registry = WP_Block_Type_Registry::get_instance();
|
||||
$block_type = $registry->get_registered( $block_name );
|
||||
$block_atts = array( 'style' => array( 'typography' => array( 'fontFamily' => 'serif' ) ) );
|
||||
|
||||
$actual = wp_apply_typography_support( $block_type, $block_atts );
|
||||
$expected = array( 'style' => 'font-family: serif;' );
|
||||
|
||||
$this->assertSame( $expected, $actual );
|
||||
unregister_block_type( $block_name );
|
||||
}
|
||||
|
||||
function test_font_family_with_legacy_inline_styles_using_a_css_var() {
|
||||
$block_name = 'test/font-family-with-inline-styles-using-css-var';
|
||||
register_block_type(
|
||||
$block_name,
|
||||
array(
|
||||
'api_version' => 2,
|
||||
'attributes' => array(
|
||||
'style' => array(
|
||||
'type' => 'object',
|
||||
),
|
||||
),
|
||||
'supports' => array(
|
||||
'typography' => array(
|
||||
'__experimentalFontFamily' => true,
|
||||
),
|
||||
),
|
||||
)
|
||||
);
|
||||
$registry = WP_Block_Type_Registry::get_instance();
|
||||
$block_type = $registry->get_registered( $block_name );
|
||||
$block_atts = array( 'style' => array( 'typography' => array( 'fontFamily' => 'var:preset|font-family|h1' ) ) );
|
||||
|
||||
$actual = wp_apply_typography_support( $block_type, $block_atts );
|
||||
$expected = array( 'style' => 'font-family: var(--wp--preset--font-family--h-1);' );
|
||||
|
||||
$this->assertSame( $expected, $actual );
|
||||
unregister_block_type( $block_name );
|
||||
}
|
||||
|
||||
function test_font_family_with_class() {
|
||||
$block_name = 'test/font-family-with-class';
|
||||
register_block_type(
|
||||
$block_name,
|
||||
array(
|
||||
'api_version' => 2,
|
||||
'attributes' => array(
|
||||
'style' => array(
|
||||
'type' => 'object',
|
||||
),
|
||||
),
|
||||
'supports' => array(
|
||||
'typography' => array(
|
||||
'__experimentalFontFamily' => true,
|
||||
),
|
||||
),
|
||||
)
|
||||
);
|
||||
$registry = WP_Block_Type_Registry::get_instance();
|
||||
$block_type = $registry->get_registered( $block_name );
|
||||
$block_atts = array( 'fontFamily' => 'h1' );
|
||||
|
||||
$actual = wp_apply_typography_support( $block_type, $block_atts );
|
||||
$expected = array( 'class' => 'has-h-1-font-family' );
|
||||
|
||||
$this->assertSame( $expected, $actual );
|
||||
unregister_block_type( $block_name );
|
||||
}
|
||||
|
||||
}
|
||||
@@ -75,7 +75,7 @@ class Block_Template_Utils_Test extends WP_UnitTestCase {
|
||||
wp_delete_post( self::$post->ID );
|
||||
}
|
||||
|
||||
public function test_build_template_result_from_post() {
|
||||
public function test_build_block_template_result_from_post() {
|
||||
$template = _build_block_template_result_from_post(
|
||||
self::$post,
|
||||
'wp_template'
|
||||
|
||||
@@ -154,8 +154,15 @@ class WP_Test_REST_Schema_Initialization extends WP_Test_REST_TestCase {
|
||||
'/wp/v2/widget-types',
|
||||
'/wp/v2/widget-types/(?P<id>[a-zA-Z0-9_-]+)',
|
||||
'/wp/v2/widget-types/(?P<id>[a-zA-Z0-9_-]+)/encode',
|
||||
'/wp/v2/widget-types/(?P<id>[a-zA-Z0-9_-]+)/render',
|
||||
'/wp/v2/widgets',
|
||||
'/wp/v2/widgets/(?P<id>[\w\-]+)',
|
||||
'/wp/v2/navigation',
|
||||
'/wp/v2/navigation/(?P<id>[\d]+)',
|
||||
'/wp/v2/navigation/(?P<id>[\d]+)/autosaves',
|
||||
'/wp/v2/navigation/(?P<parent>[\d]+)/autosaves/(?P<id>[\d]+)',
|
||||
'/wp/v2/navigation/(?P<parent>[\d]+)/revisions',
|
||||
'/wp/v2/navigation/(?P<parent>[\d]+)/revisions/(?P<id>[\d]+)',
|
||||
'/wp-site-health/v1',
|
||||
'/wp-site-health/v1/tests/background-updates',
|
||||
'/wp-site-health/v1/tests/loopback-requests',
|
||||
|
||||
@@ -207,6 +207,7 @@ class WP_Test_REST_Users_Controller extends WP_Test_REST_Controller_Testcase {
|
||||
'search',
|
||||
'slug',
|
||||
'who',
|
||||
'has_published_posts',
|
||||
),
|
||||
$keys
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user