Make WordPress Core

Changeset 63622


Ignore:
Timestamp:
09/15/2026 03:40:28 PM (8 weeks ago)
Author:
lancewillett
Message:

Tests: Use strict assertions in Interactivity API tests.

Compare updated HTML strings explicitly with assertSame() in the directives processor tests. Use a strict comparison for the sorted directive suffixes and unique IDs, preserving the distinction between strings and null.

Developed in: ​https://github.com/WordPress/wordpress-develop/pull/13528

Props haritpanchal.
See #64895.

Location:
trunk/tests/phpunit/tests/interactivity-api
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/tests/interactivity-api/wpInteractivityAPI.php

    r62944 r63622  
    12101210                $results = $get_directive_entries->invoke( $this->interactivity, $p, 'test' );
    12111211                $this->assertCount( 6, $results );
    1212                 $this->assertEquals(
     1212                $this->assertSame(
    12131213                        array(
    12141214                                array( null, null ),
  • trunk/tests/phpunit/tests/interactivity-api/wpInteractivityAPIDirectivesProcessor.php

    r58594 r63622  
    183183                $result = $p->set_content_between_balanced_tags( 'New text' );
    184184                $this->assertTrue( $result );
    185                 $this->assertEquals( '<div>New text</div>', $p );
     185                $this->assertSame( '<div>New text</div>', $p->get_updated_html() );
    186186
    187187                $content = '<div>Text</div><div>More text</div>';
    … …  
    190190                $result = $p->set_content_between_balanced_tags( 'New text' );
    191191                $this->assertTrue( $result );
    192                 $this->assertEquals( '<div>New text</div><div>More text</div>', $p );
     192                $this->assertSame( '<div>New text</div><div>More text</div>', $p->get_updated_html() );
    193193                $p->next_tag();
    194194                $result = $p->set_content_between_balanced_tags( 'More new text' );
    195195                $this->assertTrue( $result );
    196                 $this->assertEquals( '<div>New text</div><div>More new text</div>', $p );
     196                $this->assertSame( '<div>New text</div><div>More new text</div>', $p->get_updated_html() );
    197197        }
    198198
    … …  
    212212                $result = $p->set_content_between_balanced_tags( 'New text' );
    213213                $this->assertFalse( $result );
    214                 $this->assertEquals( '<div>Text</div>', $p );
     214                $this->assertSame( '<div>Text</div>', $p->get_updated_html() );
    215215        }
    216216
    … …  
    229229                $result = $p->set_content_between_balanced_tags( 'New text' );
    230230                $this->assertTrue( $result );
    231                 $this->assertEquals( '<div>New text</div>', $p );
     231                $this->assertSame( '<div>New text</div>', $p->get_updated_html() );
    232232                $result = $p->set_content_between_balanced_tags( 'More text' );
    233233                $this->assertTrue( $result );
    234                 $this->assertEquals( '<div>More text</div>', $p );
     234                $this->assertSame( '<div>More text</div>', $p->get_updated_html() );
    235235        }
    236236
    … …  
    250250                $result = $p->set_content_between_balanced_tags( 'New text' );
    251251                $this->assertTrue( $result );
    252                 $this->assertEquals( '<div class="test">New text</div>', $p );
     252                $this->assertSame( '<div class="test">New text</div>', $p->get_updated_html() );
    253253
    254254                $content = '<div>Text</div>';
    … …  
    258258                $this->assertTrue( $result );
    259259                $p->set_attribute( 'class', 'test' );
    260                 $this->assertEquals( '<div class="test">New text</div>', $p );
     260                $this->assertSame( '<div class="test">New text</div>', $p->get_updated_html() );
    261261        }
    262262
    … …  
    275275                $result = $p->set_content_between_balanced_tags( 'New text' );
    276276                $this->assertTrue( $result );
    277                 $this->assertEquals( '<div>New text</div>', $p );
     277                $this->assertSame( '<div>New text</div>', $p->get_updated_html() );
    278278        }
    279279
    … …  
    292292                $p->next_tag();
    293293                $p->set_content_between_balanced_tags( $new_content );
    294                 $this->assertEquals( '<div>&lt;span&gt;New text&lt;/span&gt;&lt;a href=&quot;#&quot;&gt;Link&lt;/a&gt;</div>', $p );
     294                $this->assertSame( '<div>&lt;span&gt;New text&lt;/span&gt;&lt;a href=&quot;#&quot;&gt;Link&lt;/a&gt;</div>', $p->get_updated_html() );
    295295        }
    296296
    … …  
    308308                $result = $p->set_content_between_balanced_tags( '' );
    309309                $this->assertTrue( $result );
    310                 $this->assertEquals( '<div></div>', $p );
     310                $this->assertSame( '<div></div>', $p->get_updated_html() );
    311311
    312312                $content = '<div><div>Text</div></div>';
    … …  
    315315                $result = $p->set_content_between_balanced_tags( '' );
    316316                $this->assertTrue( $result );
    317                 $this->assertEquals( '<div></div>', $p );
     317                $this->assertSame( '<div></div>', $p->get_updated_html() );
    318318        }
    319319
    … …  
    331331                $result = $p->set_content_between_balanced_tags( 'New text' );
    332332                $this->assertFalse( $result );
    333                 $this->assertEquals( $content, $p );
     333                $this->assertSame( $content, $p->get_updated_html() );
    334334        }
    335335
    … …  
    347347                $result = $p->set_content_between_balanced_tags( 'New text' );
    348348                $this->assertFalse( $result );
    349                 $this->assertEquals( $content, $p );
     349                $this->assertSame( $content, $p->get_updated_html() );
    350350        }
    351351
    … …  
    365365                $result = $p->set_content_between_balanced_tags( $new_content );
    366366                $this->assertFalse( $result );
    367                 $this->assertEquals( $content, $p );
     367                $this->assertSame( $content, $p->get_updated_html() );
    368368
    369369                $content = '<div><div>Missing closing div</div>';
    … …  
    372372                $result = $p->set_content_between_balanced_tags( $new_content );
    373373                $this->assertFalse( $result );
    374                 $this->assertEquals( $content, $p );
     374                $this->assertSame( $content, $p->get_updated_html() );
    375375
    376376                $content = '<div>Missing closing div</span>';
    … …  
    379379                $result = $p->set_content_between_balanced_tags( $new_content );
    380380                $this->assertFalse( $result );
    381                 $this->assertEquals( $content, $p );
     381                $this->assertSame( $content, $p->get_updated_html() );
    382382
    383383                // It supports unbalanced tags inside the content.
    … …  
    387387                $result = $p->set_content_between_balanced_tags( $new_content );
    388388                $this->assertTrue( $result );
    389                 $this->assertEquals( '<div>New text</div>', $p );
     389                $this->assertSame( '<div>New text</div>', $p->get_updated_html() );
    390390        }
    391391
    … …  
    457457                $result = $p->append_content_after_template_tag_closer( $content_2 );
    458458                $this->assertTrue( $result );
    459                 $this->assertEquals( $content_1 . $content_2, $p );
     459                $this->assertSame( $content_1 . $content_2, $p->get_updated_html() );
    460460                $this->assertFalse( $p->next_tag() ); // There are no more tags.
    461461        }
    … …  
    478478                $result = $p->append_content_after_template_tag_closer( $content_2 );
    479479                $this->assertTrue( $result );
    480                 $this->assertEquals( $content_1 . $content_2, $p );
     480                $this->assertSame( $content_1 . $content_2, $p->get_updated_html() );
    481481                $p->next_tag( array( 'tag_closers' => 'visit' ) );
    482482                $this->assertSame( 'content-2', $p->get_attribute( 'class' ) );
    … …  
    485485                $this->assertTrue( $result );
    486486                $p->next_tag( array( 'tag_closers' => 'visit' ) );
    487                 $this->assertEquals( $content_1 . $content_2 . $content_3, $p );
     487                $this->assertSame( $content_1 . $content_2 . $content_3, $p->get_updated_html() );
    488488                $this->assertSame( 'content-3', $p->get_attribute( 'class' ) );
    489489        }
    … …  
    508508                $result = $p->append_content_after_template_tag_closer( $content_2 );
    509509                $this->assertTrue( $result );
    510                 $this->assertEquals( $content_1 . $content_2 . $content_3, $p );
     510                $this->assertSame( $content_1 . $content_2 . $content_3, $p->get_updated_html() );
    511511                $p->next_tag( array( 'tag_closers' => 'visit' ) );
    512512                $this->assertSame( 'content-3', $p->get_attribute( 'class' ) );
    … …  
    517517                $result = $p->append_content_after_template_tag_closer( $content_4 );
    518518                $this->assertTrue( $result );
    519                 $this->assertEquals( $content_1 . $content_4 . $content_3, $p );
     519                $this->assertSame( $content_1 . $content_4 . $content_3, $p->get_updated_html() );
    520520                $p->next_tag( array( 'tag_closers' => 'visit' ) );
    521521                $this->assertSame( 'content-4', $p->get_attribute( 'class' ) );
    … …  
    536536                $result = $p->append_content_after_template_tag_closer( 'New text' );
    537537                $this->assertFalse( $result );
    538                 $this->assertEquals( $content, $p );
     538                $this->assertSame( $content, $p->get_updated_html() );
    539539        }
    540540
    … …  
    557557                $result = $p->append_content_after_template_tag_closer( $content_2 );
    558558                $this->assertTrue( $result );
    559                 $this->assertEquals( $content_1 . $content_2, $p );
     559                $this->assertSame( $content_1 . $content_2, $p->get_updated_html() );
    560560                $p->next_tag( array( 'tag_closers' => 'visit' ) );
    561561                $this->assertSame( 'content-2', $p->get_attribute( 'class' ) );
    … …  
    566566                $p->next_tag( array( 'tag_closers' => 'visit' ) );
    567567                $result = $p->append_content_after_template_tag_closer( $content_3 );
    568                 $this->assertEquals( $content_1 . $content_3 . $content_2, $p );
     568                $this->assertSame( $content_1 . $content_3 . $content_2, $p->get_updated_html() );
    569569                $p->next_tag( array( 'tag_closers' => 'visit' ) );
    570570                $this->assertSame( 'content-3', $p->get_attribute( 'class' ) );
    … …  
    589589                $result = $p->append_content_after_template_tag_closer( $content_2 );
    590590                $this->assertTrue( $result );
    591                 $this->assertEquals( '<template class="test">Text</template>' . $content_2, $p );
     591                $this->assertSame( '<template class="test">Text</template>' . $content_2, $p->get_updated_html() );
    592592        }
    593593
    … …  
    614614                $result = $p->append_content_after_template_tag_closer( $content_2 );
    615615                $this->assertTrue( $result );
    616                 $this->assertEquals( $content_1 . $content_2, $p );
     616                $this->assertSame( $content_1 . $content_2, $p->get_updated_html() );
    617617                $p->next_tag();
    618618                $this->assertSame( 'content-2-template-1', $p->get_attribute( 'class' ) );
    … …  
    622622                $result = $p->append_content_after_template_tag_closer( $content_3 );
    623623                $this->assertTrue( $result );
    624                 $this->assertEquals( $content_1 . '<template class="content-2-template-1"><template class="content-2-template-2">New text</template>' . $content_3 . '</template>', $p );
     624                $this->assertSame( $content_1 . '<template class="content-2-template-1"><template class="content-2-template-2">New text</template>' . $content_3 . '</template>', $p->get_updated_html() );
    625625        }
    626626
    … …  
    640640                $result = $p->append_content_after_template_tag_closer( '' );
    641641                $this->assertFalse( $result );
    642                 $this->assertEquals( $content, $p );
     642                $this->assertSame( $content, $p->get_updated_html() );
    643643                $this->assertSame( 'TEMPLATE', $p->get_tag() ); // It didn't move.
    644644                $this->assertTrue( $p->is_tag_closer() ); // It didn't move.
    … …  
    660660                $result = $p->append_content_after_template_tag_closer( $content_2 );
    661661                $this->assertFalse( $result );
    662                 $this->assertEquals( $content_1, $p );
     662                $this->assertSame( $content_1, $p->get_updated_html() );
    663663        }
    664664
    … …  
    679679                $result = $p->append_content_after_template_tag_closer( $content_2 );
    680680                $this->assertFalse( $result );
    681                 $this->assertEquals( $content_1, $p );
     681                $this->assertSame( $content_1, $p->get_updated_html() );
    682682        }
    683683
Note: See TracChangeset for help on using the changeset viewer.