File tree Expand file tree Collapse file tree
tests/phpunit/tests/html-api Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -19,6 +19,44 @@ class WP_HTML_Template {
1919
2020 private array $ replacements = array ();
2121
22+ /**
23+ * Compiled placeholder metadata.
24+ *
25+ * Array of placeholder_name => array with keys:
26+ * - 'offsets': array of [start, length] pairs for each occurrence
27+ * - 'context': 'text' or 'attribute' (attribute takes precedence)
28+ *
29+ * @since 7.0.0
30+ * @var array|null
31+ */
32+ private ?array $ compiled = null ;
33+
34+ /**
35+ * Returns the compiled placeholder metadata.
36+ *
37+ * Triggers compilation if not already done.
38+ *
39+ * @since 7.0.0
40+ *
41+ * @return array Associative array of placeholder_name => metadata.
42+ */
43+ public function get_placeholders (): array {
44+ $ this ->compile ();
45+ return $ this ->compiled ;
46+ }
47+
48+ /**
49+ * Compiles the template to extract placeholder metadata.
50+ *
51+ * @since 7.0.0
52+ */
53+ private function compile (): void {
54+ if ( null !== $ this ->compiled ) {
55+ return ;
56+ }
57+ $ this ->compiled = array ();
58+ }
59+
2260 private function __construct ( string $ template_string , array $ replacements ) {
2361 $ this ->template_string = $ template_string ;
2462 $ this ->replacements = $ replacements ;
Original file line number Diff line number Diff line change @@ -754,4 +754,22 @@ public static function data_pre_element_leading_newline() {
754754 ),
755755 );
756756 }
757+
758+ /**
759+ * Verifies that get_placeholders returns placeholder metadata.
760+ *
761+ * @ticket 60229
762+ *
763+ * @covers ::get_placeholders
764+ */
765+ public function test_get_placeholders_returns_metadata () {
766+ $ template = T::from ( '<p class="</%class>"></%content></p> ' );
767+
768+ $ placeholders = $ template ->get_placeholders ();
769+
770+ $ this ->assertArrayHasKey ( 'class ' , $ placeholders );
771+ $ this ->assertArrayHasKey ( 'content ' , $ placeholders );
772+ $ this ->assertSame ( 'attribute ' , $ placeholders ['class ' ]['context ' ] );
773+ $ this ->assertSame ( 'text ' , $ placeholders ['content ' ]['context ' ] );
774+ }
757775}
You can’t perform that action at this time.
0 commit comments