From 5e9eca671d3e24e36ffcf857a49549092ca60d7a Mon Sep 17 00:00:00 2001 From: im3dabasia Date: Tue, 3 Mar 2026 12:26:14 +0530 Subject: [PATCH 01/15] feat: Updated registry method with rigid checks --- .../wordpress-7.0/class-wp-icons-registry.php | 28 +++++ phpunit/experimental/wpIconsRegistry.php | 112 ++++++++++++++++++ 2 files changed, 140 insertions(+) create mode 100644 phpunit/experimental/wpIconsRegistry.php diff --git a/lib/compat/wordpress-7.0/class-wp-icons-registry.php b/lib/compat/wordpress-7.0/class-wp-icons-registry.php index 1fa66e54001a04..e31b36c23aca3d 100644 --- a/lib/compat/wordpress-7.0/class-wp-icons-registry.php +++ b/lib/compat/wordpress-7.0/class-wp-icons-registry.php @@ -100,6 +100,34 @@ protected function register( $icon_name, $icon_properties ) { return false; } + if ( preg_match( '/[A-Z]+/', $icon_name ) ) { + _doing_it_wrong( + __METHOD__, + __( 'Icon names must not contain uppercase characters.' ), + '7.0.0' + ); + return false; + } + + $name_matcher = '/^[a-z0-9-]+\/[a-z0-9-]+$/'; + if ( ! preg_match( $name_matcher, $icon_name ) ) { + _doing_it_wrong( + __METHOD__, + __( 'Icon names must contain a namespace prefix. Example: my-plugin/my-custom-icon' ), + '7.0.0' + ); + return false; + } + + if ( $this->is_registered( $icon_name ) ) { + _doing_it_wrong( + __METHOD__, + __( 'Icon is already registered.' ), + '7.0.0' + ); + return false; + } + $allowed_keys = array_fill_keys( array( 'label', 'content', 'filePath' ), 1 ); foreach ( array_keys( $icon_properties ) as $key ) { if ( ! array_key_exists( $key, $allowed_keys ) ) { diff --git a/phpunit/experimental/wpIconsRegistry.php b/phpunit/experimental/wpIconsRegistry.php new file mode 100644 index 00000000000000..b7a2f8425e422e --- /dev/null +++ b/phpunit/experimental/wpIconsRegistry.php @@ -0,0 +1,112 @@ +registry = WP_Icons_Registry::get_instance(); + } + + /** + * Tear down each test method. + */ + public function tear_down() { + $this->registry = null; + parent::tear_down(); + } + + /** + * Helper to call the protected register method. + * + * @param string $name Icon name. + * @param array $args Icon settings. + * @return bool True on success, false on failure. + * @throws ReflectionException If the method does not exist. + * + * @expectedIncorrectUsage WP_Icons_Registry::register + */ + private function register_icon( $name, $args = array() ) { + $method = new ReflectionMethod( $this->registry, 'register' ); + $method->setAccessible( true ); + return $method->invoke( $this->registry, $name, $args ); + } + + /** + * Should reject non-string names. + * + * @expectedIncorrectUsage WP_Icons_Registry::register + */ + public function test_invalid_non_string_names() { + $result = $this->register_icon( 1, array() ); + $this->assertFalse( $result ); + } + + /** + * Should reject icons without a namespace. + * + * @expectedIncorrectUsage WP_Icons_Registry::register + */ + public function test_invalid_names_without_namespace() { + $result = $this->register_icon( 'plus', array() ); + $this->assertFalse( $result ); + } + + /** + * Should reject icons with uppercase characters. + * + * @expectedIncorrectUsage WP_Icons_Registry::register + */ + public function test_uppercase_characters() { + $result = $this->register_icon( 'Core/Plus', array() ); + $this->assertFalse( $result ); + } + + /** + * Should accept valid icon names. + */ + public function test_register_icon() { + $name = 'test-plugin/my-icon'; + $settings = array( + 'label' => 'My Icon', + 'content' => '', + ); + + $result = $this->register_icon( $name, $settings ); + $this->assertTrue( $result ); + $this->assertTrue( $this->registry->is_registered( $name ) ); + } + + /** + * Should fail to re-register the same icon. + */ + public function test_register_icon_twice() { + $name = 'test-plugin/duplicate'; + $settings = array( + 'label' => 'Icon', + 'content' => '', + ); + + $result = $this->register_icon( $name, $settings ); + $this->assertTrue( $result ); + $result2 = $this->register_icon( $name, $settings ); + $this->assertFalse( $result2 ); + } +} From 7693957833a5a92daa0884e3fb64a8ec348f662a Mon Sep 17 00:00:00 2001 From: im3dabasia Date: Tue, 3 Mar 2026 16:57:10 +0530 Subject: [PATCH 02/15] fix: Updated test_register_icon_twice test --- phpunit/experimental/wpIconsRegistry.php | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/phpunit/experimental/wpIconsRegistry.php b/phpunit/experimental/wpIconsRegistry.php index b7a2f8425e422e..ca75ccc35eb3d9 100644 --- a/phpunit/experimental/wpIconsRegistry.php +++ b/phpunit/experimental/wpIconsRegistry.php @@ -104,9 +104,13 @@ public function test_register_icon_twice() { 'content' => '', ); - $result = $this->register_icon( $name, $settings ); - $this->assertTrue( $result ); - $result2 = $this->register_icon( $name, $settings ); - $this->assertFalse( $result2 ); + $this->register_icon( $name, $settings ); + $this->assertTrue( $this->registry->is_registered( $name ) ); + + $registered_icons = $this->registry->get_registered_icons(); + $this->register_icon( $name, $settings ); + + $registered_icons_after = $this->registry->get_registered_icons(); + $this->assertEquals( count( $registered_icons ), count( $registered_icons_after ) ); } } From 5c559bd47837a0ff8835824823bf129b7b36a580 Mon Sep 17 00:00:00 2001 From: im3dabasia Date: Tue, 3 Mar 2026 17:34:16 +0530 Subject: [PATCH 03/15] fix: PHP lint errors fix --- lib/compat/wordpress-7.0/class-wp-icons-registry.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/compat/wordpress-7.0/class-wp-icons-registry.php b/lib/compat/wordpress-7.0/class-wp-icons-registry.php index e31b36c23aca3d..06e3a99eebc0de 100644 --- a/lib/compat/wordpress-7.0/class-wp-icons-registry.php +++ b/lib/compat/wordpress-7.0/class-wp-icons-registry.php @@ -122,7 +122,7 @@ protected function register( $icon_name, $icon_properties ) { if ( $this->is_registered( $icon_name ) ) { _doing_it_wrong( __METHOD__, - __( 'Icon is already registered.' ), + __( 'Icon is already registered.' ), '7.0.0' ); return false; From 9bedf377f0113e7c6ed67cf11cfd755d8c346fde Mon Sep 17 00:00:00 2001 From: im3dabasia Date: Thu, 12 Mar 2026 19:03:16 +0530 Subject: [PATCH 04/15] chore: Move register regex checks to 7.1 and renamed tests class/file_name --- .../wordpress-7.0/class-wp-icons-registry.php | 28 ------------------- ...ass-gutenberg-icons-registry-7-1-test.php} | 20 ++++++------- 2 files changed, 10 insertions(+), 38 deletions(-) rename phpunit/experimental/{wpIconsRegistry.php => class-gutenberg-icons-registry-7-1-test.php} (82%) diff --git a/lib/compat/wordpress-7.0/class-wp-icons-registry.php b/lib/compat/wordpress-7.0/class-wp-icons-registry.php index 06e3a99eebc0de..1fa66e54001a04 100644 --- a/lib/compat/wordpress-7.0/class-wp-icons-registry.php +++ b/lib/compat/wordpress-7.0/class-wp-icons-registry.php @@ -100,34 +100,6 @@ protected function register( $icon_name, $icon_properties ) { return false; } - if ( preg_match( '/[A-Z]+/', $icon_name ) ) { - _doing_it_wrong( - __METHOD__, - __( 'Icon names must not contain uppercase characters.' ), - '7.0.0' - ); - return false; - } - - $name_matcher = '/^[a-z0-9-]+\/[a-z0-9-]+$/'; - if ( ! preg_match( $name_matcher, $icon_name ) ) { - _doing_it_wrong( - __METHOD__, - __( 'Icon names must contain a namespace prefix. Example: my-plugin/my-custom-icon' ), - '7.0.0' - ); - return false; - } - - if ( $this->is_registered( $icon_name ) ) { - _doing_it_wrong( - __METHOD__, - __( 'Icon is already registered.' ), - '7.0.0' - ); - return false; - } - $allowed_keys = array_fill_keys( array( 'label', 'content', 'filePath' ), 1 ); foreach ( array_keys( $icon_properties ) as $key ) { if ( ! array_key_exists( $key, $allowed_keys ) ) { diff --git a/phpunit/experimental/wpIconsRegistry.php b/phpunit/experimental/class-gutenberg-icons-registry-7-1-test.php similarity index 82% rename from phpunit/experimental/wpIconsRegistry.php rename to phpunit/experimental/class-gutenberg-icons-registry-7-1-test.php index ca75ccc35eb3d9..af78eaef99c771 100644 --- a/phpunit/experimental/wpIconsRegistry.php +++ b/phpunit/experimental/class-gutenberg-icons-registry-7-1-test.php @@ -1,19 +1,19 @@ registry = WP_Icons_Registry::get_instance(); + $this->registry = Gutenberg_Icons_Registry_7_1::get_instance(); } /** @@ -41,7 +41,7 @@ public function tear_down() { * @return bool True on success, false on failure. * @throws ReflectionException If the method does not exist. * - * @expectedIncorrectUsage WP_Icons_Registry::register + * @expectedIncorrectUsage Gutenberg_Icons_Registry_7_1::register */ private function register_icon( $name, $args = array() ) { $method = new ReflectionMethod( $this->registry, 'register' ); @@ -52,7 +52,7 @@ private function register_icon( $name, $args = array() ) { /** * Should reject non-string names. * - * @expectedIncorrectUsage WP_Icons_Registry::register + * @expectedIncorrectUsage Gutenberg_Icons_Registry_7_1::register */ public function test_invalid_non_string_names() { $result = $this->register_icon( 1, array() ); @@ -62,7 +62,7 @@ public function test_invalid_non_string_names() { /** * Should reject icons without a namespace. * - * @expectedIncorrectUsage WP_Icons_Registry::register + * @expectedIncorrectUsage Gutenberg_Icons_Registry_7_1::register */ public function test_invalid_names_without_namespace() { $result = $this->register_icon( 'plus', array() ); @@ -72,7 +72,7 @@ public function test_invalid_names_without_namespace() { /** * Should reject icons with uppercase characters. * - * @expectedIncorrectUsage WP_Icons_Registry::register + * @expectedIncorrectUsage Gutenberg_Icons_Registry_7_1::register */ public function test_uppercase_characters() { $result = $this->register_icon( 'Core/Plus', array() ); From 6f1de67f1cacf24ab458933d1725521b08c3f9bb Mon Sep 17 00:00:00 2001 From: im3dabasia Date: Thu, 12 Mar 2026 19:07:49 +0530 Subject: [PATCH 05/15] chore: Added register function in wp-7.1/ --- .../class-gutenberg-icons-registry-7-1.php | 121 ++++++++++++++++++ 1 file changed, 121 insertions(+) diff --git a/lib/compat/wordpress-7.1/class-gutenberg-icons-registry-7-1.php b/lib/compat/wordpress-7.1/class-gutenberg-icons-registry-7-1.php index e827056064e7b1..ba7c5fbfa9a6be 100644 --- a/lib/compat/wordpress-7.1/class-gutenberg-icons-registry-7-1.php +++ b/lib/compat/wordpress-7.1/class-gutenberg-icons-registry-7-1.php @@ -50,6 +50,127 @@ protected function __construct() { } } + /** + * Registers an icon. + * + * @param string $icon_name Icon name including namespace. + * @param array $icon_properties { + * List of properties for the icon. + * + * @type string $label Required. A human-readable label for the icon. + * @type string $content Optional. SVG markup for the icon. + * If not provided, the content will be retrieved from the `filePath` if set. + * If both `content` and `filePath` are not set, the icon will not be registered. + * @type string $filePath Optional. The full path to the file containing the icon content. + * } + * @return bool True if the icon was registered with success and false otherwise. + */ + protected function register( $icon_name, $icon_properties ) { + if ( ! isset( $icon_name ) || ! is_string( $icon_name ) ) { + _doing_it_wrong( + __METHOD__, + __( 'Icon name must be a string.', 'gutenberg' ), + '7.0.0' + ); + return false; + } + + if ( preg_match( '/[A-Z]+/', $icon_name ) ) { + _doing_it_wrong( + __METHOD__, + __( 'Icon names must not contain uppercase characters.' ), + '7.1.0' + ); + return false; + } + + $name_matcher = '/^[a-z0-9-]+\/[a-z0-9-]+$/'; + if ( ! preg_match( $name_matcher, $icon_name ) ) { + _doing_it_wrong( + __METHOD__, + __( 'Icon names must contain a namespace prefix. Example: my-plugin/my-custom-icon' ), + '7.1.0' + ); + return false; + } + + if ( $this->is_registered( $icon_name ) ) { + _doing_it_wrong( + __METHOD__, + __( 'Icon is already registered.' ), + '7.1.0' + ); + return false; + } + + $allowed_keys = array_fill_keys( array( 'label', 'content', 'filePath' ), 1 ); + foreach ( array_keys( $icon_properties ) as $key ) { + if ( ! array_key_exists( $key, $allowed_keys ) ) { + _doing_it_wrong( + __METHOD__, + sprintf( + // translators: %s is the name of any user-provided key + __( 'Invalid icon property: "%s".', 'gutenberg' ), + $key + ), + '7.0.0' + ); + return false; + } + } + + if ( ! isset( $icon_properties['label'] ) || ! is_string( $icon_properties['label'] ) ) { + _doing_it_wrong( + __METHOD__, + __( 'Icon label must be a string.', 'gutenberg' ), + '7.0.0' + ); + return false; + } + + if ( + ( ! isset( $icon_properties['content'] ) && ! isset( $icon_properties['filePath'] ) ) || + ( isset( $icon_properties['content'] ) && isset( $icon_properties['filePath'] ) ) + ) { + _doing_it_wrong( + __METHOD__, + __( 'Icons must provide either `content` or `filePath`.', 'gutenberg' ), + '7.0.0' + ); + return false; + } + + if ( isset( $icon_properties['content'] ) ) { + if ( ! is_string( $icon_properties['content'] ) ) { + _doing_it_wrong( + __METHOD__, + __( 'Icon content must be a string.', 'gutenberg' ), + '7.0.0' + ); + return false; + } + + $sanitized_icon_content = $this->sanitize_icon_content( $icon_properties['content'] ); + if ( empty( $sanitized_icon_content ) ) { + _doing_it_wrong( + __METHOD__, + __( 'Icon content does not contain valid SVG markup.', 'gutenberg' ), + '7.0.0' + ); + return false; + } + } + + $icon = array_merge( + $icon_properties, + array( 'name' => $icon_name ) + ); + + $this->registered_icons[ $icon_name ] = $icon; + + return true; + } + /** * Modified to also search in icon labels */ From 398b9d02b720b93dc57832f3b015e321831cc1a9 Mon Sep 17 00:00:00 2001 From: im3dabasia Date: Fri, 13 Mar 2026 12:55:46 +0530 Subject: [PATCH 06/15] chore: Update tests --- ...lass-gutenberg-icons-registry-7-1-test.php | 53 +++++++++---------- 1 file changed, 24 insertions(+), 29 deletions(-) diff --git a/phpunit/experimental/class-gutenberg-icons-registry-7-1-test.php b/phpunit/experimental/class-gutenberg-icons-registry-7-1-test.php index af78eaef99c771..c27713779666d7 100644 --- a/phpunit/experimental/class-gutenberg-icons-registry-7-1-test.php +++ b/phpunit/experimental/class-gutenberg-icons-registry-7-1-test.php @@ -1,24 +1,20 @@ setAccessible( true ); + $instance_property->setValue( null, null ); + $this->registry = null; parent::tear_down(); } /** - * Helper to call the protected register method. - * - * @param string $name Icon name. - * @param array $args Icon settings. - * @return bool True on success, false on failure. - * @throws ReflectionException If the method does not exist. + * Invokes the Gutenberg_Icons_Registry_7_1::register method on the registry instance. * - * @expectedIncorrectUsage Gutenberg_Icons_Registry_7_1::register + * @param string $icon_name Icon name including namespace. + * @param array $icon_properties Icon properties (label, content, filePath). + * @return bool True if the icon was registered successfully. */ - private function register_icon( $name, $args = array() ) { + private function register( $icon_name, $icon_properties ) { $method = new ReflectionMethod( $this->registry, 'register' ); $method->setAccessible( true ); - return $method->invoke( $this->registry, $name, $args ); + return $method->invoke( $this->registry, $icon_name, $icon_properties ); } /** @@ -55,7 +52,7 @@ private function register_icon( $name, $args = array() ) { * @expectedIncorrectUsage Gutenberg_Icons_Registry_7_1::register */ public function test_invalid_non_string_names() { - $result = $this->register_icon( 1, array() ); + $result = $this->register( 1, array() ); $this->assertFalse( $result ); } @@ -65,7 +62,7 @@ public function test_invalid_non_string_names() { * @expectedIncorrectUsage Gutenberg_Icons_Registry_7_1::register */ public function test_invalid_names_without_namespace() { - $result = $this->register_icon( 'plus', array() ); + $result = $this->register( 'plus', array() ); $this->assertFalse( $result ); } @@ -75,7 +72,7 @@ public function test_invalid_names_without_namespace() { * @expectedIncorrectUsage Gutenberg_Icons_Registry_7_1::register */ public function test_uppercase_characters() { - $result = $this->register_icon( 'Core/Plus', array() ); + $result = $this->register( 'Core/Plus', array() ); $this->assertFalse( $result ); } @@ -89,13 +86,15 @@ public function test_register_icon() { 'content' => '', ); - $result = $this->register_icon( $name, $settings ); + $result = $this->register( $name, $settings ); $this->assertTrue( $result ); $this->assertTrue( $this->registry->is_registered( $name ) ); } /** * Should fail to re-register the same icon. + * + * @expectedIncorrectUsage Gutenberg_Icons_Registry_7_1::register */ public function test_register_icon_twice() { $name = 'test-plugin/duplicate'; @@ -104,13 +103,9 @@ public function test_register_icon_twice() { 'content' => '', ); - $this->register_icon( $name, $settings ); - $this->assertTrue( $this->registry->is_registered( $name ) ); - - $registered_icons = $this->registry->get_registered_icons(); - $this->register_icon( $name, $settings ); - - $registered_icons_after = $this->registry->get_registered_icons(); - $this->assertEquals( count( $registered_icons ), count( $registered_icons_after ) ); + $result = $this->register( $name, $settings ); + $this->assertTrue( $result ); + $result2 = $this->register( $name, $settings ); + $this->assertFalse( $result2 ); } } From 6b9cd3253bba1e08e1498694c5f9b9b64f83d39b Mon Sep 17 00:00:00 2001 From: im3dabasia Date: Fri, 13 Mar 2026 16:50:21 +0530 Subject: [PATCH 07/15] docs: Add changelog for backport --- backport-changelog/7.1/11245.md | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 backport-changelog/7.1/11245.md diff --git a/backport-changelog/7.1/11245.md b/backport-changelog/7.1/11245.md new file mode 100644 index 00000000000000..7324c0d65f4cc4 --- /dev/null +++ b/backport-changelog/7.1/11245.md @@ -0,0 +1,3 @@ +https://github.com/WordPress/wordpress-develop/pull/11245 + +* https://github.com/WordPress/gutenberg/pull/76079 From ef7d67ca2836122ce1ad9ee6d7fba38ab9ed0f0a Mon Sep 17 00:00:00 2001 From: im3dabasia Date: Thu, 19 Mar 2026 13:02:14 +0530 Subject: [PATCH 08/15] chore: Feedbacks addressed as per upstream suggestions --- ...lass-gutenberg-icons-registry-7-1-test.php | 52 +++++++++++-------- 1 file changed, 29 insertions(+), 23 deletions(-) diff --git a/phpunit/experimental/class-gutenberg-icons-registry-7-1-test.php b/phpunit/experimental/class-gutenberg-icons-registry-7-1-test.php index c27713779666d7..9543e2e64d52a5 100644 --- a/phpunit/experimental/class-gutenberg-icons-registry-7-1-test.php +++ b/phpunit/experimental/class-gutenberg-icons-registry-7-1-test.php @@ -26,7 +26,9 @@ public function set_up() { */ public function tear_down() { $instance_property = new ReflectionProperty( Gutenberg_Icons_Registry_7_1::class, 'instance' ); - $instance_property->setAccessible( true ); + if ( PHP_VERSION_ID < 80100 ) { + $instance_property->setAccessible( true ); + } $instance_property->setValue( null, null ); $this->registry = null; @@ -42,37 +44,27 @@ public function tear_down() { */ private function register( $icon_name, $icon_properties ) { $method = new ReflectionMethod( $this->registry, 'register' ); - $method->setAccessible( true ); + if ( PHP_VERSION_ID < 80100 ) { + $instance_property->setAccessible( true ); + } return $method->invoke( $this->registry, $icon_name, $icon_properties ); } /** - * Should reject non-string names. + * Should reject invalid icon names. * + * @dataProvider data_invalid_icon_names * @expectedIncorrectUsage Gutenberg_Icons_Registry_7_1::register - */ - public function test_invalid_non_string_names() { - $result = $this->register( 1, array() ); - $this->assertFalse( $result ); - } - - /** - * Should reject icons without a namespace. * - * @expectedIncorrectUsage Gutenberg_Icons_Registry_7_1::register + * @param mixed $icon_name Icon name to test. */ - public function test_invalid_names_without_namespace() { - $result = $this->register( 'plus', array() ); - $this->assertFalse( $result ); - } + public function test_invalid_icon_names( $icon_name ) { + $settings = array( + 'label' => 'Icon', + 'content' => '', + ); - /** - * Should reject icons with uppercase characters. - * - * @expectedIncorrectUsage Gutenberg_Icons_Registry_7_1::register - */ - public function test_uppercase_characters() { - $result = $this->register( 'Core/Plus', array() ); + $result = $this->register( $icon_name, $settings ); $this->assertFalse( $result ); } @@ -91,6 +83,20 @@ public function test_register_icon() { $this->assertTrue( $this->registry->is_registered( $name ) ); } + /** + * Provides invalid icon names. + * + * @return array[] + */ + public function data_invalid_icon_names() { + return array( + 'non-string name' => array( 1 ), + 'no namespace' => array( 'plus' ), + 'uppercase characters' => array( 'Core/Plus' ), + 'invalid characters' => array( 'test/_doing_it_wrong' ), + ); + } + /** * Should fail to re-register the same icon. * From 8d42b8634943db6be977f8413ef2ac69c1665b45 Mon Sep 17 00:00:00 2001 From: Miguel Fonseca <150562+mcsf@users.noreply.github.com> Date: Tue, 24 Mar 2026 17:28:28 +0000 Subject: [PATCH 09/15] Remove broken code and comment use of PHP_VERSION_ID --- .../class-gutenberg-icons-registry-7-1-test.php | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/phpunit/experimental/class-gutenberg-icons-registry-7-1-test.php b/phpunit/experimental/class-gutenberg-icons-registry-7-1-test.php index 9543e2e64d52a5..9fe32901a2f3fe 100644 --- a/phpunit/experimental/class-gutenberg-icons-registry-7-1-test.php +++ b/phpunit/experimental/class-gutenberg-icons-registry-7-1-test.php @@ -26,9 +26,17 @@ public function set_up() { */ public function tear_down() { $instance_property = new ReflectionProperty( Gutenberg_Icons_Registry_7_1::class, 'instance' ); + + /* + * ReflectionProperty::setAccessible is: + * - redundant as of 8.1.0, which made all properties accessible + * - deprecated as of 8.5.0 + * - needed until 8.1.0, as property `instance` is private + */ if ( PHP_VERSION_ID < 80100 ) { $instance_property->setAccessible( true ); } + $instance_property->setValue( null, null ); $this->registry = null; @@ -44,9 +52,6 @@ public function tear_down() { */ private function register( $icon_name, $icon_properties ) { $method = new ReflectionMethod( $this->registry, 'register' ); - if ( PHP_VERSION_ID < 80100 ) { - $instance_property->setAccessible( true ); - } return $method->invoke( $this->registry, $icon_name, $icon_properties ); } From f455376d0e962299e4d2833cdc24e06165141605 Mon Sep 17 00:00:00 2001 From: Miguel Fonseca <150562+mcsf@users.noreply.github.com> Date: Tue, 24 Mar 2026 17:28:59 +0000 Subject: [PATCH 10/15] Fix test case to avoid name collisions `core/plus` is a real icon, so use the `test/` namespace instead. --- .../experimental/class-gutenberg-icons-registry-7-1-test.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/phpunit/experimental/class-gutenberg-icons-registry-7-1-test.php b/phpunit/experimental/class-gutenberg-icons-registry-7-1-test.php index 9fe32901a2f3fe..1e7c2f13d68969 100644 --- a/phpunit/experimental/class-gutenberg-icons-registry-7-1-test.php +++ b/phpunit/experimental/class-gutenberg-icons-registry-7-1-test.php @@ -97,7 +97,7 @@ public function data_invalid_icon_names() { return array( 'non-string name' => array( 1 ), 'no namespace' => array( 'plus' ), - 'uppercase characters' => array( 'Core/Plus' ), + 'uppercase characters' => array( 'Test/Plus' ), 'invalid characters' => array( 'test/_doing_it_wrong' ), ); } From 23ca8a28de58548c82934f99959afc84095100b5 Mon Sep 17 00:00:00 2001 From: Miguel Fonseca <150562+mcsf@users.noreply.github.com> Date: Tue, 24 Mar 2026 17:29:58 +0000 Subject: [PATCH 11/15] Actually test the cases in `data_invalid_icon_names` --- .../class-gutenberg-icons-registry-7-1-test.php | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/phpunit/experimental/class-gutenberg-icons-registry-7-1-test.php b/phpunit/experimental/class-gutenberg-icons-registry-7-1-test.php index 1e7c2f13d68969..73f8bf28180054 100644 --- a/phpunit/experimental/class-gutenberg-icons-registry-7-1-test.php +++ b/phpunit/experimental/class-gutenberg-icons-registry-7-1-test.php @@ -119,4 +119,21 @@ public function test_register_icon_twice() { $result2 = $this->register( $name, $settings ); $this->assertFalse( $result2 ); } + + /** + * Should fail to register icon with invalid names. + * + * @expectedIncorrectUsage Gutenberg_Icons_Registry_7_1::register + */ + public function test_register_invalid_name() { + foreach ( $this->data_invalid_icon_names() as $name ) { + $settings = array( + 'label' => 'Icon', + 'content' => '', + ); + + $result = $this->register( $name, $settings ); + $this->assertFalse( $result ); + } + } } From a7c0f37135b3d467890b40c029b9978a75bf145e Mon Sep 17 00:00:00 2001 From: Miguel Fonseca <150562+mcsf@users.noreply.github.com> Date: Tue, 24 Mar 2026 17:35:44 +0000 Subject: [PATCH 12/15] Fix comments --- .../class-gutenberg-icons-registry-7-1-test.php | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/phpunit/experimental/class-gutenberg-icons-registry-7-1-test.php b/phpunit/experimental/class-gutenberg-icons-registry-7-1-test.php index 73f8bf28180054..24bdca577d9d89 100644 --- a/phpunit/experimental/class-gutenberg-icons-registry-7-1-test.php +++ b/phpunit/experimental/class-gutenberg-icons-registry-7-1-test.php @@ -13,17 +13,11 @@ class Gutenberg_Icons_Registry_7_1_Test extends WP_UnitTestCase { */ private $registry; - /** - * Sets up the test fixture. - */ public function set_up() { parent::set_up(); $this->registry = Gutenberg_Icons_Registry_7_1::get_instance(); } - /** - * Tear down each test method. - */ public function tear_down() { $instance_property = new ReflectionProperty( Gutenberg_Icons_Registry_7_1::class, 'instance' ); @@ -44,7 +38,7 @@ public function tear_down() { } /** - * Invokes the Gutenberg_Icons_Registry_7_1::register method on the registry instance. + * Invokes Gutenberg_Icons_Registry_7_1::register despite it being private * * @param string $icon_name Icon name including namespace. * @param array $icon_properties Icon properties (label, content, filePath). @@ -58,7 +52,6 @@ private function register( $icon_name, $icon_properties ) { /** * Should reject invalid icon names. * - * @dataProvider data_invalid_icon_names * @expectedIncorrectUsage Gutenberg_Icons_Registry_7_1::register * * @param mixed $icon_name Icon name to test. @@ -123,6 +116,7 @@ public function test_register_icon_twice() { /** * Should fail to register icon with invalid names. * + * @dataProvider data_invalid_icon_names * @expectedIncorrectUsage Gutenberg_Icons_Registry_7_1::register */ public function test_register_invalid_name() { From ac6fe80f4060169d287e7f8fb268d72c63364fb6 Mon Sep 17 00:00:00 2001 From: Miguel Fonseca <150562+mcsf@users.noreply.github.com> Date: Tue, 24 Mar 2026 18:26:53 +0000 Subject: [PATCH 13/15] Remove test in favour of test_register_invalid_name --- .../class-gutenberg-icons-registry-7-1-test.php | 17 ----------------- 1 file changed, 17 deletions(-) diff --git a/phpunit/experimental/class-gutenberg-icons-registry-7-1-test.php b/phpunit/experimental/class-gutenberg-icons-registry-7-1-test.php index 24bdca577d9d89..68666682190e7a 100644 --- a/phpunit/experimental/class-gutenberg-icons-registry-7-1-test.php +++ b/phpunit/experimental/class-gutenberg-icons-registry-7-1-test.php @@ -49,23 +49,6 @@ private function register( $icon_name, $icon_properties ) { return $method->invoke( $this->registry, $icon_name, $icon_properties ); } - /** - * Should reject invalid icon names. - * - * @expectedIncorrectUsage Gutenberg_Icons_Registry_7_1::register - * - * @param mixed $icon_name Icon name to test. - */ - public function test_invalid_icon_names( $icon_name ) { - $settings = array( - 'label' => 'Icon', - 'content' => '', - ); - - $result = $this->register( $icon_name, $settings ); - $this->assertFalse( $result ); - } - /** * Should accept valid icon names. */ From 3be4b1a9dd29558b77504ce513c0195d1bf0e5cf Mon Sep 17 00:00:00 2001 From: im3dabasia Date: Mon, 30 Mar 2026 15:59:17 +0530 Subject: [PATCH 14/15] chore: Update fix feedbacks --- .../wordpress-7.1/class-gutenberg-icons-registry-7-1.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/compat/wordpress-7.1/class-gutenberg-icons-registry-7-1.php b/lib/compat/wordpress-7.1/class-gutenberg-icons-registry-7-1.php index ba7c5fbfa9a6be..727064c9b9e7a0 100644 --- a/lib/compat/wordpress-7.1/class-gutenberg-icons-registry-7-1.php +++ b/lib/compat/wordpress-7.1/class-gutenberg-icons-registry-7-1.php @@ -75,7 +75,7 @@ protected function register( $icon_name, $icon_properties ) { return false; } - if ( preg_match( '/[A-Z]+/', $icon_name ) ) { + if ( preg_match( '/[A-Z]/', $icon_name ) ) { _doing_it_wrong( __METHOD__, __( 'Icon names must not contain uppercase characters.' ), @@ -84,7 +84,7 @@ protected function register( $icon_name, $icon_properties ) { return false; } - $name_matcher = '/^[a-z0-9-]+\/[a-z0-9-]+$/'; + $name_matcher = '/^[a-z][a-z0-9-]*\/[a-z][a-z0-9-]*$/'; if ( ! preg_match( $name_matcher, $icon_name ) ) { _doing_it_wrong( __METHOD__, From e02cd8faabd633869375faf60194c8e6fb4f6f67 Mon Sep 17 00:00:00 2001 From: Miguel Fonseca <150562+mcsf@users.noreply.github.com> Date: Tue, 31 Mar 2026 16:08:32 +0100 Subject: [PATCH 15/15] Add missin ReflectionMethod::setAccessible for older PHPs --- .../class-gutenberg-icons-registry-7-1-test.php | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/phpunit/experimental/class-gutenberg-icons-registry-7-1-test.php b/phpunit/experimental/class-gutenberg-icons-registry-7-1-test.php index 68666682190e7a..89696277f4720a 100644 --- a/phpunit/experimental/class-gutenberg-icons-registry-7-1-test.php +++ b/phpunit/experimental/class-gutenberg-icons-registry-7-1-test.php @@ -46,6 +46,17 @@ public function tear_down() { */ private function register( $icon_name, $icon_properties ) { $method = new ReflectionMethod( $this->registry, 'register' ); + + /* + * ReflectionMethod::setAccessible is: + * - redundant as of 8.1.0, which made all properties accessible + * - deprecated as of 8.5.0 + * - needed until 8.1.0, as property `instance` is private + */ + if ( PHP_VERSION_ID < 80100 ) { + $method->setAccessible( true ); + } + return $method->invoke( $this->registry, $icon_name, $icon_properties ); }