Make WordPress Core


Ignore:
Timestamp:
09/02/2020 12:35:36 AM (6 years ago)
Author:
SergeyBiryukov
Message:

Tests: First pass at using assertSame() instead of assertEquals() in most of the unit 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.

Props johnbillion, jrf, SergeyBiryukov.
See #38266.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/tests/post/wpUniquePostSlug.php

    r48121 r48937  
    3737
    3838                        $post = get_post( $id );
    39                         $this->assertEquals( $outputs[ $k ], urldecode( $post->post_name ) );
     39                        $this->assertSame( $outputs[ $k ], urldecode( $post->post_name ) );
    4040                }
    4141        }
    … …  
    5757                $two               = self::factory()->post->create( $args );
    5858
    59                 $this->assertEquals( 'some-slug', get_post( $one )->post_name );
    60                 $this->assertEquals( 'some-slug', get_post( $two )->post_name );
    61 
    62                 $this->assertEquals( 'some-other-slug', wp_unique_post_slug( 'some-other-slug', $one, 'publish', 'post-type-1', 0 ) );
    63                 $this->assertEquals( 'some-other-slug', wp_unique_post_slug( 'some-other-slug', $one, 'publish', 'post-type-2', 0 ) );
     59                $this->assertSame( 'some-slug', get_post( $one )->post_name );
     60                $this->assertSame( 'some-slug', get_post( $two )->post_name );
     61
     62                $this->assertSame( 'some-other-slug', wp_unique_post_slug( 'some-other-slug', $one, 'publish', 'post-type-1', 0 ) );
     63                $this->assertSame( 'some-other-slug', wp_unique_post_slug( 'some-other-slug', $one, 'publish', 'post-type-2', 0 ) );
    6464
    6565                _unregister_post_type( 'post-type-1' );
    … …  
    8282                $two               = self::factory()->post->create( $args );
    8383
    84                 $this->assertEquals( 'some-slug', get_post( $one )->post_name );
    85                 $this->assertEquals( 'some-slug-2', get_post( $two )->post_name );
    86 
    87                 $this->assertEquals( 'some-slug-3', wp_unique_post_slug( 'some-slug', 0, 'publish', 'post-type-1', 0 ) );
     84                $this->assertSame( 'some-slug', get_post( $one )->post_name );
     85                $this->assertSame( 'some-slug-2', get_post( $two )->post_name );
     86
     87                $this->assertSame( 'some-slug-3', wp_unique_post_slug( 'some-slug', 0, 'publish', 'post-type-1', 0 ) );
    8888
    8989                _unregister_post_type( 'post-type-1' );
    … …  
    118118                $two  = self::factory()->post->create( $args );
    119119
    120                 $this->assertEquals( 'some-slug', get_post( $one )->post_name );
    121                 $this->assertEquals( 'image', get_post( $attachment )->post_name );
    122                 $this->assertEquals( 'image-2', get_post( $two )->post_name );
     120                $this->assertSame( 'some-slug', get_post( $one )->post_name );
     121                $this->assertSame( 'image', get_post( $attachment )->post_name );
     122                $this->assertSame( 'image-2', get_post( $two )->post_name );
    123123
    124124                // 'image' can be a child of image-2.
    125                 $this->assertEquals( 'image', wp_unique_post_slug( 'image', 0, 'publish', 'post-type-1', $two ) );
     125                $this->assertSame( 'image', wp_unique_post_slug( 'image', 0, 'publish', 'post-type-1', $two ) );
    126126
    127127                _unregister_post_type( 'post-type-1' );
    … …  
    191191
    192192                $found = wp_unique_post_slug( '2015', $p, 'publish', 'post', 0 );
    193                 $this->assertEquals( '2015-2', $found );
     193                $this->assertSame( '2015-2', $found );
    194194        }
    195195
    … …  
    209209
    210210                $found = wp_unique_post_slug( '2015', $p, 'publish', 'post', 0 );
    211                 $this->assertEquals( '2015-2', $found );
     211                $this->assertSame( '2015-2', $found );
    212212        }
    213213
    … …  
    226226
    227227                $found = wp_unique_post_slug( '2015', $p, 'publish', 'post', 0 );
    228                 $this->assertEquals( '2015', $found );
     228                $this->assertSame( '2015', $found );
    229229        }
    230230
    … …  
    243243
    244244                $found = wp_unique_post_slug( '11', $p, 'publish', 'post', 0 );
    245                 $this->assertEquals( '11-2', $found );
     245                $this->assertSame( '11-2', $found );
    246246        }
    247247
    … …  
    260260
    261261                $found = wp_unique_post_slug( '11', $p, 'publish', 'post', 0 );
    262                 $this->assertEquals( '11', $found );
     262                $this->assertSame( '11', $found );
    263263        }
    264264
    … …  
    277277
    278278                $found = wp_unique_post_slug( '13', $p, 'publish', 'post', 0 );
    279                 $this->assertEquals( '13', $found );
     279                $this->assertSame( '13', $found );
    280280        }
    281281
    … …  
    294294
    295295                $found = wp_unique_post_slug( '30', $p, 'publish', 'post', 0 );
    296                 $this->assertEquals( '30-2', $found );
     296                $this->assertSame( '30-2', $found );
    297297        }
    298298
    … …  
    311311
    312312                $found = wp_unique_post_slug( '30', $p, 'publish', 'post', 0 );
    313                 $this->assertEquals( '30', $found );
     313                $this->assertSame( '30', $found );
    314314        }
    315315
    … …  
    328328
    329329                $found = wp_unique_post_slug( '32', $p, 'publish', 'post', 0 );
    330                 $this->assertEquals( '32', $found );
     330                $this->assertSame( '32', $found );
    331331        }
    332332
Note: See TracChangeset for help on using the changeset viewer.