<!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>[57375] trunk: Editor: Add Block Bindings API helpers</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/57375">57375</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/57375","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-01-29 13:06:09 +0000 (Mon, 29 Jan 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'>Editor: Add Block Bindings API helpers
It is part of the sync from the Gutenberg plugin that introduces the registry for block binding sources required for the new Block Bindings API: WordPress/gutenberg<a href="https://core.trac.wordpress.org/ticket/54536">#54536</a>.
See <a href="https://core.trac.wordpress.org/ticket/60282">#60282</a>.
Follow-up <a href="https://core.trac.wordpress.org/changeset/57373">[57373]</a>.
Props czapla, artemiosans, santosguillamot, sc0ttkclark, lgladdy, talldanwp, swissspidy, youknowriad, fabiankaegy, mukesh27.</pre>
<h3>Modified Paths</h3>
<ul>
<li><a href="#trunksrcwpincludesclasswpblockbindingsregistryphp">trunk/src/wp-includes/class-wp-block-bindings-registry.php</a></li>
<li><a href="#trunksrcwpsettingsphp">trunk/src/wp-settings.php</a></li>
<li><a href="#trunktestsphpunittestsblockbindingswpBlockBindingsRegistryphp">trunk/tests/phpunit/tests/block-bindings/wpBlockBindingsRegistry.php</a></li>
</ul>
<h3>Added Paths</h3>
<ul>
<li><a href="#trunksrcwpincludesblockbindingsphp">trunk/src/wp-includes/block-bindings.php</a></li>
<li><a href="#trunktestsphpunittestsblockbindingsregisterphp">trunk/tests/phpunit/tests/block-bindings/register.php</a></li>
</ul>
</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunksrcwpincludesblockbindingsphp"></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-bindings.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/src/wp-includes/block-bindings.php (rev 0)
+++ trunk/src/wp-includes/block-bindings.php 2024-01-29 13:06:09 UTC (rev 57375)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -0,0 +1,66 @@
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+<?php
+/**
+ * Block Bindings API
+ *
+ * Contains functions for managing block bindings in WordPress.
+ *
+ * @package WordPress
+ * @subpackage Block Bindings
+ * @since 6.5.0
+ */
+
+/**
+ * Registers a new block bindings source.
+ *
+ * Sources are used to override block's original attributes with a value
+ * coming from the source. Once a source is registered, it can be used by a
+ * block by setting its `metadata.bindings` attribute to a value that refers
+ * to the source.
+ *
+ * @since 6.5.0
+ *
+ * @param string $source_name The name of the source.
+ * @param array $source_properties {
+ * The array of arguments that are used to register a source.
+ *
+ * @type string $label The label of the source.
+ * @type callback $get_value_callback A callback executed when the source is processed during block rendering.
+ * The callback should have the following signature:
+ *
+ * `function ($source_args, $block_instance,$attribute_name): mixed`
+ * - @param array $source_args Array containing source arguments
+ * used to look up the override value,
+ * i.e. {"key": "foo"}.
+ * - @param WP_Block $block_instance The block instance.
+ * - @param string $attribute_name The name of an attribute .
+ * The callback has a mixed return type; it may return a string to override
+ * the block's original value, null, false to remove an attribute, etc.
+ * }
+ * @return array|false Source when the registration was successful, or `false` on failure.
+ */
+function register_block_bindings_source( $source_name, array $source_properties ) {
+ return WP_Block_Bindings_Registry::get_instance()->register( $source_name, $source_properties );
+}
+
+/**
+ * Unregisters a block bindings source.
+ *
+ * @since 6.5.0
+ *
+ * @param string $source_name Block bindings source name including namespace.
+ * @return array|false The unregistred block bindings source on success and `false` otherwise.
+ */
+function unregister_block_bindings_source( $source_name ) {
+ return WP_Block_Bindings_Registry::get_instance()->unregister( $source_name );
+}
+
+/**
+ * Retrieves the list of all registered block bindings sources.
+ *
+ * @since 6.5.0
+ *
+ * @return array The array of registered block bindings sources.
+ */
+function get_all_registered_block_bindings_sources() {
+ return WP_Block_Bindings_Registry::get_instance()->get_all_registered();
+}
</ins><span class="cx" style="display: block; padding: 0 10px">Property changes on: trunk/src/wp-includes/block-bindings.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="trunksrcwpincludesclasswpblockbindingsregistryphp"></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/class-wp-block-bindings-registry.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/src/wp-includes/class-wp-block-bindings-registry.php 2024-01-29 12:32:26 UTC (rev 57374)
+++ trunk/src/wp-includes/class-wp-block-bindings-registry.php 2024-01-29 13:06:09 UTC (rev 57375)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -10,7 +10,7 @@
</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">- * Core class used for interacting with block binding sources.
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * Core class used for interacting with block bindings sources.
</ins><span class="cx" style="display: block; padding: 0 10px"> *
</span><span class="cx" style="display: block; padding: 0 10px"> * @since 6.5.0
</span><span class="cx" style="display: block; padding: 0 10px"> */
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -20,7 +20,6 @@
</span><span class="cx" style="display: block; padding: 0 10px"> * Holds the registered block bindings sources, keyed by source identifier.
</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><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- *
</del><span class="cx" style="display: block; padding: 0 10px"> * @var array
</span><span class="cx" style="display: block; padding: 0 10px"> */
</span><span class="cx" style="display: block; padding: 0 10px"> private $sources = array();
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -34,7 +33,7 @@
</span><span class="cx" style="display: block; padding: 0 10px"> private static $instance = null;
</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">- * Registers a new block binding source.
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * Registers a new block bindings source.
</ins><span class="cx" style="display: block; padding: 0 10px"> *
</span><span class="cx" style="display: block; padding: 0 10px"> * Sources are used to override block's original attributes with a value
</span><span class="cx" style="display: block; padding: 0 10px"> * coming from the source. Once a source is registered, it can be used by a
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -66,7 +65,7 @@
</span><span class="cx" style="display: block; padding: 0 10px"> if ( ! is_string( $source_name ) ) {
</span><span class="cx" style="display: block; padding: 0 10px"> _doing_it_wrong(
</span><span class="cx" style="display: block; padding: 0 10px"> __METHOD__,
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- __( 'Block binding source name must be a string.' ),
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ __( 'Block bindings source name must be a string.' ),
</ins><span class="cx" style="display: block; padding: 0 10px"> '6.5.0'
</span><span class="cx" style="display: block; padding: 0 10px"> );
</span><span class="cx" style="display: block; padding: 0 10px"> return false;
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -75,7 +74,7 @@
</span><span class="cx" style="display: block; padding: 0 10px"> if ( preg_match( '/[A-Z]+/', $source_name ) ) {
</span><span class="cx" style="display: block; padding: 0 10px"> _doing_it_wrong(
</span><span class="cx" style="display: block; padding: 0 10px"> __METHOD__,
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- __( 'Block binding source names must not contain uppercase characters.' ),
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ __( 'Block bindings source names must not contain uppercase characters.' ),
</ins><span class="cx" style="display: block; padding: 0 10px"> '6.5.0'
</span><span class="cx" style="display: block; padding: 0 10px"> );
</span><span class="cx" style="display: block; padding: 0 10px"> return false;
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -85,7 +84,7 @@
</span><span class="cx" style="display: block; padding: 0 10px"> if ( ! preg_match( $name_matcher, $source_name ) ) {
</span><span class="cx" style="display: block; padding: 0 10px"> _doing_it_wrong(
</span><span class="cx" style="display: block; padding: 0 10px"> __METHOD__,
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- __( 'Block binding source names must contain a namespace prefix. Example: my-plugin/my-custom-source' ),
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ __( 'Block bindings source names must contain a namespace prefix. Example: my-plugin/my-custom-source' ),
</ins><span class="cx" style="display: block; padding: 0 10px"> '6.5.0'
</span><span class="cx" style="display: block; padding: 0 10px"> );
</span><span class="cx" style="display: block; padding: 0 10px"> return false;
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -94,8 +93,8 @@
</span><span class="cx" style="display: block; padding: 0 10px"> if ( $this->is_registered( $source_name ) ) {
</span><span class="cx" style="display: block; padding: 0 10px"> _doing_it_wrong(
</span><span class="cx" style="display: block; padding: 0 10px"> __METHOD__,
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- /* translators: %s: Block binding source name. */
- sprintf( __( 'Block binding source "%s" already registered.' ), $source_name ),
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ /* translators: %s: Block bindings source name. */
+ sprintf( __( 'Block bindings source "%s" already registered.' ), $source_name ),
</ins><span class="cx" style="display: block; padding: 0 10px"> '6.5.0'
</span><span class="cx" style="display: block; padding: 0 10px"> );
</span><span class="cx" style="display: block; padding: 0 10px"> return false;
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -112,18 +111,18 @@
</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">- * Unregisters a block binding source.
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * Unregisters a block bindings source.
</ins><span class="cx" style="display: block; padding: 0 10px"> *
</span><span class="cx" style="display: block; padding: 0 10px"> * @since 6.5.0
</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 $source_name Block binding source name including namespace.
- * @return array|false The unregistred block binding source on success and `false` otherwise.
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * @param string $source_name Block bindings source name including namespace.
+ * @return array|false The unregistred block bindings source on success and `false` otherwise.
</ins><span class="cx" style="display: block; padding: 0 10px"> */
</span><span class="cx" style="display: block; padding: 0 10px"> public function unregister( $source_name ) {
</span><span class="cx" style="display: block; padding: 0 10px"> if ( ! $this->is_registered( $source_name ) ) {
</span><span class="cx" style="display: block; padding: 0 10px"> _doing_it_wrong(
</span><span class="cx" style="display: block; padding: 0 10px"> __METHOD__,
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- /* translators: %s: Block binding source name. */
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ /* translators: %s: Block bindings source name. */
</ins><span class="cx" style="display: block; padding: 0 10px"> sprintf( __( 'Block binding "%s" not found.' ), $source_name ),
</span><span class="cx" style="display: block; padding: 0 10px"> '6.5.0'
</span><span class="cx" style="display: block; padding: 0 10px"> );
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -153,7 +152,7 @@
</span><span class="cx" style="display: block; padding: 0 10px"> * @since 6.5.0
</span><span class="cx" style="display: block; padding: 0 10px"> *
</span><span class="cx" style="display: block; padding: 0 10px"> * @param string $source_name The name of the source.
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- * @return array|null The registered block binding source, or `null` if it is not registered.
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * @return array|null The registered block bindings source, or `null` if it is not registered.
</ins><span class="cx" style="display: block; padding: 0 10px"> */
</span><span class="cx" style="display: block; padding: 0 10px"> public function get_registered( $source_name ) {
</span><span class="cx" style="display: block; padding: 0 10px"> if ( ! $this->is_registered( $source_name ) ) {
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -164,12 +163,12 @@
</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">- * Checks if a block binding source is registered.
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * Checks if a block bindings source is registered.
</ins><span class="cx" style="display: block; padding: 0 10px"> *
</span><span class="cx" style="display: block; padding: 0 10px"> * @since 6.5.0
</span><span class="cx" style="display: block; padding: 0 10px"> *
</span><span class="cx" style="display: block; padding: 0 10px"> * @param string $source_name The name of the source.
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- * @return bool `true` if the block binding source is registered, `false` otherwise.
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * @return bool `true` if the block bindings source is registered, `false` otherwise.
</ins><span class="cx" style="display: block; padding: 0 10px"> */
</span><span class="cx" style="display: block; padding: 0 10px"> public function is_registered( $source_name ) {
</span><span class="cx" style="display: block; padding: 0 10px"> return isset( $this->sources[ $source_name ] );
</span></span></pre></div>
<a id="trunksrcwpsettingsphp"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: trunk/src/wp-settings.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/src/wp-settings.php 2024-01-29 12:32:26 UTC (rev 57374)
+++ trunk/src/wp-settings.php 2024-01-29 13:06:09 UTC (rev 57375)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -329,8 +329,8 @@
</span><span class="cx" style="display: block; padding: 0 10px"> require ABSPATH . WPINC . '/sitemaps/providers/class-wp-sitemaps-posts.php';
</span><span class="cx" style="display: block; padding: 0 10px"> require ABSPATH . WPINC . '/sitemaps/providers/class-wp-sitemaps-taxonomies.php';
</span><span class="cx" style="display: block; padding: 0 10px"> require ABSPATH . WPINC . '/sitemaps/providers/class-wp-sitemaps-users.php';
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+require ABSPATH . WPINC . '/class-wp-block-bindings-registry.php';
</ins><span class="cx" style="display: block; padding: 0 10px"> require ABSPATH . WPINC . '/class-wp-block-editor-context.php';
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-require ABSPATH . WPINC . '/class-wp-block-bindings-registry.php';
</del><span class="cx" style="display: block; padding: 0 10px"> require ABSPATH . WPINC . '/class-wp-block-type.php';
</span><span class="cx" style="display: block; padding: 0 10px"> require ABSPATH . WPINC . '/class-wp-block-pattern-categories-registry.php';
</span><span class="cx" style="display: block; padding: 0 10px"> require ABSPATH . WPINC . '/class-wp-block-patterns-registry.php';
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -343,6 +343,7 @@
</span><span class="cx" style="display: block; padding: 0 10px"> require ABSPATH . WPINC . '/class-wp-block-parser.php';
</span><span class="cx" style="display: block; padding: 0 10px"> require ABSPATH . WPINC . '/class-wp-classic-to-block-menu-converter.php';
</span><span class="cx" style="display: block; padding: 0 10px"> require ABSPATH . WPINC . '/class-wp-navigation-fallback.php';
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+require ABSPATH . WPINC . '/block-bindings.php';
</ins><span class="cx" style="display: block; padding: 0 10px"> require ABSPATH . WPINC . '/blocks.php';
</span><span class="cx" style="display: block; padding: 0 10px"> require ABSPATH . WPINC . '/blocks/index.php';
</span><span class="cx" style="display: block; padding: 0 10px"> require ABSPATH . WPINC . '/block-editor.php';
</span></span></pre></div>
<a id="trunktestsphpunittestsblockbindingsregisterphp"></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-bindings/register.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/tests/phpunit/tests/block-bindings/register.php (rev 0)
+++ trunk/tests/phpunit/tests/block-bindings/register.php 2024-01-29 13:06:09 UTC (rev 57375)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -0,0 +1,86 @@
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+<?php
+/**
+ * Tests for Block Bindings API helper functions.
+ *
+ * @package WordPress
+ * @subpackage Blocks
+ * @since 6.5.0
+ *
+ * @group blocks
+ * @group block-bindings
+ */
+class Tests_Block_Bindings_Register extends WP_UnitTestCase {
+
+ const TEST_SOURCE_NAME = 'test/source';
+ const TEST_SOURCE_PROPERTIES = array(
+ 'label' => 'Test source',
+ );
+
+ /**
+ * Tear down after each test.
+ *
+ * @since 6.5.0
+ */
+ public function tear_down() {
+ foreach ( get_all_registered_block_bindings_sources() as $source_name => $source_properties ) {
+ if ( str_starts_with( $source_name, 'test/' ) ) {
+ unregister_block_bindings_source( $source_name );
+ }
+ unregister_block_bindings_source( $source_name );
+ }
+
+ parent::tear_down();
+ }
+
+ /**
+ * Should find all registered sources.
+ *
+ * @ticket 60282
+ *
+ * @covers ::register_block_bindings_source
+ * @covers ::get_all_registered_block_bindings_sources
+ */
+ public function test_get_all_registered() {
+ $source_one_name = 'test/source-one';
+ $source_one_properties = self::TEST_SOURCE_PROPERTIES;
+ register_block_bindings_source( $source_one_name, $source_one_properties );
+
+ $source_two_name = 'test/source-two';
+ $source_two_properties = self::TEST_SOURCE_PROPERTIES;
+ register_block_bindings_source( $source_two_name, $source_two_properties );
+
+ $source_three_name = 'test/source-three';
+ $source_three_properties = self::TEST_SOURCE_PROPERTIES;
+ register_block_bindings_source( $source_three_name, $source_three_properties );
+
+ $expected = array(
+ $source_one_name => array_merge( array( 'name' => $source_one_name ), $source_one_properties ),
+ $source_two_name => array_merge( array( 'name' => $source_two_name ), $source_two_properties ),
+ $source_three_name => array_merge( array( 'name' => $source_three_name ), $source_three_properties ),
+ );
+
+ $registered = get_all_registered_block_bindings_sources();
+ $this->assertSame( $expected, $registered );
+ }
+
+ /**
+ * Should unregister existing block binding source.
+ *
+ * @ticket 60282
+ *
+ * @covers ::register_block_bindings_source
+ * @covers ::unregister_block_bindings_source
+ */
+ public function test_unregister_block_source() {
+ register_block_bindings_source( self::TEST_SOURCE_NAME, self::TEST_SOURCE_PROPERTIES );
+
+ $result = unregister_block_bindings_source( self::TEST_SOURCE_NAME );
+ $this->assertSame(
+ array_merge(
+ array( 'name' => self::TEST_SOURCE_NAME ),
+ self::TEST_SOURCE_PROPERTIES
+ ),
+ $result
+ );
+ }
+}
</ins><span class="cx" style="display: block; padding: 0 10px">Property changes on: trunk/tests/phpunit/tests/block-bindings/register.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="trunktestsphpunittestsblockbindingswpBlockBindingsRegistryphp"></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/block-bindings/wpBlockBindingsRegistry.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/tests/phpunit/tests/block-bindings/wpBlockBindingsRegistry.php 2024-01-29 12:32:26 UTC (rev 57374)
+++ trunk/tests/phpunit/tests/block-bindings/wpBlockBindingsRegistry.php 2024-01-29 13:06:09 UTC (rev 57375)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -141,6 +141,7 @@
</span><span class="cx" style="display: block; padding: 0 10px"> *
</span><span class="cx" style="display: block; padding: 0 10px"> * @ticket 60282
</span><span class="cx" style="display: block; padding: 0 10px"> *
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * @covers WP_Block_Bindings_Registry::register
</ins><span class="cx" style="display: block; padding: 0 10px"> * @covers WP_Block_Bindings_Registry::unregister
</span><span class="cx" style="display: block; padding: 0 10px"> */
</span><span class="cx" style="display: block; padding: 0 10px"> public function test_unregister_block_source() {
</span></span></pre>
</div>
</div>
</body>
</html>