mirror of
https://github.com/gosticks/wordpress-develop.git
synced 2026-08-16 23:00:21 +00:00
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. git-svn-id: https://develop.svn.wordpress.org/trunk@48937 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
@@ -29,7 +29,7 @@ class Tests_Category extends WP_UnitTestCase {
|
||||
|
||||
// Validate length is 1 + created due to uncategorized.
|
||||
$cat_ids = get_all_category_ids();
|
||||
$this->assertEquals( 3, count( $cat_ids ) );
|
||||
$this->assertSame( 3, count( $cat_ids ) );
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -53,9 +53,9 @@ class Tests_Category extends WP_UnitTestCase {
|
||||
|
||||
// Validate category is returned by slug.
|
||||
$ret_testcat = get_category_by_slug( 'testcat' );
|
||||
$this->assertEquals( $testcat->term_id, $ret_testcat->term_id );
|
||||
$this->assertSame( $testcat->term_id, $ret_testcat->term_id );
|
||||
$ret_testcat = get_category_by_slug( 'TeStCaT' );
|
||||
$this->assertEquals( $testcat->term_id, $ret_testcat->term_id );
|
||||
$this->assertSame( $testcat->term_id, $ret_testcat->term_id );
|
||||
|
||||
// Validate unknown category returns false.
|
||||
$this->assertFalse( get_category_by_slug( 'testcat3' ) );
|
||||
@@ -107,36 +107,36 @@ class Tests_Category extends WP_UnitTestCase {
|
||||
_make_cat_compat( $testcat2_array );
|
||||
|
||||
// Validate compatibility object.
|
||||
$this->assertEquals( $testcat->cat_ID, $testcat->term_id );
|
||||
$this->assertEquals( $testcat->category_count, $testcat->count );
|
||||
$this->assertEquals( $testcat->category_description, $testcat->description );
|
||||
$this->assertEquals( $testcat->cat_name, $testcat->name );
|
||||
$this->assertEquals( $testcat->category_nicename, $testcat->slug );
|
||||
$this->assertEquals( $testcat->category_parent, $testcat->parent );
|
||||
$this->assertSame( $testcat->cat_ID, $testcat->term_id );
|
||||
$this->assertSame( $testcat->category_count, $testcat->count );
|
||||
$this->assertSame( $testcat->category_description, $testcat->description );
|
||||
$this->assertSame( $testcat->cat_name, $testcat->name );
|
||||
$this->assertSame( $testcat->category_nicename, $testcat->slug );
|
||||
$this->assertSame( $testcat->category_parent, $testcat->parent );
|
||||
|
||||
// Validate compatibility object with parent.
|
||||
$this->assertEquals( $testcat->cat_ID, $testcat->term_id );
|
||||
$this->assertEquals( $testcat->category_count, $testcat->count );
|
||||
$this->assertEquals( $testcat->category_description, $testcat->description );
|
||||
$this->assertEquals( $testcat->cat_name, $testcat->name );
|
||||
$this->assertEquals( $testcat->category_nicename, $testcat->slug );
|
||||
$this->assertEquals( $testcat->category_parent, $testcat->parent );
|
||||
$this->assertSame( $testcat->cat_ID, $testcat->term_id );
|
||||
$this->assertSame( $testcat->category_count, $testcat->count );
|
||||
$this->assertSame( $testcat->category_description, $testcat->description );
|
||||
$this->assertSame( $testcat->cat_name, $testcat->name );
|
||||
$this->assertSame( $testcat->category_nicename, $testcat->slug );
|
||||
$this->assertSame( $testcat->category_parent, $testcat->parent );
|
||||
|
||||
// Validate compatibility array.
|
||||
$this->assertEquals( $testcat_array['cat_ID'], $testcat_array['term_id'] );
|
||||
$this->assertEquals( $testcat_array['category_count'], $testcat_array['count'] );
|
||||
$this->assertEquals( $testcat_array['category_description'], $testcat_array['description'] );
|
||||
$this->assertEquals( $testcat_array['cat_name'], $testcat_array['name'] );
|
||||
$this->assertEquals( $testcat_array['category_nicename'], $testcat_array['slug'] );
|
||||
$this->assertEquals( $testcat_array['category_parent'], $testcat_array['parent'] );
|
||||
$this->assertSame( $testcat_array['cat_ID'], $testcat_array['term_id'] );
|
||||
$this->assertSame( $testcat_array['category_count'], $testcat_array['count'] );
|
||||
$this->assertSame( $testcat_array['category_description'], $testcat_array['description'] );
|
||||
$this->assertSame( $testcat_array['cat_name'], $testcat_array['name'] );
|
||||
$this->assertSame( $testcat_array['category_nicename'], $testcat_array['slug'] );
|
||||
$this->assertSame( $testcat_array['category_parent'], $testcat_array['parent'] );
|
||||
|
||||
// Validate compatibility array with parent.
|
||||
$this->assertEquals( $testcat_array['cat_ID'], $testcat_array['term_id'] );
|
||||
$this->assertEquals( $testcat_array['category_count'], $testcat_array['count'] );
|
||||
$this->assertEquals( $testcat_array['category_description'], $testcat_array['description'] );
|
||||
$this->assertEquals( $testcat_array['cat_name'], $testcat_array['name'] );
|
||||
$this->assertEquals( $testcat_array['category_nicename'], $testcat_array['slug'] );
|
||||
$this->assertEquals( $testcat_array['category_parent'], $testcat_array['parent'] );
|
||||
$this->assertSame( $testcat_array['cat_ID'], $testcat_array['term_id'] );
|
||||
$this->assertSame( $testcat_array['category_count'], $testcat_array['count'] );
|
||||
$this->assertSame( $testcat_array['category_description'], $testcat_array['description'] );
|
||||
$this->assertSame( $testcat_array['cat_name'], $testcat_array['name'] );
|
||||
$this->assertSame( $testcat_array['category_nicename'], $testcat_array['slug'] );
|
||||
$this->assertSame( $testcat_array['category_parent'], $testcat_array['parent'] );
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -153,9 +153,9 @@ class Tests_Category extends WP_UnitTestCase {
|
||||
);
|
||||
|
||||
// Validate.
|
||||
$this->assertEquals( $testcat->name, get_cat_name( $testcat->term_id ) );
|
||||
$this->assertEquals( '', get_cat_name( -1 ) );
|
||||
$this->assertEquals( '', get_cat_name( $testcat->term_id + 100 ) );
|
||||
$this->assertSame( $testcat->name, get_cat_name( $testcat->term_id ) );
|
||||
$this->assertSame( '', get_cat_name( -1 ) );
|
||||
$this->assertSame( '', get_cat_name( $testcat->term_id + 100 ) );
|
||||
|
||||
}
|
||||
|
||||
@@ -173,9 +173,9 @@ class Tests_Category extends WP_UnitTestCase {
|
||||
);
|
||||
|
||||
// Validate.
|
||||
$this->assertEquals( $testcat->term_id, get_cat_ID( $testcat->name ) );
|
||||
$this->assertEquals( 0, get_cat_ID( 'NO CAT' ) );
|
||||
$this->assertEquals( 0, get_cat_ID( 12 ) );
|
||||
$this->assertSame( $testcat->term_id, get_cat_ID( $testcat->name ) );
|
||||
$this->assertSame( 0, get_cat_ID( 'NO CAT' ) );
|
||||
$this->assertSame( 0, get_cat_ID( 12 ) );
|
||||
|
||||
}
|
||||
|
||||
@@ -229,17 +229,17 @@ class Tests_Category extends WP_UnitTestCase {
|
||||
|
||||
// Validate full match.
|
||||
$ret_cat = get_category_by_path( '/root/level-1', true );
|
||||
$this->assertEquals( $root_level_id, $ret_cat->term_id );
|
||||
$this->assertSame( $root_level_id, $ret_cat->term_id );
|
||||
$this->assertNull( get_category_by_path( 'level-1', true ) );
|
||||
$this->assertNull( get_category_by_path( 'nocat/nocat/', true ) );
|
||||
|
||||
// Validate partial match.
|
||||
$ret_cat = get_category_by_path( 'level-1', false );
|
||||
$this->assertEquals( $root_level_id, $ret_cat->term_id );
|
||||
$this->assertSame( $root_level_id, $ret_cat->term_id );
|
||||
$ret_cat = get_category_by_path( 'root/cat/level-1', false );
|
||||
$this->assertEquals( $root_level_id, $ret_cat->term_id );
|
||||
$this->assertSame( $root_level_id, $ret_cat->term_id );
|
||||
$ret_cat = get_category_by_path( 'root$2Fcat%20%2Flevel-1', false );
|
||||
$this->assertEquals( $root_level_id, $ret_cat->term_id );
|
||||
$this->assertSame( $root_level_id, $ret_cat->term_id );
|
||||
$this->assertNull( get_category_by_path( 'nocat/nocat/', false ) );
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user