Make WordPress Core

Changeset 56746

Timestamp:
09/29/2023 03:22:12 PM (10 months ago)
Author:
jorbin
Message:

Tests: Reduce usage of assertEquals

Replaces assertSame with assertCount in a number of tests.

Props ayeshrajans, jorbin.
See #58956.

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

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/tests/blocks/getBlockTemplates.php

    r56559 r56746  
    162162
    163163        $block_template_ids = wp_list_pluck( $block_templates, 'id' );
    164         $this->assertSame( count( array_unique( $block_template_ids ) ), count( $block_template_ids ), $error_message );
     164        $this->assert, $error_message );
    165165    }
    166166
  • trunk/tests/phpunit/tests/customize/widgets.php

    r54872 r56746  
    237237        $selective_refreshable_widgets = $this->manager->widgets->get_selective_refreshable_widgets();
    238238        $this->assertIsArray( $selective_refreshable_widgets );
    239         $this->assertSame( count( $wp_widget_factory->widgets ), count( $selective_refreshable_widgets ) );
     239        $this->assert );
    240240        $this->assertArrayHasKey( 'text', $selective_refreshable_widgets );
    241241        $this->assertTrue( $selective_refreshable_widgets['text'] );
  • trunk/tests/phpunit/tests/date/query.php

    r56548 r56746  
    11851185        $parts = mb_split( '\)\s+AND\s+\(', $sql );
    11861186        $this->assertIsArray( $parts, 'SQL query cannot be split into multiple parts using operator AND.' );
    1187         $this->assertSame( 2, count( $parts ), 'SQL query does not contain correct number of AND operators.' );
     1187        $this->assert, 'SQL query does not contain correct number of AND operators.' );
    11881188
    11891189        $this->assertStringNotContainsString( 'OR', $sql, 'SQL query contains conditions joined by operator OR.' );
     
    12321232        $parts = mb_split( '\)\s+OR\s+\(', $sql );
    12331233        $this->assertIsArray( $parts, 'SQL query cannot be split into multiple parts using operator OR.' );
    1234         $this->assertSame( 2, count( $parts ), 'SQL query does not contain correct number of OR operators.' );
     1234        $this->assert, 'SQL query does not contain correct number of OR operators.' );
    12351235
    12361236        // Checking number of occurrences of AND while skipping the one at the beginning.
     
    12781278        $parts = mb_split( '\)\s+AND\s+\(', $sql );
    12791279        $this->assertIsArray( $parts, 'SQL query cannot be split into multiple parts using operator AND.' );
    1280         $this->assertSame( 2, count( $parts ), 'SQL query does not contain correct number of AND operators.' );
     1280        $this->assert, 'SQL query does not contain correct number of AND operators.' );
    12811281
    12821282        $this->assertStringNotContainsString( 'OR', $sql, 'SQL query contains conditions joined by operator OR.' );
  • trunk/tests/phpunit/tests/feed/rss2.php

    r56559 r56746  
    247247            $cats = array_filter( $cats );
    248248            // Should be the same number of categories.
    249             $this->assertSame( count( $cats ), count( $categories ) );
     249            $this->assert );
    250250
    251251            // ..with the same names.
  • trunk/tests/phpunit/tests/meta.php

    r56695 r56746  
    152152
    153153        // Test EXISTS and NOT EXISTS together, no users should be found.
    154         $this->assertSame(
     154        $this->assert(
    155155            0,
    156             count(
    157                 get_users(
    158                     array(
    159                         'meta_query' => array(
    160                             array(
    161                                 'key'     => 'meta_key',
    162                                 'compare' => 'NOT EXISTS',
    163                             ),
    164                             array(
    165                                 'key'     => 'delete_meta_key',
    166                                 'compare' => 'EXISTS',
    167                             ),
     156            get_users(
     157                array(
     158                    'meta_query' => array(
     159                        array(
     160                            'key'     => 'meta_key',
     161                            'compare' => 'NOT EXISTS',
    168162                        ),
    169                     )
     163                        array(
     164                            'key'     => 'delete_meta_key',
     165                            'compare' => 'EXISTS',
     166                        ),
     167                    ),
    170168                )
    171169            )
    172170        );
    173171
    174         $this->assertSame(
     172        $this->assert(
    175173            2,
    176             count(
    177                 get_users(
    178                     array(
    179                         'meta_query' => array(
    180                             array(
    181                                 'key'     => 'non_existing_meta',
    182                                 'compare' => 'NOT EXISTS',
    183                             ),
     174            get_users(
     175                array(
     176                    'meta_query' => array(
     177                        array(
     178                            'key'     => 'non_existing_meta',
     179                            'compare' => 'NOT EXISTS',
    184180                        ),
    185                     )
     181                    )
    186182                )
    187183            )
     
    190186        delete_metadata( 'user', $this->author->ID, 'meta_key' );
    191187
    192         $this->assertSame(
     188        $this->assert(
    193189            2,
    194             count(
    195                 get_users(
    196                     array(
    197                         'meta_query' => array(
    198                             array(
    199                                 'key'     => 'meta_key',
    200                                 'compare' => 'NOT EXISTS',
    201                             ),
     190            get_users(
     191                array(
     192                    'meta_query' => array(
     193                        array(
     194                            'key'     => 'meta_key',
     195                            'compare' => 'NOT EXISTS',
    202196                        ),
    203                     )
     197                    )
    204198                )
    205199            )
  • trunk/tests/phpunit/tests/post/getPages.php

    r56559 r56746  
    275275        add_post_meta( $posts[2], 'some-meta-key', '1' );
    276276
    277         $this->assertSame(
     277        $this->assert(
    278278            1,
    279             count(
    280                 get_pages(
    281                     array(
    282                         'meta_key'   => 'some-meta-key',
    283                         'meta_value' => '0',
    284                     )
     279            get_pages(
     280                array(
     281                    'meta_key'   => 'some-meta-key',
     282                    'meta_value' => '0',
    285283                )
    286284            )
    287285        );
    288         $this->assertSame(
     286        $this->assert(
    289287            1,
    290             count(
    291                 get_pages(
    292                     array(
    293                         'meta_key'   => 'some-meta-key',
    294                         'meta_value' => '1',
    295                     )
     288            get_pages(
     289                array(
     290                    'meta_key'   => 'some-meta-key',
     291                    'meta_value' => '1',
    296292                )
    297293            )
  • trunk/tests/phpunit/tests/rest-api/rest-categories-controller.php

    r56549 r56746  
    224224        );
    225225        $categories = get_terms( 'category', $args );
    226         $this->assertSame( count( $categories ), count( $data ) );
     226        $this->assert );
    227227    }
    228228
     
    256256        );
    257257        $categories = get_terms( 'category', $args );
    258         $this->assertSame( count( $categories ), count( $data ) );
     258        $this->assert );
    259259    }
    260260
     
    11901190        );
    11911191        $categories = get_terms( 'category', $args );
    1192         $this->assertSame( count( $categories ), count( $data ) );
     1192        $this->assert );
    11931193        $this->assertSame( $categories[0]->term_id, $data[0]['id'] );
    11941194        $this->assertSame( $categories[0]->name, $data[0]['name'] );
  • trunk/tests/phpunit/tests/rest-api/rest-post-types-controller.php

    r56547 r56746  
    3737        $data       = $response->get_data();
    3838        $post_types = get_post_types( array( 'show_in_rest' => true ), 'objects' );
    39         $this->assertSame( count( $post_types ), count( $data ) );
     39        $this->assert );
    4040        $this->assertSame( $post_types['post']->name, $data['post']['slug'] );
    4141        $this->check_post_type_obj( 'view', $post_types['post'], $data['post'], $data['post']['_links'] );
  • trunk/tests/phpunit/tests/rest-api/rest-tags-controller.php

    r56549 r56746  
    14101410        );
    14111411        $tags = get_terms( 'post_tag', $args );
    1412         $this->assertSame( count( $tags ), count( $data ) );
     1412        $this->assert );
    14131413        $this->assertSame( $tags[0]->term_id, $data[0]['id'] );
    14141414        $this->assertSame( $tags[0]->name, $data[0]['name'] );
  • trunk/tests/phpunit/tests/rest-api/rest-taxonomies-controller.php

    r56547 r56746  
    5151        $data       = $response->get_data();
    5252        $taxonomies = $this->get_public_taxonomies( get_taxonomies( '', 'objects' ) );
    53         $this->assertSame( count( $taxonomies ), count( $data ) );
     53        $this->assert );
    5454        $this->assertSame( 'Categories', $data['category']['name'] );
    5555        $this->assertSame( 'category', $data['category']['slug'] );
     
    7070        unset( $taxonomies['nav_menu'] ); // Menus are not editable by contributors.
    7171        $taxonomies = $this->get_public_taxonomies( $taxonomies );
    72         $this->assertSame( count( $taxonomies ), count( $data ) );
     72        $this->assert );
    7373        $this->assertSame( 'Categories', $data['category']['name'] );
    7474        $this->assertSame( 'category', $data['category']['slug'] );
     
    287287        $data       = $response->get_data();
    288288        $taxonomies = $this->get_public_taxonomies( get_object_taxonomies( $type, 'objects' ) );
    289         $this->assertSame( count( $taxonomies ), count( $data ) );
     289        $this->assert );
    290290    }
    291291
  • trunk/tests/phpunit/tests/rest-api/wpRestMenuItemsController.php

    r56549 r56746  
    744744        $data       = $response->get_data();
    745745        $properties = $data['schema']['properties'];
    746         $this->assertSame( 18, count( $properties ) );
     746        $this->assert );
    747747        $this->assertArrayHasKey( 'type_label', $properties );
    748748        $this->assertArrayHasKey( 'attr_title', $properties );
  • trunk/tests/phpunit/tests/rest-api/wpRestMenuLocationsController.php

    r55457 r56746  
    182182        $data       = $response->get_data();
    183183        $properties = $data['schema']['properties'];
    184         $this->assertSame( 3, count( $properties ) );
     184        $this->assert );
    185185        $this->assertArrayHasKey( 'name', $properties );
    186186        $this->assertArrayHasKey( 'description', $properties );
  • trunk/tests/phpunit/tests/rest-api/wpRestMenusController.php

    r55457 r56746  
    339339        $data       = $response->get_data();
    340340        $properties = $data['schema']['properties'];
    341         $this->assertSame( 7, count( $properties ) );
     341        $this->assert );
    342342        $this->assertArrayHasKey( 'id', $properties );
    343343        $this->assertArrayHasKey( 'description', $properties );
     
    574574        );
    575575        $tags = get_terms( self::TAXONOMY, $args );
    576         $this->assertSame( count( $tags ), count( $data ) );
     576        $this->assert );
    577577        $this->assertSame( $tags[0]->term_id, $data[0]['id'] );
    578578        $this->assertSame( $tags[0]->name, $data[0]['name'] );
  • trunk/tests/phpunit/tests/term/getTerms.php

    r56585 r56746  
    31733173        $query2        = get_terms( $args_2 );
    31743174        $this->assertSame( $num_queries_1, get_num_queries() );
    3175         $this->assertSame( count( $query1 ), count( $query2 ) );
     3175        $this->assert );
    31763176    }
    31773177
  • trunk/tests/phpunit/tests/user.php

    r56548 r56746  
    20842084
    20852085        // Check that the item added by the filter was retained.
    2086         $this->assertSame(
     2086        $this->assert(
    20872087            1,
    2088             count(
    2089                 wp_list_filter(
    2090                     $actual['data'][0]['data'],
    2091                     array(
    2092                         'name'  => 'Test Additional Data Name',
    2093                         'value' => 'Test Additional Data Value',
    2094                     )
     2088            wp_list_filter(
     2089                $actual['data'][0]['data'],
     2090                array(
     2091                    'name'  => 'Test Additional Data Name',
     2092                    'value' => 'Test Additional Data Value',
    20952093                )
    20962094            )
     
    21162114
    21172115        // Check that the duplicate 'name' => 'User ID' was stripped.
    2118         $this->assertSame(
     2116        $this->assert(
    21192117            1,
    2120             count(
    2121                 wp_list_filter(
    2122                     $actual['data'][0]['data'],
    2123                     array(
    2124                         'name' => 'User ID',
    2125                     )
     2118            wp_list_filter(
     2119                $actual['data'][0]['data'],
     2120                array(
     2121                    'name' => 'User ID',
    21262122                )
    21272123            )
     
    21292125
    21302126        // Check that the item added by the filter was retained.
    2131         $this->assertSame(
     2127        $this->assert(
    21322128            1,
    2133             count(
    2134                 wp_list_filter(
    2135                     $actual['data'][0]['data'],
    2136                     array(
    2137                         'name'  => 'Test Additional Data Name',
    2138                         'value' => 'Test Additional Data Value',
    2139                     )
     2129            wp_list_filter(
     2130                $actual['data'][0]['data'],
     2131                array(
     2132                    'name'  => 'Test Additional Data Name',
     2133                    'value' => 'Test Additional Data Value',
    21402134                )
    21412135            )
  • trunk/tests/phpunit/tests/widgets/wpWidgetMedia.php

    r55120 r56746  
    7777            array_keys( $widget->l10n )
    7878        );
    79         $this->assertSame( count( $widget->l10n ), count( array_filter( $widget->l10n ) ), 'Expected all translation strings to be defined.' );
     79        $this->assert ), 'Expected all translation strings to be defined.' );
    8080        $this->assertSame( 10, has_action( 'admin_print_scripts-widgets.php', array( $widget, 'enqueue_admin_scripts' ) ) );
    8181        $this->assertFalse( has_action( 'wp_enqueue_scripts', array( $widget, 'enqueue_preview_scripts' ) ), 'Did not expect preview scripts to be enqueued when not in customize preview context.' );
Note: See TracChangeset for help on using the changeset viewer.