<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>[55286] trunk: Editor: `svn add` new files missed in [55285].</title>
</head>
<body>
<style type="text/css"><!--
#msg dl.meta { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dl.meta dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer, #logmsg { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; }
#msg dl a { font-weight: bold}
#msg dl a:link { color:#fc3; }
#msg dl a:active { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { white-space: pre-line; overflow: auto; background: #ffc; border: 1px #fa0 solid; padding: 6px; }
#logmsg { background: #ffc; border: 1px #fa0 solid; padding: 1em 1em 0 1em; }
#logmsg p, #logmsg pre, #logmsg blockquote { margin: 0 0 1em 0; }
#logmsg p, #logmsg li, #logmsg dt, #logmsg dd { line-height: 14pt; }
#logmsg h1, #logmsg h2, #logmsg h3, #logmsg h4, #logmsg h5, #logmsg h6 { margin: .5em 0; }
#logmsg h1:first-child, #logmsg h2:first-child, #logmsg h3:first-child, #logmsg h4:first-child, #logmsg h5:first-child, #logmsg h6:first-child { margin-top: 0; }
#logmsg ul, #logmsg ol { padding: 0; list-style-position: inside; margin: 0 0 0 1em; }
#logmsg ul { text-indent: -1em; padding-left: 1em; }#logmsg ol { text-indent: -1.5em; padding-left: 1.5em; }
#logmsg > ul, #logmsg > ol { margin: 0 0 1em 0; }
#logmsg pre { background: #eee; padding: 1em; }
#logmsg blockquote { border: 1px solid #fa0; border-left-width: 10px; padding: 1em 1em 0 1em; background: white;}
#logmsg dl { margin: 0; }
#logmsg dt { font-weight: bold; }
#logmsg dd { margin: 0; padding: 0 0 0.5em 0; }
#logmsg dd:before { content:'\00bb';}
#logmsg table { border-spacing: 0px; border-collapse: collapse; border-top: 4px solid #fa0; border-bottom: 1px solid #fa0; background: #fff; }
#logmsg table th { text-align: left; font-weight: normal; padding: 0.2em 0.5em; border-top: 1px dotted #fa0; }
#logmsg table td { text-align: right; border-top: 1px dotted #fa0; padding: 0.2em 0.5em; }
#logmsg table thead th { text-align: center; border-bottom: 1px solid #fa0; }
#logmsg table th.Corner { text-align: left; }
#logmsg hr { border: none 0; border-top: 2px dashed #fa0; height: 1px; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<div id="msg">
<dl class="meta" style="font-size: 105%">
<dt style="float: left; width: 6em; font-weight: bold">Revision</dt> <dd><a style="font-weight: bold" href="https://core.trac.wordpress.org/changeset/55286">55286</a><script type="application/ld+json">{"@context":"http://schema.org","@type":"EmailMessage","description":"Review this Commit","action":{"@type":"ViewAction","url":"https://core.trac.wordpress.org/changeset/55286","name":"Review Commit"}}</script></dd>
<dt style="float: left; width: 6em; font-weight: bold">Author</dt> <dd>davidbaumwald</dd>
<dt style="float: left; width: 6em; font-weight: bold">Date</dt> <dd>2023-02-07 18:09:44 +0000 (Tue, 07 Feb 2023)</dd>
</dl>
<pre style='padding-left: 1em; margin: 2em 0; border-left: 2px solid #ccc; line-height: 1.25; font-size: 105%; font-family: sans-serif'>Editor: `svn add` new files missed in <a href="https://core.trac.wordpress.org/changeset/55285">[55285]</a>.
Follow-up to <a href="https://core.trac.wordpress.org/changeset/55285">[55285]</a>.
See <a href="https://core.trac.wordpress.org/ticket/57618">#57618</a>.</pre>
<h3>Added Paths</h3>
<ul>
<li><a href="#trunksrcwpincludesblocksupportspositionphp">trunk/src/wp-includes/block-supports/position.php</a></li>
<li><a href="#trunktestsphpunittestsblocksupportswpRenderPositionSupportphp">trunk/tests/phpunit/tests/block-supports/wpRenderPositionSupport.php</a></li>
</ul>
</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunksrcwpincludesblocksupportspositionphp"></a>
<div class="addfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Added: trunk/src/wp-includes/block-supports/position.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/src/wp-includes/block-supports/position.php (rev 0)
+++ trunk/src/wp-includes/block-supports/position.php 2023-02-07 18:09:44 UTC (rev 55286)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -0,0 +1,151 @@
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+<?php
+/**
+ * Position block support flag.
+ *
+ * @package WordPress
+ * @since 6.2.0
+ */
+
+/**
+ * Registers the style block attribute for block types that support it.
+ *
+ * @since 6.2.0
+ * @access private
+ *
+ * @param WP_Block_Type $block_type Block Type.
+ */
+function wp_register_position_support( $block_type ) {
+ $has_position_support = block_has_support( $block_type, array( 'position' ), false );
+
+ // Set up attributes and styles within that if needed.
+ if ( ! $block_type->attributes ) {
+ $block_type->attributes = array();
+ }
+
+ if ( $has_position_support && ! array_key_exists( 'style', $block_type->attributes ) ) {
+ $block_type->attributes['style'] = array(
+ 'type' => 'object',
+ );
+ }
+}
+
+/**
+ * Renders position styles to the block wrapper.
+ *
+ * @since 6.2.0
+ * @access private
+ *
+ * @param string $block_content Rendered block content.
+ * @param array $block Block object.
+ * @return string Filtered block content.
+ */
+function wp_render_position_support( $block_content, $block ) {
+ $block_type = WP_Block_Type_Registry::get_instance()->get_registered( $block['blockName'] );
+ $has_position_support = block_has_support( $block_type, array( 'position' ), false );
+
+ if (
+ ! $has_position_support ||
+ empty( $block['attrs']['style']['position'] )
+ ) {
+ return $block_content;
+ }
+
+ $global_settings = wp_get_global_settings();
+ $theme_has_sticky_support = _wp_array_get( $global_settings, array( 'position', 'sticky' ), false );
+ $theme_has_fixed_support = _wp_array_get( $global_settings, array( 'position', 'fixed' ), false );
+
+ // Only allow output for position types that the theme supports.
+ $allowed_position_types = array();
+ if ( true === $theme_has_sticky_support ) {
+ $allowed_position_types[] = 'sticky';
+ }
+ if ( true === $theme_has_fixed_support ) {
+ $allowed_position_types[] = 'fixed';
+ }
+
+ $style_attribute = _wp_array_get( $block, array( 'attrs', 'style' ), null );
+ $class_name = wp_unique_id( 'wp-container-' );
+ $selector = ".$class_name";
+ $position_styles = array();
+ $position_type = _wp_array_get( $style_attribute, array( 'position', 'type' ), '' );
+ $wrapper_classes = array();
+
+ if (
+ in_array( $position_type, $allowed_position_types, true )
+ ) {
+ $wrapper_classes[] = $class_name;
+ $wrapper_classes[] = 'is-position-' . $position_type;
+ $sides = array( 'top', 'right', 'bottom', 'left' );
+
+ foreach ( $sides as $side ) {
+ $side_value = _wp_array_get( $style_attribute, array( 'position', $side ) );
+ if ( null !== $side_value ) {
+ /*
+ * For fixed or sticky top positions,
+ * ensure the value includes an offset for the logged in admin bar.
+ */
+ if (
+ 'top' === $side &&
+ ( 'fixed' === $position_type || 'sticky' === $position_type )
+ ) {
+ // Ensure 0 values can be used in `calc()` calculations.
+ if ( '0' === $side_value || 0 === $side_value ) {
+ $side_value = '0px';
+ }
+
+ // Ensure current side value also factors in the height of the logged in admin bar.
+ $side_value = "calc($side_value + var(--wp-admin--admin-bar--position-offset, 0px))";
+ }
+
+ $position_styles[] =
+ array(
+ 'selector' => $selector,
+ 'declarations' => array(
+ $side => $side_value,
+ ),
+ );
+ }
+ }
+
+ $position_styles[] =
+ array(
+ 'selector' => $selector,
+ 'declarations' => array(
+ 'position' => $position_type,
+ 'z-index' => '10',
+ ),
+ );
+ }
+
+ if ( ! empty( $position_styles ) ) {
+ /*
+ * Add to the style engine store to enqueue and render position styles.
+ */
+ wp_style_engine_get_stylesheet_from_css_rules(
+ $position_styles,
+ array(
+ 'context' => 'block-supports',
+ 'prettify' => false,
+ )
+ );
+
+ // Inject class name to block container markup.
+ $content = new WP_HTML_Tag_Processor( $block_content );
+ $content->next_tag();
+ foreach ( $wrapper_classes as $class ) {
+ $content->add_class( $class );
+ }
+ return (string) $content;
+ }
+
+ return $block_content;
+}
+
+// Register the block support.
+WP_Block_Supports::get_instance()->register(
+ 'position',
+ array(
+ 'register_attribute' => 'wp_register_position_support',
+ )
+);
+add_filter( 'render_block', 'wp_render_position_support', 10, 2 );
</ins><span class="cx" style="display: block; padding: 0 10px">Property changes on: trunk/src/wp-includes/block-supports/position.php
</span><span class="cx" style="display: block; padding: 0 10px">___________________________________________________________________
</span></span></pre></div>
<a id="svneolstyle"></a>
<div class="addfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Added: svn:eol-style</h4></div>
<ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+native
</ins><span class="cx" style="display: block; padding: 0 10px">\ No newline at end of property
</span><a id="trunktestsphpunittestsblocksupportswpRenderPositionSupportphp"></a>
<div class="addfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Added: trunk/tests/phpunit/tests/block-supports/wpRenderPositionSupport.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/tests/phpunit/tests/block-supports/wpRenderPositionSupport.php (rev 0)
+++ trunk/tests/phpunit/tests/block-supports/wpRenderPositionSupport.php 2023-02-07 18:09:44 UTC (rev 55286)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -0,0 +1,186 @@
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+<?php
+
+/**
+ * @group block-supports
+ *
+ * @covers ::wp_render_position_support
+ */
+class Tests_Block_Supports_WpRenderPositionSupport extends WP_UnitTestCase {
+ /**
+ * @var string|null
+ */
+ private $test_block_name;
+
+ /**
+ * Theme root directory.
+ *
+ * @var string
+ */
+ private $theme_root;
+
+ /**
+ * Original theme directory.
+ *
+ * @var string
+ */
+ private $orig_theme_dir;
+
+ public function set_up() {
+ parent::set_up();
+ $this->test_block_name = null;
+ $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 );
+
+ 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'] );
+ WP_Style_Engine_CSS_Rules_Store::remove_all_stores();
+ }
+
+ public 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'] );
+ WP_Style_Engine_CSS_Rules_Store::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.
+ *
+ * @ticket 57618
+ *
+ * @covers ::wp_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 = wp_render_position_support( '<div>Content</div>', $block );
+
+ $this->assertMatchesRegularExpression(
+ $expected_wrapper,
+ $actual,
+ 'Position block wrapper markup should be correct'
+ );
+
+ $actual_stylesheet = wp_style_engine_get_stylesheet_from_context(
+ 'block-supports',
+ array(
+ 'prettify' => false,
+ )
+ );
+
+ $this->assertMatchesRegularExpression(
+ $expected_styles,
+ $actual_stylesheet,
+ 'Position style rules output should be correct'
+ );
+ }
+
+ /**
+ * Data provider.
+ *
+ * @return array
+ */
+ public function data_position_block_support() {
+ return array(
+ 'sticky position style is applied' => array(
+ 'theme_name' => 'block-theme-child-with-fluid-typography',
+ 'block_name' => 'test/position-rules-are-output',
+ 'position_settings' => true,
+ 'position_style' => array(
+ 'type' => 'sticky',
+ 'top' => '0px',
+ ),
+ 'expected_wrapper' => '/^<div class="wp-container-\d+ is-position-sticky">Content<\/div>$/',
+ 'expected_styles' => '/^.wp-container-\d+' . preg_quote( '{top:calc(0px + var(--wp-admin--admin-bar--position-offset, 0px));position:sticky;z-index:10;}' ) . '$/',
+ ),
+ 'sticky position style is not applied if theme does not support it' => array(
+ 'theme_name' => 'default',
+ 'block_name' => 'test/position-rules-without-theme-support',
+ 'position_settings' => true,
+ 'position_style' => array(
+ 'type' => 'sticky',
+ 'top' => '0px',
+ ),
+ 'expected_wrapper' => '/^<div>Content<\/div>$/',
+ 'expected_styles' => '/^$/',
+ ),
+ 'sticky position style is not applied if block does not support it' => array(
+ 'theme_name' => 'block-theme-child-with-fluid-typography',
+ 'block_name' => 'test/position-rules-without-block-support',
+ 'position_settings' => false,
+ 'position_style' => array(
+ 'type' => 'sticky',
+ 'top' => '0px',
+ ),
+ 'expected_wrapper' => '/^<div>Content<\/div>$/',
+ 'expected_styles' => '/^$/',
+ ),
+ 'sticky position style is not applied if type is not valid' => array(
+ 'theme_name' => 'block-theme-child-with-fluid-typography',
+ 'block_name' => 'test/position-rules-with-valid-type',
+ 'position_settings' => true,
+ 'position_style' => array(
+ 'type' => 'illegal-type',
+ 'top' => '0px',
+ ),
+ 'expected_wrapper' => '/^<div>Content<\/div>$/',
+ 'expected_styles' => '/^$/',
+ ),
+ );
+ }
+}
</ins><span class="cx" style="display: block; padding: 0 10px">Property changes on: trunk/tests/phpunit/tests/block-supports/wpRenderPositionSupport.php
</span><span class="cx" style="display: block; padding: 0 10px">___________________________________________________________________
</span></span></pre></div>
<a id="svneolstyle"></a>
<div class="addfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Added: svn:eol-style</h4></div>
<ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+native
</ins><span class="cx" style="display: block; padding: 0 10px">\ No newline at end of property
</span></div>
</body>
</html>