<!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>[53091] trunk: Editor: Allow registration of blocks that include assets from within a theme</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/53091">53091</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/53091","name":"Review Commit"}}</script></dd>
<dt style="float: left; width: 6em; font-weight: bold">Author</dt> <dd>gziolo</dd>
<dt style="float: left; width: 6em; font-weight: bold">Date</dt> <dd>2022-04-07 11:57:16 +0000 (Thu, 07 Apr 2022)</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: Allow registration of blocks that include assets from within a theme
Fixes the issue when you register blocks with `block.json` in your theme. There is no longer an assets's URL error because it resolves correctly in relation to the theme where it is located.
Props fabiankaegy, ocean90, whoisnegrello, audrasjb, peterwilsoncc,
Fixes <a href="https://core.trac.wordpress.org/ticket/54647">#54647</a>, <a href="https://core.trac.wordpress.org/ticket/55513">#55513</a>.</pre>
<h3>Modified Paths</h3>
<ul>
<li><a href="#trunksrcwpincludesblocksphp">trunk/src/wp-includes/blocks.php</a></li>
<li><a href="#trunktestsphpunittestsblocksregisterphp">trunk/tests/phpunit/tests/blocks/register.php</a></li>
</ul>
<h3>Added Paths</h3>
<ul>
<li>trunk/tests/phpunit/data/themedir1/block-theme/blocks/</li>
<li>trunk/tests/phpunit/data/themedir1/block-theme/blocks/example-block/</li>
<li><a href="#trunktestsphpunitdatathemedir1blockthemeblocksexampleblockblockjson">trunk/tests/phpunit/data/themedir1/block-theme/blocks/example-block/block.json</a></li>
<li><a href="#trunktestsphpunitdatathemedir1blockthemeblocksexampleblockeditorstylertlcss">trunk/tests/phpunit/data/themedir1/block-theme/blocks/example-block/editor-style-rtl.css</a></li>
<li><a href="#trunktestsphpunitdatathemedir1blockthemeblocksexampleblockeditorstylecss">trunk/tests/phpunit/data/themedir1/block-theme/blocks/example-block/editor-style.css</a></li>
<li><a href="#trunktestsphpunitdatathemedir1blockthemeblocksexampleblockindexassetphp">trunk/tests/phpunit/data/themedir1/block-theme/blocks/example-block/index.asset.php</a></li>
<li><a href="#trunktestsphpunitdatathemedir1blockthemeblocksexampleblockindexjs">trunk/tests/phpunit/data/themedir1/block-theme/blocks/example-block/index.js</a></li>
<li><a href="#trunktestsphpunitdatathemedir1blockthemeblocksexampleblockstylertlcss">trunk/tests/phpunit/data/themedir1/block-theme/blocks/example-block/style-rtl.css</a></li>
<li><a href="#trunktestsphpunitdatathemedir1blockthemeblocksexampleblockstylecss">trunk/tests/phpunit/data/themedir1/block-theme/blocks/example-block/style.css</a></li>
<li><a href="#trunktestsphpunitdatathemedir1blockthemeblocksexampleblockviewassetphp">trunk/tests/phpunit/data/themedir1/block-theme/blocks/example-block/view.asset.php</a></li>
<li><a href="#trunktestsphpunitdatathemedir1blockthemeblocksexampleblockviewjs">trunk/tests/phpunit/data/themedir1/block-theme/blocks/example-block/view.js</a></li>
<li><a href="#trunktestsphpunitdatathemedir1blockthemefunctionsphp">trunk/tests/phpunit/data/themedir1/block-theme/functions.php</a></li>
</ul>
</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunksrcwpincludesblocksphp"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: trunk/src/wp-includes/blocks.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/src/wp-includes/blocks.php 2022-04-07 11:14:46 UTC (rev 53090)
+++ trunk/src/wp-includes/blocks.php 2022-04-07 11:57:16 UTC (rev 53091)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -108,12 +108,20 @@
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px"> // Path needs to be normalized to work in Windows env.
</span><span class="cx" style="display: block; padding: 0 10px"> $wpinc_path_norm = wp_normalize_path( realpath( ABSPATH . WPINC ) );
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $theme_path_norm = wp_normalize_path( get_theme_file_path() );
</ins><span class="cx" style="display: block; padding: 0 10px"> $script_path_norm = wp_normalize_path( realpath( dirname( $metadata['file'] ) . '/' . $script_path ) );
</span><span class="cx" style="display: block; padding: 0 10px"> $is_core_block = isset( $metadata['file'] ) && 0 === strpos( $metadata['file'], $wpinc_path_norm );
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $is_theme_block = 0 === strpos( $script_path_norm, $theme_path_norm );
</ins><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $script_uri = $is_core_block ?
- includes_url( str_replace( $wpinc_path_norm, '', $script_path_norm ) ) :
- plugins_url( $script_path, $metadata['file'] );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $script_uri;
+ if ( $is_core_block ) {
+ $script_uri = includes_url( str_replace( $wpinc_path_norm, '', $script_path_norm ) );
+ } elseif ( $is_theme_block ) {
+ $script_uri = get_theme_file_uri( str_replace( $theme_path_norm, '', $script_path_norm ) );
+ } else {
+ $script_uri = plugins_url( $script_path, $metadata['file'] );
+ }
+
</ins><span class="cx" style="display: block; padding: 0 10px"> $script_asset = require $script_asset_path;
</span><span class="cx" style="display: block; padding: 0 10px"> $script_dependencies = isset( $script_asset['dependencies'] ) ? $script_asset['dependencies'] : array();
</span><span class="cx" style="display: block; padding: 0 10px"> $result = wp_register_script(
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -150,6 +158,7 @@
</span><span class="cx" style="display: block; padding: 0 10px"> return false;
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px"> $wpinc_path_norm = wp_normalize_path( realpath( ABSPATH . WPINC ) );
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $theme_path_norm = wp_normalize_path( get_theme_file_path() );
</ins><span class="cx" style="display: block; padding: 0 10px"> $is_core_block = isset( $metadata['file'] ) && 0 === strpos( $metadata['file'], $wpinc_path_norm );
</span><span class="cx" style="display: block; padding: 0 10px"> if ( $is_core_block && ! wp_should_load_separate_core_block_assets() ) {
</span><span class="cx" style="display: block; padding: 0 10px"> return false;
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -171,6 +180,13 @@
</span><span class="cx" style="display: block; padding: 0 10px"> $style_uri = includes_url( 'blocks/' . str_replace( 'core/', '', $metadata['name'] ) . "/style$suffix.css" );
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $style_path_norm = wp_normalize_path( realpath( dirname( $metadata['file'] ) . '/' . $style_path ) );
+ $is_theme_block = 0 === strpos( $style_path_norm, $theme_path_norm );
+
+ if ( $is_theme_block ) {
+ $style_uri = get_theme_file_uri( str_replace( $theme_path_norm, '', $style_path_norm ) );
+ }
+
</ins><span class="cx" style="display: block; padding: 0 10px"> $style_handle = generate_block_asset_handle( $metadata['name'], $field_name );
</span><span class="cx" style="display: block; padding: 0 10px"> $block_dir = dirname( $metadata['file'] );
</span><span class="cx" style="display: block; padding: 0 10px"> $style_file = realpath( "$block_dir/$style_path" );
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -1315,10 +1331,20 @@
</span><span class="cx" style="display: block; padding: 0 10px"> foreach ( $metadata[ $key ] as $handle ) {
</span><span class="cx" style="display: block; padding: 0 10px"> $args = array( 'handle' => $handle );
</span><span class="cx" style="display: block; padding: 0 10px"> if ( 0 === strpos( $handle, 'file:' ) && isset( $metadata['file'] ) ) {
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $style_path = remove_block_asset_path_prefix( $handle );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $style_path = remove_block_asset_path_prefix( $handle );
+ $theme_path_norm = wp_normalize_path( get_theme_file_path() );
+ $style_path_norm = wp_normalize_path( realpath( dirname( $metadata['file'] ) . '/' . $style_path ) );
+ $is_theme_block = isset( $metadata['file'] ) && 0 === strpos( $metadata['file'], $theme_path_norm );
+
+ $style_uri = plugins_url( $style_path, $metadata['file'] );
+
+ if ( $is_theme_block ) {
+ $style_uri = get_theme_file_uri( str_replace( $theme_path_norm, '', $style_path_norm ) );
+ }
+
</ins><span class="cx" style="display: block; padding: 0 10px"> $args = array(
</span><span class="cx" style="display: block; padding: 0 10px"> 'handle' => sanitize_key( "{$metadata['name']}-{$style_path}" ),
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- 'src' => plugins_url( $style_path, $metadata['file'] ),
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ 'src' => $style_uri,
</ins><span class="cx" style="display: block; padding: 0 10px"> );
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span></span></pre></div>
<a id="trunktestsphpunitdatathemedir1blockthemeblocksexampleblockblockjson"></a>
<div class="addfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Added: trunk/tests/phpunit/data/themedir1/block-theme/blocks/example-block/block.json</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/tests/phpunit/data/themedir1/block-theme/blocks/example-block/block.json (rev 0)
+++ trunk/tests/phpunit/data/themedir1/block-theme/blocks/example-block/block.json 2022-04-07 11:57:16 UTC (rev 53091)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -0,0 +1,8 @@
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+{
+ "apiVersion": 2,
+ "title": "Example Theme Block",
+ "name": "block-theme/example-block",
+ "description": "Custom block registered from within a theme",
+ "editorScript": "file:./index.js",
+ "style": "file:./style.css"
+}
</ins><span class="cx" style="display: block; padding: 0 10px">Property changes on: trunk/tests/phpunit/data/themedir1/block-theme/blocks/example-block/block.json
</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="trunktestsphpunitdatathemedir1blockthemeblocksexampleblockeditorstylertlcss"></a>
<div class="addfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Added: trunk/tests/phpunit/data/themedir1/block-theme/blocks/example-block/editor-style-rtl.css</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/tests/phpunit/data/themedir1/block-theme/blocks/example-block/editor-style-rtl.css (rev 0)
+++ trunk/tests/phpunit/data/themedir1/block-theme/blocks/example-block/editor-style-rtl.css 2022-04-07 11:57:16 UTC (rev 53091)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -0,0 +1 @@
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+/* Test CSS file - RTL version */
</ins><span class="cx" style="display: block; padding: 0 10px">Property changes on: trunk/tests/phpunit/data/themedir1/block-theme/blocks/example-block/editor-style-rtl.css
</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="trunktestsphpunitdatathemedir1blockthemeblocksexampleblockeditorstylecss"></a>
<div class="addfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Added: trunk/tests/phpunit/data/themedir1/block-theme/blocks/example-block/editor-style.css</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/tests/phpunit/data/themedir1/block-theme/blocks/example-block/editor-style.css (rev 0)
+++ trunk/tests/phpunit/data/themedir1/block-theme/blocks/example-block/editor-style.css 2022-04-07 11:57:16 UTC (rev 53091)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -0,0 +1 @@
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+/* Test CSS file */
</ins><span class="cx" style="display: block; padding: 0 10px">Property changes on: trunk/tests/phpunit/data/themedir1/block-theme/blocks/example-block/editor-style.css
</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="trunktestsphpunitdatathemedir1blockthemeblocksexampleblockindexassetphp"></a>
<div class="addfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Added: trunk/tests/phpunit/data/themedir1/block-theme/blocks/example-block/index.asset.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/tests/phpunit/data/themedir1/block-theme/blocks/example-block/index.asset.php (rev 0)
+++ trunk/tests/phpunit/data/themedir1/block-theme/blocks/example-block/index.asset.php 2022-04-07 11:57:16 UTC (rev 53091)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -0,0 +1,6 @@
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+<?php
+
+return array(
+ 'dependencies' => array( 'wp-element', 'wp-blocks' ),
+ 'version' => 'test',
+);
</ins><span class="cx" style="display: block; padding: 0 10px">Property changes on: trunk/tests/phpunit/data/themedir1/block-theme/blocks/example-block/index.asset.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="trunktestsphpunitdatathemedir1blockthemeblocksexampleblockindexjs"></a>
<div class="addfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Added: trunk/tests/phpunit/data/themedir1/block-theme/blocks/example-block/index.js</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/tests/phpunit/data/themedir1/block-theme/blocks/example-block/index.js (rev 0)
+++ trunk/tests/phpunit/data/themedir1/block-theme/blocks/example-block/index.js 2022-04-07 11:57:16 UTC (rev 53091)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -0,0 +1 @@
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+/* Test JavaScript file. */
</ins><span class="cx" style="display: block; padding: 0 10px">Property changes on: trunk/tests/phpunit/data/themedir1/block-theme/blocks/example-block/index.js
</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="trunktestsphpunitdatathemedir1blockthemeblocksexampleblockstylertlcss"></a>
<div class="addfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Added: trunk/tests/phpunit/data/themedir1/block-theme/blocks/example-block/style-rtl.css</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/tests/phpunit/data/themedir1/block-theme/blocks/example-block/style-rtl.css (rev 0)
+++ trunk/tests/phpunit/data/themedir1/block-theme/blocks/example-block/style-rtl.css 2022-04-07 11:57:16 UTC (rev 53091)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -0,0 +1 @@
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+/* Test CSS file - RTL version */
</ins><span class="cx" style="display: block; padding: 0 10px">Property changes on: trunk/tests/phpunit/data/themedir1/block-theme/blocks/example-block/style-rtl.css
</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="trunktestsphpunitdatathemedir1blockthemeblocksexampleblockstylecss"></a>
<div class="addfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Added: trunk/tests/phpunit/data/themedir1/block-theme/blocks/example-block/style.css</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/tests/phpunit/data/themedir1/block-theme/blocks/example-block/style.css (rev 0)
+++ trunk/tests/phpunit/data/themedir1/block-theme/blocks/example-block/style.css 2022-04-07 11:57:16 UTC (rev 53091)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -0,0 +1 @@
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+/* Test CSS file */
</ins><span class="cx" style="display: block; padding: 0 10px">Property changes on: trunk/tests/phpunit/data/themedir1/block-theme/blocks/example-block/style.css
</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="trunktestsphpunitdatathemedir1blockthemeblocksexampleblockviewassetphp"></a>
<div class="addfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Added: trunk/tests/phpunit/data/themedir1/block-theme/blocks/example-block/view.asset.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/tests/phpunit/data/themedir1/block-theme/blocks/example-block/view.asset.php (rev 0)
+++ trunk/tests/phpunit/data/themedir1/block-theme/blocks/example-block/view.asset.php 2022-04-07 11:57:16 UTC (rev 53091)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -0,0 +1,6 @@
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+<?php
+
+return array(
+ 'dependencies' => array( 'wp-element', 'wp-blocks' ),
+ 'version' => 'test',
+);
</ins><span class="cx" style="display: block; padding: 0 10px">Property changes on: trunk/tests/phpunit/data/themedir1/block-theme/blocks/example-block/view.asset.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="trunktestsphpunitdatathemedir1blockthemeblocksexampleblockviewjs"></a>
<div class="addfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Added: trunk/tests/phpunit/data/themedir1/block-theme/blocks/example-block/view.js</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/tests/phpunit/data/themedir1/block-theme/blocks/example-block/view.js (rev 0)
+++ trunk/tests/phpunit/data/themedir1/block-theme/blocks/example-block/view.js 2022-04-07 11:57:16 UTC (rev 53091)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -0,0 +1 @@
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+/* Test JavaScript file. */
</ins><span class="cx" style="display: block; padding: 0 10px">Property changes on: trunk/tests/phpunit/data/themedir1/block-theme/blocks/example-block/view.js
</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="trunktestsphpunitdatathemedir1blockthemefunctionsphp"></a>
<div class="addfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Added: trunk/tests/phpunit/data/themedir1/block-theme/functions.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/tests/phpunit/data/themedir1/block-theme/functions.php (rev 0)
+++ trunk/tests/phpunit/data/themedir1/block-theme/functions.php 2022-04-07 11:57:16 UTC (rev 53091)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -0,0 +1,7 @@
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+<?php
+
+add_action( 'init', 'register_theme_blocks' );
+
+function register_theme_blocks() {
+ register_block_type( __DIR__ . 'blocks/example-block' );
+}
</ins><span class="cx" style="display: block; padding: 0 10px">Property changes on: trunk/tests/phpunit/data/themedir1/block-theme/functions.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="trunktestsphpunittestsblocksregisterphp"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: trunk/tests/phpunit/tests/blocks/register.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/tests/phpunit/tests/blocks/register.php 2022-04-07 11:14:46 UTC (rev 53090)
+++ trunk/tests/phpunit/tests/blocks/register.php 2022-04-07 11:57:16 UTC (rev 53091)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -253,6 +253,23 @@
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> /**
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * @ticket 55513
+ */
+ public function test_success_register_block_script_handle_in_theme() {
+ switch_theme( 'block-theme' );
+
+ $metadata = array(
+ 'file' => wp_normalize_path( get_theme_file_path( 'blocks/example-block/block.json' ) ),
+ 'name' => 'block-theme/example-block',
+ 'viewScript' => 'file:./view.js',
+ );
+ $result = register_block_script_handle( $metadata, 'viewScript' );
+
+ $expected_script_handle = 'block-theme-example-block-view-script';
+ $this->assertSame( $expected_script_handle, $result );
+ }
+
+ /**
</ins><span class="cx" style="display: block; padding: 0 10px"> * @ticket 50263
</span><span class="cx" style="display: block; padding: 0 10px"> */
</span><span class="cx" style="display: block; padding: 0 10px"> public function test_field_not_found_register_block_style_handle() {
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -306,6 +323,24 @@
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> /**
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * @ticket 55513
+ */
+ public function test_success_register_block_style_handle_in_theme() {
+ switch_theme( 'block-theme' );
+
+ $metadata = array(
+ 'file' => wp_normalize_path( get_theme_file_path( 'blocks/example-block/block.json' ) ),
+ 'name' => 'block-theme/example-block',
+ 'editorStyle' => 'file:./editor-style.css',
+ );
+ $result = register_block_style_handle( $metadata, 'editorStyle' );
+
+ $expected_style_handle = 'block-theme-example-block-editor-style';
+ $this->assertSame( $expected_style_handle, $result );
+ $this->assertSame( 'replace', wp_styles()->get_data( $expected_style_handle, 'rtl' ) );
+ }
+
+ /**
</ins><span class="cx" style="display: block; padding: 0 10px"> * Tests that the function returns false when the `block.json` is not found
</span><span class="cx" style="display: block; padding: 0 10px"> * in the WordPress core.
</span><span class="cx" style="display: block; padding: 0 10px"> *
</span></span></pre>
</div>
</div>
</body>
</html>