Changeset 56790
- Timestamp:
- 10/05/2023 10:40:48 PM (16 months ago)
- Location:
- trunk
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/html-api/class-wp-html-processor.php
r56702 r56790 40 40 * Example: 41 41 * 42 * $processor = WP_HTML_Processor::create Fragment( $html );42 * $processor = WP_HTML_Processor::create_fragment( $html ); 43 43 * if ( $processor->next_tag( array( 'breadcrumbs' => array( 'DIV', 'FIGURE', 'IMG' ) ) ) ) { 44 44 * $processor->add_class( 'responsive-image' ); … … 59 59 * when parsed, the return value from `get_breadcrumbs()` will always 60 60 * contain any implicit outermost elements. For example, when parsing 61 * with `create Fragment()` in the `BODY` context (the default), any61 * with `create_fragment()` in the `BODY` context (the default), any 62 62 * tag in the given HTML document will contain `array( 'HTML', 'BODY', … )` 63 63 * in its breadcrumbs. … … 240 240 * @return WP_HTML_Processor|null The created processor if successful, otherwise null. 241 241 */ 242 public static function create Fragment( $html, $context = '<body>', $encoding = 'UTF-8' ) {242 public static function create_fragment( $html, $context = '<body>', $encoding = 'UTF-8' ) { 243 243 if ( '<body>' !== $context || 'UTF-8' !== $encoding ) { 244 244 return null; … … 281 281 * @since 6.4.0 282 282 * 283 * @see WP_HTML_Processor::create Fragment()283 * @see WP_HTML_Processor::create_fragment() 284 284 * 285 285 * @param string $html HTML to process. … … 293 293 __METHOD__, 294 294 sprintf( 295 /* translators: %s: WP_HTML_Processor::create Fragment. */295 /* translators: %s: WP_HTML_Processor::create_fragment(). */ 296 296 __( 'Call %s to create an HTML Processor instead of calling the constructor directly.' ), 297 '<code>WP_HTML_Processor::create Fragment</code>'297 '<code>WP_HTML_Processor::create_fragment()</code>' 298 298 ), 299 299 '6.4.0' … … 325 325 * Example 326 326 * 327 * $processor = WP_HTML_Processor::create Fragment( '<template><strong><button><em><p><em>' );327 * $processor = WP_HTML_Processor::create_fragment( '<template><strong><button><em><p><em>' ); 328 328 * false === $processor->next_tag(); 329 329 * WP_HTML_Processor::ERROR_UNSUPPORTED === $processor->get_last_error(); … … 429 429 * Example: 430 430 * 431 * $processor = WP_HTML_Processor::create Fragment( '<div><span><figure><img></figure></span></div>' );431 * $processor = WP_HTML_Processor::create_fragment( '<div><span><figure><img></figure></span></div>' ); 432 432 * $processor->next_tag( 'img' ); 433 433 * true === $processor->matches_breadcrumbs( array( 'figure', 'img' ) ); … … 558 558 * Example 559 559 * 560 * $processor = WP_HTML_Processor::create Fragment( '<p><strong><em><img></em></strong></p>' );560 * $processor = WP_HTML_Processor::create_fragment( '<p><strong><em><img></em></strong></p>' ); 561 561 * $processor->next_tag( 'IMG' ); 562 562 * $processor->get_breadcrumbs() === array( 'HTML', 'BODY', 'P', 'STRONG', 'EM', 'IMG' ); … … 1440 1440 * @access private 1441 1441 */ 1442 const CONSTRUCTOR_UNLOCK_CODE = 'Use WP_HTML_Processor::create Fragmentinstead of calling the class constructor directly.';1442 const CONSTRUCTOR_UNLOCK_CODE = 'Use WP_HTML_Processor::create_fragment() instead of calling the class constructor directly.'; 1443 1443 } -
trunk/tests/phpunit/tests/html-api/wpHtmlProcessor.php
r56493 r56790 53 53 */ 54 54 public function test_get_tag_is_null_once_document_is_finished() { 55 $p = WP_HTML_Processor::create Fragment( '<div class="test">Test</div>' );55 $p = WP_HTML_Processor::create_fragment( '<div class="test">Test</div>' ); 56 56 $p->next_tag(); 57 57 $this->assertSame( 'DIV', $p->get_tag() ); … … 70 70 */ 71 71 public function test_stops_processing_after_unsupported_elements() { 72 $p = WP_HTML_Processor::create Fragment( '<p><x-not-supported></p><p></p>' );72 $p = WP_HTML_Processor::create_fragment( '<p><x-not-supported></p><p></p>' ); 73 73 $p->next_tag( 'P' ); 74 74 $this->assertFalse( $p->next_tag(), 'Stepped into a tag after encountering X-NOT-SUPPORTED element when it should have aborted.' ); … … 96 96 */ 97 97 public function test_clear_to_navigate_after_seeking() { 98 $p = WP_HTML_Processor::create Fragment( '<div one><strong></strong></div><p><strong two></strong></p>' );98 $p = WP_HTML_Processor::create_fragment( '<div one><strong></strong></div><p><strong two></strong></p>' ); 99 99 100 100 while ( $p->next_tag() ) { … … 145 145 */ 146 146 public function test_fails_to_reconstruct_formatting_elements() { 147 $p = WP_HTML_Processor::create Fragment( '<p><em>One<p><em>Two<p><em>Three<p><em>Four' );147 $p = WP_HTML_Processor::create_fragment( '<p><em>One<p><em>Two<p><em>Three<p><em>Four' ); 148 148 149 149 $this->assertTrue( $p->next_tag( 'EM' ), 'Could not find first EM.' ); -
trunk/tests/phpunit/tests/html-api/wpHtmlProcessorBreadcrumbs.php
r56702 r56790 24 24 */ 25 25 public function test_navigates_into_normative_html_for_supported_elements( $html, $tag_name ) { 26 $p = WP_HTML_Processor::create Fragment( $html );26 $p = WP_HTML_Processor::create_fragment( $html ); 27 27 28 28 $this->assertTrue( $p->step(), "Failed to step into supported {$tag_name} element." ); … … 86 86 */ 87 87 public function test_fails_when_encountering_unsupported_tag( $html ) { 88 $p = WP_HTML_Processor::create Fragment( $html );88 $p = WP_HTML_Processor::create_fragment( $html ); 89 89 90 90 $this->assertFalse( $p->step(), "Should not have stepped into unsupported {$p->get_tag()} element." ); … … 237 237 */ 238 238 public function test_fails_when_encountering_unsupported_markup( $html, $description ) { 239 $p = WP_HTML_Processor::create Fragment( $html );239 $p = WP_HTML_Processor::create_fragment( $html ); 240 240 241 241 while ( $p->step() && null === $p->get_attribute( 'supported' ) ) { … … 278 278 */ 279 279 public function test_finds_correct_tag_given_breadcrumbs( $html, $breadcrumbs, $n ) { 280 $p = WP_HTML_Processor::create Fragment( $html );280 $p = WP_HTML_Processor::create_fragment( $html ); 281 281 282 282 $p->next_tag( … … 304 304 */ 305 305 public function test_reports_correct_breadcrumbs_for_html( $html, $breadcrumbs, $ignored_n ) { 306 $p = WP_HTML_Processor::create Fragment( $html );306 $p = WP_HTML_Processor::create_fragment( $html ); 307 307 308 308 while ( $p->next_tag() && null === $p->get_attribute( 'target' ) ) { … … 363 363 */ 364 364 public function test_reports_if_tag_matches_breadcrumbs_of_various_specificity( $html_with_target_node, $breadcrumbs, $should_match ) { 365 $processor = WP_HTML_Processor::create Fragment( $html_with_target_node );365 $processor = WP_HTML_Processor::create_fragment( $html_with_target_node ); 366 366 while ( $processor->next_tag() && null === $processor->get_attribute( 'target' ) ) { 367 367 continue; … … 421 421 */ 422 422 public function test_can_modify_attributes_after_finding_tag() { 423 $p = WP_HTML_Processor::create Fragment( '<div><figure><img><figcaption>test</figcaption></figure>' );423 $p = WP_HTML_Processor::create_fragment( '<div><figure><img><figcaption>test</figcaption></figure>' ); 424 424 425 425 $this->assertTrue( $p->next_tag( array( 'breadcrumbs' => array( 'figcaption' ) ) ), 'Unable to find given tag.' ); … … 439 439 */ 440 440 public function test_can_query_an_element_by_tag_name() { 441 $p = WP_HTML_Processor::create Fragment( '<div><DIV><strong><img></strong></DIV>' );441 $p = WP_HTML_Processor::create_fragment( '<div><DIV><strong><img></strong></DIV>' ); 442 442 $p->next_tag( 'IMG' ); 443 443 $p->set_attribute( 'loading', 'lazy' ); … … 456 456 */ 457 457 public function test_can_seek_back_and_forth() { 458 $p = WP_HTML_Processor::create Fragment( '<div><p one><div><p><div two><p><div><p><div><p three>' );458 $p = WP_HTML_Processor::create_fragment( '<div><p one><div><p><div two><p><div><p><div><p three>' ); 459 459 460 460 // Find first tag of interest. -
trunk/tests/phpunit/tests/html-api/wpHtmlProcessorSemanticRules.php
r56380 r56790 28 28 */ 29 29 public function test_in_body_skips_unexpected_button_closer() { 30 $p = WP_HTML_Processor::create Fragment( '<div>Test</button></div>' );30 $p = WP_HTML_Processor::create_fragment( '<div>Test</button></div>' ); 31 31 32 32 $p->step(); … … 53 53 */ 54 54 public function test_in_body_button_with_no_button_in_scope() { 55 $p = WP_HTML_Processor::create Fragment( '<div><p>Click the button <button one>here</button>!</p></div><button two>not here</button>' );55 $p = WP_HTML_Processor::create_fragment( '<div><p>Click the button <button one>here</button>!</p></div><button two>not here</button>' ); 56 56 57 57 $this->assertTrue( $p->next_tag( 'BUTTON' ), 'Could not find expected first button.' ); … … 80 80 */ 81 81 public function test_in_body_button_with_button_in_scope_as_parent() { 82 $p = WP_HTML_Processor::create Fragment( '<div><p>Click the button <button one>almost<button two>here</button>!</p></div><button three>not here</button>' );82 $p = WP_HTML_Processor::create_fragment( '<div><p>Click the button <button one>almost<button two>here</button>!</p></div><button three>not here</button>' ); 83 83 84 84 $this->assertTrue( $p->next_tag( 'BUTTON' ), 'Could not find expected first button.' ); … … 115 115 */ 116 116 public function test_in_body_button_with_button_in_scope_as_ancestor() { 117 $p = WP_HTML_Processor::create Fragment( '<div><button one><p>Click the button <span><button two>here</button>!</span></p></div><button three>not here</button>' );117 $p = WP_HTML_Processor::create_fragment( '<div><button one><p>Click the button <span><button two>here</button>!</span></p></div><button three>not here</button>' ); 118 118 119 119 // This button finds itself normally nesting inside the DIV. … … 150 150 */ 151 151 public function test_in_body_any_other_end_tag_with_unclosed_special_element() { 152 $p = WP_HTML_Processor::create Fragment( '<div><span><p></span><div>' );152 $p = WP_HTML_Processor::create_fragment( '<div><span><p></span><div>' ); 153 153 154 154 $p->next_tag( 'P' ); … … 173 173 */ 174 174 public function test_in_body_any_other_end_tag_with_unclosed_non_special_element() { 175 $p = WP_HTML_Processor::create Fragment( '<div><span><code></span><div>' );175 $p = WP_HTML_Processor::create_fragment( '<div><span><code></span><div>' ); 176 176 177 177 $p->next_tag( 'CODE' ); -
trunk/tests/phpunit/tests/html-api/wpHtmlSupportRequiredHtmlProcessor.php
r56331 r56790 43 43 */ 44 44 private function ensure_support_is_added_everywhere( $tag_name ) { 45 $p = WP_HTML_Processor::create Fragment( "<$tag_name>" );45 $p = WP_HTML_Processor::create_fragment( "<$tag_name>" ); 46 46 47 47 $this->assertFalse( $p->step(), "Must support terminating elements in specific scope check before adding support for the {$tag_name} element." ); -
trunk/tests/phpunit/tests/html-api/wpHtmlSupportRequiredOpenElements.php
r56380 r56790 45 45 */ 46 46 private function ensure_support_is_added_everywhere( $tag_name ) { 47 $p = WP_HTML_Processor::create Fragment( "<$tag_name>" );47 $p = WP_HTML_Processor::create_fragment( "<$tag_name>" ); 48 48 49 49 $this->assertFalse( $p->step(), "Must support terminating elements in specific scope check before adding support for the {$tag_name} element." );
Note: See TracChangeset
for help on using the changeset viewer.