<!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>[58321] trunk: Interactivity API: Print debug warning when server directives processing encounters errors</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/58321">58321</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/58321","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>2024-06-04 07:16:48 +0000 (Tue, 04 Jun 2024)</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'>Interactivity API: Print debug warning when server directives processing encounters errors
Aims to improve the developer experience of the Interactivity API server directives processing.
Props cbravobernal, jonsurrell, westonruter, darerodz, czapla, gziolo.
Fixes <a href="https://core.trac.wordpress.org/ticket/61044">#61044</a>.</pre>
<h3>Modified Paths</h3>
<ul>
<li><a href="#trunksrcwpincludesinteractivityapiclasswpinteractivityapidirectivesprocessorphp">trunk/src/wp-includes/interactivity-api/class-wp-interactivity-api-directives-processor.php</a></li>
<li><a href="#trunksrcwpincludesinteractivityapiclasswpinteractivityapiphp">trunk/src/wp-includes/interactivity-api/class-wp-interactivity-api.php</a></li>
<li><a href="#trunktestsphpunittestsinteractivityapiwpInteractivityAPIwpbindphp">trunk/tests/phpunit/tests/interactivity-api/wpInteractivityAPI-wp-bind.php</a></li>
<li><a href="#trunktestsphpunittestsinteractivityapiwpInteractivityAPIwpclassphp">trunk/tests/phpunit/tests/interactivity-api/wpInteractivityAPI-wp-class.php</a></li>
<li><a href="#trunktestsphpunittestsinteractivityapiwpInteractivityAPIwpcontextphp">trunk/tests/phpunit/tests/interactivity-api/wpInteractivityAPI-wp-context.php</a></li>
<li><a href="#trunktestsphpunittestsinteractivityapiwpInteractivityAPIwpeachphp">trunk/tests/phpunit/tests/interactivity-api/wpInteractivityAPI-wp-each.php</a></li>
<li><a href="#trunktestsphpunittestsinteractivityapiwpInteractivityAPIwpstylephp">trunk/tests/phpunit/tests/interactivity-api/wpInteractivityAPI-wp-style.php</a></li>
<li><a href="#trunktestsphpunittestsinteractivityapiwpInteractivityAPIwptextphp">trunk/tests/phpunit/tests/interactivity-api/wpInteractivityAPI-wp-text.php</a></li>
<li><a href="#trunktestsphpunittestsinteractivityapiwpInteractivityAPIphp">trunk/tests/phpunit/tests/interactivity-api/wpInteractivityAPI.php</a></li>
</ul>
</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunksrcwpincludesinteractivityapiclasswpinteractivityapidirectivesprocessorphp"></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/interactivity-api/class-wp-interactivity-api-directives-processor.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/src/wp-includes/interactivity-api/class-wp-interactivity-api-directives-processor.php 2024-06-04 06:56:25 UTC (rev 58320)
+++ trunk/src/wp-includes/interactivity-api/class-wp-interactivity-api-directives-processor.php 2024-06-04 07:16:48 UTC (rev 58321)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -198,16 +198,19 @@
</span><span class="cx" style="display: block; padding: 0 10px"> public function skip_to_tag_closer(): bool {
</span><span class="cx" style="display: block; padding: 0 10px"> $depth = 1;
</span><span class="cx" style="display: block; padding: 0 10px"> $tag_name = $this->get_tag();
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- while ( $depth > 0 && $this->next_tag(
- array(
- 'tag_name' => $tag_name,
- 'tag_closers' => 'visit',
- )
- ) ) {
- if ( $this->has_self_closing_flag() ) {
- continue;
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+
+ while ( $depth > 0 && $this->next_tag( array( 'tag_closers' => 'visit' ) ) ) {
+ if ( ! $this->is_tag_closer() && $this->get_attribute_names_with_prefix( 'data-wp-' ) ) {
+ /* translators: 1: SVG or MATH HTML tag. */
+ $message = sprintf( __( 'Interactivity directives were detected inside an incompatible %1$s tag. These directives will be ignored in the server side render.' ), $tag_name );
+ _doing_it_wrong( __METHOD__, $message, '6.6.0' );
</ins><span class="cx" style="display: block; padding: 0 10px"> }
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $depth += $this->is_tag_closer() ? -1 : 1;
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ if ( $this->get_tag() === $tag_name ) {
+ if ( $this->has_self_closing_flag() ) {
+ continue;
+ }
+ $depth += $this->is_tag_closer() ? -1 : 1;
+ }
</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"> return 0 === $depth;
</span></span></pre></div>
<a id="trunksrcwpincludesinteractivityapiclasswpinteractivityapiphp"></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/interactivity-api/class-wp-interactivity-api.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/src/wp-includes/interactivity-api/class-wp-interactivity-api.php 2024-06-04 06:56:25 UTC (rev 58320)
+++ trunk/src/wp-includes/interactivity-api/class-wp-interactivity-api.php 2024-06-04 07:16:48 UTC (rev 58321)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -272,6 +272,7 @@
</span><span class="cx" style="display: block; padding: 0 10px"> * it returns null if the HTML contains unbalanced tags.
</span><span class="cx" style="display: block; padding: 0 10px"> *
</span><span class="cx" style="display: block; padding: 0 10px"> * @since 6.5.0
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * @since 6.6.0 The function displays a warning message when the HTML contains unbalanced tags or a directive appears in a MATH or SVG tag.
</ins><span class="cx" style="display: block; padding: 0 10px"> *
</span><span class="cx" style="display: block; padding: 0 10px"> * @param string $html The HTML content to process.
</span><span class="cx" style="display: block; padding: 0 10px"> * @param array $context_stack The reference to the array used to keep track of contexts during processing.
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -295,6 +296,11 @@
</span><span class="cx" style="display: block; padding: 0 10px"> * We still process the rest of the HTML.
</span><span class="cx" style="display: block; padding: 0 10px"> */
</span><span class="cx" style="display: block; padding: 0 10px"> if ( 'SVG' === $tag_name || 'MATH' === $tag_name ) {
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ if ( $p->get_attribute_names_with_prefix( 'data-wp-' ) ) {
+ /* translators: 1: SVG or MATH HTML tag, 2: Namespace of the interactive block. */
+ $message = sprintf( __( 'Interactivity directives were detected on an incompatible %1$s tag when processing "%2$s". These directives will be ignored in the server side render.' ), $tag_name, end( $namespace_stack ) );
+ _doing_it_wrong( __METHOD__, $message, '6.6.0' );
+ }
</ins><span class="cx" style="display: block; padding: 0 10px"> $p->skip_to_tag_closer();
</span><span class="cx" style="display: block; padding: 0 10px"> continue;
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -382,13 +388,21 @@
</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><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-
</del><span class="cx" style="display: block; padding: 0 10px"> /*
</span><span class="cx" style="display: block; padding: 0 10px"> * It returns null if the HTML is unbalanced because unbalanced HTML is
</span><span class="cx" style="display: block; padding: 0 10px"> * not safe to process. In that case, the Interactivity API runtime will
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- * update the HTML on the client side during the hydration.
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * update the HTML on the client side during the hydration. It will also
+ * display a notice to the developer to inform them about the issue.
</ins><span class="cx" style="display: block; padding: 0 10px"> */
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- return $unbalanced || 0 < count( $tag_stack ) ? null : $p->get_updated_html();
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ if ( $unbalanced || 0 < count( $tag_stack ) ) {
+ $tag_errored = 0 < count( $tag_stack ) ? end( $tag_stack )[0] : $tag_name;
+ /* translators: %1s: Namespace processed, %2s: The tag that caused the error; could be any HTML tag. */
+ $message = sprintf( __( 'Interactivity directives failed to process in "%1$s" due to a missing "%2$s" end tag.' ), end( $namespace_stack ), $tag_errored );
+ _doing_it_wrong( __METHOD__, $message, '6.6.0' );
+ return null;
+ }
+
+ return $p->get_updated_html();
</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 class="lines" style="display: block; padding: 0 10px; color: #888">@@ -396,6 +410,7 @@
</span><span class="cx" style="display: block; padding: 0 10px"> * store namespace, state and context.
</span><span class="cx" style="display: block; padding: 0 10px"> *
</span><span class="cx" style="display: block; padding: 0 10px"> * @since 6.5.0
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * @since 6.6.0 The function now adds a warning when the namespace is null, falsy, or the directive value is empty.
</ins><span class="cx" style="display: block; padding: 0 10px"> *
</span><span class="cx" style="display: block; padding: 0 10px"> * @param string|true $directive_value The directive attribute value string or `true` when it's a boolean attribute.
</span><span class="cx" style="display: block; padding: 0 10px"> * @param string $default_namespace The default namespace to use if none is explicitly defined in the directive
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -402,11 +417,14 @@
</span><span class="cx" style="display: block; padding: 0 10px"> * value.
</span><span class="cx" style="display: block; padding: 0 10px"> * @param array|false $context The current context for evaluating the directive or false if there is no
</span><span class="cx" style="display: block; padding: 0 10px"> * context.
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- * @return mixed|null The result of the evaluation. Null if the reference path doesn't exist.
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * @return mixed|null The result of the evaluation. Null if the reference path doesn't exist or the namespace is falsy.
</ins><span class="cx" style="display: block; padding: 0 10px"> */
</span><span class="cx" style="display: block; padding: 0 10px"> private function evaluate( $directive_value, string $default_namespace, $context = false ) {
</span><span class="cx" style="display: block; padding: 0 10px"> list( $ns, $path ) = $this->extract_directive_value( $directive_value, $default_namespace );
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- if ( empty( $path ) ) {
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ if ( ! $ns || ! $path ) {
+ /* translators: %s: The directive value referenced. */
+ $message = sprintf( __( 'Namespace or reference path cannot be empty. Directive value referenced: %s' ), $directive_value );
+ _doing_it_wrong( __METHOD__, $message, '6.6.0' );
</ins><span class="cx" style="display: block; padding: 0 10px"> return null;
</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="trunktestsphpunittestsinteractivityapiwpInteractivityAPIwpbindphp"></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/interactivity-api/wpInteractivityAPI-wp-bind.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/tests/phpunit/tests/interactivity-api/wpInteractivityAPI-wp-bind.php 2024-06-04 06:56:25 UTC (rev 58320)
+++ trunk/tests/phpunit/tests/interactivity-api/wpInteractivityAPI-wp-bind.php 2024-06-04 07:16:48 UTC (rev 58321)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -154,6 +154,7 @@
</span><span class="cx" style="display: block; padding: 0 10px"> * @ticket 60356
</span><span class="cx" style="display: block; padding: 0 10px"> *
</span><span class="cx" style="display: block; padding: 0 10px"> * @covers ::process_directives
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * @expectedIncorrectUsage WP_Interactivity_API::evaluate
</ins><span class="cx" style="display: block; padding: 0 10px"> */
</span><span class="cx" style="display: block; padding: 0 10px"> public function test_wp_bind_ignores_empty_value() {
</span><span class="cx" style="display: block; padding: 0 10px"> $html = '<div data-wp-bind--id="">Text</div>';
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -167,6 +168,7 @@
</span><span class="cx" style="display: block; padding: 0 10px"> * @ticket 60356
</span><span class="cx" style="display: block; padding: 0 10px"> *
</span><span class="cx" style="display: block; padding: 0 10px"> * @covers ::process_directives
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * @expectedIncorrectUsage WP_Interactivity_API::evaluate
</ins><span class="cx" style="display: block; padding: 0 10px"> */
</span><span class="cx" style="display: block; padding: 0 10px"> public function test_wp_bind_ignores_without_value() {
</span><span class="cx" style="display: block; padding: 0 10px"> $html = '<div data-wp-bind--id>Text</div>';
</span></span></pre></div>
<a id="trunktestsphpunittestsinteractivityapiwpInteractivityAPIwpclassphp"></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/interactivity-api/wpInteractivityAPI-wp-class.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/tests/phpunit/tests/interactivity-api/wpInteractivityAPI-wp-class.php 2024-06-04 06:56:25 UTC (rev 58320)
+++ trunk/tests/phpunit/tests/interactivity-api/wpInteractivityAPI-wp-class.php 2024-06-04 07:16:48 UTC (rev 58321)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -237,6 +237,7 @@
</span><span class="cx" style="display: block; padding: 0 10px"> * @ticket 60356
</span><span class="cx" style="display: block; padding: 0 10px"> *
</span><span class="cx" style="display: block; padding: 0 10px"> * @covers ::process_directives
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * @expectedIncorrectUsage WP_Interactivity_API::evaluate
</ins><span class="cx" style="display: block; padding: 0 10px"> */
</span><span class="cx" style="display: block; padding: 0 10px"> public function test_wp_class_doesnt_change_class_attribute_with_empty_value() {
</span><span class="cx" style="display: block; padding: 0 10px"> $html = '<div class="other-class" data-wp-class--some-class="">Text</div>';
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -251,6 +252,7 @@
</span><span class="cx" style="display: block; padding: 0 10px"> * @ticket 60356
</span><span class="cx" style="display: block; padding: 0 10px"> *
</span><span class="cx" style="display: block; padding: 0 10px"> * @covers ::process_directives
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * @expectedIncorrectUsage WP_Interactivity_API::evaluate
</ins><span class="cx" style="display: block; padding: 0 10px"> */
</span><span class="cx" style="display: block; padding: 0 10px"> public function test_wp_class_doesnt_change_class_attribute_without_value() {
</span><span class="cx" style="display: block; padding: 0 10px"> $html = '<div class="other-class" data-wp-class--some-class>Text</div>';
</span></span></pre></div>
<a id="trunktestsphpunittestsinteractivityapiwpInteractivityAPIwpcontextphp"></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/interactivity-api/wpInteractivityAPI-wp-context.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/tests/phpunit/tests/interactivity-api/wpInteractivityAPI-wp-context.php 2024-06-04 06:56:25 UTC (rev 58320)
+++ trunk/tests/phpunit/tests/interactivity-api/wpInteractivityAPI-wp-context.php 2024-06-04 07:16:48 UTC (rev 58321)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -317,6 +317,7 @@
</span><span class="cx" style="display: block; padding: 0 10px"> * @ticket 60356
</span><span class="cx" style="display: block; padding: 0 10px"> *
</span><span class="cx" style="display: block; padding: 0 10px"> * @covers ::process_directives
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * @expectedIncorrectUsage WP_Interactivity_API::evaluate
</ins><span class="cx" style="display: block; padding: 0 10px"> */
</span><span class="cx" style="display: block; padding: 0 10px"> public function test_wp_context_directive_doesnt_work_without_any_namespace() {
</span><span class="cx" style="display: block; padding: 0 10px"> $html = '
</span></span></pre></div>
<a id="trunktestsphpunittestsinteractivityapiwpInteractivityAPIwpeachphp"></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/interactivity-api/wpInteractivityAPI-wp-each.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/tests/phpunit/tests/interactivity-api/wpInteractivityAPI-wp-each.php 2024-06-04 06:56:25 UTC (rev 58320)
+++ trunk/tests/phpunit/tests/interactivity-api/wpInteractivityAPI-wp-each.php 2024-06-04 07:16:48 UTC (rev 58321)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -580,6 +580,8 @@
</span><span class="cx" style="display: block; padding: 0 10px"> * @ticket 60356
</span><span class="cx" style="display: block; padding: 0 10px"> *
</span><span class="cx" style="display: block; padding: 0 10px"> * @covers ::process_directives
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ *
+ * @expectedIncorrectUsage WP_Interactivity_API::process_directives_args
</ins><span class="cx" style="display: block; padding: 0 10px"> */
</span><span class="cx" style="display: block; padding: 0 10px"> public function test_wp_each_unbalanced_tags() {
</span><span class="cx" style="display: block; padding: 0 10px"> $original = '' .
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -598,6 +600,8 @@
</span><span class="cx" style="display: block; padding: 0 10px"> * @ticket 60356
</span><span class="cx" style="display: block; padding: 0 10px"> *
</span><span class="cx" style="display: block; padding: 0 10px"> * @covers ::process_directives
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ *
+ * @expectedIncorrectUsage WP_Interactivity_API::process_directives_args
</ins><span class="cx" style="display: block; padding: 0 10px"> */
</span><span class="cx" style="display: block; padding: 0 10px"> public function test_wp_each_unbalanced_tags_in_nested_template_tags() {
</span><span class="cx" style="display: block; padding: 0 10px"> $this->interactivity->state( 'myPlugin', array( 'list2' => array( 3, 4 ) ) );
</span></span></pre></div>
<a id="trunktestsphpunittestsinteractivityapiwpInteractivityAPIwpstylephp"></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/interactivity-api/wpInteractivityAPI-wp-style.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/tests/phpunit/tests/interactivity-api/wpInteractivityAPI-wp-style.php 2024-06-04 06:56:25 UTC (rev 58320)
+++ trunk/tests/phpunit/tests/interactivity-api/wpInteractivityAPI-wp-style.php 2024-06-04 07:16:48 UTC (rev 58321)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -365,6 +365,7 @@
</span><span class="cx" style="display: block; padding: 0 10px"> * @ticket 60356
</span><span class="cx" style="display: block; padding: 0 10px"> *
</span><span class="cx" style="display: block; padding: 0 10px"> * @covers ::process_directives
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * @expectedIncorrectUsage WP_Interactivity_API::evaluate
</ins><span class="cx" style="display: block; padding: 0 10px"> */
</span><span class="cx" style="display: block; padding: 0 10px"> public function test_wp_style_doesnt_change_style_attribute_with_empty_value() {
</span><span class="cx" style="display: block; padding: 0 10px"> $html = '<div style="padding:10px" data-wp-style--color="">Text</div>';
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -379,6 +380,7 @@
</span><span class="cx" style="display: block; padding: 0 10px"> * @ticket 60356
</span><span class="cx" style="display: block; padding: 0 10px"> *
</span><span class="cx" style="display: block; padding: 0 10px"> * @covers ::process_directives
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * @expectedIncorrectUsage WP_Interactivity_API::evaluate
</ins><span class="cx" style="display: block; padding: 0 10px"> */
</span><span class="cx" style="display: block; padding: 0 10px"> public function test_wp_style_doesnt_change_style_attribute_without_value() {
</span><span class="cx" style="display: block; padding: 0 10px"> $html = '<div style="padding: 10px;" data-wp-style--color>Text</div>';
</span></span></pre></div>
<a id="trunktestsphpunittestsinteractivityapiwpInteractivityAPIwptextphp"></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/interactivity-api/wpInteractivityAPI-wp-text.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/tests/phpunit/tests/interactivity-api/wpInteractivityAPI-wp-text.php 2024-06-04 06:56:25 UTC (rev 58320)
+++ trunk/tests/phpunit/tests/interactivity-api/wpInteractivityAPI-wp-text.php 2024-06-04 07:16:48 UTC (rev 58321)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -12,7 +12,7 @@
</span><span class="cx" style="display: block; padding: 0 10px"> *
</span><span class="cx" style="display: block; padding: 0 10px"> * @group interactivity-api
</span><span class="cx" style="display: block; padding: 0 10px"> */
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-class Tests_WP_Interactivity_API_WP_Text extends WP_UnitTestCase {
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+class Tests_Interactivity_API_WpInteractivityAPIWPText extends WP_UnitTestCase {
</ins><span class="cx" style="display: block; padding: 0 10px"> /**
</span><span class="cx" style="display: block; padding: 0 10px"> * Instance of WP_Interactivity_API.
</span><span class="cx" style="display: block; padding: 0 10px"> *
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -131,6 +131,8 @@
</span><span class="cx" style="display: block; padding: 0 10px"> * @ticket 60356
</span><span class="cx" style="display: block; padding: 0 10px"> *
</span><span class="cx" style="display: block; padding: 0 10px"> * @covers ::process_directives
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ *
+ * @expectedIncorrectUsage WP_Interactivity_API::process_directives_args
</ins><span class="cx" style="display: block; padding: 0 10px"> */
</span><span class="cx" style="display: block; padding: 0 10px"> public function test_wp_text_fails_with_unbalanced_and_same_tags_inside_content() {
</span><span class="cx" style="display: block; padding: 0 10px"> $html = '<div data-wp-text="myPlugin::state.text">Text<div></div>';
</span></span></pre></div>
<a id="trunktestsphpunittestsinteractivityapiwpInteractivityAPIphp"></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/interactivity-api/wpInteractivityAPI.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/tests/phpunit/tests/interactivity-api/wpInteractivityAPI.php 2024-06-04 06:56:25 UTC (rev 58320)
+++ trunk/tests/phpunit/tests/interactivity-api/wpInteractivityAPI.php 2024-06-04 07:16:48 UTC (rev 58321)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -649,6 +649,8 @@
</span><span class="cx" style="display: block; padding: 0 10px"> *
</span><span class="cx" style="display: block; padding: 0 10px"> * @dataProvider data_html_with_unbalanced_tags
</span><span class="cx" style="display: block; padding: 0 10px"> *
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * @expectedIncorrectUsage WP_Interactivity_API::process_directives_args
+ *
</ins><span class="cx" style="display: block; padding: 0 10px"> * @param string $html HTML containing unbalanced tags and also a directive.
</span><span class="cx" style="display: block; padding: 0 10px"> */
</span><span class="cx" style="display: block; padding: 0 10px"> public function test_process_directives_doesnt_change_html_if_contains_unbalanced_tags( $html ) {
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -696,22 +698,17 @@
</span><span class="cx" style="display: block; padding: 0 10px"> );
</span><span class="cx" style="display: block; padding: 0 10px"> $html = '
</span><span class="cx" style="display: block; padding: 0 10px"> <header>
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- <svg height="100" data-wp-bind--width="myPlugin::state.width">
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ <svg height="100">
</ins><span class="cx" style="display: block; padding: 0 10px"> <title>Red Circle</title>
</span><span class="cx" style="display: block; padding: 0 10px"> <circle cx="50" cy="50" r="40" stroke="black" stroke-width="3" fill="red" />
</span><span class="cx" style="display: block; padding: 0 10px"> </svg>
</span><span class="cx" style="display: block; padding: 0 10px"> <div data-wp-bind--id="myPlugin::state.id"></div>
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- <div data-wp-bind--id="myPlugin::state.width"></div>
</del><span class="cx" style="display: block; padding: 0 10px"> </header>
</span><span class="cx" style="display: block; padding: 0 10px"> ';
</span><span class="cx" style="display: block; padding: 0 10px"> $processed_html = $this->interactivity->process_directives( $html );
</span><span class="cx" style="display: block; padding: 0 10px"> $p = new WP_HTML_Tag_Processor( $processed_html );
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $p->next_tag( 'svg' );
- $this->assertNull( $p->get_attribute( 'width' ) );
</del><span class="cx" style="display: block; padding: 0 10px"> $p->next_tag( 'div' );
</span><span class="cx" style="display: block; padding: 0 10px"> $this->assertEquals( 'some-id', $p->get_attribute( 'id' ) );
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $p->next_tag( 'div' );
- $this->assertEquals( '100', $p->get_attribute( 'id' ) );
</del><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 class="lines" style="display: block; padding: 0 10px; color: #888">@@ -721,6 +718,7 @@
</span><span class="cx" style="display: block; padding: 0 10px"> * @ticket 60517
</span><span class="cx" style="display: block; padding: 0 10px"> *
</span><span class="cx" style="display: block; padding: 0 10px"> * @covers ::process_directives
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * @expectedIncorrectUsage WP_Interactivity_API_Directives_Processor::skip_to_tag_closer
</ins><span class="cx" style="display: block; padding: 0 10px"> */
</span><span class="cx" style="display: block; padding: 0 10px"> public function test_process_directives_does_not_change_inner_html_in_svgs() {
</span><span class="cx" style="display: block; padding: 0 10px"> $this->interactivity->state(
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -750,6 +748,7 @@
</span><span class="cx" style="display: block; padding: 0 10px"> * @ticket 60517
</span><span class="cx" style="display: block; padding: 0 10px"> *
</span><span class="cx" style="display: block; padding: 0 10px"> * @covers ::process_directives
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * @expectedIncorrectUsage WP_Interactivity_API::process_directives_args
</ins><span class="cx" style="display: block; padding: 0 10px"> */
</span><span class="cx" style="display: block; padding: 0 10px"> public function test_process_directives_change_html_if_contains_math() {
</span><span class="cx" style="display: block; padding: 0 10px"> $this->interactivity->state(
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -784,6 +783,8 @@
</span><span class="cx" style="display: block; padding: 0 10px"> * @ticket 60517
</span><span class="cx" style="display: block; padding: 0 10px"> *
</span><span class="cx" style="display: block; padding: 0 10px"> * @covers ::process_directives
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * @expectedIncorrectUsage WP_Interactivity_API::process_directives_args
+ * @expectedIncorrectUsage WP_Interactivity_API_Directives_Processor::skip_to_tag_closer
</ins><span class="cx" style="display: block; padding: 0 10px"> */
</span><span class="cx" style="display: block; padding: 0 10px"> public function test_process_directives_does_not_change_inner_html_in_math() {
</span><span class="cx" style="display: block; padding: 0 10px"> $this->interactivity->state(
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -811,10 +812,11 @@
</span><span class="cx" style="display: block; padding: 0 10px"> /**
</span><span class="cx" style="display: block; padding: 0 10px"> * Invokes the private `evaluate` method of WP_Interactivity_API class.
</span><span class="cx" style="display: block; padding: 0 10px"> *
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- * @param string $directive_value The directive attribute value to evaluate.
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * @param string $directive_value The directive attribute value to evaluate.
+ * @param string $default_namespace The default namespace used with directives.
</ins><span class="cx" style="display: block; padding: 0 10px"> * @return mixed The result of the evaluate method.
</span><span class="cx" style="display: block; padding: 0 10px"> */
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- private function evaluate( $directive_value ) {
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ private function evaluate( $directive_value, $default_namespace = 'myPlugin' ) {
</ins><span class="cx" style="display: block; padding: 0 10px"> $generate_state = function ( $name ) {
</span><span class="cx" style="display: block; padding: 0 10px"> $obj = new stdClass();
</span><span class="cx" style="display: block; padding: 0 10px"> $obj->prop = $name;
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -847,7 +849,7 @@
</span><span class="cx" style="display: block; padding: 0 10px"> );
</span><span class="cx" style="display: block; padding: 0 10px"> $evaluate = new ReflectionMethod( $this->interactivity, 'evaluate' );
</span><span class="cx" style="display: block; padding: 0 10px"> $evaluate->setAccessible( true );
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- return $evaluate->invokeArgs( $this->interactivity, array( $directive_value, 'myPlugin', $context ) );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ return $evaluate->invokeArgs( $this->interactivity, array( $directive_value, $default_namespace, $context ) );
</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 class="lines" style="display: block; padding: 0 10px; color: #888">@@ -948,6 +950,25 @@
</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">+ * Tests the `evaluate` method for non valid namespace values.
+ *
+ * @ticket 61044
+ *
+ * @covers ::evaluate
+ * @expectedIncorrectUsage WP_Interactivity_API::evaluate
+ */
+ public function test_evaluate_unvalid_namespaces() {
+ $result = $this->evaluate( 'path', 'null' );
+ $this->assertNull( $result );
+
+ $result = $this->evaluate( 'path', '' );
+ $this->assertNull( $result );
+
+ $result = $this->evaluate( 'path', '{}' );
+ $this->assertNull( $result );
+ }
+
+ /**
</ins><span class="cx" style="display: block; padding: 0 10px"> * Tests the `kebab_to_camel_case` method.
</span><span class="cx" style="display: block; padding: 0 10px"> *
</span><span class="cx" style="display: block; padding: 0 10px"> * @covers ::kebab_to_camel_case
</span></span></pre>
</div>
</div>
</body>
</html>