Make WordPress Core


Ignore:
Timestamp:
05/22/2024 03:39:51 PM (22 months ago)
Author:
SergeyBiryukov
Message:

Tests: Use assertSame() in navigation fallback tests.

This ensures that not only the return values match the expected results, but also that their type is the same.

Going forward, stricter type checking by using assertSame() should generally be preferred to assertEquals() where appropriate, to make the tests more reliable.

Follow-up to [56052].

See #60705.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/tests/editor/navigation-fallback.php

    r56971 r58183  
    4646        $this->assertInstanceOf( 'WP_Post', $data, 'Response should be of the correct type.' );
    4747
    48         $this->assertEquals( 'wp_navigation', $data->post_type, 'Fallback menu type should be `wp_navigation`' );
    49 
    50         $this->assertEquals( 'Navigation', $data->post_title, 'Fallback menu title should be the default fallback title' );
    51 
    52         $this->assertEquals( 'navigation', $data->post_name, 'Fallback menu slug (post_name) should be the default slug' );
    53 
    54         $this->assertEquals( '<!-- wp:page-list /-->', $data->post_content );
     48        $this->assertSame( 'wp_navigation', $data->post_type, 'Fallback menu type should be `wp_navigation`' );
     49
     50        $this->assertSame( 'Navigation', $data->post_title, 'Fallback menu title should be the default fallback title' );
     51
     52        $this->assertSame( 'navigation', $data->post_name, 'Fallback menu slug (post_name) should be the default slug' );
     53
     54        $this->assertSame( '<!-- wp:page-list /-->', $data->post_content );
    5555
    5656        $navs_in_db = $this->get_navigations_in_database();
     
    9393        $this->assertInstanceOf( 'WP_Post', $data, 'Response should be of the correct type.' );
    9494
    95         $this->assertNotEquals( '<!-- wp:page-list /-->', $data->post_content, 'Navigation Menu should not contain a Page List block.' );
     95        $this->assertNotSame( '<!-- wp:page-list /-->', $data->post_content, 'Navigation Menu should not contain a Page List block.' );
    9696
    9797        $this->assertEmpty( $data->post_content, 'Menu should be empty.' );
     
    114114        $this->assertInstanceOf( 'WP_Post', $data, 'Response should be of the correct type.' );
    115115
    116         $this->assertEquals( 'Navigation', $data->post_title, 'Fallback menu title should be the default title' );
     116        $this->assertSame( 'Navigation', $data->post_title, 'Fallback menu title should be the default title' );
    117117
    118118        $navs_in_db = $this->get_navigations_in_database();
     
    147147        $this->assertInstanceOf( 'WP_Post', $data, 'Response should be of the correct type.' );
    148148
    149         $this->assertEquals( $most_recently_published_nav->post_title, $data->post_title, 'Fallback menu title should be the same as the most recently created menu.' );
    150 
    151         $this->assertEquals( $most_recently_published_nav->post_name, $data->post_name, 'Post name should be the same as the most recently created menu.' );
    152 
    153         $this->assertEquals( $most_recently_published_nav->post_content, $data->post_content, 'Post content should be the same as the most recently created menu.' );
     149        $this->assertSame( $most_recently_published_nav->post_title, $data->post_title, 'Fallback menu title should be the same as the most recently created menu.' );
     150
     151        $this->assertSame( $most_recently_published_nav->post_name, $data->post_name, 'Post name should be the same as the most recently created menu.' );
     152
     153        $this->assertSame( $most_recently_published_nav->post_content, $data->post_content, 'Post content should be the same as the most recently created menu.' );
    154154
    155155        // Check that no new Navigation menu was created.
     
    180180        $this->assertInstanceOf( 'WP_Post', $data, 'Response should be of the correct type.' );
    181181
    182         $this->assertEquals( 'Existing Classic Menu', $data->post_title, 'Fallback menu title should be the same as the classic menu.' );
     182        $this->assertSame( 'Existing Classic Menu', $data->post_title, 'Fallback menu title should be the same as the classic menu.' );
    183183
    184184        // Assert that the fallback contains a navigation-link block.
     
    234234        $this->assertInstanceOf( 'WP_Post', $data, 'Response should be of the correct type.' );
    235235
    236         $this->assertEquals( 'Classic Menu in Primary Location', $data->post_title, 'Fallback menu title should match the menu in the "primary" location.' );
     236        $this->assertSame( 'Classic Menu in Primary Location', $data->post_title, 'Fallback menu title should match the menu in the "primary" location.' );
    237237    }
    238238
     
    272272        $this->assertInstanceOf( 'WP_Post', $data, 'Response should be of the correct type.' );
    273273
    274         $this->assertEquals( 'Primary', $data->post_title, 'Fallback menu title should match the menu with the slug "primary".' );
     274        $this->assertSame( 'Primary', $data->post_title, 'Fallback menu title should match the menu with the slug "primary".' );
    275275    }
    276276
     
    310310        $this->assertInstanceOf( 'WP_Post', $data, 'Response should be of the correct type.' );
    311311
    312         $this->assertEquals( 'Most Recent Classic Menu', $data->post_title, 'Fallback menu title should match the menu that was created most recently.' );
     312        $this->assertSame( 'Most Recent Classic Menu', $data->post_title, 'Fallback menu title should match the menu that was created most recently.' );
    313313    }
    314314
     
    342342        $this->assertInstanceOf( 'WP_Post', $data, 'Response should be of the correct type.' );
    343343
    344         $this->assertEquals( $existing_navigation_menu->post_title, $data->post_title, 'Fallback menu title should be the same as the existing Navigation menu.' );
    345 
    346         $this->assertNotEquals( 'Existing Classic Menu', $data->post_title, 'Fallback menu title should not be the same as the Classic Menu.' );
     344        $this->assertSame( $existing_navigation_menu->post_title, $data->post_title, 'Fallback menu title should be the same as the existing Navigation menu.' );
     345
     346        $this->assertNotSame( 'Existing Classic Menu', $data->post_title, 'Fallback menu title should not be the same as the Classic Menu.' );
    347347
    348348        // Check that only a single Navigation fallback was created.
Note: See TracChangeset for help on using the changeset viewer.