Changeset 59743 for branches/6.7
- Timestamp:
- 01/30/2025 10:30:13 PM (3 weeks ago)
- Location:
- branches/6.7
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/6.7
-
branches/6.7/src/wp-includes/class-wp-block-templates-registry.php
r59073 r59743 51 51 $error_message = __( 'Template names must not contain uppercase characters.' ); 52 52 $error_code = 'template_name_no_uppercase'; 53 } elseif ( ! preg_match( '/^[a-z0-9 -]+\/\/[a-z0-9-]+$/', $template_name ) ) {53 } elseif ( ! preg_match( '/^[a-z0-9_\-]+\/\/[a-z0-9_\-]+$/', $template_name ) ) { 54 54 $error_message = __( 'Template names must contain a namespace prefix. Example: my-plugin//my-custom-template' ); 55 55 $error_code = 'template_no_prefix'; -
branches/6.7/tests/phpunit/tests/block-templates/WpBlockTemplatesRegistry.php
r59073 r59743 268 268 $this->assertFalse( self::$registry->is_registered( $template_name ), 'Template should not be registered after unregistering.' ); 269 269 } 270 271 /** 272 * Data provider for test_template_name_validation. 273 * 274 * @return array[] Test data. 275 */ 276 public static function data_template_name_validation() { 277 return array( 278 'valid_simple_name' => array( 279 'my-plugin//my-template', 280 true, 281 'Valid template name with simple characters should be accepted', 282 ), 283 'valid_with_underscores' => array( 284 'my-plugin//my_template', 285 true, 286 'Template name with underscores should be accepted', 287 ), 288 'valid_cpt_archive' => array( 289 'my-plugin//archive-my_post_type', 290 true, 291 'Template name for CPT archive with underscore should be accepted', 292 ), 293 ); 294 } 295 296 /** 297 * Tests template name validation with various inputs. 298 * 299 * @ticket 62523 300 * 301 * @dataProvider data_template_name_validation 302 * 303 * @param string $template_name The template name to test. 304 * @param bool $expected Expected validation result. 305 * @param string $message Test assertion message. 306 */ 307 public function test_template_name_validation( $template_name, $expected, $message ) { 308 $result = self::$registry->register( $template_name, array() ); 309 310 if ( $expected ) { 311 self::$registry->unregister( $template_name ); 312 $this->assertNotWPError( $result, $message ); 313 } else { 314 $this->assertWPError( $result, $message ); 315 } 316 } 270 317 }
Note: See TracChangeset
for help on using the changeset viewer.