Make WordPress Core

Changeset 59364


Ignore:
Timestamp:
11/06/2024 07:22:22 PM (5 weeks ago)
Author:
westonruter
Message:

HTML API: Improve private method name used by WP_HTML_Processor::next_token().

This renames the private _next_token method to next_visitable_token. It also removes irrelevant assertions from the unit test.

Follow-up to [59285].

Props dmsnell, jonsurrell, westonruter.
See #62269.

Location:
trunk
Files:
1 added
1 deleted
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/html-api/class-wp-html-processor.php

    r59285 r59364  
    617617     */
    618618    public function next_token(): bool {
    619         return $this->_next_token();
     619        return $this->next_visitable_token();
    620620    }
    621621
     
    628628     * WP_HTML_Tag_Processor instead.
    629629     *
    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.
    631636     *
    632637     * @access private
     
    634639     * @return bool
    635640     */
    636     private function _next_token(): bool {
     641    private function next_visitable_token(): bool {
    637642        $this->current_element = null;
    638643
     
    652657         */
    653658        if ( empty( $this->element_queue ) && $this->step() ) {
    654             return $this->_next_token();
     659            return $this->next_visitable_token();
    655660        }
    656661
     
    663668            }
    664669
    665             return empty( $this->element_queue ) ? false : $this->_next_token();
     670            return empty( $this->element_queue ) ? false : $this->next_visitable_token();
    666671        }
    667672
     
    674679         */
    675680        if ( 'root-node' === $this->current_element->token->bookmark_name ) {
    676             return $this->_next_token();
     681            return $this->next_visitable_token();
    677682        }
    678683
     
    686691        // Avoid sending close events for elements which don't expect a closing.
    687692        if ( $is_pop && ! $this->expects_closer( $this->current_element->token ) ) {
    688             return $this->_next_token();
     693            return $this->next_visitable_token();
    689694        }
    690695
  • trunk/tests/phpunit/tests/html-api/wpHtmlProcessor.php

    r59285 r59364  
    926926                    ''         => 1,
    927927                ),
    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                 ),
    939928            ),
    940929
     
    973962                    ''      => 1,
    974963                ),
    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                 ),
    988964            ),
    989965
     
    1022998                    ''        => 1,
    1023999                ),
    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                 ),
    10361000            ),
    10371001        );
     
    10411005     * Ensures that subclasses to WP_HTML_Processor can do bookkeeping by extending the next_token() method.
    10421006     *
    1043      * @ticket ?
     1007     * @ticket 62269
    10441008     * @dataProvider data_html_processor_with_extended_next_token
    10451009     */
    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 );
    10511014        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;
    10561016        }
    10571017
    10581018        $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 ) );
    10601019    }
    10611020}
Note: See TracChangeset for help on using the changeset viewer.