From 068d131a2eae7114083173ec248202067dc1f2e3 Mon Sep 17 00:00:00 2001 From: Felix Arntz Date: Wed, 15 Jan 2025 11:55:42 -0800 Subject: [PATCH 1/7] Relax allowed path restrictions for block metadata collections and make the allowed root list filterable. --- .../class-wp-block-metadata-registry.php | 123 +++++++++++------- 1 file changed, 78 insertions(+), 45 deletions(-) diff --git a/src/wp-includes/class-wp-block-metadata-registry.php b/src/wp-includes/class-wp-block-metadata-registry.php index 17bbf320d51b5..194b6be214c3f 100644 --- a/src/wp-includes/class-wp-block-metadata-registry.php +++ b/src/wp-includes/class-wp-block-metadata-registry.php @@ -38,20 +38,12 @@ class WP_Block_Metadata_Registry { private static $last_matched_collection = null; /** - * Stores the WordPress 'wp-includes' directory path. + * Stores the default allowed collection root paths. * - * @since 6.7.0 - * @var string|null - */ - private static $wpinc_dir = null; - - /** - * Stores the normalized WordPress plugin directory path. - * - * @since 6.7.0 - * @var string|null + * @since 6.8.0 + * @var string[]|null */ - private static $plugin_dir = null; + private static $default_allowed_collection_roots = null; /** * Registers a block metadata collection. @@ -92,29 +84,41 @@ class WP_Block_Metadata_Registry { public static function register_collection( $path, $manifest ) { $path = wp_normalize_path( rtrim( $path, '/' ) ); - $wpinc_dir = self::get_wpinc_dir(); - $plugin_dir = self::get_plugin_dir(); + $allowed_collection_roots = self::get_default_allowed_collection_roots(); + + /** + * Filters in which root directory paths block metadata collections are allowed. + * + * The default list encompasses the `wp-includes` directory, as well as the root directories for plugins, + * must-use plugins, and themes. This filter can be used to expand the list, e.g. to custom directories with + * symlinked plugins. + * + * Any block metadata collection that is registered must be within one of these directories. It must however + * not match any of these directories exactly, as then the collection may conflict with another one within the + * same root. + * + * @since 6.8.0 + * + * @param string[] $allowed_collection_roots List of allowed metadata collection root paths. + */ + $allowed_collection_roots = apply_filters( 'wp_allowed_block_metadata_collection_roots', $allowed_collection_roots ); + + $allowed_collection_roots = array_map( + static function ( $allowed_root ) { + return rtrim( $allowed_root, '/' ); + }, + $allowed_collection_roots + ); // Check if the path is valid: - if ( str_starts_with( $path, $plugin_dir ) ) { - // For plugins, ensure the path is within a specific plugin directory and not the base plugin directory. - $relative_path = substr( $path, strlen( $plugin_dir ) + 1 ); - $plugin_name = strtok( $relative_path, '/' ); - - if ( empty( $plugin_name ) || $plugin_name === $relative_path ) { - _doing_it_wrong( - __METHOD__, - __( 'Block metadata collections can only be registered for a specific plugin. The provided path is neither a core path nor a valid plugin path.' ), - '6.7.0' - ); - return false; - } - } elseif ( ! str_starts_with( $path, $wpinc_dir ) ) { - // If it's neither a plugin directory path nor within 'wp-includes', the path is invalid. + if ( ! self::is_valid_collection_path( $path, $allowed_collection_roots ) ) { _doing_it_wrong( __METHOD__, - __( 'Block metadata collections can only be registered for a specific plugin. The provided path is neither a core path nor a valid plugin path.' ), - '6.7.0' + sprintf( + __( 'Block metadata collections can only be registered within one of the following directories: %s' ), + esc_html( implode( wp_get_list_item_separator(), $allowed_collection_roots ) ) + ), + '6.8.0' ); return false; } @@ -244,30 +248,59 @@ private static function default_identifier_callback( $path ) { } /** - * Gets the WordPress 'wp-includes' directory path. + * Checks whether the given block metadata collection path is valid against the list of allowed collection roots. * - * @since 6.7.0 + * @since 6.8.0 * - * @return string The WordPress 'wp-includes' directory path. + * @param string $path Block metadata collection path, without trailing slash. + * @param string[] $allowed_collection_roots List of allowed collection root paths, without trailing slashes. + * @return bool True if the path is allowed, false otherwise. */ - private static function get_wpinc_dir() { - if ( ! isset( self::$wpinc_dir ) ) { - self::$wpinc_dir = wp_normalize_path( ABSPATH . WPINC ); + private static function is_valid_collection_path( $path, $allowed_collection_roots ) { + $matching_root_found = false; + + foreach ( $allowed_collection_roots as $allowed_root ) { + // If the path matches any allowed root exactly, it is invalid. + if ( $allowed_root === $path ) { + return false; + } + + // Otherwise, if the path is within any of the allowed roots, it is valid. + if ( str_starts_with( $allowed_root, $path ) ) { + $matching_root_found = true; + } } - return self::$wpinc_dir; + + return $matching_root_found; } /** - * Gets the normalized WordPress plugin directory path. + * Gets the default allowed collection root paths. * - * @since 6.7.0 + * @since 6.8.0 * - * @return string The normalized WordPress plugin directory path. + * @return string[] List of directory paths within which metadata collections are allowed. */ - private static function get_plugin_dir() { - if ( ! isset( self::$plugin_dir ) ) { - self::$plugin_dir = wp_normalize_path( WP_PLUGIN_DIR ); + private static function get_default_allowed_collection_roots() { + if ( isset( self::$default_allowed_collection_roots ) ) { + return self::$default_allowed_collection_roots; } - return self::$plugin_dir; + + $allowed_collection_roots = array( + wp_normalize_path( ABSPATH . WPINC ), + wp_normalize_path( WPMU_PLUGIN_DIR ), + wp_normalize_path( WP_PLUGIN_DIR ), + ); + + $theme_roots = get_theme_roots(); + if ( ! is_array( $theme_roots ) ) { + $theme_roots = array( $theme_roots ); + } + foreach ( $theme_roots as $theme_root ) { + $allowed_collection_roots[] = trailingslashit( wp_normalize_path( WP_CONTENT_DIR ) ) . ltrim( wp_normalize_path( $theme_root ), '/' ); + } + + self::$default_allowed_collection_roots = $allowed_collection_roots; + return self::$default_allowed_collection_roots; } } From f3c060c4b7be7fc7090b12d119cd7cb812d71863 Mon Sep 17 00:00:00 2001 From: Felix Arntz Date: Wed, 15 Jan 2025 13:06:12 -0800 Subject: [PATCH 2/7] Fix incorrect condition and ensure allowed collection roots are unique. --- .../class-wp-block-metadata-registry.php | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/src/wp-includes/class-wp-block-metadata-registry.php b/src/wp-includes/class-wp-block-metadata-registry.php index 194b6be214c3f..c0e9647d5cfd6 100644 --- a/src/wp-includes/class-wp-block-metadata-registry.php +++ b/src/wp-includes/class-wp-block-metadata-registry.php @@ -103,11 +103,13 @@ public static function register_collection( $path, $manifest ) { */ $allowed_collection_roots = apply_filters( 'wp_allowed_block_metadata_collection_roots', $allowed_collection_roots ); - $allowed_collection_roots = array_map( - static function ( $allowed_root ) { - return rtrim( $allowed_root, '/' ); - }, - $allowed_collection_roots + $allowed_collection_roots = array_unique( + array_map( + static function ( $allowed_root ) { + return rtrim( $allowed_root, '/' ); + }, + $allowed_collection_roots + ) ); // Check if the path is valid: @@ -266,7 +268,7 @@ private static function is_valid_collection_path( $path, $allowed_collection_roo } // Otherwise, if the path is within any of the allowed roots, it is valid. - if ( str_starts_with( $allowed_root, $path ) ) { + if ( str_starts_with( $path, $allowed_root ) ) { $matching_root_found = true; } } @@ -300,7 +302,7 @@ private static function get_default_allowed_collection_roots() { $allowed_collection_roots[] = trailingslashit( wp_normalize_path( WP_CONTENT_DIR ) ) . ltrim( wp_normalize_path( $theme_root ), '/' ); } - self::$default_allowed_collection_roots = $allowed_collection_roots; + self::$default_allowed_collection_roots = array_unique( $allowed_collection_roots ); return self::$default_allowed_collection_roots; } } From c717430673bc1e21aa0ddbc6bc04b7f9db7637f7 Mon Sep 17 00:00:00 2001 From: Felix Arntz Date: Wed, 15 Jan 2025 13:06:55 -0800 Subject: [PATCH 3/7] Add missing translator comment. --- src/wp-includes/class-wp-block-metadata-registry.php | 1 + 1 file changed, 1 insertion(+) diff --git a/src/wp-includes/class-wp-block-metadata-registry.php b/src/wp-includes/class-wp-block-metadata-registry.php index c0e9647d5cfd6..b0c7d607c7239 100644 --- a/src/wp-includes/class-wp-block-metadata-registry.php +++ b/src/wp-includes/class-wp-block-metadata-registry.php @@ -117,6 +117,7 @@ static function ( $allowed_root ) { _doing_it_wrong( __METHOD__, sprintf( + /* translators: %s: list of allowed collection roots */ __( 'Block metadata collections can only be registered within one of the following directories: %s' ), esc_html( implode( wp_get_list_item_separator(), $allowed_collection_roots ) ) ), From 63d4c9e2be8c6325f11f91798ac1a9f37263f3f5 Mon Sep 17 00:00:00 2001 From: Felix Arntz Date: Thu, 16 Jan 2025 09:52:28 -0800 Subject: [PATCH 4/7] Revise implementation to use collection roots only as a denylist, failing for exact matches and parent directories. --- .../class-wp-block-metadata-registry.php | 75 +++++++++-------- .../tests/blocks/wpBlockMetadataRegistry.php | 84 ++++++++++++++++++- 2 files changed, 120 insertions(+), 39 deletions(-) diff --git a/src/wp-includes/class-wp-block-metadata-registry.php b/src/wp-includes/class-wp-block-metadata-registry.php index b0c7d607c7239..6e038d9484983 100644 --- a/src/wp-includes/class-wp-block-metadata-registry.php +++ b/src/wp-includes/class-wp-block-metadata-registry.php @@ -43,7 +43,7 @@ class WP_Block_Metadata_Registry { * @since 6.8.0 * @var string[]|null */ - private static $default_allowed_collection_roots = null; + private static $default_collection_roots = null; /** * Registers a block metadata collection. @@ -84,42 +84,48 @@ class WP_Block_Metadata_Registry { public static function register_collection( $path, $manifest ) { $path = wp_normalize_path( rtrim( $path, '/' ) ); - $allowed_collection_roots = self::get_default_allowed_collection_roots(); + $collection_roots = self::get_default_collection_roots(); /** - * Filters in which root directory paths block metadata collections are allowed. + * Filters the root directory paths for block metadata collections. * - * The default list encompasses the `wp-includes` directory, as well as the root directories for plugins, - * must-use plugins, and themes. This filter can be used to expand the list, e.g. to custom directories with - * symlinked plugins. + * Any block metadata collection that is registered must not use any of these paths, or any parent directory + * path of them. Most commonly, block metadata collections should reside within one of these paths, though in + * some scenarios they may also reside in entirely different directories (e.g. in case of symlinked plugins). + * + * Example: + * * It is allowed to register a collection with path `WP_PLUGIN_DIR . '/my-plugin'`. + * * It is not allowed to register a collection with path `WP_PLUGIN_DIR`. + * * It is not allowed to register a collection with path `dirname( WP_PLUGIN_DIR )`. * - * Any block metadata collection that is registered must be within one of these directories. It must however - * not match any of these directories exactly, as then the collection may conflict with another one within the - * same root. + * The default list encompasses the `wp-includes` directory, as well as the root directories for plugins, + * must-use plugins, and themes. This filter can be used to expand the list, e.g. to custom directories that + * contain symlinked plugins, so that these root directories cannot be used themselves for a block metadata + * collection either. * * @since 6.8.0 * - * @param string[] $allowed_collection_roots List of allowed metadata collection root paths. + * @param string[] $collection_roots List of allowed metadata collection root paths. */ - $allowed_collection_roots = apply_filters( 'wp_allowed_block_metadata_collection_roots', $allowed_collection_roots ); + $collection_roots = apply_filters( 'wp_allowed_block_metadata_collection_roots', $collection_roots ); - $allowed_collection_roots = array_unique( + $collection_roots = array_unique( array_map( static function ( $allowed_root ) { return rtrim( $allowed_root, '/' ); }, - $allowed_collection_roots + $collection_roots ) ); // Check if the path is valid: - if ( ! self::is_valid_collection_path( $path, $allowed_collection_roots ) ) { + if ( ! self::is_valid_collection_path( $path, $collection_roots ) ) { _doing_it_wrong( __METHOD__, sprintf( /* translators: %s: list of allowed collection roots */ __( 'Block metadata collections can only be registered within one of the following directories: %s' ), - esc_html( implode( wp_get_list_item_separator(), $allowed_collection_roots ) ) + esc_html( implode( wp_get_list_item_separator(), $collection_roots ) ) ), '6.8.0' ); @@ -251,46 +257,45 @@ private static function default_identifier_callback( $path ) { } /** - * Checks whether the given block metadata collection path is valid against the list of allowed collection roots. + * Checks whether the given block metadata collection path is valid against the list of collection roots. * * @since 6.8.0 * - * @param string $path Block metadata collection path, without trailing slash. - * @param string[] $allowed_collection_roots List of allowed collection root paths, without trailing slashes. + * @param string $path Block metadata collection path, without trailing slash. + * @param string[] $collection_roots List of collection root paths, without trailing slashes. * @return bool True if the path is allowed, false otherwise. */ - private static function is_valid_collection_path( $path, $allowed_collection_roots ) { - $matching_root_found = false; - - foreach ( $allowed_collection_roots as $allowed_root ) { - // If the path matches any allowed root exactly, it is invalid. + private static function is_valid_collection_path( $path, $collection_roots ) { + foreach ( $collection_roots as $allowed_root ) { + // If the path matches any root exactly, it is invalid. if ( $allowed_root === $path ) { return false; } - // Otherwise, if the path is within any of the allowed roots, it is valid. - if ( str_starts_with( $path, $allowed_root ) ) { - $matching_root_found = true; + // If the path is a parent path of any of the roots, it is invalid. + if ( str_starts_with( $allowed_root, $path ) ) { + return false; } } - return $matching_root_found; + return true; } /** - * Gets the default allowed collection root paths. + * Gets the default collection root directory paths. * * @since 6.8.0 * * @return string[] List of directory paths within which metadata collections are allowed. */ - private static function get_default_allowed_collection_roots() { - if ( isset( self::$default_allowed_collection_roots ) ) { - return self::$default_allowed_collection_roots; + private static function get_default_collection_roots() { + if ( isset( self::$default_collection_roots ) ) { + return self::$default_collection_roots; } - $allowed_collection_roots = array( + $collection_roots = array( wp_normalize_path( ABSPATH . WPINC ), + wp_normalize_path( WP_CONTENT_DIR ), wp_normalize_path( WPMU_PLUGIN_DIR ), wp_normalize_path( WP_PLUGIN_DIR ), ); @@ -300,10 +305,10 @@ private static function get_default_allowed_collection_roots() { $theme_roots = array( $theme_roots ); } foreach ( $theme_roots as $theme_root ) { - $allowed_collection_roots[] = trailingslashit( wp_normalize_path( WP_CONTENT_DIR ) ) . ltrim( wp_normalize_path( $theme_root ), '/' ); + $collection_roots[] = trailingslashit( wp_normalize_path( WP_CONTENT_DIR ) ) . ltrim( wp_normalize_path( $theme_root ), '/' ); } - self::$default_allowed_collection_roots = array_unique( $allowed_collection_roots ); - return self::$default_allowed_collection_roots; + self::$default_collection_roots = array_unique( $collection_roots ); + return self::$default_collection_roots; } } diff --git a/tests/phpunit/tests/blocks/wpBlockMetadataRegistry.php b/tests/phpunit/tests/blocks/wpBlockMetadataRegistry.php index 3f0ec006b0a0a..9313d645e3f36 100644 --- a/tests/phpunit/tests/blocks/wpBlockMetadataRegistry.php +++ b/tests/phpunit/tests/blocks/wpBlockMetadataRegistry.php @@ -80,12 +80,88 @@ public function test_register_collection_with_invalid_plugin_path() { $this->assertFalse( $result, 'Invalid plugin path should not be registered' ); } - public function test_register_collection_with_non_existent_path() { - $non_existent_path = '/path/that/does/not/exist'; + public function test_register_collection_with_valid_muplugin_path() { + $plugin_path = WPMU_PLUGIN_DIR . '/my-plugin/blocks'; + $result = WP_Block_Metadata_Registry::register_collection( $plugin_path, $this->temp_manifest_file ); + $this->assertTrue( $result, 'Valid must-use plugin path should be registered successfully' ); + } + + public function test_register_collection_with_invalid_muplugin_path() { + $invalid_plugin_path = WPMU_PLUGIN_DIR; + + $this->setExpectedIncorrectUsage( 'WP_Block_Metadata_Registry::register_collection' ); + + $result = WP_Block_Metadata_Registry::register_collection( $invalid_plugin_path, $this->temp_manifest_file ); + $this->assertFalse( $result, 'Invalid must-use plugin path should not be registered' ); + } + + public function test_register_collection_with_valid_theme_path() { + $theme_path = WP_CONTENT_DIR . '/themes/my-theme/blocks'; + $result = WP_Block_Metadata_Registry::register_collection( $theme_path, $this->temp_manifest_file ); + $this->assertTrue( $result, 'Valid theme path should be registered successfully' ); + } + + public function test_register_collection_with_invalid_theme_path() { + $invalid_theme_path = WP_CONTENT_DIR . '/themes'; + + $this->setExpectedIncorrectUsage( 'WP_Block_Metadata_Registry::register_collection' ); + + $result = WP_Block_Metadata_Registry::register_collection( $invalid_theme_path, $this->temp_manifest_file ); + $this->assertFalse( $result, 'Invalid theme path should not be registered' ); + } + + public function test_register_collection_with_arbitrary_path() { + $arbitrary_path = '/var/arbitrary/path'; + $result = WP_Block_Metadata_Registry::register_collection( $arbitrary_path, $this->temp_manifest_file ); + $this->assertTrue( $result, 'Arbitrary path should be registered successfully' ); + } + + public function test_register_collection_with_arbitrary_path_and_collection_roots_filter() { + $arbitrary_path = '/var/arbitrary/path'; + add_filter( + 'wp_allowed_block_metadata_collection_roots', + static function ( $paths ) use ( $arbitrary_path ) { + $paths[] = $arbitrary_path; + return $paths; + } + ); + + $this->setExpectedIncorrectUsage( 'WP_Block_Metadata_Registry::register_collection' ); + + $result = WP_Block_Metadata_Registry::register_collection( $arbitrary_path, $this->temp_manifest_file ); + $this->assertFalse( $result, 'Arbitrary path should not be registered if it matches a collection root' ); + + $result = WP_Block_Metadata_Registry::register_collection( dirname( $arbitrary_path ), $this->temp_manifest_file ); + $this->assertFalse( $result, 'Arbitrary path should not be registered if it is a parent directory of a collection root' ); + + $result = WP_Block_Metadata_Registry::register_collection( $arbitrary_path . '/my-plugin/blocks', $this->temp_manifest_file ); + $this->assertTrue( $result, 'Arbitrary path should be registered successfully if it is within a collection root' ); + } + + public function test_register_collection_with_wp_content_parent_directory_path() { + $invalid_path = dirname( WP_CONTENT_DIR ); + + $this->setExpectedIncorrectUsage( 'WP_Block_Metadata_Registry::register_collection' ); + + $result = WP_Block_Metadata_Registry::register_collection( $invalid_path, $this->temp_manifest_file ); + $this->assertFalse( $result, 'Invalid path (parent directory of "wp-content") should not be registered' ); + } + + public function test_register_collection_with_wp_includes_parent_directory_path() { + $invalid_path = ABSPATH; + + $this->setExpectedIncorrectUsage( 'WP_Block_Metadata_Registry::register_collection' ); + + $result = WP_Block_Metadata_Registry::register_collection( $invalid_path, $this->temp_manifest_file ); + $this->assertFalse( $result, 'Invalid path (parent directory of "wp-includes") should not be registered' ); + } + + public function test_register_collection_with_non_existent_manifest() { + $non_existent_manifest = '/path/that/does/not/exist/block-manifest.php'; $this->setExpectedIncorrectUsage( 'WP_Block_Metadata_Registry::register_collection' ); - $result = WP_Block_Metadata_Registry::register_collection( $non_existent_path, $this->temp_manifest_file ); - $this->assertFalse( $result, 'Non-existent path should not be registered' ); + $result = WP_Block_Metadata_Registry::register_collection( '/var/arbitrary/path', $non_existent_manifest ); + $this->assertFalse( $result, 'Non-existent manifest should not be registered' ); } } From eb99af0a808761753cba339c1bdf32a9d59f2b5e Mon Sep 17 00:00:00 2001 From: Felix Arntz Date: Thu, 16 Jan 2025 10:01:59 -0800 Subject: [PATCH 5/7] Adjust now incorrect doing it wrong message. --- src/wp-includes/class-wp-block-metadata-registry.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/wp-includes/class-wp-block-metadata-registry.php b/src/wp-includes/class-wp-block-metadata-registry.php index 6e038d9484983..f208ce35ecd8c 100644 --- a/src/wp-includes/class-wp-block-metadata-registry.php +++ b/src/wp-includes/class-wp-block-metadata-registry.php @@ -124,7 +124,7 @@ static function ( $allowed_root ) { __METHOD__, sprintf( /* translators: %s: list of allowed collection roots */ - __( 'Block metadata collections can only be registered within one of the following directories: %s' ), + __( 'Block metadata collections cannot be registered as one of the following directories or their parent directories: %s' ), esc_html( implode( wp_get_list_item_separator(), $collection_roots ) ) ), '6.8.0' From 71cc8e4347fd57ab0eb07c401ff7d3d9067a1ca7 Mon Sep 17 00:00:00 2001 From: Felix Arntz Date: Wed, 29 Jan 2025 11:26:01 -0800 Subject: [PATCH 6/7] Update since annotations to 6.7.2. --- src/wp-includes/class-wp-block-metadata-registry.php | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/wp-includes/class-wp-block-metadata-registry.php b/src/wp-includes/class-wp-block-metadata-registry.php index f208ce35ecd8c..4b567d7d6f3bd 100644 --- a/src/wp-includes/class-wp-block-metadata-registry.php +++ b/src/wp-includes/class-wp-block-metadata-registry.php @@ -40,7 +40,7 @@ class WP_Block_Metadata_Registry { /** * Stores the default allowed collection root paths. * - * @since 6.8.0 + * @since 6.7.2 * @var string[]|null */ private static $default_collection_roots = null; @@ -103,7 +103,7 @@ public static function register_collection( $path, $manifest ) { * contain symlinked plugins, so that these root directories cannot be used themselves for a block metadata * collection either. * - * @since 6.8.0 + * @since 6.7.2 * * @param string[] $collection_roots List of allowed metadata collection root paths. */ @@ -127,7 +127,7 @@ static function ( $allowed_root ) { __( 'Block metadata collections cannot be registered as one of the following directories or their parent directories: %s' ), esc_html( implode( wp_get_list_item_separator(), $collection_roots ) ) ), - '6.8.0' + '6.7.2' ); return false; } @@ -259,7 +259,7 @@ private static function default_identifier_callback( $path ) { /** * Checks whether the given block metadata collection path is valid against the list of collection roots. * - * @since 6.8.0 + * @since 6.7.2 * * @param string $path Block metadata collection path, without trailing slash. * @param string[] $collection_roots List of collection root paths, without trailing slashes. @@ -284,7 +284,7 @@ private static function is_valid_collection_path( $path, $collection_roots ) { /** * Gets the default collection root directory paths. * - * @since 6.8.0 + * @since 6.7.2 * * @return string[] List of directory paths within which metadata collections are allowed. */ From 90fee84b115af679928465604bb118116dd0b5f1 Mon Sep 17 00:00:00 2001 From: Felix Arntz Date: Wed, 29 Jan 2025 11:28:13 -0800 Subject: [PATCH 7/7] Add ticket annotations to tests for the new bug fix. --- .../tests/blocks/wpBlockMetadataRegistry.php | 24 +++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/tests/phpunit/tests/blocks/wpBlockMetadataRegistry.php b/tests/phpunit/tests/blocks/wpBlockMetadataRegistry.php index 9313d645e3f36..bc62131c6aea0 100644 --- a/tests/phpunit/tests/blocks/wpBlockMetadataRegistry.php +++ b/tests/phpunit/tests/blocks/wpBlockMetadataRegistry.php @@ -80,12 +80,18 @@ public function test_register_collection_with_invalid_plugin_path() { $this->assertFalse( $result, 'Invalid plugin path should not be registered' ); } + /** + * @ticket 62140 + */ public function test_register_collection_with_valid_muplugin_path() { $plugin_path = WPMU_PLUGIN_DIR . '/my-plugin/blocks'; $result = WP_Block_Metadata_Registry::register_collection( $plugin_path, $this->temp_manifest_file ); $this->assertTrue( $result, 'Valid must-use plugin path should be registered successfully' ); } + /** + * @ticket 62140 + */ public function test_register_collection_with_invalid_muplugin_path() { $invalid_plugin_path = WPMU_PLUGIN_DIR; @@ -95,12 +101,18 @@ public function test_register_collection_with_invalid_muplugin_path() { $this->assertFalse( $result, 'Invalid must-use plugin path should not be registered' ); } + /** + * @ticket 62140 + */ public function test_register_collection_with_valid_theme_path() { $theme_path = WP_CONTENT_DIR . '/themes/my-theme/blocks'; $result = WP_Block_Metadata_Registry::register_collection( $theme_path, $this->temp_manifest_file ); $this->assertTrue( $result, 'Valid theme path should be registered successfully' ); } + /** + * @ticket 62140 + */ public function test_register_collection_with_invalid_theme_path() { $invalid_theme_path = WP_CONTENT_DIR . '/themes'; @@ -110,12 +122,18 @@ public function test_register_collection_with_invalid_theme_path() { $this->assertFalse( $result, 'Invalid theme path should not be registered' ); } + /** + * @ticket 62140 + */ public function test_register_collection_with_arbitrary_path() { $arbitrary_path = '/var/arbitrary/path'; $result = WP_Block_Metadata_Registry::register_collection( $arbitrary_path, $this->temp_manifest_file ); $this->assertTrue( $result, 'Arbitrary path should be registered successfully' ); } + /** + * @ticket 62140 + */ public function test_register_collection_with_arbitrary_path_and_collection_roots_filter() { $arbitrary_path = '/var/arbitrary/path'; add_filter( @@ -138,6 +156,9 @@ static function ( $paths ) use ( $arbitrary_path ) { $this->assertTrue( $result, 'Arbitrary path should be registered successfully if it is within a collection root' ); } + /** + * @ticket 62140 + */ public function test_register_collection_with_wp_content_parent_directory_path() { $invalid_path = dirname( WP_CONTENT_DIR ); @@ -147,6 +168,9 @@ public function test_register_collection_with_wp_content_parent_directory_path() $this->assertFalse( $result, 'Invalid path (parent directory of "wp-content") should not be registered' ); } + /** + * @ticket 62140 + */ public function test_register_collection_with_wp_includes_parent_directory_path() { $invalid_path = ABSPATH;