Make WordPress Core

Changeset 57508


Ignore:
Timestamp:
02/01/2024 01:00:56 AM (9 months ago)
Author:
dmsnell
Message:

HTML API: Test cleanup

Rename $p variable to $processor in tests for clarity.

Use static data providers. A mix of static and non-static data providers were
used in HTML API tests. Data providers are required to be static in the next
PHPUnit version and there's no harm in using them consistently now.

Follow-up to [57507]

Props jonsurrell
See #59647

Location:
trunk/tests/phpunit/tests/html-api
Files:
9 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/tests/html-api/wpHtmlProcessor.php

    r57507 r57508  
    5353     */
    5454    public function test_get_tag_is_null_once_document_is_finished() {
    55         $p = WP_HTML_Processor::create_fragment( '<div class="test">Test</div>' );
    56         $p->next_tag();
    57         $this->assertSame( 'DIV', $p->get_tag() );
    58 
    59         $this->assertFalse( $p->next_tag() );
    60         $this->assertNull( $p->get_tag() );
     55        $processor = WP_HTML_Processor::create_fragment( '<div class="test">Test</div>' );
     56        $processor->next_tag();
     57        $this->assertSame( 'DIV', $processor->get_tag() );
     58
     59        $this->assertFalse( $processor->next_tag() );
     60        $this->assertNull( $processor->get_tag() );
    6161    }
    6262
     
    7878     */
    7979    public function test_clear_to_navigate_after_seeking() {
    80         $p = WP_HTML_Processor::create_fragment( '<div one><strong></strong></div><p><strong two></strong></p>' );
    81 
    82         while ( $p->next_tag() ) {
     80        $processor = WP_HTML_Processor::create_fragment( '<div one><strong></strong></div><p><strong two></strong></p>' );
     81
     82        while ( $processor->next_tag() ) {
    8383            // Create a bookmark before entering a stack of elements and formatting elements.
    84             if ( null !== $p->get_attribute( 'one' ) ) {
    85                 $this->assertTrue( $p->set_bookmark( 'one' ) );
     84            if ( null !== $processor->get_attribute( 'one' ) ) {
     85                $this->assertTrue( $processor->set_bookmark( 'one' ) );
    8686                continue;
    8787            }
    8888
    8989            // Create a bookmark inside of that stack.
    90             if ( null !== $p->get_attribute( 'two' ) ) {
    91                 $p->set_bookmark( 'two' );
     90            if ( null !== $processor->get_attribute( 'two' ) ) {
     91                $processor->set_bookmark( 'two' );
    9292                break;
    9393            }
     
    9595
    9696        // Ensure that it's possible to seek back to the outside location.
    97         $this->assertTrue( $p->seek( 'one' ), 'Could not seek to earlier-seen location.' );
    98         $this->assertSame( 'DIV', $p->get_tag(), "Should have jumped back to DIV but found {$p->get_tag()} instead." );
     97        $this->assertTrue( $processor->seek( 'one' ), 'Could not seek to earlier-seen location.' );
     98        $this->assertSame( 'DIV', $processor->get_tag(), "Should have jumped back to DIV but found {$processor->get_tag()} instead." );
    9999
    100100        /*
     
    102102         * If it were, then the first STRONG element, inside the outer DIV would match the next call.
    103103         */
    104         $this->assertTrue( $p->next_tag( array( 'breadcrumbs' => array( 'P', 'STRONG' ) ) ), 'Failed to find given location after seeking.' );
     104        $this->assertTrue( $processor->next_tag( array( 'breadcrumbs' => array( 'P', 'STRONG' ) ) ), 'Failed to find given location after seeking.' );
    105105
    106106        // Only if the stack is properly managed will the processor advance to the inner STRONG element.
    107         $this->assertTrue( $p->get_attribute( 'two' ), "Found the wrong location given the breadcrumbs, at {$p->get_tag()}." );
     107        $this->assertTrue( $processor->get_attribute( 'two' ), "Found the wrong location given the breadcrumbs, at {$processor->get_tag()}." );
    108108
    109109        // Ensure that in seeking backwards the processor reports the correct full set of breadcrumbs.
    110         $this->assertTrue( $p->seek( 'one' ), 'Failed to jump back to first bookmark.' );
    111         $this->assertSame( array( 'HTML', 'BODY', 'DIV' ), $p->get_breadcrumbs(), 'Found wrong set of breadcrumbs navigating to node "one".' );
     110        $this->assertTrue( $processor->seek( 'one' ), 'Failed to jump back to first bookmark.' );
     111        $this->assertSame( array( 'HTML', 'BODY', 'DIV' ), $processor->get_breadcrumbs(), 'Found wrong set of breadcrumbs navigating to node "one".' );
    112112
    113113        // Ensure that in seeking forwards the processor reports the correct full set of breadcrumbs.
    114         $this->assertTrue( $p->seek( 'two' ), 'Failed to jump forward to second bookmark.' );
    115         $this->assertTrue( $p->get_attribute( 'two' ), "Found the wrong location given the bookmark, at {$p->get_tag()}." );
    116 
    117         $this->assertSame( array( 'HTML', 'BODY', 'P', 'STRONG' ), $p->get_breadcrumbs(), 'Found wrong set of bookmarks navigating to node "two".' );
     114        $this->assertTrue( $processor->seek( 'two' ), 'Failed to jump forward to second bookmark.' );
     115        $this->assertTrue( $processor->get_attribute( 'two' ), "Found the wrong location given the bookmark, at {$processor->get_tag()}." );
     116
     117        $this->assertSame( array( 'HTML', 'BODY', 'P', 'STRONG' ), $processor->get_breadcrumbs(), 'Found wrong set of bookmarks navigating to node "two".' );
    118118    }
    119119
     
    127127     */
    128128    public function test_fails_to_reconstruct_formatting_elements() {
    129         $p = WP_HTML_Processor::create_fragment( '<p><em>One<p><em>Two<p><em>Three<p><em>Four' );
    130 
    131         $this->assertTrue( $p->next_tag( 'EM' ), 'Could not find first EM.' );
    132         $this->assertFalse( $p->next_tag( 'EM' ), 'Should have aborted before finding second EM as it required reconstructing the first EM.' );
     129        $processor = WP_HTML_Processor::create_fragment( '<p><em>One<p><em>Two<p><em>Three<p><em>Four' );
     130
     131        $this->assertTrue( $processor->next_tag( 'EM' ), 'Could not find first EM.' );
     132        $this->assertFalse( $processor->next_tag( 'EM' ), 'Should have aborted before finding second EM as it required reconstructing the first EM.' );
    133133    }
    134134
     
    247247     * @return array[]
    248248     */
    249     public function data_void_tags() {
     249    public static function data_void_tags() {
    250250        return array(
    251251            'AREA'   => array( 'AREA' ),
     
    291291     * @return array[]
    292292     */
    293     public function data_unsupported_special_in_body_tags() {
     293    public static function data_unsupported_special_in_body_tags() {
    294294        return array(
    295295            'APPLET'    => array( 'APPLET' ),
  • trunk/tests/phpunit/tests/html-api/wpHtmlProcessorBreadcrumbs.php

    r57348 r57508  
    2424     */
    2525    public function test_navigates_into_normative_html_for_supported_elements( $html, $tag_name ) {
    26         $p = WP_HTML_Processor::create_fragment( $html );
    27 
    28         $this->assertTrue( $p->step(), "Failed to step into supported {$tag_name} element." );
    29         $this->assertSame( $tag_name, $p->get_tag(), "Misread {$tag_name} as a {$p->get_tag()} element." );
     26        $processor = WP_HTML_Processor::create_fragment( $html );
     27
     28        $this->assertTrue( $processor->step(), "Failed to step into supported {$tag_name} element." );
     29        $this->assertSame( $tag_name, $processor->get_tag(), "Misread {$tag_name} as a {$processor->get_tag()} element." );
    3030    }
    3131
     
    3535     * @return array[]
    3636     */
    37     public function data_single_tag_of_supported_elements() {
     37    public static function data_single_tag_of_supported_elements() {
    3838        $supported_elements = array(
    3939            'A',
     
    156156     */
    157157    public function test_fails_when_encountering_unsupported_tag( $html ) {
    158         $p = WP_HTML_Processor::create_fragment( $html );
    159 
    160         $this->assertFalse( $p->step(), "Should not have stepped into unsupported {$p->get_tag()} element." );
     158        $processor = WP_HTML_Processor::create_fragment( $html );
     159
     160        $this->assertFalse( $processor->step(), "Should not have stepped into unsupported {$processor->get_tag()} element." );
    161161    }
    162162
     
    166166     * @return array[]
    167167     */
    168     public function data_unsupported_elements() {
     168    public static function data_unsupported_elements() {
    169169        $unsupported_elements = array(
    170170            'APPLET', // Deprecated.
     
    230230     */
    231231    public function test_fails_when_encountering_unsupported_markup( $html, $description ) {
    232         $p = WP_HTML_Processor::create_fragment( $html );
    233 
    234         while ( $p->step() && null === $p->get_attribute( 'supported' ) ) {
     232        $processor = WP_HTML_Processor::create_fragment( $html );
     233
     234        while ( $processor->step() && null === $processor->get_attribute( 'supported' ) ) {
    235235            continue;
    236236        }
    237237
    238         $this->assertTrue( $p->get_attribute( 'supported' ), 'Did not find required supported element.' );
    239         $this->assertFalse( $p->step(), "Didn't properly reject unsupported markup: {$description}" );
     238        $this->assertTrue( $processor->get_attribute( 'supported' ), 'Did not find required supported element.' );
     239        $this->assertFalse( $processor->step(), "Didn't properly reject unsupported markup: {$description}" );
    240240    }
    241241
     
    245245     * @return array[]
    246246     */
    247     public function data_unsupported_markup() {
     247    public static function data_unsupported_markup() {
    248248        return array(
    249249            'A with formatting following unclosed A' => array(
     
    271271     */
    272272    public function test_finds_correct_tag_given_breadcrumbs( $html, $breadcrumbs, $n ) {
    273         $p = WP_HTML_Processor::create_fragment( $html );
    274 
    275         $p->next_tag(
     273        $processor = WP_HTML_Processor::create_fragment( $html );
     274
     275        $processor->next_tag(
    276276            array(
    277277                'breadcrumbs'  => $breadcrumbs,
     
    280280        );
    281281
    282         $this->assertNotNull( $p->get_tag(), 'Failed to find target node.' );
    283         $this->assertTrue( $p->get_attribute( 'target' ), "Found {$p->get_tag()} element didn't contain the necessary 'target' attribute." );
     282        $this->assertNotNull( $processor->get_tag(), 'Failed to find target node.' );
     283        $this->assertTrue( $processor->get_attribute( 'target' ), "Found {$processor->get_tag()} element didn't contain the necessary 'target' attribute." );
    284284    }
    285285
     
    296296     */
    297297    public function test_reports_correct_breadcrumbs_for_html( $html, $breadcrumbs, $ignored_n ) {
    298         $p = WP_HTML_Processor::create_fragment( $html );
    299 
    300         while ( $p->next_tag() && null === $p->get_attribute( 'target' ) ) {
     298        $processor = WP_HTML_Processor::create_fragment( $html );
     299
     300        while ( $processor->next_tag() && null === $processor->get_attribute( 'target' ) ) {
    301301            continue;
    302302        }
    303303
    304         $this->assertNotNull( $p->get_tag(), 'Failed to find the target node.' );
    305         $this->assertSame( $breadcrumbs, $p->get_breadcrumbs(), 'Found the wrong path from the root of the HTML document to the target node.' );
     304        $this->assertNotNull( $processor->get_tag(), 'Failed to find the target node.' );
     305        $this->assertSame( $breadcrumbs, $processor->get_breadcrumbs(), 'Found the wrong path from the root of the HTML document to the target node.' );
    306306    }
    307307
     
    311311     * @return array[]
    312312     */
    313     public function data_html_target_with_breadcrumbs() {
     313    public static function data_html_target_with_breadcrumbs() {
    314314        return array(
    315315            'Simple IMG tag'                        => array( '<img target>', array( 'HTML', 'BODY', 'IMG' ), 1 ),
     
    394394     * @return array[].
    395395     */
    396     public function data_html_with_breadcrumbs_of_various_specificity() {
     396    public static function data_html_with_breadcrumbs_of_various_specificity() {
    397397        return array(
    398398            // Test with void elements.
     
    434434     */
    435435    public function test_remains_stable_when_editing_attributes() {
    436         $p = WP_HTML_Processor::create_fragment( '<div><button>First<button><b here>Second' );
    437         $p->next_tag( array( 'breadcrumbs' => array( 'BUTTON', 'B' ) ) );
     436        $processor = WP_HTML_Processor::create_fragment( '<div><button>First<button><b here>Second' );
     437        $processor->next_tag( array( 'breadcrumbs' => array( 'BUTTON', 'B' ) ) );
    438438
    439439        $this->assertSame(
    440440            array( 'HTML', 'BODY', 'DIV', 'BUTTON', 'B' ),
    441             $p->get_breadcrumbs(),
     441            $processor->get_breadcrumbs(),
    442442            'Found the wrong nested structure at the matched tag.'
    443443        );
    444444
    445         $p->set_attribute( 'a-name', 'a-value' );
     445        $processor->set_attribute( 'a-name', 'a-value' );
    446446
    447447        $this->assertTrue(
    448             $p->get_attribute( 'here' ),
     448            $processor->get_attribute( 'here' ),
    449449            'Should have found the B tag but could not find expected "here" attribute.'
    450450        );
     
    452452        $this->assertSame(
    453453            array( 'HTML', 'BODY', 'DIV', 'BUTTON', 'B' ),
    454             $p->get_breadcrumbs(),
     454            $processor->get_breadcrumbs(),
    455455            'Found the wrong nested structure at the matched tag.'
    456456        );
    457457
    458         $p->get_updated_html();
     458        $processor->get_updated_html();
    459459
    460460        $this->assertTrue(
    461             $p->get_attribute( 'here' ),
     461            $processor->get_attribute( 'here' ),
    462462            'Should have stayed at the B tag but could not find expected "here" attribute.'
    463463        );
     
    465465        $this->assertSame(
    466466            array( 'HTML', 'BODY', 'DIV', 'BUTTON', 'B' ),
    467             $p->get_breadcrumbs(),
     467            $processor->get_breadcrumbs(),
    468468            'Found the wrong nested structure at the matched tag after updating attributes.'
    469469        );
     
    480480     */
    481481    public function test_can_modify_attributes_after_finding_tag() {
    482         $p = WP_HTML_Processor::create_fragment( '<div><figure><img><figcaption>test</figcaption></figure>' );
    483 
    484         $this->assertTrue( $p->next_tag( array( 'breadcrumbs' => array( 'figcaption' ) ) ), 'Unable to find given tag.' );
    485 
    486         $p->set_attribute( 'found-it', true );
    487         $this->assertSame( '<div><figure><img><figcaption found-it>test</figcaption></figure>', $p->get_updated_html() );
     482        $processor = WP_HTML_Processor::create_fragment( '<div><figure><img><figcaption>test</figcaption></figure>' );
     483
     484        $this->assertTrue( $processor->next_tag( array( 'breadcrumbs' => array( 'figcaption' ) ) ), 'Unable to find given tag.' );
     485
     486        $processor->set_attribute( 'found-it', true );
     487        $this->assertSame( '<div><figure><img><figcaption found-it>test</figcaption></figure>', $processor->get_updated_html() );
    488488    }
    489489
     
    498498     */
    499499    public function test_can_query_an_element_by_tag_name() {
    500         $p = WP_HTML_Processor::create_fragment( '<div><DIV><strong><img></strong></DIV>' );
    501         $p->next_tag( 'IMG' );
    502         $p->set_attribute( 'loading', 'lazy' );
    503 
    504         $this->assertSame( '<div><DIV><strong><img loading="lazy"></strong></DIV>', $p->get_updated_html() );
     500        $processor = WP_HTML_Processor::create_fragment( '<div><DIV><strong><img></strong></DIV>' );
     501        $processor->next_tag( 'IMG' );
     502        $processor->set_attribute( 'loading', 'lazy' );
     503
     504        $this->assertSame( '<div><DIV><strong><img loading="lazy"></strong></DIV>', $processor->get_updated_html() );
    505505    }
    506506
     
    515515     */
    516516    public function test_can_seek_back_and_forth() {
    517         $p = WP_HTML_Processor::create_fragment(
     517        $processor = WP_HTML_Processor::create_fragment(
    518518            <<<'HTML'
    519519<div>text<p one>more stuff<div><![CDATA[this is not real CDATA]]><p><!-- hi --><div two><p><div><p>three comes soon<div><p three>' );
     
    522522
    523523        // Find first tag of interest.
    524         while ( $p->next_tag() && null === $p->get_attribute( 'one' ) ) {
     524        while ( $processor->next_tag() && null === $processor->get_attribute( 'one' ) ) {
    525525            continue;
    526526        }
    527         $p->set_bookmark( 'first' );
     527        $processor->set_bookmark( 'first' );
    528528
    529529        // Find second tag of interest.
    530         while ( $p->next_tag() && null === $p->get_attribute( 'two' ) ) {
     530        while ( $processor->next_tag() && null === $processor->get_attribute( 'two' ) ) {
    531531            continue;
    532532        }
    533         $p->set_bookmark( 'second' );
     533        $processor->set_bookmark( 'second' );
    534534
    535535        // Find third tag of interest.
    536         while ( $p->next_tag() && null === $p->get_attribute( 'three' ) ) {
     536        while ( $processor->next_tag() && null === $processor->get_attribute( 'three' ) ) {
    537537            continue;
    538538        }
    539         $p->set_bookmark( 'third' );
     539        $processor->set_bookmark( 'third' );
    540540
    541541        // Seek backwards.
    542         $p->seek( 'first' );
     542        $processor->seek( 'first' );
    543543
    544544        // Seek forwards. If the current token isn't also updated this could appear like a backwards seek.
    545         $p->seek( 'second' );
    546         $this->assertTrue( $p->get_attribute( 'two' ) );
     545        $processor->seek( 'second' );
     546        $this->assertTrue( $processor->get_attribute( 'two' ) );
    547547    }
    548548}
  • trunk/tests/phpunit/tests/html-api/wpHtmlProcessorSemanticRules.php

    r57316 r57508  
    8080     * @return array[].
    8181     */
    82     public function data_article_container_group() {
     82    public static function data_article_container_group() {
    8383        $group = array();
    8484
     
    123123     */
    124124    public function test_in_body_skips_unexpected_button_closer() {
    125         $p = WP_HTML_Processor::create_fragment( '<div>Test</button></div>' );
    126 
    127         $p->step();
    128         $this->assertSame( 'DIV', $p->get_tag(), 'Did not stop at initial DIV tag.' );
    129         $this->assertFalse( $p->is_tag_closer(), 'Did not find that initial DIV tag is an opener.' );
     125        $processor = WP_HTML_Processor::create_fragment( '<div>Test</button></div>' );
     126
     127        $processor->step();
     128        $this->assertSame( 'DIV', $processor->get_tag(), 'Did not stop at initial DIV tag.' );
     129        $this->assertFalse( $processor->is_tag_closer(), 'Did not find that initial DIV tag is an opener.' );
    130130
    131131        /*
     
    133133         * It should be ignored as there's no BUTTON to close.
    134134         */
    135         $this->assertTrue( $p->step(), 'Found no further tags when it should have found the closing DIV' );
    136         $this->assertSame( 'DIV', $p->get_tag(), "Did not skip unexpected BUTTON; stopped at {$p->get_tag()}." );
    137         $this->assertTrue( $p->is_tag_closer(), 'Did not find that the terminal DIV tag is a closer.' );
     135        $this->assertTrue( $processor->step(), 'Found no further tags when it should have found the closing DIV' );
     136        $this->assertSame( 'DIV', $processor->get_tag(), "Did not skip unexpected BUTTON; stopped at {$processor->get_tag()}." );
     137        $this->assertTrue( $processor->is_tag_closer(), 'Did not find that the terminal DIV tag is a closer.' );
    138138    }
    139139
     
    144144     */
    145145    public function test_in_body_button_with_no_button_in_scope() {
    146         $p = WP_HTML_Processor::create_fragment( '<div><p>Click the button <button one>here</button>!</p></div><button two>not here</button>' );
    147 
    148         $this->assertTrue( $p->next_tag( 'BUTTON' ), 'Could not find expected first button.' );
    149         $this->assertTrue( $p->get_attribute( 'one' ), 'Failed to match expected attribute on first button.' );
    150         $this->assertSame( array( 'HTML', 'BODY', 'DIV', 'P', 'BUTTON' ), $p->get_breadcrumbs(), 'Failed to produce expected DOM nesting for first button.' );
     146        $processor = WP_HTML_Processor::create_fragment( '<div><p>Click the button <button one>here</button>!</p></div><button two>not here</button>' );
     147
     148        $this->assertTrue( $processor->next_tag( 'BUTTON' ), 'Could not find expected first button.' );
     149        $this->assertTrue( $processor->get_attribute( 'one' ), 'Failed to match expected attribute on first button.' );
     150        $this->assertSame( array( 'HTML', 'BODY', 'DIV', 'P', 'BUTTON' ), $processor->get_breadcrumbs(), 'Failed to produce expected DOM nesting for first button.' );
    151151
    152152        /*
     
    155155         * malformed and unexpected ones.
    156156         */
    157         $this->assertTrue( $p->next_tag( 'BUTTON' ), 'Could not find expected second button.' );
    158         $this->assertTrue( $p->get_attribute( 'two' ), 'Failed to match expected attribute on second button.' );
    159         $this->assertSame( array( 'HTML', 'BODY', 'BUTTON' ), $p->get_breadcrumbs(), 'Failed to produce expected DOM nesting for second button.' );
     157        $this->assertTrue( $processor->next_tag( 'BUTTON' ), 'Could not find expected second button.' );
     158        $this->assertTrue( $processor->get_attribute( 'two' ), 'Failed to match expected attribute on second button.' );
     159        $this->assertSame( array( 'HTML', 'BODY', 'BUTTON' ), $processor->get_breadcrumbs(), 'Failed to produce expected DOM nesting for second button.' );
    160160    }
    161161
     
    169169     */
    170170    public function test_in_body_button_with_button_in_scope_as_parent() {
    171         $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>' );
    172 
    173         $this->assertTrue( $p->next_tag( 'BUTTON' ), 'Could not find expected first button.' );
    174         $this->assertTrue( $p->get_attribute( 'one' ), 'Failed to match expected attribute on first button.' );
    175         $this->assertSame( array( 'HTML', 'BODY', 'DIV', 'P', 'BUTTON' ), $p->get_breadcrumbs(), 'Failed to produce expected DOM nesting for first button.' );
     171        $processor = WP_HTML_Processor::create_fragment( '<div><p>Click the button <button one>almost<button two>here</button>!</p></div><button three>not here</button>' );
     172
     173        $this->assertTrue( $processor->next_tag( 'BUTTON' ), 'Could not find expected first button.' );
     174        $this->assertTrue( $processor->get_attribute( 'one' ), 'Failed to match expected attribute on first button.' );
     175        $this->assertSame( array( 'HTML', 'BODY', 'DIV', 'P', 'BUTTON' ), $processor->get_breadcrumbs(), 'Failed to produce expected DOM nesting for first button.' );
    176176
    177177        /*
     
    179179         * or it may place it as a child of the first one, but it implicitly closes the open BUTTON.
    180180         */
    181         $this->assertTrue( $p->next_tag( 'BUTTON' ), 'Could not find expected second button.' );
    182         $this->assertTrue( $p->get_attribute( 'two' ), 'Failed to match expected attribute on second button.' );
    183         $this->assertSame( array( 'HTML', 'BODY', 'DIV', 'P', 'BUTTON' ), $p->get_breadcrumbs(), 'Failed to produce expected DOM nesting for second button.' );
     181        $this->assertTrue( $processor->next_tag( 'BUTTON' ), 'Could not find expected second button.' );
     182        $this->assertTrue( $processor->get_attribute( 'two' ), 'Failed to match expected attribute on second button.' );
     183        $this->assertSame( array( 'HTML', 'BODY', 'DIV', 'P', 'BUTTON' ), $processor->get_breadcrumbs(), 'Failed to produce expected DOM nesting for second button.' );
    184184
    185185        /*
     
    187187         * looking for proper handling of the open and close sequence for the BUTTON tags.
    188188         */
    189         $this->assertTrue( $p->next_tag( 'BUTTON' ), 'Could not find expected third button.' );
    190         $this->assertTrue( $p->get_attribute( 'three' ), 'Failed to match expected attribute on third button.' );
    191         $this->assertSame( array( 'HTML', 'BODY', 'BUTTON' ), $p->get_breadcrumbs(), 'Failed to produce expected DOM nesting for third button.' );
     189        $this->assertTrue( $processor->next_tag( 'BUTTON' ), 'Could not find expected third button.' );
     190        $this->assertTrue( $processor->get_attribute( 'three' ), 'Failed to match expected attribute on third button.' );
     191        $this->assertSame( array( 'HTML', 'BODY', 'BUTTON' ), $processor->get_breadcrumbs(), 'Failed to produce expected DOM nesting for third button.' );
    192192    }
    193193
     
    202202     */
    203203    public function test_in_body_button_with_button_in_scope_as_ancestor() {
    204         $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>' );
     204        $processor = 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>' );
    205205
    206206        // This button finds itself normally nesting inside the DIV.
    207         $this->assertTrue( $p->next_tag( 'BUTTON' ), 'Could not find expected first button.' );
    208         $this->assertTrue( $p->get_attribute( 'one' ), 'Failed to match expected attribute on first button.' );
    209         $this->assertSame( array( 'HTML', 'BODY', 'DIV', 'BUTTON' ), $p->get_breadcrumbs(), 'Failed to produce expected DOM nesting for first button.' );
     207        $this->assertTrue( $processor->next_tag( 'BUTTON' ), 'Could not find expected first button.' );
     208        $this->assertTrue( $processor->get_attribute( 'one' ), 'Failed to match expected attribute on first button.' );
     209        $this->assertSame( array( 'HTML', 'BODY', 'DIV', 'BUTTON' ), $processor->get_breadcrumbs(), 'Failed to produce expected DOM nesting for first button.' );
    210210
    211211        /*
     
    215215         * itself a child of the most-recent open element above the most-recent BUTTON, or the DIV.
    216216         */
    217         $this->assertTrue( $p->next_tag( 'BUTTON' ), 'Could not find expected second button.' );
    218         $this->assertTrue( $p->get_attribute( 'two' ), 'Failed to match expected attribute on second button.' );
    219         $this->assertSame( array( 'HTML', 'BODY', 'DIV', 'BUTTON' ), $p->get_breadcrumbs(), 'Failed to produce expected DOM nesting for second button.' );
     217        $this->assertTrue( $processor->next_tag( 'BUTTON' ), 'Could not find expected second button.' );
     218        $this->assertTrue( $processor->get_attribute( 'two' ), 'Failed to match expected attribute on second button.' );
     219        $this->assertSame( array( 'HTML', 'BODY', 'DIV', 'BUTTON' ), $processor->get_breadcrumbs(), 'Failed to produce expected DOM nesting for second button.' );
    220220
    221221        // The third button is back to normal, because everything has been implicitly or explicitly closed by now.
    222         $this->assertTrue( $p->next_tag( 'BUTTON' ), 'Could not find expected third button.' );
    223         $this->assertTrue( $p->get_attribute( 'three' ), 'Failed to match expected attribute on third button.' );
    224         $this->assertSame( array( 'HTML', 'BODY', 'BUTTON' ), $p->get_breadcrumbs(), 'Failed to produce expected DOM nesting for third button.' );
     222        $this->assertTrue( $processor->next_tag( 'BUTTON' ), 'Could not find expected third button.' );
     223        $this->assertTrue( $processor->get_attribute( 'three' ), 'Failed to match expected attribute on third button.' );
     224        $this->assertSame( array( 'HTML', 'BODY', 'BUTTON' ), $processor->get_breadcrumbs(), 'Failed to produce expected DOM nesting for third button.' );
    225225    }
    226226
     
    275275     * @return array[].
    276276     */
    277     public function data_heading_elements() {
     277    public static function data_heading_elements() {
    278278        return array(
    279279            'H1' => array( 'H1' ),
     
    329329     * @return array[]
    330330     */
    331     public function data_heading_combinations() {
     331    public static function data_heading_combinations() {
    332332        $headings = array( 'H1', 'H2', 'H3', 'H4', 'H5', 'H6' );
    333333
     
    356356     */
    357357    public function test_in_body_any_other_end_tag_with_unclosed_special_element() {
    358         $p = WP_HTML_Processor::create_fragment( '<div><span><p></span><div>' );
    359 
    360         $p->next_tag( 'P' );
    361         $this->assertSame( 'P', $p->get_tag(), "Expected to start test on P element but found {$p->get_tag()} instead." );
    362         $this->assertSame( array( 'HTML', 'BODY', 'DIV', 'SPAN', 'P' ), $p->get_breadcrumbs(), 'Failed to produce expected DOM nesting.' );
    363 
    364         $this->assertTrue( $p->next_tag(), 'Failed to advance past P tag to expected DIV opener.' );
    365         $this->assertSame( 'DIV', $p->get_tag(), "Expected to find DIV element, but found {$p->get_tag()} instead." );
    366         $this->assertSame( array( 'HTML', 'BODY', 'DIV', 'SPAN', 'DIV' ), $p->get_breadcrumbs(), 'Failed to produce expected DOM nesting: SPAN should still be open and DIV should be its child.' );
     358        $processor = WP_HTML_Processor::create_fragment( '<div><span><p></span><div>' );
     359
     360        $processor->next_tag( 'P' );
     361        $this->assertSame( 'P', $processor->get_tag(), "Expected to start test on P element but found {$processor->get_tag()} instead." );
     362        $this->assertSame( array( 'HTML', 'BODY', 'DIV', 'SPAN', 'P' ), $processor->get_breadcrumbs(), 'Failed to produce expected DOM nesting.' );
     363
     364        $this->assertTrue( $processor->next_tag(), 'Failed to advance past P tag to expected DIV opener.' );
     365        $this->assertSame( 'DIV', $processor->get_tag(), "Expected to find DIV element, but found {$processor->get_tag()} instead." );
     366        $this->assertSame( array( 'HTML', 'BODY', 'DIV', 'SPAN', 'DIV' ), $processor->get_breadcrumbs(), 'Failed to produce expected DOM nesting: SPAN should still be open and DIV should be its child.' );
    367367    }
    368368
     
    379379     */
    380380    public function test_in_body_any_other_end_tag_with_unclosed_non_special_element() {
    381         $p = WP_HTML_Processor::create_fragment( '<div><span><code></span><div>' );
    382 
    383         $p->next_tag( 'CODE' );
    384         $this->assertSame( 'CODE', $p->get_tag(), "Expected to start test on CODE element but found {$p->get_tag()} instead." );
    385         $this->assertSame( array( 'HTML', 'BODY', 'DIV', 'SPAN', 'CODE' ), $p->get_breadcrumbs(), 'Failed to produce expected DOM nesting.' );
    386 
    387         $this->assertTrue( $p->step(), 'Failed to advance past CODE tag to expected SPAN closer.' );
    388         $this->assertTrue( $p->is_tag_closer(), 'Expected to find closing SPAN, but found opener instead.' );
    389         $this->assertSame( array( 'HTML', 'BODY', 'DIV' ), $p->get_breadcrumbs(), 'Failed to advance past CODE tag to expected DIV opener.' );
    390 
    391         $this->assertTrue( $p->next_tag(), 'Failed to advance past SPAN closer to expected DIV opener.' );
    392         $this->assertSame( 'DIV', $p->get_tag(), "Expected to find DIV element, but found {$p->get_tag()} instead." );
    393         $this->assertSame( array( 'HTML', 'BODY', 'DIV', 'DIV' ), $p->get_breadcrumbs(), 'Failed to produce expected DOM nesting: SPAN should be closed and DIV should be its sibling.' );
     381        $processor = WP_HTML_Processor::create_fragment( '<div><span><code></span><div>' );
     382
     383        $processor->next_tag( 'CODE' );
     384        $this->assertSame( 'CODE', $processor->get_tag(), "Expected to start test on CODE element but found {$processor->get_tag()} instead." );
     385        $this->assertSame( array( 'HTML', 'BODY', 'DIV', 'SPAN', 'CODE' ), $processor->get_breadcrumbs(), 'Failed to produce expected DOM nesting.' );
     386
     387        $this->assertTrue( $processor->step(), 'Failed to advance past CODE tag to expected SPAN closer.' );
     388        $this->assertTrue( $processor->is_tag_closer(), 'Expected to find closing SPAN, but found opener instead.' );
     389        $this->assertSame( array( 'HTML', 'BODY', 'DIV' ), $processor->get_breadcrumbs(), 'Failed to advance past CODE tag to expected DIV opener.' );
     390
     391        $this->assertTrue( $processor->next_tag(), 'Failed to advance past SPAN closer to expected DIV opener.' );
     392        $this->assertSame( 'DIV', $processor->get_tag(), "Expected to find DIV element, but found {$processor->get_tag()} instead." );
     393        $this->assertSame( array( 'HTML', 'BODY', 'DIV', 'DIV' ), $processor->get_breadcrumbs(), 'Failed to produce expected DOM nesting: SPAN should be closed and DIV should be its sibling.' );
    394394    }
    395395
     
    413413     */
    414414    public function test_br_end_tag_unsupported() {
    415         $p = WP_HTML_Processor::create_fragment( '</br>' );
    416 
    417         $this->assertFalse( $p->next_tag(), 'Found a BR tag that should not be handled.' );
    418         $this->assertSame( WP_HTML_Processor::ERROR_UNSUPPORTED, $p->get_last_error() );
     415        $processor = WP_HTML_Processor::create_fragment( '</br>' );
     416
     417        $this->assertFalse( $processor->next_tag(), 'Found a BR tag that should not be handled.' );
     418        $this->assertSame( WP_HTML_Processor::ERROR_UNSUPPORTED, $processor->get_last_error() );
    419419    }
    420420}
  • trunk/tests/phpunit/tests/html-api/wpHtmlProcessorSemanticRulesHeadingElements.php

    r57186 r57508  
    5454     * @return array[].
    5555     */
    56     public function data_heading_elements() {
     56    public static function data_heading_elements() {
    5757        return array(
    5858            'H1' => array( 'H1' ),
     
    110110     * @return array[]
    111111     */
    112     public function data_heading_combinations() {
     112    public static function data_heading_combinations() {
    113113        $headings = array( 'H1', 'H2', 'H3', 'H4', 'H5', 'H6' );
    114114
  • trunk/tests/phpunit/tests/html-api/wpHtmlSupportRequiredHtmlProcessor.php

    r57264 r57508  
    4343     */
    4444    private function ensure_support_is_added_everywhere( $tag_name ) {
    45         $p = WP_HTML_Processor::create_fragment( "<$tag_name>" );
     45        $processor = WP_HTML_Processor::create_fragment( "<$tag_name>" );
    4646
    47         $this->assertFalse( $p->step(), "Must support terminating elements in specific scope check before adding support for the {$tag_name} element." );
     47        $this->assertFalse( $processor->step(), "Must support terminating elements in specific scope check before adding support for the {$tag_name} element." );
    4848    }
    4949
  • trunk/tests/phpunit/tests/html-api/wpHtmlSupportRequiredOpenElements.php

    r57264 r57508  
    4545     */
    4646    private function ensure_support_is_added_everywhere( $tag_name ) {
    47         $p = WP_HTML_Processor::create_fragment( "<$tag_name>" );
    48 
    49         $this->assertFalse( $p->step(), "Must support terminating elements in specific scope check before adding support for the {$tag_name} element." );
     47        $processor = WP_HTML_Processor::create_fragment( "<$tag_name>" );
     48
     49        $this->assertFalse( $processor->step(), "Must support terminating elements in specific scope check before adding support for the {$tag_name} element." );
    5050    }
    5151
  • trunk/tests/phpunit/tests/html-api/wpHtmlTagProcessor-bookmark.php

    r56299 r57508  
    2020     */
    2121    public function test_set_bookmark() {
    22         $p = new WP_HTML_Tag_Processor( '<ul><li>One</li><li>Two</li><li>Three</li></ul>' );
    23         $p->next_tag( 'li' );
    24         $this->assertTrue( $p->set_bookmark( 'first li' ), 'Could not allocate a "first li" bookmark' );
    25         $p->next_tag( 'li' );
    26         $this->assertTrue( $p->set_bookmark( 'second li' ), 'Could not allocate a "second li" bookmark' );
    27         $this->assertTrue( $p->set_bookmark( 'first li' ), 'Could not move the "first li" bookmark' );
     22        $processor = new WP_HTML_Tag_Processor( '<ul><li>One</li><li>Two</li><li>Three</li></ul>' );
     23        $processor->next_tag( 'li' );
     24        $this->assertTrue( $processor->set_bookmark( 'first li' ), 'Could not allocate a "first li" bookmark' );
     25        $processor->next_tag( 'li' );
     26        $this->assertTrue( $processor->set_bookmark( 'second li' ), 'Could not allocate a "second li" bookmark' );
     27        $this->assertTrue( $processor->set_bookmark( 'first li' ), 'Could not move the "first li" bookmark' );
    2828    }
    2929
     
    3434     */
    3535    public function test_release_bookmark() {
    36         $p = new WP_HTML_Tag_Processor( '<ul><li>One</li><li>Two</li><li>Three</li></ul>' );
    37         $p->next_tag( 'li' );
    38         $this->assertFalse( $p->release_bookmark( 'first li' ), 'Released a non-existing bookmark' );
    39         $p->set_bookmark( 'first li' );
    40         $this->assertTrue( $p->release_bookmark( 'first li' ), 'Could not release a bookmark' );
     36        $processor = new WP_HTML_Tag_Processor( '<ul><li>One</li><li>Two</li><li>Three</li></ul>' );
     37        $processor->next_tag( 'li' );
     38        $this->assertFalse( $processor->release_bookmark( 'first li' ), 'Released a non-existing bookmark' );
     39        $processor->set_bookmark( 'first li' );
     40        $this->assertTrue( $processor->release_bookmark( 'first li' ), 'Could not release a bookmark' );
    4141    }
    4242
     
    4747     */
    4848    public function test_has_bookmark_returns_false_if_bookmark_does_not_exist() {
    49         $p = new WP_HTML_Tag_Processor( '<div>Test</div>' );
    50         $this->assertFalse( $p->has_bookmark( 'my-bookmark' ) );
     49        $processor = new WP_HTML_Tag_Processor( '<div>Test</div>' );
     50        $this->assertFalse( $processor->has_bookmark( 'my-bookmark' ) );
    5151    }
    5252
     
    5757     */
    5858    public function test_has_bookmark_returns_true_if_bookmark_exists() {
    59         $p = new WP_HTML_Tag_Processor( '<div>Test</div>' );
    60         $p->next_tag();
    61         $p->set_bookmark( 'my-bookmark' );
    62         $this->assertTrue( $p->has_bookmark( 'my-bookmark' ) );
     59        $processor = new WP_HTML_Tag_Processor( '<div>Test</div>' );
     60        $processor->next_tag();
     61        $processor->set_bookmark( 'my-bookmark' );
     62        $this->assertTrue( $processor->has_bookmark( 'my-bookmark' ) );
    6363    }
    6464
     
    6969     */
    7070    public function test_has_bookmark_returns_false_if_bookmark_has_been_released() {
    71         $p = new WP_HTML_Tag_Processor( '<div>Test</div>' );
    72         $p->next_tag();
    73         $p->set_bookmark( 'my-bookmark' );
    74         $p->release_bookmark( 'my-bookmark' );
    75         $this->assertFalse( $p->has_bookmark( 'my-bookmark' ) );
     71        $processor = new WP_HTML_Tag_Processor( '<div>Test</div>' );
     72        $processor->next_tag();
     73        $processor->set_bookmark( 'my-bookmark' );
     74        $processor->release_bookmark( 'my-bookmark' );
     75        $this->assertFalse( $processor->has_bookmark( 'my-bookmark' ) );
    7676    }
    7777
     
    8282     */
    8383    public function test_seek() {
    84         $p = new WP_HTML_Tag_Processor( '<ul><li>One</li><li>Two</li><li>Three</li></ul>' );
    85         $p->next_tag( 'li' );
    86         $p->set_bookmark( 'first li' );
    87 
    88         $p->next_tag( 'li' );
    89         $p->set_attribute( 'foo-2', 'bar-2' );
    90 
    91         $p->seek( 'first li' );
    92         $p->set_attribute( 'foo-1', 'bar-1' );
     84        $processor = new WP_HTML_Tag_Processor( '<ul><li>One</li><li>Two</li><li>Three</li></ul>' );
     85        $processor->next_tag( 'li' );
     86        $processor->set_bookmark( 'first li' );
     87
     88        $processor->next_tag( 'li' );
     89        $processor->set_attribute( 'foo-2', 'bar-2' );
     90
     91        $processor->seek( 'first li' );
     92        $processor->set_attribute( 'foo-1', 'bar-1' );
    9393
    9494        $this->assertSame(
    9595            '<ul><li foo-1="bar-1">One</li><li foo-2="bar-2">Two</li><li>Three</li></ul>',
    96             $p->get_updated_html(),
     96            $processor->get_updated_html(),
    9797            'Did not seek to the intended bookmark locations'
    9898        );
     
    105105     */
    106106    public function test_seeks_to_tag_closer_bookmark() {
    107         $p = new WP_HTML_Tag_Processor( '<div>First</div><span>Second</span>' );
    108         $p->next_tag( array( 'tag_closers' => 'visit' ) );
    109         $p->set_bookmark( 'first' );
    110         $p->next_tag( array( 'tag_closers' => 'visit' ) );
    111         $p->set_bookmark( 'second' );
    112 
    113         $p->seek( 'first' );
    114         $p->seek( 'second' );
     107        $processor = new WP_HTML_Tag_Processor( '<div>First</div><span>Second</span>' );
     108        $processor->next_tag( array( 'tag_closers' => 'visit' ) );
     109        $processor->set_bookmark( 'first' );
     110        $processor->next_tag( array( 'tag_closers' => 'visit' ) );
     111        $processor->set_bookmark( 'second' );
     112
     113        $processor->seek( 'first' );
     114        $processor->seek( 'second' );
    115115
    116116        $this->assertSame(
    117117            'DIV',
    118             $p->get_tag(),
     118            $processor->get_tag(),
    119119            'Did not seek to the intended bookmark location'
    120120        );
     
    160160     */
    161161    public function test_removing_long_attributes_doesnt_break_seek() {
    162         $input = <<<HTML
     162        $input     = <<<HTML
    163163        <button twenty_one_characters 7_chars></button><button></button>
    164164HTML;
    165         $p    = new WP_HTML_Tag_Processor( $input );
    166         $p->next_tag( 'button' );
    167         $p->set_bookmark( 'first' );
    168         $p->next_tag( 'button' );
    169         $p->set_bookmark( 'second' );
    170 
    171         $this->assertTrue(
    172             $p->seek( 'first' ),
     165        $processor = new WP_HTML_Tag_Processor( $input );
     166        $processor->next_tag( 'button' );
     167        $processor->set_bookmark( 'first' );
     168        $processor->next_tag( 'button' );
     169        $processor->set_bookmark( 'second' );
     170
     171        $this->assertTrue(
     172            $processor->seek( 'first' ),
    173173            'Seek() to the first button has failed'
    174174        );
    175         $p->remove_attribute( 'twenty_one_characters' );
    176         $p->remove_attribute( '7_chars' );
    177 
    178         $this->assertTrue(
    179             $p->seek( 'second' ),
     175        $processor->remove_attribute( 'twenty_one_characters' );
     176        $processor->remove_attribute( '7_chars' );
     177
     178        $this->assertTrue(
     179            $processor->seek( 'second' ),
    180180            'Seek() to the second button has failed'
    181181        );
     
    233233</div>
    234234HTML;
    235         $p               = new WP_HTML_Tag_Processor( $input );
    236         $p->next_tag( 'div' );
    237         $p->next_tag( 'div' );
    238         $p->next_tag( 'div' );
    239         $p->set_bookmark( 'first div' );
    240         $p->next_tag( 'button' );
    241         $p->set_bookmark( 'first button' );
    242         $p->next_tag( 'button' );
    243         $p->set_bookmark( 'second button' );
    244         $p->next_tag( 'button' );
    245         $p->set_bookmark( 'third button' );
    246         $p->next_tag( 'button' );
    247         $p->set_bookmark( 'fourth button' );
    248 
    249         $p->seek( 'first button' );
    250         $p->set_attribute( 'type', 'submit' );
    251 
    252         $this->assertTrue(
    253             $p->seek( 'third button' ),
     235        $processor       = new WP_HTML_Tag_Processor( $input );
     236        $processor->next_tag( 'div' );
     237        $processor->next_tag( 'div' );
     238        $processor->next_tag( 'div' );
     239        $processor->set_bookmark( 'first div' );
     240        $processor->next_tag( 'button' );
     241        $processor->set_bookmark( 'first button' );
     242        $processor->next_tag( 'button' );
     243        $processor->set_bookmark( 'second button' );
     244        $processor->next_tag( 'button' );
     245        $processor->set_bookmark( 'third button' );
     246        $processor->next_tag( 'button' );
     247        $processor->set_bookmark( 'fourth button' );
     248
     249        $processor->seek( 'first button' );
     250        $processor->set_attribute( 'type', 'submit' );
     251
     252        $this->assertTrue(
     253            $processor->seek( 'third button' ),
    254254            'Seek() to the third button failed'
    255255        );
    256         $p->remove_attribute( 'class' );
    257         $p->remove_attribute( 'type' );
    258         $p->remove_attribute( 'aria-expanded' );
    259         $p->set_attribute( 'id', 'rebase-and-merge' );
    260         $p->remove_attribute( 'data-details-container' );
    261 
    262         $this->assertTrue(
    263             $p->seek( 'first div' ),
     256        $processor->remove_attribute( 'class' );
     257        $processor->remove_attribute( 'type' );
     258        $processor->remove_attribute( 'aria-expanded' );
     259        $processor->set_attribute( 'id', 'rebase-and-merge' );
     260        $processor->remove_attribute( 'data-details-container' );
     261
     262        $this->assertTrue(
     263            $processor->seek( 'first div' ),
    264264            'Seek() to the first div failed'
    265265        );
    266         $p->set_attribute( 'checked', false );
    267 
    268         $this->assertTrue(
    269             $p->seek( 'fourth button' ),
     266        $processor->set_attribute( 'checked', false );
     267
     268        $this->assertTrue(
     269            $processor->seek( 'fourth button' ),
    270270            'Seek() to the fourth button failed'
    271271        );
    272         $p->set_attribute( 'id', 'last-button' );
    273         $p->remove_attribute( 'class' );
    274         $p->remove_attribute( 'type' );
    275         $p->remove_attribute( 'checked' );
    276         $p->remove_attribute( 'aria-label' );
    277         $p->remove_attribute( 'disabled' );
    278         $p->remove_attribute( 'data-view-component' );
    279 
    280         $this->assertTrue(
    281             $p->seek( 'second button' ),
     272        $processor->set_attribute( 'id', 'last-button' );
     273        $processor->remove_attribute( 'class' );
     274        $processor->remove_attribute( 'type' );
     275        $processor->remove_attribute( 'checked' );
     276        $processor->remove_attribute( 'aria-label' );
     277        $processor->remove_attribute( 'disabled' );
     278        $processor->remove_attribute( 'data-view-component' );
     279
     280        $this->assertTrue(
     281            $processor->seek( 'second button' ),
    282282            'Seek() to the second button failed'
    283283        );
    284         $p->remove_attribute( 'type' );
    285         $p->set_attribute( 'class', 'hx_create-pr-button' );
     284        $processor->remove_attribute( 'type' );
     285        $processor->set_attribute( 'class', 'hx_create-pr-button' );
    286286
    287287        $this->assertSame(
    288288            $expected_output,
    289             $p->get_updated_html(),
     289            $processor->get_updated_html(),
    290290            'Performing several attribute updates on different tags does not produce the expected HTML snippet'
    291291        );
     
    298298     */
    299299    public function test_updates_bookmark_for_additions_after_both_sides() {
    300         $p = new WP_HTML_Tag_Processor( '<div>First</div><div>Second</div>' );
    301         $p->next_tag();
    302         $p->set_bookmark( 'first' );
    303         $p->next_tag();
    304         $p->add_class( 'second' );
    305 
    306         $p->seek( 'first' );
    307         $p->add_class( 'first' );
     300        $processor = new WP_HTML_Tag_Processor( '<div>First</div><div>Second</div>' );
     301        $processor->next_tag();
     302        $processor->set_bookmark( 'first' );
     303        $processor->next_tag();
     304        $processor->add_class( 'second' );
     305
     306        $processor->seek( 'first' );
     307        $processor->add_class( 'first' );
    308308
    309309        $this->assertSame(
    310310            '<div class="first">First</div><div class="second">Second</div>',
    311             $p->get_updated_html(),
     311            $processor->get_updated_html(),
    312312            'The bookmark was updated incorrectly in response to HTML markup updates'
    313313        );
     
    320320     */
    321321    public function test_updates_bookmark_for_additions_before_both_sides() {
    322         $p = new WP_HTML_Tag_Processor( '<div>First</div><div>Second</div>' );
    323         $p->next_tag();
    324         $p->set_bookmark( 'first' );
    325         $p->next_tag();
    326         $p->set_bookmark( 'second' );
    327 
    328         $p->seek( 'first' );
    329         $p->add_class( 'first' );
    330 
    331         $p->seek( 'second' );
    332         $p->add_class( 'second' );
     322        $processor = new WP_HTML_Tag_Processor( '<div>First</div><div>Second</div>' );
     323        $processor->next_tag();
     324        $processor->set_bookmark( 'first' );
     325        $processor->next_tag();
     326        $processor->set_bookmark( 'second' );
     327
     328        $processor->seek( 'first' );
     329        $processor->add_class( 'first' );
     330
     331        $processor->seek( 'second' );
     332        $processor->add_class( 'second' );
    333333
    334334        $this->assertSame(
    335335            '<div class="first">First</div><div class="second">Second</div>',
    336             $p->get_updated_html(),
     336            $processor->get_updated_html(),
    337337            'The bookmark was updated incorrectly in response to HTML markup updates'
    338338        );
     
    345345     */
    346346    public function test_updates_bookmark_for_deletions_after_both_sides() {
    347         $p = new WP_HTML_Tag_Processor( '<div>First</div><div disabled>Second</div>' );
    348         $p->next_tag();
    349         $p->set_bookmark( 'first' );
    350         $p->next_tag();
    351         $p->remove_attribute( 'disabled' );
    352 
    353         $p->seek( 'first' );
    354         $p->set_attribute( 'untouched', true );
     347        $processor = new WP_HTML_Tag_Processor( '<div>First</div><div disabled>Second</div>' );
     348        $processor->next_tag();
     349        $processor->set_bookmark( 'first' );
     350        $processor->next_tag();
     351        $processor->remove_attribute( 'disabled' );
     352
     353        $processor->seek( 'first' );
     354        $processor->set_attribute( 'untouched', true );
    355355
    356356        $this->assertSame(
     
    364364             */
    365365            '<div untouched>First</div><div >Second</div>',
    366             $p->get_updated_html(),
     366            $processor->get_updated_html(),
    367367            'The bookmark was incorrectly in response to HTML markup updates'
    368368        );
     
    375375     */
    376376    public function test_updates_bookmark_for_deletions_before_both_sides() {
    377         $p = new WP_HTML_Tag_Processor( '<div disabled>First</div><div>Second</div>' );
    378         $p->next_tag();
    379         $p->set_bookmark( 'first' );
    380         $p->next_tag();
    381         $p->set_bookmark( 'second' );
    382 
    383         $p->seek( 'first' );
    384         $p->remove_attribute( 'disabled' );
    385 
    386         $p->seek( 'second' );
    387         $p->set_attribute( 'safe', true );
     377        $processor = new WP_HTML_Tag_Processor( '<div disabled>First</div><div>Second</div>' );
     378        $processor->next_tag();
     379        $processor->set_bookmark( 'first' );
     380        $processor->next_tag();
     381        $processor->set_bookmark( 'second' );
     382
     383        $processor->seek( 'first' );
     384        $processor->remove_attribute( 'disabled' );
     385
     386        $processor->seek( 'second' );
     387        $processor->set_attribute( 'safe', true );
    388388
    389389        $this->assertSame(
     
    397397             */
    398398            '<div >First</div><div safe>Second</div>',
    399             $p->get_updated_html(),
     399            $processor->get_updated_html(),
    400400            'The bookmark was updated incorrectly in response to HTML markup updates'
    401401        );
     
    408408     */
    409409    public function test_limits_the_number_of_bookmarks() {
    410         $p = new WP_HTML_Tag_Processor( '<ul><li>One</li><li>Two</li><li>Three</li></ul>' );
    411         $p->next_tag( 'li' );
     410        $processor = new WP_HTML_Tag_Processor( '<ul><li>One</li><li>Two</li><li>Three</li></ul>' );
     411        $processor->next_tag( 'li' );
    412412
    413413        for ( $i = 0; $i < WP_HTML_Tag_Processor::MAX_BOOKMARKS; $i++ ) {
    414             $this->assertTrue( $p->set_bookmark( "bookmark $i" ), "Could not allocate the bookmark #$i" );
     414            $this->assertTrue( $processor->set_bookmark( "bookmark $i" ), "Could not allocate the bookmark #$i" );
    415415        }
    416416
    417417        $this->setExpectedIncorrectUsage( 'WP_HTML_Tag_Processor::set_bookmark' );
    418         $this->assertFalse( $p->set_bookmark( 'final bookmark' ), "Allocated $i bookmarks, which is one above the limit" );
     418        $this->assertFalse( $processor->set_bookmark( 'final bookmark' ), "Allocated $i bookmarks, which is one above the limit" );
    419419    }
    420420
     
    425425     */
    426426    public function test_limits_the_number_of_seek_calls() {
    427         $p = new WP_HTML_Tag_Processor( '<ul><li>One</li><li>Two</li><li>Three</li></ul>' );
    428         $p->next_tag( 'li' );
    429         $p->set_bookmark( 'bookmark' );
     427        $processor = new WP_HTML_Tag_Processor( '<ul><li>One</li><li>Two</li><li>Three</li></ul>' );
     428        $processor->next_tag( 'li' );
     429        $processor->set_bookmark( 'bookmark' );
    430430
    431431        for ( $i = 0; $i < WP_HTML_Tag_Processor::MAX_SEEK_OPS; $i++ ) {
    432             $this->assertTrue( $p->seek( 'bookmark' ), 'Could not seek to the "bookmark"' );
     432            $this->assertTrue( $processor->seek( 'bookmark' ), 'Could not seek to the "bookmark"' );
    433433        }
    434434
    435435        $this->setExpectedIncorrectUsage( 'WP_HTML_Tag_Processor::seek' );
    436         $this->assertFalse( $p->seek( 'bookmark' ), "$i-th seek() to the bookmark succeeded, even though it should exceed the allowed limit" );
     436        $this->assertFalse( $processor->seek( 'bookmark' ), "$i-th seek() to the bookmark succeeded, even though it should exceed the allowed limit" );
    437437    }
    438438}
  • trunk/tests/phpunit/tests/html-api/wpHtmlTagProcessor-token-scanning.php

    r57506 r57508  
    296296     * @return array[].
    297297     */
    298     public function data_rawtext_elements() {
     298    public static function data_rawtext_elements() {
    299299        return array(
    300300            'IFRAME'   => array( 'IFRAME' ),
     
    581581     * @return array[].
    582582     */
    583     public function data_common_comments() {
     583    public static function data_common_comments() {
    584584        return array(
    585585            'Shortest comment'        => array( '<!-->', '' ),
  • trunk/tests/phpunit/tests/html-api/wpHtmlTagProcessor.php

    r57489 r57508  
    2323     */
    2424    public function test_get_tag_returns_null_before_finding_tags() {
    25         $p = new WP_HTML_Tag_Processor( '<div>Test</div>' );
    26 
    27         $this->assertNull( $p->get_tag(), 'Calling get_tag() without selecting a tag did not return null' );
     25        $processor = new WP_HTML_Tag_Processor( '<div>Test</div>' );
     26
     27        $this->assertNull( $processor->get_tag(), 'Calling get_tag() without selecting a tag did not return null' );
    2828    }
    2929
     
    3434     */
    3535    public function test_get_tag_returns_null_when_not_in_open_tag() {
    36         $p = new WP_HTML_Tag_Processor( '<div>Test</div>' );
    37 
    38         $this->assertFalse( $p->next_tag( 'p' ), 'Querying a non-existing tag did not return false' );
    39         $this->assertNull( $p->get_tag(), 'Accessing a non-existing tag did not return null' );
     36        $processor = new WP_HTML_Tag_Processor( '<div>Test</div>' );
     37
     38        $this->assertFalse( $processor->next_tag( 'p' ), 'Querying a non-existing tag did not return false' );
     39        $this->assertNull( $processor->get_tag(), 'Accessing a non-existing tag did not return null' );
    4040    }
    4141
     
    4646     */
    4747    public function test_get_tag_returns_open_tag_name() {
    48         $p = new WP_HTML_Tag_Processor( '<div>Test</div>' );
    49 
    50         $this->assertTrue( $p->next_tag( 'div' ), 'Querying an existing tag did not return true' );
    51         $this->assertSame( 'DIV', $p->get_tag(), 'Accessing an existing tag name did not return "div"' );
     48        $processor = new WP_HTML_Tag_Processor( '<div>Test</div>' );
     49
     50        $this->assertTrue( $processor->next_tag( 'div' ), 'Querying an existing tag did not return true' );
     51        $this->assertSame( 'DIV', $processor->get_tag(), 'Accessing an existing tag name did not return "div"' );
    5252    }
    5353
     
    6363     */
    6464    public function test_has_self_closing_flag_matches_input_html( $html, $flag_is_set ) {
    65         $p = new WP_HTML_Tag_Processor( $html );
    66         $p->next_tag( array( 'tag_closers' => 'visit' ) );
     65        $processor = new WP_HTML_Tag_Processor( $html );
     66        $processor->next_tag( array( 'tag_closers' => 'visit' ) );
    6767
    6868        if ( $flag_is_set ) {
    69             $this->assertTrue( $p->has_self_closing_flag(), 'Did not find the self-closing tag when it was present.' );
     69            $this->assertTrue( $processor->has_self_closing_flag(), 'Did not find the self-closing tag when it was present.' );
    7070        } else {
    71             $this->assertFalse( $p->has_self_closing_flag(), 'Found the self-closing tag when it was absent.' );
     71            $this->assertFalse( $processor->has_self_closing_flag(), 'Found the self-closing tag when it was absent.' );
    7272        }
    7373    }
     
    7878     * @return array[]
    7979     */
    80     public function data_has_self_closing_flag() {
     80    public static function data_has_self_closing_flag() {
    8181        return array(
    8282            // These should not have a self-closer, and will leave an element un-closed if it's assumed they are self-closing.
     
    108108     */
    109109    public function test_get_attribute_returns_null_before_finding_tags() {
    110         $p = new WP_HTML_Tag_Processor( '<div class="test">Test</div>' );
    111 
    112         $this->assertNull( $p->get_attribute( 'class' ), 'Accessing an attribute without selecting a tag did not return null' );
     110        $processor = new WP_HTML_Tag_Processor( '<div class="test">Test</div>' );
     111
     112        $this->assertNull( $processor->get_attribute( 'class' ), 'Accessing an attribute without selecting a tag did not return null' );
    113113    }
    114114
     
    119119     */
    120120    public function test_get_attribute_returns_null_when_not_in_open_tag() {
    121         $p = new WP_HTML_Tag_Processor( '<div class="test">Test</div>' );
    122 
    123         $this->assertFalse( $p->next_tag( 'p' ), 'Querying a non-existing tag did not return false' );
    124         $this->assertNull( $p->get_attribute( 'class' ), 'Accessing an attribute of a non-existing tag did not return null' );
     121        $processor = new WP_HTML_Tag_Processor( '<div class="test">Test</div>' );
     122
     123        $this->assertFalse( $processor->next_tag( 'p' ), 'Querying a non-existing tag did not return false' );
     124        $this->assertNull( $processor->get_attribute( 'class' ), 'Accessing an attribute of a non-existing tag did not return null' );
    125125    }
    126126
     
    131131     */
    132132    public function test_get_attribute_returns_null_when_in_closing_tag() {
    133         $p = new WP_HTML_Tag_Processor( '<div class="test">Test</div>' );
    134 
    135         $this->assertTrue( $p->next_tag( 'div' ), 'Querying an existing tag did not return true' );
    136         $this->assertTrue( $p->next_tag( array( 'tag_closers' => 'visit' ) ), 'Querying an existing closing tag did not return true' );
    137         $this->assertNull( $p->get_attribute( 'class' ), 'Accessing an attribute of a closing tag did not return null' );
     133        $processor = new WP_HTML_Tag_Processor( '<div class="test">Test</div>' );
     134
     135        $this->assertTrue( $processor->next_tag( 'div' ), 'Querying an existing tag did not return true' );
     136        $this->assertTrue( $processor->next_tag( array( 'tag_closers' => 'visit' ) ), 'Querying an existing closing tag did not return true' );
     137        $this->assertNull( $processor->get_attribute( 'class' ), 'Accessing an attribute of a closing tag did not return null' );
    138138    }
    139139
     
    144144     */
    145145    public function test_get_attribute_returns_null_when_attribute_missing() {
    146         $p = new WP_HTML_Tag_Processor( '<div class="test">Test</div>' );
    147 
    148         $this->assertTrue( $p->next_tag( 'div' ), 'Querying an existing tag did not return true' );
    149         $this->assertNull( $p->get_attribute( 'test-id' ), 'Accessing a non-existing attribute did not return null' );
     146        $processor = new WP_HTML_Tag_Processor( '<div class="test">Test</div>' );
     147
     148        $this->assertTrue( $processor->next_tag( 'div' ), 'Querying an existing tag did not return true' );
     149        $this->assertNull( $processor->get_attribute( 'test-id' ), 'Accessing a non-existing attribute did not return null' );
    150150    }
    151151
     
    156156     */
    157157    public function test_get_attribute_returns_attribute_value() {
    158         $p = new WP_HTML_Tag_Processor( '<div class="test">Test</div>' );
    159 
    160         $this->assertTrue( $p->next_tag( 'div' ), 'Querying an existing tag did not return true' );
    161         $this->assertSame( 'test', $p->get_attribute( 'class' ), 'Accessing a class="test" attribute value did not return "test"' );
     158        $processor = new WP_HTML_Tag_Processor( '<div class="test">Test</div>' );
     159
     160        $this->assertTrue( $processor->next_tag( 'div' ), 'Querying an existing tag did not return true' );
     161        $this->assertSame( 'test', $processor->get_attribute( 'class' ), 'Accessing a class="test" attribute value did not return "test"' );
    162162    }
    163163
     
    168168     */
    169169    public function test_get_attribute_returns_true_for_boolean_attribute() {
    170         $p = new WP_HTML_Tag_Processor( '<div enabled class="test">Test</div>' );
    171 
    172         $this->assertTrue( $p->next_tag( array( 'class_name' => 'test' ) ), 'Querying an existing tag did not return true' );
    173         $this->assertTrue( $p->get_attribute( 'enabled' ), 'Accessing a boolean "enabled" attribute value did not return true' );
     170        $processor = new WP_HTML_Tag_Processor( '<div enabled class="test">Test</div>' );
     171
     172        $this->assertTrue( $processor->next_tag( array( 'class_name' => 'test' ) ), 'Querying an existing tag did not return true' );
     173        $this->assertTrue( $processor->get_attribute( 'enabled' ), 'Accessing a boolean "enabled" attribute value did not return true' );
    174174    }
    175175
     
    180180     */
    181181    public function test_get_attribute_returns_string_for_truthy_attributes() {
    182         $p = new WP_HTML_Tag_Processor( '<div enabled=enabled checked=1 hidden="true" class="test">Test</div>' );
    183 
    184         $this->assertTrue( $p->next_tag(), 'Querying an existing tag did not return true' );
    185         $this->assertSame( 'enabled', $p->get_attribute( 'enabled' ), 'Accessing a boolean "enabled" attribute value did not return true' );
    186         $this->assertSame( '1', $p->get_attribute( 'checked' ), 'Accessing a checked=1 attribute value did not return "1"' );
    187         $this->assertSame( 'true', $p->get_attribute( 'hidden' ), 'Accessing a hidden="true" attribute value did not return "true"' );
     182        $processor = new WP_HTML_Tag_Processor( '<div enabled=enabled checked=1 hidden="true" class="test">Test</div>' );
     183
     184        $this->assertTrue( $processor->next_tag(), 'Querying an existing tag did not return true' );
     185        $this->assertSame( 'enabled', $processor->get_attribute( 'enabled' ), 'Accessing a boolean "enabled" attribute value did not return true' );
     186        $this->assertSame( '1', $processor->get_attribute( 'checked' ), 'Accessing a checked=1 attribute value did not return "1"' );
     187        $this->assertSame( 'true', $processor->get_attribute( 'hidden' ), 'Accessing a hidden="true" attribute value did not return "true"' );
    188188    }
    189189
     
    194194     */
    195195    public function test_get_attribute_decodes_html_character_references() {
    196         $p = new WP_HTML_Tag_Processor( '<div id="the &quot;grande&quot; is &lt; &#x033;&#50;oz&dagger;"></div>' );
    197         $p->next_tag();
    198 
    199         $this->assertSame( 'the "grande" is < 32oz†', $p->get_attribute( 'id' ), 'HTML Attribute value was returned without decoding character references' );
     196        $processor = new WP_HTML_Tag_Processor( '<div id="the &quot;grande&quot; is &lt; &#x033;&#50;oz&dagger;"></div>' );
     197        $processor->next_tag();
     198
     199        $this->assertSame( 'the "grande" is < 32oz†', $processor->get_attribute( 'id' ), 'HTML Attribute value was returned without decoding character references' );
    200200    }
    201201
     
    206206     */
    207207    public function test_attributes_parser_treats_slash_as_attribute_separator() {
    208         $p = new WP_HTML_Tag_Processor( '<div a/b/c/d/e="test">Test</div>' );
    209 
    210         $this->assertTrue( $p->next_tag(), 'Querying an existing tag did not return true' );
    211         $this->assertTrue( $p->get_attribute( 'a' ), 'Accessing an existing attribute did not return true' );
    212         $this->assertTrue( $p->get_attribute( 'b' ), 'Accessing an existing attribute did not return true' );
    213         $this->assertTrue( $p->get_attribute( 'c' ), 'Accessing an existing attribute did not return true' );
    214         $this->assertTrue( $p->get_attribute( 'd' ), 'Accessing an existing attribute did not return true' );
    215         $this->assertSame( 'test', $p->get_attribute( 'e' ), 'Accessing an existing e="test" did not return "test"' );
     208        $processor = new WP_HTML_Tag_Processor( '<div a/b/c/d/e="test">Test</div>' );
     209
     210        $this->assertTrue( $processor->next_tag(), 'Querying an existing tag did not return true' );
     211        $this->assertTrue( $processor->get_attribute( 'a' ), 'Accessing an existing attribute did not return true' );
     212        $this->assertTrue( $processor->get_attribute( 'b' ), 'Accessing an existing attribute did not return true' );
     213        $this->assertTrue( $processor->get_attribute( 'c' ), 'Accessing an existing attribute did not return true' );
     214        $this->assertTrue( $processor->get_attribute( 'd' ), 'Accessing an existing attribute did not return true' );
     215        $this->assertSame( 'test', $processor->get_attribute( 'e' ), 'Accessing an existing e="test" did not return "test"' );
    216216    }
    217217
     
    226226     */
    227227    public function test_get_attribute_is_case_insensitive_for_attributes_with_values( $attribute_name ) {
    228         $p = new WP_HTML_Tag_Processor( '<div DATA-enabled="true">Test</div>' );
    229         $p->next_tag();
     228        $processor = new WP_HTML_Tag_Processor( '<div DATA-enabled="true">Test</div>' );
     229        $processor->next_tag();
    230230
    231231        $this->assertSame(
    232232            'true',
    233             $p->get_attribute( $attribute_name ),
     233            $processor->get_attribute( $attribute_name ),
    234234            'Accessing an attribute by a differently-cased name did not return its value'
    235235        );
     
    246246     */
    247247    public function test_attributes_parser_is_case_insensitive_for_attributes_without_values( $attribute_name ) {
    248         $p = new WP_HTML_Tag_Processor( '<div DATA-enabled>Test</div>' );
    249         $p->next_tag();
     248        $processor = new WP_HTML_Tag_Processor( '<div DATA-enabled>Test</div>' );
     249        $processor->next_tag();
    250250
    251251        $this->assertTrue(
    252             $p->get_attribute( $attribute_name ),
     252            $processor->get_attribute( $attribute_name ),
    253253            'Accessing an attribute by a differently-cased name did not return its value'
    254254        );
     
    260260     * @return array[].
    261261     */
    262     public function data_attribute_name_case_variants() {
     262    public static function data_attribute_name_case_variants() {
    263263        return array(
    264264            array( 'DATA-enabled' ),
     
    275275     */
    276276    public function test_remove_attribute_is_case_insensitive() {
    277         $p = new WP_HTML_Tag_Processor( '<div DATA-enabled="true">Test</div>' );
    278         $p->next_tag();
    279         $p->remove_attribute( 'data-enabled' );
    280 
    281         $this->assertSame( '<div >Test</div>', $p->get_updated_html(), 'A case-insensitive remove_attribute call did not remove the attribute' );
     277        $processor = new WP_HTML_Tag_Processor( '<div DATA-enabled="true">Test</div>' );
     278        $processor->next_tag();
     279        $processor->remove_attribute( 'data-enabled' );
     280
     281        $this->assertSame( '<div >Test</div>', $processor->get_updated_html(), 'A case-insensitive remove_attribute call did not remove the attribute' );
    282282    }
    283283
     
    288288     */
    289289    public function test_set_attribute_is_case_insensitive() {
    290         $p = new WP_HTML_Tag_Processor( '<div DATA-enabled="true">Test</div>' );
    291         $p->next_tag();
    292         $p->set_attribute( 'data-enabled', 'abc' );
    293 
    294         $this->assertSame( '<div data-enabled="abc">Test</div>', $p->get_updated_html(), 'A case-insensitive set_attribute call did not update the existing attribute' );
     290        $processor = new WP_HTML_Tag_Processor( '<div DATA-enabled="true">Test</div>' );
     291        $processor->next_tag();
     292        $processor->set_attribute( 'data-enabled', 'abc' );
     293
     294        $this->assertSame( '<div data-enabled="abc">Test</div>', $processor->get_updated_html(), 'A case-insensitive set_attribute call did not update the existing attribute' );
    295295    }
    296296
     
    301301     */
    302302    public function test_get_attribute_names_with_prefix_returns_null_before_finding_tags() {
    303         $p = new WP_HTML_Tag_Processor( '<div data-foo="bar">Test</div>' );
     303        $processor = new WP_HTML_Tag_Processor( '<div data-foo="bar">Test</div>' );
    304304        $this->assertNull(
    305             $p->get_attribute_names_with_prefix( 'data-' ),
     305            $processor->get_attribute_names_with_prefix( 'data-' ),
    306306            'Accessing attributes by their prefix did not return null when no tag was selected'
    307307        );
     
    314314     */
    315315    public function test_get_attribute_names_with_prefix_returns_null_when_not_in_open_tag() {
    316         $p = new WP_HTML_Tag_Processor( '<div data-foo="bar">Test</div>' );
    317         $p->next_tag( 'p' );
    318         $this->assertNull( $p->get_attribute_names_with_prefix( 'data-' ), 'Accessing attributes of a non-existing tag did not return null' );
     316        $processor = new WP_HTML_Tag_Processor( '<div data-foo="bar">Test</div>' );
     317        $processor->next_tag( 'p' );
     318        $this->assertNull( $processor->get_attribute_names_with_prefix( 'data-' ), 'Accessing attributes of a non-existing tag did not return null' );
    319319    }
    320320
     
    325325     */
    326326    public function test_get_attribute_names_with_prefix_returns_null_when_in_closing_tag() {
    327         $p = new WP_HTML_Tag_Processor( '<div data-foo="bar">Test</div>' );
    328         $p->next_tag( 'div' );
    329         $p->next_tag( array( 'tag_closers' => 'visit' ) );
    330 
    331         $this->assertNull( $p->get_attribute_names_with_prefix( 'data-' ), 'Accessing attributes of a closing tag did not return null' );
     327        $processor = new WP_HTML_Tag_Processor( '<div data-foo="bar">Test</div>' );
     328        $processor->next_tag( 'div' );
     329        $processor->next_tag( array( 'tag_closers' => 'visit' ) );
     330
     331        $this->assertNull( $processor->get_attribute_names_with_prefix( 'data-' ), 'Accessing attributes of a closing tag did not return null' );
    332332    }
    333333
     
    338338     */
    339339    public function test_get_attribute_names_with_prefix_returns_empty_array_when_no_attributes_present() {
    340         $p = new WP_HTML_Tag_Processor( '<div>Test</div>' );
    341         $p->next_tag( 'div' );
    342 
    343         $this->assertSame( array(), $p->get_attribute_names_with_prefix( 'data-' ), 'Accessing the attributes on a tag without any did not return an empty array' );
     340        $processor = new WP_HTML_Tag_Processor( '<div>Test</div>' );
     341        $processor->next_tag( 'div' );
     342
     343        $this->assertSame( array(), $processor->get_attribute_names_with_prefix( 'data-' ), 'Accessing the attributes on a tag without any did not return an empty array' );
    344344    }
    345345
     
    350350     */
    351351    public function test_get_attribute_names_with_prefix_returns_matching_attribute_names_in_lowercase() {
    352         $p = new WP_HTML_Tag_Processor( '<div DATA-enabled class="test" data-test-ID="14">Test</div>' );
    353         $p->next_tag();
     352        $processor = new WP_HTML_Tag_Processor( '<div DATA-enabled class="test" data-test-ID="14">Test</div>' );
     353        $processor->next_tag();
    354354
    355355        $this->assertSame(
    356356            array( 'data-enabled', 'data-test-id' ),
    357             $p->get_attribute_names_with_prefix( 'data-' ),
     357            $processor->get_attribute_names_with_prefix( 'data-' ),
    358358            'Accessing attributes by their prefix did not return their lowercase names'
    359359        );
     
    366366     */
    367367    public function test_get_attribute_names_with_prefix_returns_attribute_added_by_set_attribute() {
    368         $p = new WP_HTML_Tag_Processor( '<div data-foo="bar">Test</div>' );
    369         $p->next_tag();
    370         $p->set_attribute( 'data-test-id', '14' );
     368        $processor = new WP_HTML_Tag_Processor( '<div data-foo="bar">Test</div>' );
     369        $processor->next_tag();
     370        $processor->set_attribute( 'data-test-id', '14' );
    371371
    372372        $this->assertSame(
    373373            '<div data-test-id="14" data-foo="bar">Test</div>',
    374             $p->get_updated_html(),
     374            $processor->get_updated_html(),
    375375            "Updated HTML doesn't include attribute added via set_attribute"
    376376        );
    377377        $this->assertSame(
    378378            array( 'data-test-id', 'data-foo' ),
    379             $p->get_attribute_names_with_prefix( 'data-' ),
     379            $processor->get_attribute_names_with_prefix( 'data-' ),
    380380            "Accessing attribute names doesn't find attribute added via set_attribute"
    381381        );
     
    388388     */
    389389    public function test_to_string_returns_updated_html() {
    390         $p = new WP_HTML_Tag_Processor( '<hr id="remove" /><div enabled class="test">Test</div><span id="span-id"></span>' );
    391         $p->next_tag();
    392         $p->remove_attribute( 'id' );
    393 
    394         $p->next_tag();
    395         $p->set_attribute( 'id', 'div-id-1' );
    396         $p->add_class( 'new_class_1' );
    397 
    398         $this->assertSame(
    399             $p->get_updated_html(),
    400             (string) $p,
     390        $processor = new WP_HTML_Tag_Processor( '<hr id="remove" /><div enabled class="test">Test</div><span id="span-id"></span>' );
     391        $processor->next_tag();
     392        $processor->remove_attribute( 'id' );
     393
     394        $processor->next_tag();
     395        $processor->set_attribute( 'id', 'div-id-1' );
     396        $processor->add_class( 'new_class_1' );
     397
     398        $this->assertSame(
     399            $processor->get_updated_html(),
     400            (string) $processor,
    401401            'get_updated_html() returned a different value than __toString()'
    402402        );
     
    409409     */
    410410    public function test_get_updated_html_applies_the_updates_so_far_and_keeps_the_processor_on_the_current_tag() {
    411         $p = new WP_HTML_Tag_Processor( '<hr id="remove" /><div enabled class="test">Test</div><span id="span-id"></span>' );
    412         $p->next_tag();
    413         $p->remove_attribute( 'id' );
    414 
    415         $p->next_tag();
    416         $p->set_attribute( 'id', 'div-id-1' );
    417         $p->add_class( 'new_class_1' );
     411        $processor = new WP_HTML_Tag_Processor( '<hr id="remove" /><div enabled class="test">Test</div><span id="span-id"></span>' );
     412        $processor->next_tag();
     413        $processor->remove_attribute( 'id' );
     414
     415        $processor->next_tag();
     416        $processor->set_attribute( 'id', 'div-id-1' );
     417        $processor->add_class( 'new_class_1' );
    418418
    419419        $this->assertSame(
    420420            '<hr  /><div id="div-id-1" enabled class="test new_class_1">Test</div><span id="span-id"></span>',
    421             $p->get_updated_html(),
     421            $processor->get_updated_html(),
    422422            'Calling get_updated_html after updating the attributes of the second tag returned different HTML than expected'
    423423        );
    424424
    425         $p->set_attribute( 'id', 'div-id-2' );
    426         $p->add_class( 'new_class_2' );
     425        $processor->set_attribute( 'id', 'div-id-2' );
     426        $processor->add_class( 'new_class_2' );
    427427
    428428        $this->assertSame(
    429429            '<hr  /><div id="div-id-2" enabled class="test new_class_1 new_class_2">Test</div><span id="span-id"></span>',
    430             $p->get_updated_html(),
     430            $processor->get_updated_html(),
    431431            'Calling get_updated_html after updating the attributes of the second tag for the second time returned different HTML than expected'
    432432        );
    433433
    434         $p->next_tag();
    435         $p->remove_attribute( 'id' );
     434        $processor->next_tag();
     435        $processor->remove_attribute( 'id' );
    436436
    437437        $this->assertSame(
    438438            '<hr  /><div id="div-id-2" enabled class="test new_class_1 new_class_2">Test</div><span ></span>',
    439             $p->get_updated_html(),
     439            $processor->get_updated_html(),
    440440            'Calling get_updated_html after removing the id attribute of the third tag returned different HTML than expected'
    441441        );
     
    448448     */
    449449    public function test_get_updated_html_without_updating_any_attributes_returns_the_original_html() {
    450         $p = new WP_HTML_Tag_Processor( self::HTML_SIMPLE );
     450        $processor = new WP_HTML_Tag_Processor( self::HTML_SIMPLE );
    451451
    452452        $this->assertSame(
    453453            self::HTML_SIMPLE,
    454             $p->get_updated_html(),
     454            $processor->get_updated_html(),
    455455            'Casting WP_HTML_Tag_Processor to a string without performing any updates did not return the initial HTML snippet'
    456456        );
     
    464464     */
    465465    public function test_get_updated_html_applies_updates_to_content_after_seeking_to_before_parsed_bytes() {
    466         $p = new WP_HTML_Tag_Processor( '<div><img hidden></div>' );
    467 
    468         $p->next_tag();
    469         $p->set_attribute( 'wonky', true );
    470         $p->next_tag();
    471         $p->set_bookmark( 'here' );
    472 
    473         $p->next_tag( array( 'tag_closers' => 'visit' ) );
    474         $p->seek( 'here' );
    475 
    476         $this->assertSame( '<div wonky><img hidden></div>', $p->get_updated_html() );
     466        $processor = new WP_HTML_Tag_Processor( '<div><img hidden></div>' );
     467
     468        $processor->next_tag();
     469        $processor->set_attribute( 'wonky', true );
     470        $processor->next_tag();
     471        $processor->set_bookmark( 'here' );
     472
     473        $processor->next_tag( array( 'tag_closers' => 'visit' ) );
     474        $processor->seek( 'here' );
     475
     476        $this->assertSame( '<div wonky><img hidden></div>', $processor->get_updated_html() );
    477477    }
    478478
     
    483483     */
    484484    public function test_next_tag_with_no_arguments_should_find_the_next_existing_tag() {
    485         $p = new WP_HTML_Tag_Processor( self::HTML_SIMPLE );
    486 
    487         $this->assertTrue( $p->next_tag(), 'Querying an existing tag did not return true' );
     485        $processor = new WP_HTML_Tag_Processor( self::HTML_SIMPLE );
     486
     487        $this->assertTrue( $processor->next_tag(), 'Querying an existing tag did not return true' );
    488488    }
    489489
     
    494494     */
    495495    public function test_next_tag_should_return_false_for_a_non_existing_tag() {
    496         $p = new WP_HTML_Tag_Processor( self::HTML_SIMPLE );
    497 
    498         $this->assertFalse( $p->next_tag( 'p' ), 'Querying a non-existing tag did not return false' );
     496        $processor = new WP_HTML_Tag_Processor( self::HTML_SIMPLE );
     497
     498        $this->assertFalse( $processor->next_tag( 'p' ), 'Querying a non-existing tag did not return false' );
    499499    }
    500500
     
    505505     */
    506506    public function test_next_tag_matches_decoded_class_names() {
    507         $p = new WP_HTML_Tag_Processor( '<div class="&lt;egg&gt;">' );
    508 
    509         $this->assertTrue( $p->next_tag( array( 'class_name' => '<egg>' ) ), 'Failed to find tag with HTML-encoded class name.' );
     507        $processor = new WP_HTML_Tag_Processor( '<div class="&lt;egg&gt;">' );
     508
     509        $this->assertTrue( $processor->next_tag( array( 'class_name' => '<egg>' ) ), 'Failed to find tag with HTML-encoded class name.' );
    510510    }
    511511
     
    518518     */
    519519    public function test_next_tag_should_stop_on_closers_only_when_requested() {
    520         $p = new WP_HTML_Tag_Processor( '<div><img /></div>' );
    521 
    522         $this->assertTrue( $p->next_tag( array( 'tag_name' => 'div' ) ), 'Did not find desired tag opener' );
    523         $this->assertFalse( $p->next_tag( array( 'tag_name' => 'div' ) ), 'Visited an unwanted tag, a tag closer' );
    524 
    525         $p = new WP_HTML_Tag_Processor( '<div><img /></div>' );
    526         $p->next_tag(
     520        $processor = new WP_HTML_Tag_Processor( '<div><img /></div>' );
     521
     522        $this->assertTrue( $processor->next_tag( array( 'tag_name' => 'div' ) ), 'Did not find desired tag opener' );
     523        $this->assertFalse( $processor->next_tag( array( 'tag_name' => 'div' ) ), 'Visited an unwanted tag, a tag closer' );
     524
     525        $processor = new WP_HTML_Tag_Processor( '<div><img /></div>' );
     526        $processor->next_tag(
    527527            array(
    528528                'tag_name'    => 'div',
     
    531531        );
    532532
    533         $this->assertFalse( $p->is_tag_closer(), 'Indicated a tag opener is a tag closer' );
     533        $this->assertFalse( $processor->is_tag_closer(), 'Indicated a tag opener is a tag closer' );
    534534        $this->assertTrue(
    535             $p->next_tag(
     535            $processor->next_tag(
    536536                array(
    537537                    'tag_name'    => 'div',
     
    541541            'Did not stop at desired tag closer'
    542542        );
    543         $this->assertTrue( $p->is_tag_closer(), 'Indicated a tag closer is a tag opener' );
    544 
    545         $p = new WP_HTML_Tag_Processor( '<div>' );
    546         $this->assertTrue( $p->next_tag( array( 'tag_closers' => 'visit' ) ), "Did not find a tag opener when tag_closers was set to 'visit'" );
    547         $this->assertFalse( $p->next_tag( array( 'tag_closers' => 'visit' ) ), "Found a closer where there wasn't one" );
     543        $this->assertTrue( $processor->is_tag_closer(), 'Indicated a tag closer is a tag opener' );
     544
     545        $processor = new WP_HTML_Tag_Processor( '<div>' );
     546        $this->assertTrue( $processor->next_tag( array( 'tag_closers' => 'visit' ) ), "Did not find a tag opener when tag_closers was set to 'visit'" );
     547        $this->assertFalse( $processor->next_tag( array( 'tag_closers' => 'visit' ) ), "Found a closer where there wasn't one" );
    548548    }
    549549
     
    555555     */
    556556    public function test_next_tag_should_stop_on_rcdata_and_script_tag_closers_when_requested() {
    557         $p = new WP_HTML_Tag_Processor( '<script>abc</script>' );
    558 
    559         $p->next_tag();
     557        $processor = new WP_HTML_Tag_Processor( '<script>abc</script>' );
     558
     559        $processor->next_tag();
    560560        $this->assertFalse(
    561             $p->next_tag( array( 'tag_closers' => 'visit' ) ),
     561            $processor->next_tag( array( 'tag_closers' => 'visit' ) ),
    562562            'Should not have found closing SCRIPT tag when closing an opener.'
    563563        );
    564564
    565         $p = new WP_HTML_Tag_Processor( 'abc</script>' );
    566         $this->assertTrue( $p->next_tag( array( 'tag_closers' => 'visit' ) ), 'Did not find the </script> tag closer when there was no tag opener' );
    567 
    568         $p = new WP_HTML_Tag_Processor( '<textarea>abc</textarea>' );
    569 
    570         $p->next_tag();
     565        $processor = new WP_HTML_Tag_Processor( 'abc</script>' );
     566        $this->assertTrue( $processor->next_tag( array( 'tag_closers' => 'visit' ) ), 'Did not find the </script> tag closer when there was no tag opener' );
     567
     568        $processor = new WP_HTML_Tag_Processor( '<textarea>abc</textarea>' );
     569
     570        $processor->next_tag();
    571571        $this->assertFalse(
    572             $p->next_tag( array( 'tag_closers' => 'visit' ) ),
     572            $processor->next_tag( array( 'tag_closers' => 'visit' ) ),
    573573            'Should not have found closing TEXTAREA when closing an opener.'
    574574        );
    575575
    576         $p = new WP_HTML_Tag_Processor( 'abc</textarea>' );
    577         $this->assertTrue( $p->next_tag( array( 'tag_closers' => 'visit' ) ), 'Did not find the </textarea> tag closer when there was no tag opener' );
    578 
    579         $p = new WP_HTML_Tag_Processor( '<title>abc</title>' );
    580 
    581         $p->next_tag();
     576        $processor = new WP_HTML_Tag_Processor( 'abc</textarea>' );
     577        $this->assertTrue( $processor->next_tag( array( 'tag_closers' => 'visit' ) ), 'Did not find the </textarea> tag closer when there was no tag opener' );
     578
     579        $processor = new WP_HTML_Tag_Processor( '<title>abc</title>' );
     580
     581        $processor->next_tag();
    582582        $this->assertFalse(
    583             $p->next_tag( array( 'tag_closers' => 'visit' ) ),
     583            $processor->next_tag( array( 'tag_closers' => 'visit' ) ),
    584584            'Should not have found closing TITLE when closing an opener.'
    585585        );
    586586
    587         $p = new WP_HTML_Tag_Processor( 'abc</title>' );
    588         $this->assertTrue( $p->next_tag( array( 'tag_closers' => 'visit' ) ), 'Did not find the </title> tag closer when there was no tag opener' );
     587        $processor = new WP_HTML_Tag_Processor( 'abc</title>' );
     588        $this->assertTrue( $processor->next_tag( array( 'tag_closers' => 'visit' ) ), 'Did not find the </title> tag closer when there was no tag opener' );
    589589    }
    590590
     
    621621     */
    622622    public function test_set_attribute_on_a_non_existing_tag_does_not_change_the_markup() {
    623         $p = new WP_HTML_Tag_Processor( self::HTML_SIMPLE );
    624 
    625         $this->assertFalse( $p->next_tag( 'p' ), 'Querying a non-existing tag did not return false' );
    626         $this->assertFalse( $p->next_tag( 'div' ), 'Querying a non-existing tag did not return false' );
    627 
    628         $p->set_attribute( 'id', 'primary' );
     623        $processor = new WP_HTML_Tag_Processor( self::HTML_SIMPLE );
     624
     625        $this->assertFalse( $processor->next_tag( 'p' ), 'Querying a non-existing tag did not return false' );
     626        $this->assertFalse( $processor->next_tag( 'div' ), 'Querying a non-existing tag did not return false' );
     627
     628        $processor->set_attribute( 'id', 'primary' );
    629629
    630630        $this->assertSame(
    631631            self::HTML_SIMPLE,
    632             $p->get_updated_html(),
     632            $processor->get_updated_html(),
    633633            'Calling get_updated_html after updating a non-existing tag returned an HTML that was different from the original HTML'
    634634        );
     
    644644     */
    645645    public function test_attribute_ops_on_tag_closer_do_not_change_the_markup() {
    646         $p = new WP_HTML_Tag_Processor( '<div id=3></div invalid-id=4>' );
    647         $p->next_tag(
     646        $processor = new WP_HTML_Tag_Processor( '<div id=3></div invalid-id=4>' );
     647        $processor->next_tag(
    648648            array(
    649649                'tag_name'    => 'div',
     
    652652        );
    653653
    654         $this->assertFalse( $p->is_tag_closer(), 'Skipped tag opener' );
    655 
    656         $p->next_tag(
     654        $this->assertFalse( $processor->is_tag_closer(), 'Skipped tag opener' );
     655
     656        $processor->next_tag(
    657657            array(
    658658                'tag_name'    => 'div',
     
    661661        );
    662662
    663         $this->assertTrue( $p->is_tag_closer(), 'Skipped tag closer' );
    664         $this->assertFalse( $p->set_attribute( 'id', 'test' ), "Allowed setting an attribute on a tag closer when it shouldn't have" );
    665         $this->assertFalse( $p->remove_attribute( 'invalid-id' ), "Allowed removing an attribute on a tag closer when it shouldn't have" );
    666         $this->assertFalse( $p->add_class( 'sneaky' ), "Allowed adding a class on a tag closer when it shouldn't have" );
    667         $this->assertFalse( $p->remove_class( 'not-appearing-in-this-test' ), "Allowed removing a class on a tag closer when it shouldn't have" );
     663        $this->assertTrue( $processor->is_tag_closer(), 'Skipped tag closer' );
     664        $this->assertFalse( $processor->set_attribute( 'id', 'test' ), "Allowed setting an attribute on a tag closer when it shouldn't have" );
     665        $this->assertFalse( $processor->remove_attribute( 'invalid-id' ), "Allowed removing an attribute on a tag closer when it shouldn't have" );
     666        $this->assertFalse( $processor->add_class( 'sneaky' ), "Allowed adding a class on a tag closer when it shouldn't have" );
     667        $this->assertFalse( $processor->remove_class( 'not-appearing-in-this-test' ), "Allowed removing a class on a tag closer when it shouldn't have" );
    668668        $this->assertSame(
    669669            '<div id=3></div invalid-id=4>',
    670             $p->get_updated_html(),
     670            $processor->get_updated_html(),
    671671            'Calling get_updated_html after updating a non-existing tag returned an HTML that was different from the original HTML'
    672672        );
     
    677677     *
    678678     * ```php
    679      *     $p = new WP_HTML_Tag_Processor( '<div class="header"></div>' );
    680      *     $p->next_tag();
    681      *     $p->set_attribute('class', '" onclick="alert');
     679     *     $processor = new WP_HTML_Tag_Processor( '<div class="header"></div>' );
     680     *     $processor->next_tag();
     681     *     $processor->set_attribute('class', '" onclick="alert');
    682682     *     echo $p;
    683683     *     // <div class="" onclick="alert"></div>
     
    698698     */
    699699    public function test_set_attribute_prevents_xss( $attribute_value ) {
    700         $p = new WP_HTML_Tag_Processor( '<div></div>' );
    701         $p->next_tag();
    702         $p->set_attribute( 'test', $attribute_value );
     700        $processor = new WP_HTML_Tag_Processor( '<div></div>' );
     701        $processor->next_tag();
     702        $processor->set_attribute( 'test', $attribute_value );
    703703
    704704        /*
     
    714714         */
    715715        $match = null;
    716         preg_match( '~^<div test=(.*)></div>$~', $p->get_updated_html(), $match );
     716        preg_match( '~^<div test=(.*)></div>$~', $processor->get_updated_html(), $match );
    717717        list( , $actual_value ) = $match;
    718718
     
    725725     * @return string[][].
    726726     */
    727     public function data_set_attribute_prevents_xss() {
     727    public static function data_set_attribute_prevents_xss() {
    728728        return array(
    729729            array( '"' ),
     
    745745     */
    746746    public function test_set_attribute_with_a_non_existing_attribute_adds_a_new_attribute_to_the_markup() {
    747         $p = new WP_HTML_Tag_Processor( self::HTML_SIMPLE );
    748         $p->next_tag();
    749         $p->set_attribute( 'test-attribute', 'test-value' );
     747        $processor = new WP_HTML_Tag_Processor( self::HTML_SIMPLE );
     748        $processor->next_tag();
     749        $processor->set_attribute( 'test-attribute', 'test-value' );
    750750
    751751        $this->assertSame(
    752752            '<div test-attribute="test-value" id="first"><span id="second">Text</span></div>',
    753             $p->get_updated_html(),
     753            $processor->get_updated_html(),
    754754            'Updated HTML does not include attribute added via set_attribute()'
    755755        );
    756756        $this->assertSame(
    757757            'test-value',
    758             $p->get_attribute( 'test-attribute' ),
     758            $processor->get_attribute( 'test-attribute' ),
    759759            'get_attribute() (called after get_updated_html()) did not return attribute added via set_attribute()'
    760760        );
     
    767767     */
    768768    public function test_get_attribute_returns_updated_values_before_they_are_applied() {
    769         $p = new WP_HTML_Tag_Processor( self::HTML_SIMPLE );
    770         $p->next_tag();
    771         $p->set_attribute( 'test-attribute', 'test-value' );
     769        $processor = new WP_HTML_Tag_Processor( self::HTML_SIMPLE );
     770        $processor->next_tag();
     771        $processor->set_attribute( 'test-attribute', 'test-value' );
    772772
    773773        $this->assertSame(
    774774            'test-value',
    775             $p->get_attribute( 'test-attribute' ),
     775            $processor->get_attribute( 'test-attribute' ),
    776776            'get_attribute() (called before get_updated_html()) did not return attribute added via set_attribute()'
    777777        );
    778778        $this->assertSame(
    779779            '<div test-attribute="test-value" id="first"><span id="second">Text</span></div>',
    780             $p->get_updated_html(),
     780            $processor->get_updated_html(),
    781781            'Updated HTML does not include attribute added via set_attribute()'
    782782        );
     
    789789     */
    790790    public function test_get_attribute_returns_updated_values_before_they_are_applied_with_different_name_casing() {
    791         $p = new WP_HTML_Tag_Processor( self::HTML_SIMPLE );
    792         $p->next_tag();
    793         $p->set_attribute( 'test-ATTribute', 'test-value' );
     791        $processor = new WP_HTML_Tag_Processor( self::HTML_SIMPLE );
     792        $processor->next_tag();
     793        $processor->set_attribute( 'test-ATTribute', 'test-value' );
    794794
    795795        $this->assertSame(
    796796            'test-value',
    797             $p->get_attribute( 'test-attribute' ),
     797            $processor->get_attribute( 'test-attribute' ),
    798798            'get_attribute() (called before get_updated_html()) did not return attribute added via set_attribute()'
    799799        );
    800800        $this->assertSame(
    801801            '<div test-ATTribute="test-value" id="first"><span id="second">Text</span></div>',
    802             $p->get_updated_html(),
     802            $processor->get_updated_html(),
    803803            'Updated HTML does not include attribute added via set_attribute()'
    804804        );
     
    811811     */
    812812    public function test_get_attribute_reflects_added_class_names_before_they_are_applied() {
    813         $p = new WP_HTML_Tag_Processor( self::HTML_SIMPLE );
    814         $p->next_tag();
    815         $p->add_class( 'my-class' );
     813        $processor = new WP_HTML_Tag_Processor( self::HTML_SIMPLE );
     814        $processor->next_tag();
     815        $processor->add_class( 'my-class' );
    816816
    817817        $this->assertSame(
    818818            'my-class',
    819             $p->get_attribute( 'class' ),
     819            $processor->get_attribute( 'class' ),
    820820            'get_attribute() (called before get_updated_html()) did not return class name added via add_class()'
    821821        );
    822822        $this->assertSame(
    823823            '<div class="my-class" id="first"><span id="second">Text</span></div>',
    824             $p->get_updated_html(),
     824            $processor->get_updated_html(),
    825825            'Updated HTML does not include class name added via add_class()'
    826826        );
     
    833833     */
    834834    public function test_get_attribute_reflects_added_class_names_before_they_are_applied_and_retains_classes_from_previous_add_class_calls() {
    835         $p = new WP_HTML_Tag_Processor( self::HTML_SIMPLE );
    836         $p->next_tag();
    837         $p->add_class( 'my-class' );
     835        $processor = new WP_HTML_Tag_Processor( self::HTML_SIMPLE );
     836        $processor->next_tag();
     837        $processor->add_class( 'my-class' );
    838838
    839839        $this->assertSame(
    840840            'my-class',
    841             $p->get_attribute( 'class' ),
     841            $processor->get_attribute( 'class' ),
    842842            'get_attribute() (called before get_updated_html()) did not return class name added via add_class()'
    843843        );
    844844
    845         $p->add_class( 'my-other-class' );
     845        $processor->add_class( 'my-other-class' );
    846846
    847847        $this->assertSame(
    848848            'my-class my-other-class',
    849             $p->get_attribute( 'class' ),
     849            $processor->get_attribute( 'class' ),
    850850            'get_attribute() (called before get_updated_html()) did not return class names added via subsequent add_class() calls'
    851851        );
    852852        $this->assertSame(
    853853            '<div class="my-class my-other-class" id="first"><span id="second">Text</span></div>',
    854             $p->get_updated_html(),
     854            $processor->get_updated_html(),
    855855            'Updated HTML does not include class names added via subsequent add_class() calls'
    856856        );
     
    863863     */
    864864    public function test_get_attribute_reflects_removed_attribute_before_it_is_applied() {
    865         $p = new WP_HTML_Tag_Processor( self::HTML_SIMPLE );
    866         $p->next_tag();
    867         $p->remove_attribute( 'id' );
     865        $processor = new WP_HTML_Tag_Processor( self::HTML_SIMPLE );
     866        $processor->next_tag();
     867        $processor->remove_attribute( 'id' );
    868868
    869869        $this->assertNull(
    870             $p->get_attribute( 'id' ),
     870            $processor->get_attribute( 'id' ),
    871871            'get_attribute() (called before get_updated_html()) returned attribute that was removed by remove_attribute()'
    872872        );
    873873        $this->assertSame(
    874874            '<div ><span id="second">Text</span></div>',
    875             $p->get_updated_html(),
     875            $processor->get_updated_html(),
    876876            'Updated HTML includes attribute that was removed by remove_attribute()'
    877877        );
     
    884884     */
    885885    public function test_get_attribute_reflects_adding_and_then_removing_an_attribute_before_those_updates_are_applied() {
    886         $p = new WP_HTML_Tag_Processor( self::HTML_SIMPLE );
    887         $p->next_tag();
    888         $p->set_attribute( 'test-attribute', 'test-value' );
    889         $p->remove_attribute( 'test-attribute' );
     886        $processor = new WP_HTML_Tag_Processor( self::HTML_SIMPLE );
     887        $processor->next_tag();
     888        $processor->set_attribute( 'test-attribute', 'test-value' );
     889        $processor->remove_attribute( 'test-attribute' );
    890890
    891891        $this->assertNull(
    892             $p->get_attribute( 'test-attribute' ),
     892            $processor->get_attribute( 'test-attribute' ),
    893893            'get_attribute() (called before get_updated_html()) returned attribute that was added via set_attribute() and then removed by remove_attribute()'
    894894        );
    895895        $this->assertSame(
    896896            self::HTML_SIMPLE,
    897             $p->get_updated_html(),
     897            $processor->get_updated_html(),
    898898            'Updated HTML includes attribute that was added via set_attribute() and then removed by remove_attribute()'
    899899        );
     
    906906     */
    907907    public function test_get_attribute_reflects_setting_and_then_removing_an_existing_attribute_before_those_updates_are_applied() {
    908         $p = new WP_HTML_Tag_Processor( self::HTML_SIMPLE );
    909         $p->next_tag();
    910         $p->set_attribute( 'id', 'test-value' );
    911         $p->remove_attribute( 'id' );
     908        $processor = new WP_HTML_Tag_Processor( self::HTML_SIMPLE );
     909        $processor->next_tag();
     910        $processor->set_attribute( 'id', 'test-value' );
     911        $processor->remove_attribute( 'id' );
    912912
    913913        $this->assertNull(
    914             $p->get_attribute( 'id' ),
     914            $processor->get_attribute( 'id' ),
    915915            'get_attribute() (called before get_updated_html()) returned attribute that was overwritten by set_attribute() and then removed by remove_attribute()'
    916916        );
    917917        $this->assertSame(
    918918            '<div ><span id="second">Text</span></div>',
    919             $p->get_updated_html(),
     919            $processor->get_updated_html(),
    920920            'Updated HTML includes attribute that was overwritten by set_attribute() and then removed by remove_attribute()'
    921921        );
     
    928928     */
    929929    public function test_get_attribute_reflects_removed_class_names_before_they_are_applied() {
    930         $p = new WP_HTML_Tag_Processor( self::HTML_WITH_CLASSES );
    931         $p->next_tag();
    932         $p->remove_class( 'with-border' );
     930        $processor = new WP_HTML_Tag_Processor( self::HTML_WITH_CLASSES );
     931        $processor->next_tag();
     932        $processor->remove_class( 'with-border' );
    933933
    934934        $this->assertSame(
    935935            'main',
    936             $p->get_attribute( 'class' ),
     936            $processor->get_attribute( 'class' ),
    937937            'get_attribute() (called before get_updated_html()) returned the wrong attribute after calling remove_attribute()'
    938938        );
    939939        $this->assertSame(
    940940            '<div class="main" id="first"><span class="not-main bold with-border" id="second">Text</span></div>',
    941             $p->get_updated_html(),
     941            $processor->get_updated_html(),
    942942            'Updated HTML includes wrong attribute after calling remove_attribute()'
    943943        );
     
    950950     */
    951951    public function test_get_attribute_reflects_setting_and_then_removing_a_class_name_before_those_updates_are_applied() {
    952         $p = new WP_HTML_Tag_Processor( self::HTML_WITH_CLASSES );
    953         $p->next_tag();
    954         $p->add_class( 'foo-class' );
    955         $p->remove_class( 'foo-class' );
     952        $processor = new WP_HTML_Tag_Processor( self::HTML_WITH_CLASSES );
     953        $processor->next_tag();
     954        $processor->add_class( 'foo-class' );
     955        $processor->remove_class( 'foo-class' );
    956956
    957957        $this->assertSame(
    958958            'main with-border',
    959             $p->get_attribute( 'class' ),
     959            $processor->get_attribute( 'class' ),
    960960            'get_attribute() (called before get_updated_html()) returned class name that was added via add_class() and then removed by remove_class()'
    961961        );
    962962        $this->assertSame(
    963963            self::HTML_WITH_CLASSES,
    964             $p->get_updated_html(),
     964            $processor->get_updated_html(),
    965965            'Updated HTML includes class that was added via add_class() and then removed by remove_class()'
    966966        );
     
    973973     */
    974974    public function test_get_attribute_reflects_duplicating_and_then_removing_an_existing_class_name_before_those_updates_are_applied() {
    975         $p = new WP_HTML_Tag_Processor( self::HTML_WITH_CLASSES );
    976         $p->next_tag();
    977         $p->add_class( 'with-border' );
    978         $p->remove_class( 'with-border' );
     975        $processor = new WP_HTML_Tag_Processor( self::HTML_WITH_CLASSES );
     976        $processor->next_tag();
     977        $processor->add_class( 'with-border' );
     978        $processor->remove_class( 'with-border' );
    979979
    980980        $this->assertSame(
    981981            'main',
    982             $p->get_attribute( 'class' ),
     982            $processor->get_attribute( 'class' ),
    983983            'get_attribute() (called before get_updated_html()) returned class name that was duplicated via add_class() and then removed by remove_class()'
    984984        );
    985985        $this->assertSame(
    986986            '<div class="main" id="first"><span class="not-main bold with-border" id="second">Text</span></div>',
    987             $p->get_updated_html(),
     987            $processor->get_updated_html(),
    988988            'Updated HTML includes class that was duplicated via add_class() and then removed by remove_class()'
    989989        );
     
    999999     */
    10001000    public function test_update_first_attribute_when_duplicated_attributes_exist() {
    1001         $p = new WP_HTML_Tag_Processor( '<div id="update-me" id="ignored-id"><span id="second">Text</span></div>' );
    1002         $p->next_tag();
    1003         $p->set_attribute( 'id', 'updated-id' );
     1001        $processor = new WP_HTML_Tag_Processor( '<div id="update-me" id="ignored-id"><span id="second">Text</span></div>' );
     1002        $processor->next_tag();
     1003        $processor->set_attribute( 'id', 'updated-id' );
    10041004
    10051005        $this->assertSame(
    10061006            '<div id="updated-id" id="ignored-id"><span id="second">Text</span></div>',
    1007             $p->get_updated_html(),
     1007            $processor->get_updated_html(),
    10081008            'Proper (first) appearance of attribute was not updated when duplicates exist'
    10091009        );
     
    10161016     */
    10171017    public function test_set_attribute_with_an_existing_attribute_name_updates_its_value_in_the_markup() {
    1018         $p = new WP_HTML_Tag_Processor( self::HTML_SIMPLE );
    1019         $p->next_tag();
    1020         $p->set_attribute( 'id', 'new-id' );
     1018        $processor = new WP_HTML_Tag_Processor( self::HTML_SIMPLE );
     1019        $processor->next_tag();
     1020        $processor->set_attribute( 'id', 'new-id' );
    10211021        $this->assertSame(
    10221022            '<div id="new-id"><span id="second">Text</span></div>',
    1023             $p->get_updated_html(),
     1023            $processor->get_updated_html(),
    10241024            'Existing attribute was not updated'
    10251025        );
     
    10351035     */
    10361036    public function test_set_attribute_with_case_variants_updates_only_the_original_first_copy() {
    1037         $p = new WP_HTML_Tag_Processor( '<div data-enabled="5">' );
    1038         $p->next_tag();
    1039         $p->set_attribute( 'DATA-ENABLED', 'canary' );
    1040         $p->set_attribute( 'Data-Enabled', 'canary' );
    1041         $p->set_attribute( 'dATa-EnABled', 'canary' );
    1042 
    1043         $this->assertSame( '<div data-enabled="canary">', strtolower( $p->get_updated_html() ) );
     1037        $processor = new WP_HTML_Tag_Processor( '<div data-enabled="5">' );
     1038        $processor->next_tag();
     1039        $processor->set_attribute( 'DATA-ENABLED', 'canary' );
     1040        $processor->set_attribute( 'Data-Enabled', 'canary' );
     1041        $processor->set_attribute( 'dATa-EnABled', 'canary' );
     1042
     1043        $this->assertSame( '<div data-enabled="canary">', strtolower( $processor->get_updated_html() ) );
    10441044    }
    10451045
     
    10511051     */
    10521052    public function test_next_tag_and_set_attribute_in_a_loop_update_all_tags_in_the_markup() {
    1053         $p = new WP_HTML_Tag_Processor( self::HTML_SIMPLE );
    1054         while ( $p->next_tag() ) {
    1055             $p->set_attribute( 'data-foo', 'bar' );
     1053        $processor = new WP_HTML_Tag_Processor( self::HTML_SIMPLE );
     1054        while ( $processor->next_tag() ) {
     1055            $processor->set_attribute( 'data-foo', 'bar' );
    10561056        }
    10571057
    10581058        $this->assertSame(
    10591059            '<div data-foo="bar" id="first"><span data-foo="bar" id="second">Text</span></div>',
    1060             $p->get_updated_html(),
     1060            $processor->get_updated_html(),
    10611061            'Not all tags were updated when looping with next_tag() and set_attribute()'
    10621062        );
     
    10741074     */
    10751075    public function test_remove_first_when_duplicated_attribute() {
    1076         $p = new WP_HTML_Tag_Processor( '<div id="update-me" id="ignored-id"><span id="second">Text</span></div>' );
    1077         $p->next_tag();
    1078         $p->remove_attribute( 'id' );
     1076        $processor = new WP_HTML_Tag_Processor( '<div id="update-me" id="ignored-id"><span id="second">Text</span></div>' );
     1077        $processor->next_tag();
     1078        $processor->remove_attribute( 'id' );
    10791079
    10801080        $this->assertStringNotContainsString(
    10811081            'update-me',
    1082             $p->get_updated_html(),
     1082            $processor->get_updated_html(),
    10831083            'First attribute (when duplicates exist) was not removed'
    10841084        );
     
    10911091     */
    10921092    public function test_remove_attribute_with_an_existing_attribute_name_removes_it_from_the_markup() {
    1093         $p = new WP_HTML_Tag_Processor( self::HTML_SIMPLE );
    1094         $p->next_tag();
    1095         $p->remove_attribute( 'id' );
     1093        $processor = new WP_HTML_Tag_Processor( self::HTML_SIMPLE );
     1094        $processor->next_tag();
     1095        $processor->remove_attribute( 'id' );
    10961096
    10971097        $this->assertSame(
    10981098            '<div ><span id="second">Text</span></div>',
    1099             $p->get_updated_html(),
     1099            $processor->get_updated_html(),
    11001100            'Attribute was not removed'
    11011101        );
     
    11121112     */
    11131113    public function test_remove_attribute_with_duplicated_attributes_removes_all_of_them( $html_with_duplicate_attributes, $attribute_to_remove ) {
    1114         $p = new WP_HTML_Tag_Processor( $html_with_duplicate_attributes );
    1115         $p->next_tag();
    1116 
    1117         $p->remove_attribute( $attribute_to_remove );
    1118         $this->assertNull( $p->get_attribute( $attribute_to_remove ), 'Failed to remove all copies of an attribute when duplicated in modified source.' );
     1114        $processor = new WP_HTML_Tag_Processor( $html_with_duplicate_attributes );
     1115        $processor->next_tag();
     1116
     1117        $processor->remove_attribute( $attribute_to_remove );
     1118        $this->assertNull( $processor->get_attribute( $attribute_to_remove ), 'Failed to remove all copies of an attribute when duplicated in modified source.' );
    11191119
    11201120        // Recreate a tag processor with the updated HTML after removing the attribute.
    1121         $p = new WP_HTML_Tag_Processor( $p->get_updated_html() );
    1122         $p->next_tag();
    1123         $this->assertNull( $p->get_attribute( $attribute_to_remove ), 'Failed to remove all copies of duplicated attributes when getting updated HTML.' );
     1121        $processor = new WP_HTML_Tag_Processor( $processor->get_updated_html() );
     1122        $processor->next_tag();
     1123        $this->assertNull( $processor->get_attribute( $attribute_to_remove ), 'Failed to remove all copies of duplicated attributes when getting updated HTML.' );
    11241124    }
    11251125
     
    11321132     */
    11331133    public function test_previous_duplicated_attributes_are_not_removed_on_successive_tag_removal() {
    1134         $p = new WP_HTML_Tag_Processor( '<span id=one id=two id=three><span id=four>' );
    1135         $p->next_tag();
    1136         $p->next_tag();
    1137         $p->remove_attribute( 'id' );
    1138 
    1139         $this->assertSame( '<span id=one id=two id=three><span >', $p->get_updated_html() );
     1134        $processor = new WP_HTML_Tag_Processor( '<span id=one id=two id=three><span id=four>' );
     1135        $processor->next_tag();
     1136        $processor->next_tag();
     1137        $processor->remove_attribute( 'id' );
     1138
     1139        $this->assertSame( '<span id=one id=two id=three><span >', $processor->get_updated_html() );
    11401140    }
    11411141
     
    11471147     * @return array[].
    11481148     */
    1149     public function data_html_with_duplicated_attributes() {
     1149    public static function data_html_with_duplicated_attributes() {
    11501150        return array(
    11511151            'Double attributes'               => array( '<div id=one id=two>', 'id' ),
     
    11631163     */
    11641164    public function test_remove_attribute_with_a_non_existing_attribute_name_does_not_change_the_markup() {
    1165         $p = new WP_HTML_Tag_Processor( self::HTML_SIMPLE );
    1166         $p->next_tag();
    1167         $p->remove_attribute( 'no-such-attribute' );
     1165        $processor = new WP_HTML_Tag_Processor( self::HTML_SIMPLE );
     1166        $processor->next_tag();
     1167        $processor->remove_attribute( 'no-such-attribute' );
    11681168
    11691169        $this->assertSame(
    11701170            self::HTML_SIMPLE,
    1171             $p->get_updated_html(),
     1171            $processor->get_updated_html(),
    11721172            'Content was changed when attempting to remove an attribute that did not exist'
    11731173        );
     
    11801180     */
    11811181    public function test_add_class_creates_a_class_attribute_when_there_is_none() {
    1182         $p = new WP_HTML_Tag_Processor( self::HTML_SIMPLE );
    1183         $p->next_tag();
    1184         $p->add_class( 'foo-class' );
     1182        $processor = new WP_HTML_Tag_Processor( self::HTML_SIMPLE );
     1183        $processor->next_tag();
     1184        $processor->add_class( 'foo-class' );
    11851185
    11861186        $this->assertSame(
    11871187            '<div class="foo-class" id="first"><span id="second">Text</span></div>',
    1188             $p->get_updated_html(),
     1188            $processor->get_updated_html(),
    11891189            'Updated HTML does not include class name added via add_class()'
    11901190        );
    11911191        $this->assertSame(
    11921192            'foo-class',
    1193             $p->get_attribute( 'class' ),
     1193            $processor->get_attribute( 'class' ),
    11941194            "get_attribute( 'class' ) did not return class name added via add_class()"
    11951195        );
     
    12021202     */
    12031203    public function test_calling_add_class_twice_creates_a_class_attribute_with_both_class_names_when_there_is_no_class_attribute() {
    1204         $p = new WP_HTML_Tag_Processor( self::HTML_SIMPLE );
    1205         $p->next_tag();
    1206         $p->add_class( 'foo-class' );
    1207         $p->add_class( 'bar-class' );
     1204        $processor = new WP_HTML_Tag_Processor( self::HTML_SIMPLE );
     1205        $processor->next_tag();
     1206        $processor->add_class( 'foo-class' );
     1207        $processor->add_class( 'bar-class' );
    12081208
    12091209        $this->assertSame(
    12101210            '<div class="foo-class bar-class" id="first"><span id="second">Text</span></div>',
    1211             $p->get_updated_html(),
     1211            $processor->get_updated_html(),
    12121212            'Updated HTML does not include class names added via subsequent add_class() calls'
    12131213        );
    12141214        $this->assertSame(
    12151215            'foo-class bar-class',
    1216             $p->get_attribute( 'class' ),
     1216            $processor->get_attribute( 'class' ),
    12171217            "get_attribute( 'class' ) did not return class names added via subsequent add_class() calls"
    12181218        );
     
    12251225     */
    12261226    public function test_remove_class_does_not_change_the_markup_when_there_is_no_class_attribute() {
    1227         $p = new WP_HTML_Tag_Processor( self::HTML_SIMPLE );
    1228         $p->next_tag();
    1229         $p->remove_class( 'foo-class' );
     1227        $processor = new WP_HTML_Tag_Processor( self::HTML_SIMPLE );
     1228        $processor->next_tag();
     1229        $processor->remove_class( 'foo-class' );
    12301230
    12311231        $this->assertSame(
    12321232            self::HTML_SIMPLE,
    1233             $p->get_updated_html(),
     1233            $processor->get_updated_html(),
    12341234            'Updated HTML includes class name that was removed by remove_class()'
    12351235        );
    12361236        $this->assertNull(
    1237             $p->get_attribute( 'class' ),
     1237            $processor->get_attribute( 'class' ),
    12381238            "get_attribute( 'class' ) did not return null for class name that was removed by remove_class()"
    12391239        );
     
    12461246     */
    12471247    public function test_add_class_appends_class_names_to_the_existing_class_attribute_when_one_already_exists() {
    1248         $p = new WP_HTML_Tag_Processor( self::HTML_WITH_CLASSES );
    1249         $p->next_tag();
    1250         $p->add_class( 'foo-class' );
    1251         $p->add_class( 'bar-class' );
     1248        $processor = new WP_HTML_Tag_Processor( self::HTML_WITH_CLASSES );
     1249        $processor->next_tag();
     1250        $processor->add_class( 'foo-class' );
     1251        $processor->add_class( 'bar-class' );
    12521252
    12531253        $this->assertSame(
    12541254            '<div class="main with-border foo-class bar-class" id="first"><span class="not-main bold with-border" id="second">Text</span></div>',
    1255             $p->get_updated_html(),
     1255            $processor->get_updated_html(),
    12561256            'Updated HTML does not reflect class names added to existing class attribute via subsequent add_class() calls'
    12571257        );
    12581258        $this->assertSame(
    12591259            'main with-border foo-class bar-class',
    1260             $p->get_attribute( 'class' ),
     1260            $processor->get_attribute( 'class' ),
    12611261            "get_attribute( 'class' ) does not reflect class names added to existing class attribute via subsequent add_class() calls"
    12621262        );
     
    12691269     */
    12701270    public function test_remove_class_removes_a_single_class_from_the_class_attribute_when_one_exists() {
    1271         $p = new WP_HTML_Tag_Processor( self::HTML_WITH_CLASSES );
    1272         $p->next_tag();
    1273         $p->remove_class( 'main' );
     1271        $processor = new WP_HTML_Tag_Processor( self::HTML_WITH_CLASSES );
     1272        $processor->next_tag();
     1273        $processor->remove_class( 'main' );
    12741274
    12751275        $this->assertSame(
    12761276            '<div class=" with-border" id="first"><span class="not-main bold with-border" id="second">Text</span></div>',
    1277             $p->get_updated_html(),
     1277            $processor->get_updated_html(),
    12781278            'Updated HTML does not reflect class name removed from existing class attribute via remove_class()'
    12791279        );
    12801280        $this->assertSame(
    12811281            ' with-border',
    1282             $p->get_attribute( 'class' ),
     1282            $processor->get_attribute( 'class' ),
    12831283            "get_attribute( 'class' ) does not reflect class name removed from existing class attribute via remove_class()"
    12841284        );
     
    12911291     */
    12921292    public function test_calling_remove_class_with_all_listed_class_names_removes_the_existing_class_attribute_from_the_markup() {
    1293         $p = new WP_HTML_Tag_Processor( self::HTML_WITH_CLASSES );
    1294         $p->next_tag();
    1295         $p->remove_class( 'main' );
    1296         $p->remove_class( 'with-border' );
     1293        $processor = new WP_HTML_Tag_Processor( self::HTML_WITH_CLASSES );
     1294        $processor->next_tag();
     1295        $processor->remove_class( 'main' );
     1296        $processor->remove_class( 'with-border' );
    12971297
    12981298        $this->assertSame(
    12991299            '<div  id="first"><span class="not-main bold with-border" id="second">Text</span></div>',
    1300             $p->get_updated_html(),
     1300            $processor->get_updated_html(),
    13011301            'Updated HTML does not reflect class attribute removed via subesequent remove_class() calls'
    13021302        );
    13031303        $this->assertNull(
    1304             $p->get_attribute( 'class' ),
     1304            $processor->get_attribute( 'class' ),
    13051305            "get_attribute( 'class' ) did not return null for class attribute removed via subesequent remove_class() calls"
    13061306        );
     
    13131313     */
    13141314    public function test_add_class_does_not_add_duplicate_class_names() {
    1315         $p = new WP_HTML_Tag_Processor( self::HTML_WITH_CLASSES );
    1316         $p->next_tag();
    1317         $p->add_class( 'with-border' );
     1315        $processor = new WP_HTML_Tag_Processor( self::HTML_WITH_CLASSES );
     1316        $processor->next_tag();
     1317        $processor->add_class( 'with-border' );
    13181318
    13191319        $this->assertSame(
    13201320            '<div class="main with-border" id="first"><span class="not-main bold with-border" id="second">Text</span></div>',
    1321             $p->get_updated_html(),
     1321            $processor->get_updated_html(),
    13221322            'Updated HTML does not reflect deduplicated class name added via add_class()'
    13231323        );
    13241324        $this->assertSame(
    13251325            'main with-border',
    1326             $p->get_attribute( 'class' ),
     1326            $processor->get_attribute( 'class' ),
    13271327            "get_attribute( 'class' ) does not reflect deduplicated class name added via add_class()"
    13281328        );
     
    13351335     */
    13361336    public function test_add_class_preserves_class_name_order_when_a_duplicate_class_name_is_added() {
    1337         $p = new WP_HTML_Tag_Processor( self::HTML_WITH_CLASSES );
    1338         $p->next_tag();
    1339         $p->add_class( 'main' );
     1337        $processor = new WP_HTML_Tag_Processor( self::HTML_WITH_CLASSES );
     1338        $processor->next_tag();
     1339        $processor->add_class( 'main' );
    13401340
    13411341        $this->assertSame(
    13421342            '<div class="main with-border" id="first"><span class="not-main bold with-border" id="second">Text</span></div>',
    1343             $p->get_updated_html(),
     1343            $processor->get_updated_html(),
    13441344            'Updated HTML does not reflect class name order after adding duplicated class name via add_class()'
    13451345        );
    13461346        $this->assertSame(
    13471347            'main with-border',
    1348             $p->get_attribute( 'class' ),
     1348            $processor->get_attribute( 'class' ),
    13491349            "get_attribute( 'class' ) does not reflect class name order after adding duplicated class name added via add_class()"
    13501350        );
     
    13571357     */
    13581358    public function test_add_class_when_there_is_a_class_attribute_with_excessive_whitespaces() {
    1359         $p = new WP_HTML_Tag_Processor(
     1359        $processor = new WP_HTML_Tag_Processor(
    13601360            '<div class="   main   with-border   " id="first"><span class="not-main bold with-border" id="second">Text</span></div>'
    13611361        );
    1362         $p->next_tag();
    1363         $p->add_class( 'foo-class' );
     1362        $processor->next_tag();
     1363        $processor->add_class( 'foo-class' );
    13641364
    13651365        $this->assertSame(
    13661366            '<div class="   main   with-border foo-class" id="first"><span class="not-main bold with-border" id="second">Text</span></div>',
    1367             $p->get_updated_html(),
     1367            $processor->get_updated_html(),
    13681368            'Updated HTML does not reflect existing excessive whitespace after adding class name via add_class()'
    13691369        );
    13701370        $this->assertSame(
    13711371            '   main   with-border foo-class',
    1372             $p->get_attribute( 'class' ),
     1372            $processor->get_attribute( 'class' ),
    13731373            "get_attribute( 'class' ) does not reflect existing excessive whitespace after adding class name via add_class()"
    13741374        );
     
    13811381     */
    13821382    public function test_remove_class_preserves_whitespaces_when_there_is_a_class_attribute_with_excessive_whitespaces() {
    1383         $p = new WP_HTML_Tag_Processor(
     1383        $processor = new WP_HTML_Tag_Processor(
    13841384            '<div class="   main   with-border   " id="first"><span class="not-main bold with-border" id="second">Text</span></div>'
    13851385        );
    1386         $p->next_tag();
    1387         $p->remove_class( 'with-border' );
     1386        $processor->next_tag();
     1387        $processor->remove_class( 'with-border' );
    13881388
    13891389        $this->assertSame(
    13901390            '<div class="   main" id="first"><span class="not-main bold with-border" id="second">Text</span></div>',
    1391             $p->get_updated_html(),
     1391            $processor->get_updated_html(),
    13921392            'Updated HTML does not reflect existing excessive whitespace after removing class name via remove_class()'
    13931393        );
    13941394        $this->assertSame(
    13951395            '   main',
    1396             $p->get_attribute( 'class' ),
     1396            $processor->get_attribute( 'class' ),
    13971397            "get_attribute( 'class' ) does not reflect existing excessive whitespace after removing class name via removing_class()"
    13981398        );
     
    14051405     */
    14061406    public function test_removing_all_classes_removes_the_existing_class_attribute_from_the_markup_even_when_excessive_whitespaces_are_present() {
    1407         $p = new WP_HTML_Tag_Processor(
     1407        $processor = new WP_HTML_Tag_Processor(
    14081408            '<div class="   main   with-border   " id="first"><span class="not-main bold with-border" id="second">Text</span></div>'
    14091409        );
    1410         $p->next_tag();
    1411         $p->remove_class( 'main' );
    1412         $p->remove_class( 'with-border' );
     1410        $processor->next_tag();
     1411        $processor->remove_class( 'main' );
     1412        $processor->remove_class( 'with-border' );
    14131413        $this->assertSame(
    14141414            '<div  id="first"><span class="not-main bold with-border" id="second">Text</span></div>',
    1415             $p->get_updated_html(),
     1415            $processor->get_updated_html(),
    14161416            'Updated HTML does not reflect removed class attribute after removing all class names via remove_class()'
    14171417        );
    14181418        $this->assertNull(
    1419             $p->get_attribute( 'class' ),
     1419            $processor->get_attribute( 'class' ),
    14201420            "get_attribute( 'class' ) did not return null after removing all class names via remove_class()"
    14211421        );
     
    14361436     */
    14371437    public function test_set_attribute_takes_priority_over_add_class() {
    1438         $p = new WP_HTML_Tag_Processor( self::HTML_WITH_CLASSES );
    1439         $p->next_tag();
    1440         $p->add_class( 'add_class' );
    1441         $p->set_attribute( 'class', 'set_attribute' );
     1438        $processor = new WP_HTML_Tag_Processor( self::HTML_WITH_CLASSES );
     1439        $processor->next_tag();
     1440        $processor->add_class( 'add_class' );
     1441        $processor->set_attribute( 'class', 'set_attribute' );
    14421442        $this->assertSame(
    14431443            '<div class="set_attribute" id="first"><span class="not-main bold with-border" id="second">Text</span></div>',
    1444             $p->get_updated_html(),
     1444            $processor->get_updated_html(),
    14451445            "Calling get_updated_html after updating first tag's attributes did not return the expected HTML"
    14461446        );
    14471447        $this->assertSame(
    14481448            'set_attribute',
    1449             $p->get_attribute( 'class' ),
     1449            $processor->get_attribute( 'class' ),
    14501450            "Calling get_attribute after updating first tag's attributes did not return the expected class name"
    14511451        );
    14521452
    1453         $p = new WP_HTML_Tag_Processor( self::HTML_WITH_CLASSES );
    1454         $p->next_tag();
    1455         $p->set_attribute( 'class', 'set_attribute' );
    1456         $p->add_class( 'add_class' );
     1453        $processor = new WP_HTML_Tag_Processor( self::HTML_WITH_CLASSES );
     1454        $processor->next_tag();
     1455        $processor->set_attribute( 'class', 'set_attribute' );
     1456        $processor->add_class( 'add_class' );
    14571457        $this->assertSame(
    14581458            '<div class="set_attribute add_class" id="first"><span class="not-main bold with-border" id="second">Text</span></div>',
    1459             $p->get_updated_html(),
     1459            $processor->get_updated_html(),
    14601460            "Calling get_updated_html after updating first tag's attributes did not return the expected HTML"
    14611461        );
    14621462        $this->assertSame(
    14631463            'set_attribute add_class',
    1464             $p->get_attribute( 'class' ),
     1464            $processor->get_attribute( 'class' ),
    14651465            "Calling get_attribute after updating first tag's attributes did not return the expected class name"
    14661466        );
     
    14831483     */
    14841484    public function test_set_attribute_takes_priority_over_add_class_even_before_updating() {
    1485         $p = new WP_HTML_Tag_Processor( self::HTML_WITH_CLASSES );
    1486         $p->next_tag();
    1487         $p->add_class( 'add_class' );
    1488         $p->set_attribute( 'class', 'set_attribute' );
     1485        $processor = new WP_HTML_Tag_Processor( self::HTML_WITH_CLASSES );
     1486        $processor->next_tag();
     1487        $processor->add_class( 'add_class' );
     1488        $processor->set_attribute( 'class', 'set_attribute' );
    14891489        $this->assertSame(
    14901490            'set_attribute',
    1491             $p->get_attribute( 'class' ),
     1491            $processor->get_attribute( 'class' ),
    14921492            "Calling get_attribute after updating first tag's attributes did not return the expected class name"
    14931493        );
    14941494        $this->assertSame(
    14951495            '<div class="set_attribute" id="first"><span class="not-main bold with-border" id="second">Text</span></div>',
    1496             $p->get_updated_html(),
     1496            $processor->get_updated_html(),
    14971497            "Calling get_updated_html after updating first tag's attributes did not return the expected HTML"
    14981498        );
    14991499
    1500         $p = new WP_HTML_Tag_Processor( self::HTML_WITH_CLASSES );
    1501         $p->next_tag();
    1502         $p->set_attribute( 'class', 'set_attribute' );
    1503         $p->add_class( 'add_class' );
     1500        $processor = new WP_HTML_Tag_Processor( self::HTML_WITH_CLASSES );
     1501        $processor->next_tag();
     1502        $processor->set_attribute( 'class', 'set_attribute' );
     1503        $processor->add_class( 'add_class' );
    15041504        $this->assertSame(
    15051505            'set_attribute add_class',
    1506             $p->get_attribute( 'class' ),
     1506            $processor->get_attribute( 'class' ),
    15071507            "Calling get_attribute after updating first tag's attributes did not return the expected class name"
    15081508        );
    15091509        $this->assertSame(
    15101510            '<div class="set_attribute add_class" id="first"><span class="not-main bold with-border" id="second">Text</span></div>',
    1511             $p->get_updated_html(),
     1511            $processor->get_updated_html(),
    15121512            "Calling get_updated_html after updating first tag's attributes did not return the expected HTML"
    15131513        );
     
    15201520     */
    15211521    public function test_add_class_overrides_boolean_class_attribute() {
    1522         $p = new WP_HTML_Tag_Processor( self::HTML_SIMPLE );
    1523         $p->next_tag();
    1524         $p->set_attribute( 'class', true );
    1525         $p->add_class( 'add_class' );
     1522        $processor = new WP_HTML_Tag_Processor( self::HTML_SIMPLE );
     1523        $processor->next_tag();
     1524        $processor->set_attribute( 'class', true );
     1525        $processor->add_class( 'add_class' );
    15261526        $this->assertSame(
    15271527            '<div class="add_class" id="first"><span id="second">Text</span></div>',
    1528             $p->get_updated_html(),
     1528            $processor->get_updated_html(),
    15291529            "Updated HTML doesn't reflect class added via add_class that was originally set as boolean attribute"
    15301530        );
    15311531        $this->assertSame(
    15321532            'add_class',
    1533             $p->get_attribute( 'class' ),
     1533            $processor->get_attribute( 'class' ),
    15341534            "get_attribute (called after get_updated_html()) doesn't reflect class added via add_class that was originally set as boolean attribute"
    15351535        );
     
    15421542     */
    15431543    public function test_add_class_overrides_boolean_class_attribute_even_before_updating() {
    1544         $p = new WP_HTML_Tag_Processor( self::HTML_SIMPLE );
    1545         $p->next_tag();
    1546         $p->set_attribute( 'class', true );
    1547         $p->add_class( 'add_class' );
     1544        $processor = new WP_HTML_Tag_Processor( self::HTML_SIMPLE );
     1545        $processor->next_tag();
     1546        $processor->set_attribute( 'class', true );
     1547        $processor->add_class( 'add_class' );
    15481548        $this->assertSame(
    15491549            'add_class',
    1550             $p->get_attribute( 'class' ),
     1550            $processor->get_attribute( 'class' ),
    15511551            "get_attribute (called before get_updated_html()) doesn't reflect class added via add_class that was originally set as boolean attribute"
    15521552        );
    15531553        $this->assertSame(
    15541554            '<div class="add_class" id="first"><span id="second">Text</span></div>',
    1555             $p->get_updated_html(),
     1555            $processor->get_updated_html(),
    15561556            "Updated HTML doesn't reflect class added via add_class that was originally set as boolean attribute"
    15571557        );
     
    16141614HTML;
    16151615
    1616         $p = new WP_HTML_Tag_Processor( $input );
    1617         $this->assertTrue( $p->next_tag( 'div' ), 'Did not find first DIV tag in input.' );
    1618         $p->set_attribute( 'data-details', '{ "key": "value" }' );
    1619         $p->add_class( 'is-processed' );
     1616        $processor = new WP_HTML_Tag_Processor( $input );
     1617        $this->assertTrue( $processor->next_tag( 'div' ), 'Did not find first DIV tag in input.' );
     1618        $processor->set_attribute( 'data-details', '{ "key": "value" }' );
     1619        $processor->add_class( 'is-processed' );
    16201620        $this->assertTrue(
    1621             $p->next_tag(
     1621            $processor->next_tag(
    16221622                array(
    16231623                    'tag_name'   => 'div',
     
    16271627            'Did not find the first BtnGroup DIV tag'
    16281628        );
    1629         $p->remove_class( 'BtnGroup' );
    1630         $p->add_class( 'button-group' );
    1631         $p->add_class( 'Another-Mixed-Case' );
     1629        $processor->remove_class( 'BtnGroup' );
     1630        $processor->add_class( 'button-group' );
     1631        $processor->add_class( 'Another-Mixed-Case' );
    16321632        $this->assertTrue(
    1633             $p->next_tag(
     1633            $processor->next_tag(
    16341634                array(
    16351635                    'tag_name'   => 'div',
     
    16391639            'Did not find the second BtnGroup DIV tag'
    16401640        );
    1641         $p->remove_class( 'BtnGroup' );
    1642         $p->add_class( 'button-group' );
    1643         $p->add_class( 'Another-Mixed-Case' );
     1641        $processor->remove_class( 'BtnGroup' );
     1642        $processor->add_class( 'button-group' );
     1643        $processor->add_class( 'Another-Mixed-Case' );
    16441644        $this->assertTrue(
    1645             $p->next_tag(
     1645            $processor->next_tag(
    16461646                array(
    16471647                    'tag_name'     => 'button',
     
    16521652            'Did not find third BUTTON tag with "btn" CSS class'
    16531653        );
    1654         $p->remove_attribute( 'class' );
    1655         $this->assertFalse( $p->next_tag( 'non-existent' ), "Found a {$p->get_tag()} tag when none should have been found." );
    1656         $p->set_attribute( 'class', 'test' );
    1657         $this->assertSame( $expected_output, $p->get_updated_html(), 'Calling get_updated_html after updating the attributes did not return the expected HTML' );
     1654        $processor->remove_attribute( 'class' );
     1655        $this->assertFalse( $processor->next_tag( 'non-existent' ), "Found a {$processor->get_tag()} tag when none should have been found." );
     1656        $processor->set_attribute( 'class', 'test' );
     1657        $this->assertSame( $expected_output, $processor->get_updated_html(), 'Calling get_updated_html after updating the attributes did not return the expected HTML' );
    16581658    }
    16591659
     
    16641664     */
    16651665    public function test_correctly_parses_html_attributes_wrapped_in_single_quotation_marks() {
    1666         $p = new WP_HTML_Tag_Processor(
     1666        $processor = new WP_HTML_Tag_Processor(
    16671667            '<div id=\'first\'><span id=\'second\'>Text</span></div>'
    16681668        );
    1669         $p->next_tag(
     1669        $processor->next_tag(
    16701670            array(
    16711671                'tag_name' => 'div',
     
    16731673            )
    16741674        );
    1675         $p->remove_attribute( 'id' );
    1676         $p->next_tag(
     1675        $processor->remove_attribute( 'id' );
     1676        $processor->next_tag(
    16771677            array(
    16781678                'tag_name' => 'span',
     
    16801680            )
    16811681        );
    1682         $p->set_attribute( 'id', 'single-quote' );
     1682        $processor->set_attribute( 'id', 'single-quote' );
    16831683        $this->assertSame(
    16841684            '<div ><span id="single-quote">Text</span></div>',
    1685             $p->get_updated_html(),
     1685            $processor->get_updated_html(),
    16861686            'Did not remove single-quoted attribute'
    16871687        );
     
    16941694     */
    16951695    public function test_set_attribute_with_value_equal_to_true_adds_a_boolean_html_attribute_with_implicit_value() {
    1696         $p = new WP_HTML_Tag_Processor(
     1696        $processor = new WP_HTML_Tag_Processor(
    16971697            '<form action="/action_page.php"><input type="checkbox" name="vehicle" value="Bike"><label for="vehicle">I have a bike</label></form>'
    16981698        );
    1699         $p->next_tag( 'input' );
    1700         $p->set_attribute( 'checked', true );
     1699        $processor->next_tag( 'input' );
     1700        $processor->set_attribute( 'checked', true );
    17011701        $this->assertSame(
    17021702            '<form action="/action_page.php"><input checked type="checkbox" name="vehicle" value="Bike"><label for="vehicle">I have a bike</label></form>',
    1703             $p->get_updated_html(),
     1703            $processor->get_updated_html(),
    17041704            'Did not add "checked" as an expected boolean attribute'
    17051705        );
     
    17121712     */
    17131713    public function test_setting_a_boolean_attribute_to_false_removes_it_from_the_markup() {
    1714         $p = new WP_HTML_Tag_Processor(
     1714        $processor = new WP_HTML_Tag_Processor(
    17151715            '<form action="/action_page.php"><input checked type="checkbox" name="vehicle" value="Bike"><label for="vehicle">I have a bike</label></form>'
    17161716        );
    1717         $p->next_tag( 'input' );
    1718         $p->set_attribute( 'checked', false );
     1717        $processor->next_tag( 'input' );
     1718        $processor->set_attribute( 'checked', false );
    17191719        $this->assertSame(
    17201720            '<form action="/action_page.php"><input  type="checkbox" name="vehicle" value="Bike"><label for="vehicle">I have a bike</label></form>',
    1721             $p->get_updated_html(),
     1721            $processor->get_updated_html(),
    17221722            'Did not remove boolean attribute when set to false'
    17231723        );
     
    17311731    public function test_setting_a_missing_attribute_to_false_does_not_change_the_markup() {
    17321732        $html_input = '<form action="/action_page.php"><input type="checkbox" name="vehicle" value="Bike"><label for="vehicle">I have a bike</label></form>';
    1733         $p          = new WP_HTML_Tag_Processor( $html_input );
    1734         $p->next_tag( 'input' );
    1735         $p->set_attribute( 'checked', false );
     1733        $processor  = new WP_HTML_Tag_Processor( $html_input );
     1734        $processor->next_tag( 'input' );
     1735        $processor->set_attribute( 'checked', false );
    17361736        $this->assertSame(
    17371737            $html_input,
    1738             $p->get_updated_html(),
     1738            $processor->get_updated_html(),
    17391739            'Changed the markup unexpectedly when setting a non-existing attribute to false'
    17401740        );
     
    17471747     */
    17481748    public function test_setting_a_boolean_attribute_to_a_string_value_adds_explicit_value_to_the_markup() {
    1749         $p = new WP_HTML_Tag_Processor(
     1749        $processor = new WP_HTML_Tag_Processor(
    17501750            '<form action="/action_page.php"><input checked type="checkbox" name="vehicle" value="Bike"><label for="vehicle">I have a bike</label></form>'
    17511751        );
    1752         $p->next_tag( 'input' );
    1753         $p->set_attribute( 'checked', 'checked' );
     1752        $processor->next_tag( 'input' );
     1753        $processor->set_attribute( 'checked', 'checked' );
    17541754        $this->assertSame(
    17551755            '<form action="/action_page.php"><input checked="checked" type="checkbox" name="vehicle" value="Bike"><label for="vehicle">I have a bike</label></form>',
    1756             $p->get_updated_html(),
     1756            $processor->get_updated_html(),
    17571757            'Did not add string value to existing boolean attribute'
    17581758        );
     
    17661766     */
    17671767    public function test_unclosed_script_tag_should_not_cause_an_infinite_loop() {
    1768         $p = new WP_HTML_Tag_Processor( '<script><div>' );
     1768        $processor = new WP_HTML_Tag_Processor( '<script><div>' );
    17691769        $this->assertFalse(
    1770             $p->next_tag(),
     1770            $processor->next_tag(),
    17711771            'Should not have stopped on an opening SCRIPT tag without a proper closing tag in the document.'
    17721772        );
    17731773        $this->assertTrue(
    1774             $p->paused_at_incomplete_token(),
     1774            $processor->paused_at_incomplete_token(),
    17751775            "Should have paused the parser because of the incomplete SCRIPT tag but didn't."
    17761776        );
    17771777
    17781778        // Run this to ensure that the test ends (not in an infinite loop).
    1779         $p->next_tag();
     1779        $processor->next_tag();
    17801780    }
    17811781
     
    17901790     */
    17911791    public function test_next_tag_ignores_script_tag_contents( $script_then_div ) {
    1792         $p = new WP_HTML_Tag_Processor( $script_then_div );
    1793         $p->next_tag();
    1794         $this->assertSame( 'SCRIPT', $p->get_tag(), 'The first found tag was not "script"' );
    1795         $p->next_tag();
    1796         $this->assertSame( 'DIV', $p->get_tag(), 'The second found tag was not "div"' );
     1792        $processor = new WP_HTML_Tag_Processor( $script_then_div );
     1793        $processor->next_tag();
     1794        $this->assertSame( 'SCRIPT', $processor->get_tag(), 'The first found tag was not "script"' );
     1795        $processor->next_tag();
     1796        $this->assertSame( 'DIV', $processor->get_tag(), 'The second found tag was not "div"' );
    17971797    }
    17981798
     
    18021802     * @return array[].
    18031803     */
    1804     public function data_next_tag_ignores_script_tag_contents() {
     1804    public static function data_next_tag_ignores_script_tag_contents() {
    18051805        return array(
    18061806            'Simple script tag'                          => array(
     
    18671867     */
    18681868    public function test_next_tag_ignores_invalid_first_character_of_tag_name_comments( $html_with_markers ) {
    1869         $p = new WP_HTML_Tag_Processor( $html_with_markers );
    1870         $p->next_tag( array( 'class_name' => 'start' ) );
    1871         $p->next_tag();
    1872 
    1873         $this->assertSame( 'end', $p->get_attribute( 'class' ) );
     1869        $processor = new WP_HTML_Tag_Processor( $html_with_markers );
     1870        $processor->next_tag( array( 'class_name' => 'start' ) );
     1871        $processor->next_tag();
     1872
     1873        $this->assertSame( 'end', $processor->get_attribute( 'class' ) );
    18741874    }
    18751875
     
    18791879     * @return array[]
    18801880     */
    1881     public function data_next_tag_ignores_invalid_first_character_of_tag_name_comments() {
     1881    public static function data_next_tag_ignores_invalid_first_character_of_tag_name_comments() {
    18821882        return array(
    18831883            'Invalid tag openers as normal text'           => array(
     
    19061906     */
    19071907    public function test_next_tag_ignores_contents_of_rcdata_tag( $rcdata_then_div, $rcdata_tag ) {
    1908         $p = new WP_HTML_Tag_Processor( $rcdata_then_div );
    1909         $p->next_tag();
    1910         $this->assertSame( $rcdata_tag, $p->get_tag(), "The first found tag was not '$rcdata_tag'" );
    1911         $p->next_tag();
    1912         $this->assertSame( 'DIV', $p->get_tag(), "The second found tag was not 'div'" );
     1908        $processor = new WP_HTML_Tag_Processor( $rcdata_then_div );
     1909        $processor->next_tag();
     1910        $this->assertSame( $rcdata_tag, $processor->get_tag(), "The first found tag was not '$rcdata_tag'" );
     1911        $processor->next_tag();
     1912        $this->assertSame( 'DIV', $processor->get_tag(), "The second found tag was not 'div'" );
    19131913    }
    19141914
     
    19181918     * @return array[]
    19191919     */
    1920     public function data_next_tag_ignores_contents_of_rcdata_tag() {
     1920    public static function data_next_tag_ignores_contents_of_rcdata_tag() {
    19211921        return array(
    19221922            'simple textarea'                          => array(
     
    19651965     */
    19661966    public function test_processes_inside_of_noscript_elements() {
    1967         $p = new WP_HTML_Tag_Processor( '<noscript><input type="submit"></noscript><div>' );
    1968 
    1969         $this->assertTrue( $p->next_tag( 'INPUT' ), 'Failed to find INPUT element inside NOSCRIPT element.' );
    1970         $this->assertTrue( $p->next_tag( 'DIV' ), 'Failed to find DIV element after NOSCRIPT element.' );
     1967        $processor = new WP_HTML_Tag_Processor( '<noscript><input type="submit"></noscript><div>' );
     1968
     1969        $this->assertTrue( $processor->next_tag( 'INPUT' ), 'Failed to find INPUT element inside NOSCRIPT element.' );
     1970        $this->assertTrue( $processor->next_tag( 'DIV' ), 'Failed to find DIV element after NOSCRIPT element.' );
    19711971    }
    19721972
     
    19971997     * @return array[].
    19981998     */
    1999     public function data_next_tag_ignores_contents_of_rawtext_tags() {
     1999    public static function data_next_tag_ignores_contents_of_rawtext_tags() {
    20002000        return array(
    20012001            'IFRAME'           => array( '<iframe><section>Inside</section></iframe><section target>' ),
     
    20132013     */
    20142014    public function test_class_list_empty_when_missing_class() {
    2015         $p = new WP_HTML_Tag_Processor( '<div>' );
    2016         $p->next_tag();
     2015        $processor = new WP_HTML_Tag_Processor( '<div>' );
     2016        $processor->next_tag();
    20172017
    20182018        $found_classes = false;
    2019         foreach ( $p->class_list() as $class ) {
     2019        foreach ( $processor->class_list() as $class ) {
    20202020            $found_classes = true;
    20212021        }
     
    20302030     */
    20312031    public function test_class_list_empty_when_class_is_boolean() {
    2032         $p = new WP_HTML_Tag_Processor( '<div class>' );
    2033         $p->next_tag();
     2032        $processor = new WP_HTML_Tag_Processor( '<div class>' );
     2033        $processor->next_tag();
    20342034
    20352035        $found_classes = false;
    2036         foreach ( $p->class_list() as $class ) {
     2036        foreach ( $processor->class_list() as $class ) {
    20372037            $found_classes = true;
    20382038        }
     
    20472047     */
    20482048    public function test_class_list_empty_when_class_is_empty() {
    2049         $p = new WP_HTML_Tag_Processor( '<div class="">' );
    2050         $p->next_tag();
     2049        $processor = new WP_HTML_Tag_Processor( '<div class="">' );
     2050        $processor->next_tag();
    20512051
    20522052        $found_classes = false;
    2053         foreach ( $p->class_list() as $class ) {
     2053        foreach ( $processor->class_list() as $class ) {
    20542054            $found_classes = true;
    20552055        }
     
    20642064     */
    20652065    public function test_class_list_visits_each_class_in_order() {
    2066         $p = new WP_HTML_Tag_Processor( '<div class="one two three">' );
    2067         $p->next_tag();
     2066        $processor = new WP_HTML_Tag_Processor( '<div class="one two three">' );
     2067        $processor->next_tag();
    20682068
    20692069        $found_classes = array();
    2070         foreach ( $p->class_list() as $class ) {
     2070        foreach ( $processor->class_list() as $class ) {
    20712071            $found_classes[] = $class;
    20722072        }
     
    20812081     */
    20822082    public function test_class_list_decodes_class_names() {
    2083         $p = new WP_HTML_Tag_Processor( '<div class="&notin;-class &lt;egg&gt; &#xff03;">' );
    2084         $p->next_tag();
     2083        $processor = new WP_HTML_Tag_Processor( '<div class="&notin;-class &lt;egg&gt; &#xff03;">' );
     2084        $processor->next_tag();
    20852085
    20862086        $found_classes = array();
    2087         foreach ( $p->class_list() as $class ) {
     2087        foreach ( $processor->class_list() as $class ) {
    20882088            $found_classes[] = $class;
    20892089        }
     
    20982098     */
    20992099    public function test_class_list_visits_unique_class_names_only_once() {
    2100         $p = new WP_HTML_Tag_Processor( '<div class="one one &#x6f;ne">' );
    2101         $p->next_tag();
     2100        $processor = new WP_HTML_Tag_Processor( '<div class="one one &#x6f;ne">' );
     2101        $processor->next_tag();
    21022102
    21032103        $found_classes = array();
    2104         foreach ( $p->class_list() as $class ) {
     2104        foreach ( $processor->class_list() as $class ) {
    21052105            $found_classes[] = $class;
    21062106        }
     
    21212121     */
    21222122    public function test_has_class_handles_expected_class_name_variations( $html, $sought_class, $has_class ) {
    2123         $p = new WP_HTML_Tag_Processor( $html );
    2124         $p->next_tag();
     2123        $processor = new WP_HTML_Tag_Processor( $html );
     2124        $processor->next_tag();
    21252125
    21262126        if ( $has_class ) {
    2127             $this->assertTrue( $p->has_class( $sought_class ), "Failed to find expected class {$sought_class}." );
     2127            $this->assertTrue( $processor->has_class( $sought_class ), "Failed to find expected class {$sought_class}." );
    21282128        } else {
    2129             $this->assertFalse( $p->has_class( $sought_class ), "Found class {$sought_class} when it doesn't exist." );
     2129            $this->assertFalse( $processor->has_class( $sought_class ), "Found class {$sought_class} when it doesn't exist." );
    21302130        }
    21312131    }
     
    21362136     * @return array[]
    21372137     */
    2138     public function data_html_with_variations_of_class_values_and_sought_class_names() {
     2138    public static function data_html_with_variations_of_class_values_and_sought_class_names() {
    21392139        return array(
    21402140            'Tag without any classes'      => array( '<div>', 'foo', false ),
     
    21602160     */
    21612161    public function test_allows_incorrectly_closed_comments() {
    2162         $p = new WP_HTML_Tag_Processor( '<img id=before><!-- <img id=inside> --!><img id=after>--><img id=final>' );
    2163 
    2164         $p->next_tag();
    2165         $this->assertSame( 'before', $p->get_attribute( 'id' ), 'Did not find starting tag.' );
    2166 
    2167         $p->next_tag();
    2168         $this->assertSame( 'after', $p->get_attribute( 'id' ), 'Did not properly close improperly-closed comment.' );
    2169 
    2170         $p->next_tag();
    2171         $this->assertSame( 'final', $p->get_attribute( 'id' ), 'Did not skip over unopened comment-closer.' );
     2162        $processor = new WP_HTML_Tag_Processor( '<img id=before><!-- <img id=inside> --!><img id=after>--><img id=final>' );
     2163
     2164        $processor->next_tag();
     2165        $this->assertSame( 'before', $processor->get_attribute( 'id' ), 'Did not find starting tag.' );
     2166
     2167        $processor->next_tag();
     2168        $this->assertSame( 'after', $processor->get_attribute( 'id' ), 'Did not properly close improperly-closed comment.' );
     2169
     2170        $processor->next_tag();
     2171        $this->assertSame( 'final', $processor->get_attribute( 'id' ), 'Did not skip over unopened comment-closer.' );
    21722172    }
    21732173
     
    21852185     */
    21862186    public function test_documents_may_end_with_unclosed_comment( $html_ending_before_comment_close ) {
    2187         $p = new WP_HTML_Tag_Processor( $html_ending_before_comment_close );
     2187        $processor = new WP_HTML_Tag_Processor( $html_ending_before_comment_close );
    21882188
    21892189        $this->assertFalse(
    2190             $p->next_tag(),
    2191             "Should not have found any tag, but found {$p->get_tag()}."
     2190            $processor->next_tag(),
     2191            "Should not have found any tag, but found {$processor->get_tag()}."
    21922192        );
    21932193
    21942194        $this->assertTrue(
    2195             $p->paused_at_incomplete_token(),
     2195            $processor->paused_at_incomplete_token(),
    21962196            "Should have indicated that the parser found an incomplete token but didn't."
    21972197        );
     
    22032203     * @return array[]
    22042204     */
    2205     public function data_html_with_unclosed_comments() {
     2205    public static function data_html_with_unclosed_comments() {
    22062206        return array(
    22072207            'Shortest open valid comment'      => array( '<!--' ),
     
    22262226     */
    22272227    public function test_closes_abrupt_closing_of_empty_comment( $html_with_after_marker ) {
    2228         $p = new WP_HTML_Tag_Processor( $html_with_after_marker );
    2229         $p->next_tag();
    2230         $p->next_tag();
    2231 
    2232         $this->assertSame( 'after', $p->get_attribute( 'id' ), 'Did not find tag after closing abruptly-closed comment' );
     2228        $processor = new WP_HTML_Tag_Processor( $html_with_after_marker );
     2229        $processor->next_tag();
     2230        $processor->next_tag();
     2231
     2232        $this->assertSame( 'after', $processor->get_attribute( 'id' ), 'Did not find tag after closing abruptly-closed comment' );
    22332233    }
    22342234
     
    22382238     * @return array[]
    22392239     */
    2240     public function data_abruptly_closed_empty_comments() {
     2240    public static function data_abruptly_closed_empty_comments() {
    22412241        return array(
    22422242            'Empty comment with two dashes only' => array( '<hr><!--><hr id=after>' ),
     
    22632263     */
    22642264    public function test_skips_contents_of_script_and_rcdata_regions( $input_html ) {
    2265         $p = new WP_HTML_Tag_Processor( $input_html );
    2266         $p->next_tag( 'div' );
     2265        $processor = new WP_HTML_Tag_Processor( $input_html );
     2266        $processor->next_tag( 'div' );
    22672267
    22682268        $this->assertTrue(
    2269             $p->get_attribute( 'target' ),
     2269            $processor->get_attribute( 'target' ),
    22702270            'Did not properly skip over script and rcdata regions; incorrectly found tags inside'
    22712271        );
     
    22772277     * @return array[]
    22782278     */
    2279     public function data_skips_contents_of_script_and_rcdata_regions() {
     2279    public static function data_skips_contents_of_script_and_rcdata_regions() {
    22802280        return array(
    22812281            'Balanced SCRIPT tags'                => array( '<script>console.log("<div>");</script><div target><div>' ),
     
    22962296     */
    22972297    public function test_can_query_and_update_wrongly_nested_tags() {
    2298         $p = new WP_HTML_Tag_Processor(
     2298        $processor = new WP_HTML_Tag_Processor(
    22992299            '<span>123<p>456</span>789</p>'
    23002300        );
    2301         $p->next_tag( 'span' );
    2302         $p->set_attribute( 'class', 'span-class' );
    2303         $p->next_tag( 'p' );
    2304         $p->set_attribute( 'class', 'p-class' );
     2301        $processor->next_tag( 'span' );
     2302        $processor->set_attribute( 'class', 'span-class' );
     2303        $processor->next_tag( 'p' );
     2304        $processor->set_attribute( 'class', 'p-class' );
    23052305        $this->assertSame(
    23062306            '<span class="span-class">123<p class="p-class">456</span>789</p>',
    2307             $p->get_updated_html(),
     2307            $processor->get_updated_html(),
    23082308            'Did not find overlapping p tag'
    23092309        );
     
    23172317     */
    23182318    public function test_removing_specific_attributes_in_malformed_html() {
    2319         $p = new WP_HTML_Tag_Processor( self::HTML_MALFORMED );
    2320         $p->next_tag( 'span' );
    2321         $p->remove_attribute( 'Notifications<' );
     2319        $processor = new WP_HTML_Tag_Processor( self::HTML_MALFORMED );
     2320        $processor->next_tag( 'span' );
     2321        $processor->remove_attribute( 'Notifications<' );
    23222322        $this->assertSame(
    23232323            '<div><span class="d-md-none" /span><span class="d-none d-md-inline">Back to notifications</span></div>',
    2324             $p->get_updated_html(),
     2324            $processor->get_updated_html(),
    23252325            'Did not remove "Notifications<" attribute in malformed input'
    23262326        );
     
    23582358     * @return array[]
    23592359     */
    2360     public function data_html_without_tags() {
     2360    public static function data_html_without_tags() {
    23612361        return array(
    23622362            'DOCTYPE declaration'    => array( '<!DOCTYPE html>Just some HTML' ),
     
    23832383     */
    23842384    public function test_next_tag_returns_false_for_incomplete_syntax_elements( $incomplete_html ) {
    2385         $p = new WP_HTML_Tag_Processor( $incomplete_html );
     2385        $processor = new WP_HTML_Tag_Processor( $incomplete_html );
    23862386
    23872387        $this->assertFalse(
    2388             $p->next_tag(),
    2389             "Shouldn't have found any tags but found {$p->get_tag()}."
     2388            $processor->next_tag(),
     2389            "Shouldn't have found any tags but found {$processor->get_tag()}."
    23902390        );
    23912391
    23922392        $this->assertTrue(
    2393             $p->paused_at_incomplete_token(),
     2393            $processor->paused_at_incomplete_token(),
    23942394            "Should have indicated that the parser found an incomplete token but didn't."
    23952395        );
     
    24012401     * @return array[]
    24022402     */
    2403     public function data_incomplete_syntax_elements() {
     2403    public static function data_incomplete_syntax_elements() {
    24042404        return array(
    24052405            'Incomplete tag name'                  => array( '<swit' ),
     
    24432443     */
    24442444    public function test_updating_specific_attributes_in_malformed_html() {
    2445         $p = new WP_HTML_Tag_Processor( self::HTML_MALFORMED );
    2446         $p->next_tag( 'span' );
    2447         $p->set_attribute( 'id', 'first' );
    2448         $p->next_tag( 'span' );
    2449         $p->set_attribute( 'id', 'second' );
     2445        $processor = new WP_HTML_Tag_Processor( self::HTML_MALFORMED );
     2446        $processor->next_tag( 'span' );
     2447        $processor->set_attribute( 'id', 'first' );
     2448        $processor->next_tag( 'span' );
     2449        $processor->set_attribute( 'id', 'second' );
    24502450        $this->assertSame(
    24512451            '<div><span id="first" class="d-md-none" Notifications</span><span id="second" class="d-none d-md-inline">Back to notifications</span></div>',
    2452             $p->get_updated_html(),
     2452            $processor->get_updated_html(),
    24532453            'Did not add id attributes properly to malformed input'
    24542454        );
     
    24672467     */
    24682468    public function test_updating_attributes( $html, $expected ) {
    2469         $p = new WP_HTML_Tag_Processor( $html );
    2470         $p->next_tag();
    2471         $p->set_attribute( 'foo', 'bar' );
    2472         $p->add_class( 'firstTag' );
    2473         $p->next_tag();
    2474         $p->add_class( 'secondTag' );
     2469        $processor = new WP_HTML_Tag_Processor( $html );
     2470        $processor->next_tag();
     2471        $processor->set_attribute( 'foo', 'bar' );
     2472        $processor->add_class( 'firstTag' );
     2473        $processor->next_tag();
     2474        $processor->add_class( 'secondTag' );
    24752475
    24762476        $this->assertSame(
    24772477            $expected,
    2478             $p->get_updated_html(),
     2478            $processor->get_updated_html(),
    24792479            'Did not properly add attributes and class names'
    24802480        );
     
    24862486     * @return array[]
    24872487     */
    2488     public function data_updating_attributes() {
     2488    public static function data_updating_attributes() {
    24892489        return array(
    24902490            'tags inside of a comment' => array(
     
    25312531     */
    25322532    public function test_updating_attributes_in_malformed_html( $html, $expected ) {
    2533         $p = new WP_HTML_Tag_Processor( $html );
    2534         $this->assertTrue( $p->next_tag(), 'Could not find first tag.' );
    2535         $p->set_attribute( 'foo', 'bar' );
    2536         $p->add_class( 'firstTag' );
    2537         $p->next_tag();
    2538         $p->add_class( 'secondTag' );
     2533        $processor = new WP_HTML_Tag_Processor( $html );
     2534        $this->assertTrue( $processor->next_tag(), 'Could not find first tag.' );
     2535        $processor->set_attribute( 'foo', 'bar' );
     2536        $processor->add_class( 'firstTag' );
     2537        $processor->next_tag();
     2538        $processor->add_class( 'secondTag' );
    25392539
    25402540        $this->assertSame(
    25412541            $expected,
    2542             $p->get_updated_html(),
     2542            $processor->get_updated_html(),
    25432543            'Did not properly update attributes and classnames given malformed input'
    25442544        );
     
    25502550     * @return array[]
    25512551     */
    2552     public function data_updating_attributes_in_malformed_html() {
     2552    public static function data_updating_attributes_in_malformed_html() {
    25532553        return array(
    25542554            'Invalid entity inside attribute value'        => array(
     
    27032703     */
    27042704    public function test_handles_malformed_taglike_open_short_html() {
    2705         $p      = new WP_HTML_Tag_Processor( '<' );
    2706         $result = $p->next_tag();
     2705        $processor = new WP_HTML_Tag_Processor( '<' );
     2706        $result    = $processor->next_tag();
    27072707        $this->assertFalse( $result, 'Did not handle "<" html properly.' );
    27082708    }
     
    27122712     */
    27132713    public function test_handles_malformed_taglike_close_short_html() {
    2714         $p      = new WP_HTML_Tag_Processor( '</ ' );
    2715         $result = $p->next_tag();
     2714        $processor = new WP_HTML_Tag_Processor( '</ ' );
     2715        $result    = $processor->next_tag();
    27162716        $this->assertFalse( $result, 'Did not handle "</ " html properly.' );
    27172717    }
     
    27232723     */
    27242724    public function test_single_text_node_with_taglike_text() {
    2725         $p = new WP_HTML_Tag_Processor( 'test< /A>' );
    2726         $p->next_token();
    2727         $this->assertSame( '#text', $p->get_token_type(), 'Did not find text node.' );
    2728         $this->assertSame( 'test< /A>', $p->get_modifiable_text(), 'Did not find complete text node.' );
     2725        $processor = new WP_HTML_Tag_Processor( 'test< /A>' );
     2726        $processor->next_token();
     2727        $this->assertSame( '#text', $processor->get_token_type(), 'Did not find text node.' );
     2728        $this->assertSame( 'test< /A>', $processor->get_modifiable_text(), 'Did not find complete text node.' );
    27292729    }
    27302730}
Note: See TracChangeset for help on using the changeset viewer.