Make WordPress Core


Ignore:
Timestamp:
11/06/2024 07:22:22 PM (15 months 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.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • 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.