Make WordPress Core


Ignore:
Timestamp:
09/04/2020 07:01:00 AM (4 years ago)
Author:
SergeyBiryukov
Message:

Tests: Introduce assertSameSets() and assertSameSetsWithIndex(), and use them where appropriate.

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

These new methods replace most of the existing instances of assertEqualSets() and assertEqualSetsWithIndex().

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

Follow-up to [48937].

See #38266.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/tests/customize/manager.php

    r48937 r48939  
    675675            'page_for_posts',
    676676        );
    677         $this->assertEqualSets( $expected_setting_ids, array_keys( $changeset_values ) );
     677        $this->assertSameSets( $expected_setting_ids, array_keys( $changeset_values ) );
    678678
    679679        foreach ( array( 'widget_text[2]', 'widget_meta[3]' ) as $setting_id ) {
     
    743743        $changeset_data = $wp_customize->changeset_data();
    744744        // Auto-drafts should not get re-created and amended with each import.
    745         $this->assertEqualSets( array_values( $posts_by_name ), $changeset_data['nav_menus_created_posts']['value'] );
     745        $this->assertSameSets( array_values( $posts_by_name ), $changeset_data['nav_menus_created_posts']['value'] );
    746746
    747747        // Test that saving non-starter content on top of the changeset clears the starter_content flag.
     
    871871            'nested_array_theme_mod',
    872872        );
    873         $this->assertEqualSets( $expected_setting_ids, array_keys( $changeset_values ) );
     873        $this->assertSameSets( $expected_setting_ids, array_keys( $changeset_values ) );
    874874
    875875        $this->assertSame( $existing_published_home_page_id, $changeset_values['array_option']['home_page_id'] );
     
    16121612            $this->assertSame( $save_counts[ $setting_id ] + 1, did_action( sprintf( 'customize_save_%s', $setting_id ) ), $setting_id );
    16131613        }
    1614         $this->assertEqualSets( array( 'blogname', 'blogdescription', 'background_color', 'scratchpad' ), array_keys( $this->filtered_setting_current_user_ids ) );
     1614        $this->assertSameSets( array( 'blogname', 'blogdescription', 'background_color', 'scratchpad' ), array_keys( $this->filtered_setting_current_user_ids ) );
    16151615        $this->assertSame( $other_admin_user_id, $this->filtered_setting_current_user_ids['blogname'] );
    16161616        $this->assertSame( 0, $this->filtered_setting_current_user_ids['blogdescription'] );
     
    22222222        add_filter( 'customize_allowed_urls', array( $this, 'filter_customize_allowed_urls' ) );
    22232223        $allowed = $wp_customize->get_allowed_urls();
    2224         $this->assertEqualSets( $allowed, array( 'http://headless.example.com/', home_url( '/', 'http' ) ) );
     2224        $this->assertSameSets( $allowed, array( 'http://headless.example.com/', home_url( '/', 'http' ) ) );
    22252225    }
    22262226
     
    30903090        $this->assertNotEmpty( $data );
    30913091
    3092         $this->assertEqualSets( array( 'theme', 'url', 'browser', 'panels', 'sections', 'nonce', 'autofocus', 'documentTitleTmpl', 'previewableDevices', 'changeset', 'timeouts', 'dateFormat', 'timeFormat', 'initialClientTimestamp', 'initialServerDate', 'initialServerTimestamp', 'l10n' ), array_keys( $data ) );
     3092        $this->assertSameSets( array( 'theme', 'url', 'browser', 'panels', 'sections', 'nonce', 'autofocus', 'documentTitleTmpl', 'previewableDevices', 'changeset', 'timeouts', 'dateFormat', 'timeFormat', 'initialClientTimestamp', 'initialServerDate', 'initialServerTimestamp', 'l10n' ), array_keys( $data ) );
    30933093        $this->assertSame( $autofocus, $data['autofocus'] );
    30943094        $this->assertArrayHasKey( 'save', $data['nonce'] );
    30953095        $this->assertArrayHasKey( 'preview', $data['nonce'] );
    30963096
    3097         $this->assertEqualSets(
     3097        $this->assertSameSets(
    30983098            array(
    30993099                'branching',
Note: See TracChangeset for help on using the changeset viewer.