Make WordPress Core

Changeset 58183


Ignore:
Timestamp:
05/22/2024 03:39:51 PM (5 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.

Location:
trunk/tests/phpunit/tests/editor
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/tests/editor/classic-to-block-menu-converter.php

    r56971 r58183  
    3232        $this->assertTrue( is_wp_error( $result ), 'Should be a WP_Error instance' );
    3333
    34         $this->assertEquals( 'invalid_menu', $result->get_error_code(), 'Error code should indicate invalidity of menu argument.' );
    35 
    36         $this->assertEquals( 'The menu provided is not a valid menu.', $result->get_error_message(), 'Error message should communicate invalidity of menu argument.' );
     34        $this->assertSame( 'invalid_menu', $result->get_error_code(), 'Error code should indicate invalidity of menu argument.' );
     35
     36        $this->assertSame( 'The menu provided is not a valid menu.', $result->get_error_message(), 'Error message should communicate invalidity of menu argument.' );
    3737    }
    3838
     
    105105        $nested_block = $parsed_blocks[1]['innerBlocks'][0];
    106106
    107         $this->assertEquals( 'core/navigation-link', $first_block['blockName'], 'First block name should be "core/navigation-link"' );
    108 
    109         $this->assertEquals( 'Classic Menu Item 1', $first_block['attrs']['label'], 'First block label should match.' );
    110 
    111         $this->assertEquals( '/classic-menu-item-1', $first_block['attrs']['url'], 'First block URL should match.' );
     107        $this->assertSame( 'core/navigation-link', $first_block['blockName'], 'First block name should be "core/navigation-link"' );
     108
     109        $this->assertSame( 'Classic Menu Item 1', $first_block['attrs']['label'], 'First block label should match.' );
     110
     111        $this->assertSame( '/classic-menu-item-1', $first_block['attrs']['url'], 'First block URL should match.' );
    112112
    113113        // Assert parent of nested menu item is a submenu block.
    114         $this->assertEquals( 'core/navigation-submenu', $second_block['blockName'], 'Second block name should be "core/navigation-submenu"' );
    115 
    116         $this->assertEquals( 'Classic Menu Item 2', $second_block['attrs']['label'], 'Second block label should match.' );
    117 
    118         $this->assertEquals( '/classic-menu-item-2', $second_block['attrs']['url'], 'Second block URL should match.' );
    119 
    120         $this->assertEquals( 'core/navigation-link', $nested_block['blockName'], 'Nested block name should be "core/navigation-link"' );
    121 
    122         $this->assertEquals( 'Nested Menu Item 1', $nested_block['attrs']['label'], 'Nested block label should match.' );
    123 
    124         $this->assertEquals( '/nested-menu-item-1', $nested_block['attrs']['url'], 'Nested block URL should match.' );
     114        $this->assertSame( 'core/navigation-submenu', $second_block['blockName'], 'Second block name should be "core/navigation-submenu"' );
     115
     116        $this->assertSame( 'Classic Menu Item 2', $second_block['attrs']['label'], 'Second block label should match.' );
     117
     118        $this->assertSame( '/classic-menu-item-2', $second_block['attrs']['url'], 'Second block URL should match.' );
     119
     120        $this->assertSame( 'core/navigation-link', $nested_block['blockName'], 'Nested block name should be "core/navigation-link"' );
     121
     122        $this->assertSame( 'Nested Menu Item 1', $nested_block['attrs']['label'], 'Nested block label should match.' );
     123
     124        $this->assertSame( '/nested-menu-item-1', $nested_block['attrs']['url'], 'Nested block URL should match.' );
    125125
    126126        wp_delete_nav_menu( $menu_id );
     
    195195            $this->assertCount( 1, $parsed_blocks, 'Should only be one block in the array.' );
    196196
    197             $this->assertEquals( 'core/navigation-link', $parsed_blocks[0]['blockName'], 'First block name should be "core/navigation-link"' );
    198 
    199             $this->assertEquals( 'Classic Menu Item 1', $parsed_blocks[0]['attrs']['label'], 'First block label should match.' );
    200 
    201             $this->assertEquals( '/classic-menu-item-1', $parsed_blocks[0]['attrs']['url'], 'First block URL should match.' );
     197            $this->assertSame( 'core/navigation-link', $parsed_blocks[0]['blockName'], 'First block name should be "core/navigation-link"' );
     198
     199            $this->assertSame( 'Classic Menu Item 1', $parsed_blocks[0]['attrs']['label'], 'First block label should match.' );
     200
     201            $this->assertSame( '/classic-menu-item-1', $parsed_blocks[0]['attrs']['url'], 'First block URL should match.' );
    202202
    203203            wp_delete_nav_menu( $menu_id );
  • 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.