Changeset 59364
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/html-api/class-wp-html-processor.php
r59285 r59364 617 617 */ 618 618 public function next_token(): bool { 619 return $this-> _next_token();619 return $this->next_visitable_token(); 620 620 } 621 621 … … 628 628 * WP_HTML_Tag_Processor instead. 629 629 * 630 * @since 6.7.1 Added for internal support; do not use. 630 * Note that this method may call itself recursively. This is why it is not 631 * implemented as {@see WP_HTML_Processor::next_token()}, which instead calls 632 * this method similarly to how {@see WP_HTML_Tag_Processor::next_token()} 633 * calls the {@see WP_HTML_Tag_Processor::base_class_next_token()} method. 634 * 635 * @since 6.7.1 Added for internal support. 631 636 * 632 637 * @access private … … 634 639 * @return bool 635 640 */ 636 private function _next_token(): bool {641 private function next_visitable_token(): bool { 637 642 $this->current_element = null; 638 643 … … 652 657 */ 653 658 if ( empty( $this->element_queue ) && $this->step() ) { 654 return $this-> _next_token();659 return $this->next_visitable_token(); 655 660 } 656 661 … … 663 668 } 664 669 665 return empty( $this->element_queue ) ? false : $this-> _next_token();670 return empty( $this->element_queue ) ? false : $this->next_visitable_token(); 666 671 } 667 672 … … 674 679 */ 675 680 if ( 'root-node' === $this->current_element->token->bookmark_name ) { 676 return $this-> _next_token();681 return $this->next_visitable_token(); 677 682 } 678 683 … … 686 691 // Avoid sending close events for elements which don't expect a closing. 687 692 if ( $is_pop && ! $this->expects_closer( $this->current_element->token ) ) { 688 return $this-> _next_token();693 return $this->next_visitable_token(); 689 694 } 690 695 -
trunk/tests/phpunit/tests/html-api/wpHtmlProcessor.php
r59285 r59364 926 926 '' => 1, 927 927 ), 928 'expected_xpaths' => array(929 0 => '/*[1][self::HTML]',930 1 => '/*[1][self::HTML]/*[1][self::HEAD]',931 2 => '/*[1][self::HTML]/*[1][self::HEAD]/*[1][self::META]',932 3 => '/*[1][self::HTML]/*[1][self::HEAD]/*[2][self::TITLE]',933 4 => '/*[1][self::HTML]/*[2][self::BODY]',934 5 => '/*[1][self::HTML]/*[2][self::BODY]/*[1][self::H1]',935 6 => '/*[1][self::HTML]/*[2][self::BODY]/*[2][self::IMG]',936 7 => '/*[1][self::HTML]/*[2][self::BODY]/*[3][self::P]',937 8 => '/*[1][self::HTML]/*[2][self::BODY]/*[4][self::FOOTER]',938 ),939 928 ), 940 929 … … 973 962 '' => 1, 974 963 ), 975 'expected_xpaths' => array(976 0 => '/*[1][self::HTML]',977 1 => '/*[1][self::HTML]/*[1][self::HEAD]',978 2 => '/*[1][self::HTML]/*[2][self::BODY]',979 3 => '/*[1][self::HTML]/*[2][self::BODY]/*[1][self::H1]',980 4 => '/*[1][self::HTML]/*[2][self::BODY]/*[2][self::P]',981 5 => '/*[1][self::HTML]/*[2][self::BODY]/*[3][self::P]',982 6 => '/*[1][self::HTML]/*[2][self::BODY]/*[4][self::P]',983 7 => '/*[1][self::HTML]/*[2][self::BODY]/*[5][self::UL]',984 8 => '/*[1][self::HTML]/*[2][self::BODY]/*[5][self::UL]/*[1][self::LI]',985 9 => '/*[1][self::HTML]/*[2][self::BODY]/*[5][self::UL]/*[2][self::LI]',986 10 => '/*[1][self::HTML]/*[2][self::BODY]/*[5][self::UL]/*[3][self::LI]',987 ),988 964 ), 989 965 … … 1022 998 '' => 1, 1023 999 ), 1024 'expected_xpaths' => array(1025 0 => '/*[1][self::HTML]',1026 1 => '/*[1][self::HTML]/*[1][self::HEAD]',1027 2 => '/*[1][self::HTML]/*[2][self::BODY]',1028 3 => '/*[1][self::HTML]/*[2][self::BODY]/*[1][self::P]',1029 4 => '/*[1][self::HTML]/*[2][self::BODY]/*[1][self::P]/*[1][self::STRONG]',1030 5 => '/*[1][self::HTML]/*[2][self::BODY]/*[1][self::P]/*[1][self::STRONG]/*[1][self::EM]',1031 6 => '/*[1][self::HTML]/*[2][self::BODY]/*[1][self::P]/*[1][self::STRONG]/*[1][self::EM]/*[1][self::STRIKE]',1032 7 => '/*[1][self::HTML]/*[2][self::BODY]/*[1][self::P]/*[1][self::STRONG]/*[1][self::EM]/*[1][self::STRIKE]/*[1][self::I]',1033 8 => '/*[1][self::HTML]/*[2][self::BODY]/*[1][self::P]/*[1][self::STRONG]/*[1][self::EM]/*[1][self::STRIKE]/*[1][self::I]/*[1][self::B]',1034 9 => '/*[1][self::HTML]/*[2][self::BODY]/*[1][self::P]/*[1][self::STRONG]/*[1][self::EM]/*[1][self::STRIKE]/*[1][self::I]/*[1][self::B]/*[1][self::U]',1035 ),1036 1000 ), 1037 1001 ); … … 1041 1005 * Ensures that subclasses to WP_HTML_Processor can do bookkeeping by extending the next_token() method. 1042 1006 * 1043 * @ticket ?1007 * @ticket 62269 1044 1008 * @dataProvider data_html_processor_with_extended_next_token 1045 1009 */ 1046 public function test_ensure_next_token_method_extensibility( $html, $expected_token_counts, $expected_xpaths ) { 1047 require_once DIR_TESTDATA . '/html-api/html-xpath-generating-processor.php'; 1048 1049 $processor = HTML_XPath_Generating_Processor::create_full_parser( $html ); 1050 $actual_xpaths = array(); 1010 public function test_ensure_next_token_method_extensibility( $html, $expected_token_counts ) { 1011 require_once DIR_TESTDATA . '/html-api/token-counting-html-processor.php'; 1012 1013 $processor = Token_Counting_HTML_Processor::create_full_parser( $html ); 1051 1014 while ( $processor->next_tag() ) { 1052 if ( ! $processor->is_tag_closer() ) { 1053 $processor->set_attribute( 'xpath', $processor->get_xpath() ); 1054 $actual_xpaths[] = $processor->get_xpath(); 1055 } 1015 continue; 1056 1016 } 1057 1017 1058 1018 $this->assertEquals( $expected_token_counts, $processor->token_seen_count, 'Snapshot: ' . var_export( $processor->token_seen_count, true ) ); 1059 $this->assertEquals( $expected_xpaths, $actual_xpaths, 'Snapshot: ' . var_export( $actual_xpaths, true ) );1060 1019 } 1061 1020 }
Note: See TracChangeset
for help on using the changeset viewer.