WordPress.org

Make WordPress Core

Changeset 51137


Ignore:
Timestamp:
06/10/2021 07:18:15 PM (6 days 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.

Location:
trunk/tests/phpunit/tests
Files:
5 edited

Legend:

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

    r51026 r51137  
    11561156        $data     = $response->get_data();
    11571157
    1158         $this->assertEqualSets( $post_ids, array_column( $data, 'id' ) );
     1158        $this->assertSameSets( $post_ids, array_column( $data, 'id' ) );
    11591159    }
    11601160
  • trunk/tests/phpunit/tests/rest-api/rest-themes-controller.php

    r50491 r51137  
    220220            'version',
    221221        );
    222         $this->assertEqualSets( $fields, array_keys( $data[0] ) );
     222        $this->assertSameSets( $fields, array_keys( $data[0] ) );
    223223
    224224        $this->assertContains( 'twentytwenty', wp_list_pluck( $data, 'stylesheet' ) );
     
    12371237        $fields_links = array( 'collection', 'self' );
    12381238
    1239         $this->assertEqualSets( $fields, array_keys( $data ) );
    1240         $this->assertEqualSets( $fields_links, array_keys( $links ) );
     1239        $this->assertSameSets( $fields, array_keys( $data ) );
     1240        $this->assertSameSets( $fields_links, array_keys( $links ) );
    12411241    }
    12421242
  • trunk/tests/phpunit/tests/rest-api/rest-widget-types-controller.php

    r51135 r51137  
    403403            $data['preview']
    404404        );
    405         $this->assertEqualSets(
     405        $this->assertSameSets(
    406406            array(
    407407                'encoded' => base64_encode( serialize( array( 'title' => 'Test title' ) ) ),
     
    439439            $data['preview']
    440440        );
    441         $this->assertEqualSets(
     441        $this->assertSameSets(
    442442            array(
    443443                'encoded' => base64_encode( serialize( array( 'title' => 'Updated title' ) ) ),
     
    483483            $data['preview']
    484484        );
    485         $this->assertEqualSets(
     485        $this->assertSameSets(
    486486            array(
    487487                'encoded' => base64_encode( serialize( array( 'title' => 'Test title' ) ) ),
  • 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',
  • trunk/tests/phpunit/tests/theme/wpThemeJson.php

    r51079 r51137  
    6262        );
    6363
    64         $this->assertEqualSetsWithIndex( $expected, $actual );
     64        $this->assertSameSetsWithIndex( $expected, $actual );
    6565    }
    6666
     
    657657        $actual   = WP_Theme_JSON::get_from_editor_settings( array() );
    658658
    659         $this->assertEqualSetsWithIndex( $expected, $actual );
     659        $this->assertSameSetsWithIndex( $expected, $actual );
    660660    }
    661661
     
    674674        $actual = WP_Theme_JSON::get_from_editor_settings( $input );
    675675
    676         $this->assertEqualSetsWithIndex( $expected, $actual['settings']['spacing'] );
     676        $this->assertSameSetsWithIndex( $expected, $actual['settings']['spacing'] );
    677677    }
    678678
     
    691691        $actual = WP_Theme_JSON::get_from_editor_settings( $input );
    692692
    693         $this->assertEqualSetsWithIndex( $expected, $actual['settings']['spacing'] );
     693        $this->assertSameSetsWithIndex( $expected, $actual['settings']['spacing'] );
    694694    }
    695695
     
    708708        $actual = WP_Theme_JSON::get_from_editor_settings( $input );
    709709
    710         $this->assertEqualSetsWithIndex( $expected, $actual['settings']['spacing'] );
     710        $this->assertSameSetsWithIndex( $expected, $actual['settings']['spacing'] );
    711711    }
    712712
Note: See TracChangeset for help on using the changeset viewer.