Make WordPress Core


Ignore:
Timestamp:
06/10/2021 07:18:15 PM (4 years ago)
Author:
SergeyBiryukov
Message:

Tests: Use assertSameSets() in some newly introduced tests.

This ensures that not only the array values being compared are equal, but also that their type is the same.

Going forward, stricter type checking by using assertSameSets() or assertSameSetsWithIndex() should generally be preferred, to make the tests more reliable.

Follow-up to [48939], [49925], [50157], [50959], [50960], [50995], [51079].

See #52625.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/tests/rest-api/rest-widgets-controller.php

    r51135 r51137  
    273273        $data     = $response->get_data();
    274274        $data     = $this->remove_links( $data );
    275         $this->assertEqualSets(
     275        $this->assertSameSets(
    276276            array(
    277277                array(
     
    279279                    'id_base'  => 'block',
    280280                    'sidebar'  => 'sidebar-1',
     281                    'rendered' => '<p>Block test</p>',
    281282                    'instance' => array(
    282283                        'encoded' => base64_encode(
     
    298299                        ),
    299300                    ),
    300                     'rendered' => '<p>Block test</p>',
    301301                ),
    302302                array(
     
    304304                    'id_base'  => 'rss',
    305305                    'sidebar'  => 'sidebar-1',
     306                    'rendered' => '<a class="rsswidget" href="https://wordpress.org/news/feed"><img class="rss-widget-icon" style="border:0" width="14" height="14" src="http://example.org/wp-includes/images/rss.png" alt="RSS" /></a> <a class="rsswidget" href="https://wordpress.org/news">RSS test</a><ul><li><a class=\'rsswidget\' href=\'https://wordpress.org/news/2020/12/introducing-learn-wordpress/\'>Introducing Learn WordPress</a></li><li><a class=\'rsswidget\' href=\'https://wordpress.org/news/2020/12/simone/\'>WordPress 5.6 “Simone”</a></li><li><a class=\'rsswidget\' href=\'https://wordpress.org/news/2020/12/state-of-the-word-2020/\'>State of the Word 2020</a></li><li><a class=\'rsswidget\' href=\'https://wordpress.org/news/2020/12/the-month-in-wordpress-november-2020/\'>The Month in WordPress: November 2020</a></li><li><a class=\'rsswidget\' href=\'https://wordpress.org/news/2020/12/wordpress-5-6-release-candidate-2/\'>WordPress 5.6 Release Candidate 2</a></li><li><a class=\'rsswidget\' href=\'https://wordpress.org/news/2020/11/wordpress-5-6-release-candidate/\'>WordPress 5.6 Release Candidate</a></li><li><a class=\'rsswidget\' href=\'https://wordpress.org/news/2020/11/wordpress-5-6-beta-4/\'>WordPress 5.6 Beta 4</a></li><li><a class=\'rsswidget\' href=\'https://wordpress.org/news/2020/11/wordpress-5-6-beta-3/\'>WordPress 5.6 Beta 3</a></li><li><a class=\'rsswidget\' href=\'https://wordpress.org/news/2020/11/the-month-in-wordpress-october-2020/\'>The Month in WordPress: October 2020</a></li><li><a class=\'rsswidget\' href=\'https://wordpress.org/news/2020/10/wordpress-5-5-3-maintenance-release/\'>WordPress 5.5.3 Maintenance Release</a></li></ul>',
    306307                    'instance' => array(
    307308                        'encoded' => base64_encode(
     
    322323                        ),
    323324                    ),
    324                     'rendered' => '<a class="rsswidget" href="https://wordpress.org/news/feed"><img class="rss-widget-icon" style="border:0" width="14" height="14" src="http://example.org/wp-includes/images/rss.png" alt="RSS" /></a> <a class="rsswidget" href="https://wordpress.org/news">RSS test</a><ul><li><a class=\'rsswidget\' href=\'https://wordpress.org/news/2020/12/introducing-learn-wordpress/\'>Introducing Learn WordPress</a></li><li><a class=\'rsswidget\' href=\'https://wordpress.org/news/2020/12/simone/\'>WordPress 5.6 “Simone”</a></li><li><a class=\'rsswidget\' href=\'https://wordpress.org/news/2020/12/state-of-the-word-2020/\'>State of the Word 2020</a></li><li><a class=\'rsswidget\' href=\'https://wordpress.org/news/2020/12/the-month-in-wordpress-november-2020/\'>The Month in WordPress: November 2020</a></li><li><a class=\'rsswidget\' href=\'https://wordpress.org/news/2020/12/wordpress-5-6-release-candidate-2/\'>WordPress 5.6 Release Candidate 2</a></li><li><a class=\'rsswidget\' href=\'https://wordpress.org/news/2020/11/wordpress-5-6-release-candidate/\'>WordPress 5.6 Release Candidate</a></li><li><a class=\'rsswidget\' href=\'https://wordpress.org/news/2020/11/wordpress-5-6-beta-4/\'>WordPress 5.6 Beta 4</a></li><li><a class=\'rsswidget\' href=\'https://wordpress.org/news/2020/11/wordpress-5-6-beta-3/\'>WordPress 5.6 Beta 3</a></li><li><a class=\'rsswidget\' href=\'https://wordpress.org/news/2020/11/the-month-in-wordpress-october-2020/\'>The Month in WordPress: October 2020</a></li><li><a class=\'rsswidget\' href=\'https://wordpress.org/news/2020/10/wordpress-5-5-3-maintenance-release/\'>WordPress 5.5.3 Maintenance Release</a></li></ul>',
    325325                ),
    326326                array(
     
    328328                    'id_base'  => 'testwidget',
    329329                    'sidebar'  => 'sidebar-1',
     330                    'rendered' => '<h1>Default id</h1><span>Default text</span>',
    330331                    'instance' => null,
    331                     'rendered' => '<h1>Default id</h1><span>Default text</span>',
    332332                ),
    333333            ),
     
    448448        $response = rest_get_server()->dispatch( $request );
    449449        $data     = $response->get_data();
    450         $this->assertEqualSets(
     450        $this->assertSameSets(
    451451            array(
    452452                'id'       => 'text-1',
    453453                'id_base'  => 'text',
    454454                'sidebar'  => 'sidebar-1',
     455                'rendered' => '<div class="textwidget">Custom text test</div>',
    455456                'instance' => array(
    456457                    'encoded' => base64_encode(
     
    472473                    ),
    473474                ),
    474                 'rendered' => '<div class="textwidget">Custom text test</div>',
    475475            ),
    476476            $data
     
    566566        $this->assertSame( 'text-2', $data['id'] );
    567567        $this->assertSame( 'sidebar-1', $data['sidebar'] );
    568         $this->assertEqualSets(
     568        $this->assertSameSetsWithIndex(
    569569            array(
    570570                'text'   => 'Updated text test',
     
    658658        $this->assertSame( 'block-7', $data['id'] );
    659659        $this->assertSame( 'sidebar-1', $data['sidebar'] );
    660         $this->assertEqualSets(
     660        $this->assertSameSets(
    661661            array(
    662662                'content' => '<!-- wp:paragraph --><p>Block test</p><!-- /wp:paragraph -->',
     
    722722        $this->assertSame( 'text-2', $data['id'] );
    723723        $this->assertSame( 'sidebar-1', $data['sidebar'] );
    724         $this->assertEqualSets(
     724        $this->assertSameSetsWithIndex(
    725725            array(
    726726                'text'   => 'Updated text test',
     
    757757        $this->assertSame( 'text-2', $data['id'] );
    758758        $this->assertSame( 'sidebar-1', $data['sidebar'] );
    759         $this->assertEqualSets(
     759        $this->assertSameSetsWithIndex(
    760760            array(
    761761                'text'   => 'Text 1',
     
    780780        $this->assertSame( 'text-3', $data['id'] );
    781781        $this->assertSame( 'sidebar-1', $data['sidebar'] );
    782         $this->assertEqualSets(
     782        $this->assertSameSetsWithIndex(
    783783            array(
    784784                'text'   => 'Text 2',
     
    828828        $this->assertSame( 'text-2', $data['id'] );
    829829        $this->assertSame( 'sidebar-1', $data['sidebar'] );
    830         $this->assertEqualSets(
     830        $this->assertSameSetsWithIndex(
    831831            array(
    832832                'text'   => 'Updated text test',
     
    875875        $this->assertSame( 'text-1', $data['id'] );
    876876        $this->assertSame( 'sidebar-1', $data['sidebar'] );
    877         $this->assertEqualSets(
     877        $this->assertSameSetsWithIndex(
    878878            array(
    879879                'text'   => 'Updated text test',
     
    964964        $this->assertSame( 'text-1', $data['id'] );
    965965        $this->assertSame( 'sidebar-1', $data['sidebar'] );
    966         $this->assertEqualSets(
     966        $this->assertSameSetsWithIndex(
    967967            array(
    968968                'text'   => 'Updated text test',
     
    11711171        $data     = $response->get_data();
    11721172
    1173         $this->assertEqualSets(
     1173        $this->assertSameSetsWithIndex(
    11741174            array(
    11751175                'text'   => 'Updated \\" \\\' text test',
Note: See TracChangeset for help on using the changeset viewer.