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:
Sergey Biryukov
2020-09-02 00:35:36 +00:00
parent ba7c6a2d5f
commit 164b22cf6a
426 changed files with 7959 additions and 7949 deletions
@@ -164,8 +164,8 @@ class Test_WP_Community_Events extends WP_UnitTestCase {
$this->assertNotWPError( $response );
$this->assertEqualSetsWithIndex( $this->get_user_location(), $response['location'] );
$this->assertEquals( gmdate( 'l, M j, Y', strtotime( 'next Sunday 1pm' ) ), $response['events'][0]['formatted_date'] );
$this->assertEquals( '1:00 pm', $response['events'][0]['formatted_time'] );
$this->assertSame( gmdate( 'l, M j, Y', strtotime( 'next Sunday 1pm' ) ), $response['events'][0]['formatted_date'] );
$this->assertSame( '1:00 pm', $response['events'][0]['formatted_time'] );
remove_filter( 'pre_http_request', array( $this, '_http_request_valid_response' ) );
}
@@ -185,8 +185,8 @@ class Test_WP_Community_Events extends WP_UnitTestCase {
$this->assertNotWPError( $cached_events );
$this->assertEqualSetsWithIndex( $this->get_user_location(), $cached_events['location'] );
$this->assertEquals( gmdate( 'l, M j, Y', strtotime( 'next Sunday 1pm' ) ), $cached_events['events'][0]['formatted_date'] );
$this->assertEquals( '1:00 pm', $cached_events['events'][0]['formatted_time'] );
$this->assertSame( gmdate( 'l, M j, Y', strtotime( 'next Sunday 1pm' ) ), $cached_events['events'][0]['formatted_date'] );
$this->assertSame( '1:00 pm', $cached_events['events'][0]['formatted_time'] );
remove_filter( 'pre_http_request', array( $this, '_http_request_valid_response' ) );
}
@@ -273,9 +273,9 @@ class Test_WP_Community_Events extends WP_UnitTestCase {
* so that it remains in the list. The other events should remain unchanged.
*/
$this->assertCount( 3, $response_body['events'] );
$this->assertEquals( $response_body['events'][0]['title'], 'Flexbox + CSS Grid: Magic for Responsive Layouts' );
$this->assertEquals( $response_body['events'][1]['title'], 'Part 3- Site Maintenance - Tools to Make It Easy' );
$this->assertEquals( $response_body['events'][2]['title'], 'WordCamp San Diego' );
$this->assertSame( $response_body['events'][0]['title'], 'Flexbox + CSS Grid: Magic for Responsive Layouts' );
$this->assertSame( $response_body['events'][1]['title'], 'Part 3- Site Maintenance - Tools to Make It Easy' );
$this->assertSame( $response_body['events'][2]['title'], 'WordCamp San Diego' );
remove_filter( 'pre_http_request', array( $this, '_http_request_valid_response_unpinned_wordcamp' ) );
}
@@ -375,9 +375,9 @@ class Test_WP_Community_Events extends WP_UnitTestCase {
* WordCamp LA should not be stuck to the list, because San Diego already appears naturally.
*/
$this->assertCount( 3, $response_body['events'] );
$this->assertEquals( $response_body['events'][0]['title'], 'WordCamp San Diego' );
$this->assertEquals( $response_body['events'][1]['title'], 'Part 3- Site Maintenance - Tools to Make It Easy' );
$this->assertEquals( $response_body['events'][2]['title'], 'WordPress Q&A' );
$this->assertSame( $response_body['events'][0]['title'], 'WordCamp San Diego' );
$this->assertSame( $response_body['events'][1]['title'], 'Part 3- Site Maintenance - Tools to Make It Easy' );
$this->assertSame( $response_body['events'][2]['title'], 'WordPress Q&A' );
remove_filter( 'pre_http_request', array( $this, '_http_request_valid_response_multiple_wordcamps' ) );
}
@@ -488,7 +488,7 @@ class Test_WP_Community_Events extends WP_UnitTestCase {
$_SERVER['HTTP_CLIENT_IP'] = $raw_ip;
$actual_result = WP_Community_Events::get_unsafe_client_ip();
$this->assertEquals( $expected_result, $actual_result );
$this->assertSame( $expected_result, $actual_result );
}
/**
+6 -6
View File
@@ -13,19 +13,19 @@ class Tests_Admin_includesFile extends WP_UnitTestCase {
$home = get_option( 'home' );
$siteurl = get_option( 'siteurl' );
$sfn = $_SERVER['SCRIPT_FILENAME'];
$this->assertEquals( str_replace( '\\', '/', ABSPATH ), get_home_path() );
$this->assertSame( str_replace( '\\', '/', ABSPATH ), get_home_path() );
update_option( 'home', 'http://localhost' );
update_option( 'siteurl', 'http://localhost/wp' );
$_SERVER['SCRIPT_FILENAME'] = 'D:\root\vhosts\site\httpdocs\wp\wp-admin\options-permalink.php';
$this->assertEquals( 'D:/root/vhosts/site/httpdocs/', get_home_path() );
$this->assertSame( 'D:/root/vhosts/site/httpdocs/', get_home_path() );
$_SERVER['SCRIPT_FILENAME'] = '/Users/foo/public_html/trunk/wp/wp-admin/options-permalink.php';
$this->assertEquals( '/Users/foo/public_html/trunk/', get_home_path() );
$this->assertSame( '/Users/foo/public_html/trunk/', get_home_path() );
$_SERVER['SCRIPT_FILENAME'] = 'S:/home/wordpress/trunk/wp/wp-admin/options-permalink.php';
$this->assertEquals( 'S:/home/wordpress/trunk/', get_home_path() );
$this->assertSame( 'S:/home/wordpress/trunk/', get_home_path() );
update_option( 'home', $home );
update_option( 'siteurl', $siteurl );
@@ -40,7 +40,7 @@ class Tests_Admin_includesFile extends WP_UnitTestCase {
$error = download_url( 'test_download_url_non_200' );
$this->assertWPError( $error );
$this->assertEquals(
$this->assertSame(
array(
'code' => 418,
'body' => 'This is an unexpected error message from your favorite server.',
@@ -52,7 +52,7 @@ class Tests_Admin_includesFile extends WP_UnitTestCase {
$error = download_url( 'test_download_url_non_200' );
$this->assertWPError( $error );
$this->assertEquals(
$this->assertSame(
array(
'code' => 418,
'body' => 'This ',
+1 -1
View File
@@ -20,7 +20,7 @@ class Tests_Admin_includesMisc extends WP_UnitTestCase {
=> 'wordpress.org/about/philosophy/#…', // Shorten to 32 if > 35 after cleaning.
);
foreach ( $tests as $k => $v ) {
$this->assertEquals( $v, url_shorten( $k ) );
$this->assertSame( $v, url_shorten( $k ) );
}
}
}
+13 -13
View File
@@ -23,7 +23,7 @@ class Tests_Admin_includesPlugin extends WP_UnitTestCase {
foreach ( $default_headers as $name => $value ) {
$this->assertTrue( isset( $data[ $name ] ) );
$this->assertEquals( $value, $data[ $name ] );
$this->assertSame( $value, $data[ $name ] );
}
}
@@ -51,7 +51,7 @@ class Tests_Admin_includesPlugin extends WP_UnitTestCase {
$expected['testpages'] = 'http://example.com/wp-admin/edit.php?post_type=page&page=testpages';
foreach ( $expected as $name => $value ) {
$this->assertEquals( $value, menu_page_url( $name, false ) );
$this->assertSame( $value, menu_page_url( $name, false ) );
}
wp_set_current_user( $current_user );
@@ -349,7 +349,7 @@ class Tests_Admin_includesPlugin extends WP_UnitTestCase {
*/
public function test_get_plugin_files_single() {
$name = 'hello.php';
$this->assertEquals( array( $name ), get_plugin_files( $name ) );
$this->assertSame( array( $name ), get_plugin_files( $name ) );
}
/**
@@ -369,7 +369,7 @@ class Tests_Admin_includesPlugin extends WP_UnitTestCase {
'list_files_test_plugin/list_files_test_plugin.php',
'list_files_test_plugin/subdir/subfile.php',
);
$this->assertEquals( $expected, $plugin_files );
$this->assertSame( $expected, $plugin_files );
unlink( $sub_dir . '/subfile.php' );
unlink( $plugin[1] );
@@ -389,7 +389,7 @@ class Tests_Admin_includesPlugin extends WP_UnitTestCase {
mkdir( WPMU_PLUGIN_DIR );
}
$this->assertEquals( array(), get_mu_plugins() );
$this->assertSame( array(), get_mu_plugins() );
// Clean up.
if ( $exists ) {
@@ -410,7 +410,7 @@ class Tests_Admin_includesPlugin extends WP_UnitTestCase {
rmdir( WPMU_PLUGIN_DIR );
}
$this->assertEquals( array(), get_mu_plugins() );
$this->assertSame( array(), get_mu_plugins() );
// Clean up.
if ( $exists ) {
@@ -432,7 +432,7 @@ class Tests_Admin_includesPlugin extends WP_UnitTestCase {
}
$this->_create_plugin( '<?php\n//Silence is golden.', 'index.php', WPMU_PLUGIN_DIR );
$this->assertEquals( array(), get_mu_plugins() );
$this->assertSame( array(), get_mu_plugins() );
// Clean up.
unlink( WPMU_PLUGIN_DIR . '/index.php' );
@@ -457,7 +457,7 @@ class Tests_Admin_includesPlugin extends WP_UnitTestCase {
$this->_create_plugin( '<?php\n//Silence is not golden.', 'index.php', WPMU_PLUGIN_DIR );
$found = get_mu_plugins();
$this->assertEquals( array( 'index.php' ), array_keys( $found ) );
$this->assertSame( array( 'index.php' ), array_keys( $found ) );
// Clean up.
unlink( WPMU_PLUGIN_DIR . '/index.php' );
@@ -483,7 +483,7 @@ class Tests_Admin_includesPlugin extends WP_UnitTestCase {
$this->_create_plugin( '<?php\n//Test', 'foo.php', WPMU_PLUGIN_DIR );
$this->_create_plugin( '<?php\n//Test 2', 'bar.txt', WPMU_PLUGIN_DIR );
$found = get_mu_plugins();
$this->assertEquals( array( 'foo.php' ), array_keys( $found ) );
$this->assertSame( array( 'foo.php' ), array_keys( $found ) );
// Clean up.
unlink( WPMU_PLUGIN_DIR . '/foo.php' );
@@ -501,7 +501,7 @@ class Tests_Admin_includesPlugin extends WP_UnitTestCase {
public function test__sort_uname_callback() {
$this->assertLessThan( 0, _sort_uname_callback( array( 'Name' => 'a' ), array( 'Name' => 'b' ) ) );
$this->assertGreaterThan( 0, _sort_uname_callback( array( 'Name' => 'c' ), array( 'Name' => 'b' ) ) );
$this->assertEquals( 0, _sort_uname_callback( array( 'Name' => 'a' ), array( 'Name' => 'a' ) ) );
$this->assertSame( 0, _sort_uname_callback( array( 'Name' => 'a' ), array( 'Name' => 'a' ) ) );
}
/**
@@ -510,7 +510,7 @@ class Tests_Admin_includesPlugin extends WP_UnitTestCase {
public function test_get_dropins_empty() {
$this->_back_up_drop_ins();
$this->assertEquals( array(), get_dropins() );
$this->assertSame( array(), get_dropins() );
// Clean up.
$this->_restore_drop_ins();
@@ -526,7 +526,7 @@ class Tests_Admin_includesPlugin extends WP_UnitTestCase {
$p2 = $this->_create_plugin( "<?php\n//Test", 'not-a-dropin.php', WP_CONTENT_DIR );
$dropins = get_dropins();
$this->assertEquals( array( 'advanced-cache.php' ), array_keys( $dropins ) );
$this->assertSame( array( 'advanced-cache.php' ), array_keys( $dropins ) );
unlink( $p1[1] );
unlink( $p2[1] );
@@ -590,7 +590,7 @@ class Tests_Admin_includesPlugin extends WP_UnitTestCase {
* @covers ::validate_active_plugins
*/
public function test_validate_active_plugins_empty() {
$this->assertEquals( array(), validate_active_plugins() );
$this->assertSame( array(), validate_active_plugins() );
}
/**
+34 -34
View File
@@ -37,8 +37,8 @@ class Tests_Admin_Includes_Post extends WP_UnitTestCase {
$_results = _wp_translate_postdata( false, $_post_data );
$this->assertNotWPError( $_results );
$this->assertEquals( $_post_data['post_author'], $_results['post_author'] );
$this->assertEquals( 'draft', $_results['post_status'] );
$this->assertSame( $_post_data['post_author'], $_results['post_author'] );
$this->assertSame( 'draft', $_results['post_status'] );
// Submit post for approval.
$_post_data = array();
@@ -48,8 +48,8 @@ class Tests_Admin_Includes_Post extends WP_UnitTestCase {
$_results = _wp_translate_postdata( false, $_post_data );
$this->assertNotWPError( $_results );
$this->assertEquals( $_post_data['post_author'], $_results['post_author'] );
$this->assertEquals( 'pending', $_results['post_status'] );
$this->assertSame( $_post_data['post_author'], $_results['post_author'] );
$this->assertSame( 'pending', $_results['post_status'] );
// Create new draft post for another user.
$_post_data = array();
@@ -59,8 +59,8 @@ class Tests_Admin_Includes_Post extends WP_UnitTestCase {
$_results = _wp_translate_postdata( false, $_post_data );
$this->assertInstanceOf( 'WP_Error', $_results );
$this->assertEquals( 'edit_others_posts', $_results->get_error_code() );
$this->assertEquals( 'Sorry, you are not allowed to create posts as this user.', $_results->get_error_message() );
$this->assertSame( 'edit_others_posts', $_results->get_error_code() );
$this->assertSame( 'Sorry, you are not allowed to create posts as this user.', $_results->get_error_message() );
// Edit draft post for another user.
$_post_data = array();
@@ -72,8 +72,8 @@ class Tests_Admin_Includes_Post extends WP_UnitTestCase {
$_results = _wp_translate_postdata( true, $_post_data );
$this->assertInstanceOf( 'WP_Error', $_results );
$this->assertEquals( 'edit_others_posts', $_results->get_error_code() );
$this->assertEquals( 'Sorry, you are not allowed to edit posts as this user.', $_results->get_error_message() );
$this->assertSame( 'edit_others_posts', $_results->get_error_code() );
$this->assertSame( 'Sorry, you are not allowed to edit posts as this user.', $_results->get_error_message() );
}
function test__wp_translate_postdata_cap_checks_editor() {
@@ -87,8 +87,8 @@ class Tests_Admin_Includes_Post extends WP_UnitTestCase {
$_results = _wp_translate_postdata( false, $_post_data );
$this->assertNotWPError( $_results );
$this->assertEquals( $_post_data['post_author'], $_results['post_author'] );
$this->assertEquals( 'draft', $_results['post_status'] );
$this->assertSame( $_post_data['post_author'], $_results['post_author'] );
$this->assertSame( 'draft', $_results['post_status'] );
// Publish post.
$_post_data = array();
@@ -98,8 +98,8 @@ class Tests_Admin_Includes_Post extends WP_UnitTestCase {
$_results = _wp_translate_postdata( false, $_post_data );
$this->assertNotWPError( $_results );
$this->assertEquals( $_post_data['post_author'], $_results['post_author'] );
$this->assertEquals( 'publish', $_results['post_status'] );
$this->assertSame( $_post_data['post_author'], $_results['post_author'] );
$this->assertSame( 'publish', $_results['post_status'] );
// Create new draft post for another user.
$_post_data = array();
@@ -109,8 +109,8 @@ class Tests_Admin_Includes_Post extends WP_UnitTestCase {
$_results = _wp_translate_postdata( false, $_post_data );
$this->assertNotWPError( $_results );
$this->assertEquals( $_post_data['post_author'], $_results['post_author'] );
$this->assertEquals( 'draft', $_results['post_status'] );
$this->assertSame( $_post_data['post_author'], $_results['post_author'] );
$this->assertSame( 'draft', $_results['post_status'] );
// Edit draft post for another user.
$_post_data = array();
@@ -122,8 +122,8 @@ class Tests_Admin_Includes_Post extends WP_UnitTestCase {
$_results = _wp_translate_postdata( true, $_post_data );
$this->assertNotWPError( $_results );
$this->assertEquals( $_post_data['post_author'], $_results['post_author'] );
$this->assertEquals( 'draft', $_results['post_status'] );
$this->assertSame( $_post_data['post_author'], $_results['post_author'] );
$this->assertSame( 'draft', $_results['post_status'] );
}
/**
@@ -134,7 +134,7 @@ class Tests_Admin_Includes_Post extends WP_UnitTestCase {
function test_edit_post_auto_draft() {
wp_set_current_user( self::$editor_id );
$post = self::factory()->post->create_and_get( array( 'post_status' => 'auto-draft' ) );
$this->assertEquals( 'auto-draft', $post->post_status );
$this->assertSame( 'auto-draft', $post->post_status );
$post_data = array(
'post_title' => 'Post title',
'content' => 'Post content',
@@ -142,7 +142,7 @@ class Tests_Admin_Includes_Post extends WP_UnitTestCase {
'post_ID' => $post->ID,
);
edit_post( $post_data );
$this->assertEquals( 'draft', get_post( $post->ID )->post_status );
$this->assertSame( 'draft', get_post( $post->ID )->post_status );
}
/**
@@ -252,10 +252,10 @@ class Tests_Admin_Includes_Post extends WP_UnitTestCase {
$post = get_post( $post2 );
// Check that the first post's values don't stomp the second post.
$this->assertEquals( 'draft', $post->post_status );
$this->assertSame( 'draft', $post->post_status );
$this->assertEquals( self::$author_ids[1], $post->post_author );
$this->assertEquals( 'closed', $post->comment_status );
$this->assertEquals( 'closed', $post->ping_status );
$this->assertSame( 'closed', $post->comment_status );
$this->assertSame( 'closed', $post->ping_status );
}
/**
@@ -314,7 +314,7 @@ class Tests_Admin_Includes_Post extends WP_UnitTestCase {
public function check_post_format( $post_id ) {
if ( self::$post_id === $post_id ) {
$this->assertEquals( 'aside', get_post_format( $post_id ) );
$this->assertSame( 'aside', get_post_format( $post_id ) );
}
}
@@ -538,7 +538,7 @@ class Tests_Admin_Includes_Post extends WP_UnitTestCase {
);
$found = get_sample_permalink( $p );
$this->assertEquals( '2015-2', $found[1] );
$this->assertSame( '2015-2', $found[1] );
}
/**
@@ -554,7 +554,7 @@ class Tests_Admin_Includes_Post extends WP_UnitTestCase {
);
$found = get_sample_permalink( $p );
$this->assertEquals( '2015', $found[1] );
$this->assertSame( '2015', $found[1] );
}
/**
@@ -570,7 +570,7 @@ class Tests_Admin_Includes_Post extends WP_UnitTestCase {
);
$found = get_sample_permalink( $p );
$this->assertEquals( '11-2', $found[1] );
$this->assertSame( '11-2', $found[1] );
}
/**
@@ -586,7 +586,7 @@ class Tests_Admin_Includes_Post extends WP_UnitTestCase {
);
$found = get_sample_permalink( $p );
$this->assertEquals( '13', $found[1] );
$this->assertSame( '13', $found[1] );
}
/**
@@ -602,7 +602,7 @@ class Tests_Admin_Includes_Post extends WP_UnitTestCase {
);
$found = get_sample_permalink( $p );
$this->assertEquals( '30-2', $found[1] );
$this->assertSame( '30-2', $found[1] );
}
/**
@@ -624,7 +624,7 @@ class Tests_Admin_Includes_Post extends WP_UnitTestCase {
);
$found = get_sample_permalink( $p );
$this->assertEquals( '30-3', $found[1] );
$this->assertSame( '30-3', $found[1] );
}
/**
@@ -640,7 +640,7 @@ class Tests_Admin_Includes_Post extends WP_UnitTestCase {
);
$found = get_sample_permalink( $p );
$this->assertEquals( '32', $found[1] );
$this->assertSame( '32', $found[1] );
}
/**
@@ -656,7 +656,7 @@ class Tests_Admin_Includes_Post extends WP_UnitTestCase {
);
$found = get_sample_permalink( $p );
$this->assertEquals( '30', $found[1] );
$this->assertSame( '30', $found[1] );
}
/**
@@ -825,8 +825,8 @@ class Tests_Admin_Includes_Post extends WP_UnitTestCase {
function test_get_block_editor_server_block_settings() {
$name = 'core/test';
$settings = array(
'category' => 'common',
'icon' => 'text',
'category' => 'common',
'render_callback' => 'foo',
);
@@ -837,12 +837,12 @@ class Tests_Admin_Includes_Post extends WP_UnitTestCase {
unregister_block_type( $name );
$this->assertArrayHasKey( $name, $blocks );
$this->assertEquals(
$this->assertSame(
array(
'title' => '',
'description' => '',
'category' => 'common',
'icon' => 'text',
'category' => 'common',
'keywords' => array(),
'usesContext' => array(),
'styles' => array(),
@@ -865,7 +865,7 @@ class Tests_Admin_Includes_Post extends WP_UnitTestCase {
wp_set_current_user( self::$admin_id );
$this->assertNotFalse( add_meta( $p ) );
$this->assertEquals( '', get_post_meta( $p, 'testkey', true ) );
$this->assertSame( '', get_post_meta( $p, 'testkey', true ) );
}
/**
+17 -17
View File
@@ -110,7 +110,7 @@ class Tests_Admin_Includes_Schema extends WP_UnitTestCase {
$wpdb->options = $orig_options;
$this->assertEquals( $expected, $results );
$this->assertSame( $expected, $results );
}
public function data_populate_options() {
@@ -119,8 +119,8 @@ class Tests_Admin_Includes_Schema extends WP_UnitTestCase {
array(),
array(
// Random options to check.
'posts_per_rss' => 10,
'rss_use_excerpt' => 0,
'posts_per_rss' => '10',
'rss_use_excerpt' => '0',
'mailserver_url' => 'mail.example.com',
'mailserver_login' => 'login@example.com',
'mailserver_pass' => 'password',
@@ -128,13 +128,13 @@ class Tests_Admin_Includes_Schema extends WP_UnitTestCase {
),
array(
array(
'posts_per_rss' => 7,
'rss_use_excerpt' => 1,
'posts_per_rss' => '7',
'rss_use_excerpt' => '1',
),
array(
// Random options to check.
'posts_per_rss' => 7,
'rss_use_excerpt' => 1,
'posts_per_rss' => '7',
'rss_use_excerpt' => '1',
'mailserver_url' => 'mail.example.com',
'mailserver_login' => 'login@example.com',
'mailserver_pass' => 'password',
@@ -147,8 +147,8 @@ class Tests_Admin_Includes_Schema extends WP_UnitTestCase {
array(
// Random options to check.
'custom_option' => '1',
'posts_per_rss' => 10,
'rss_use_excerpt' => 0,
'posts_per_rss' => '10',
'rss_use_excerpt' => '0',
'mailserver_url' => 'mail.example.com',
'mailserver_login' => 'login@example.com',
'mailserver_pass' => 'password',
@@ -200,7 +200,7 @@ class Tests_Admin_Includes_Schema extends WP_UnitTestCase {
$wpdb->blogmeta = $orig_blogmeta;
$this->assertEquals( $expected, $results );
$this->assertSame( $expected, $results );
}
public function data_populate_site_meta() {
@@ -248,7 +248,7 @@ class Tests_Admin_Includes_Schema extends WP_UnitTestCase {
$wpdb->sitemeta = $orig_sitemeta;
$this->assertEquals( $expected, $results );
$this->assertSame( $expected, $results );
}
public function data_populate_network_meta() {
@@ -258,8 +258,8 @@ class Tests_Admin_Includes_Schema extends WP_UnitTestCase {
array(
// Random meta to check.
'registration' => 'none',
'blog_upload_space' => 100,
'fileupload_maxk' => 1500,
'blog_upload_space' => '100',
'fileupload_maxk' => '1500',
),
),
array(
@@ -271,8 +271,8 @@ class Tests_Admin_Includes_Schema extends WP_UnitTestCase {
// Random meta to check.
'site_name' => 'My Great Network',
'registration' => 'none',
'blog_upload_space' => 100,
'fileupload_maxk' => 1500,
'blog_upload_space' => '100',
'fileupload_maxk' => '1500',
'WPLANG' => 'fr_FR',
),
),
@@ -284,8 +284,8 @@ class Tests_Admin_Includes_Schema extends WP_UnitTestCase {
// Random meta to check.
'custom_meta' => '1',
'registration' => 'none',
'blog_upload_space' => 100,
'fileupload_maxk' => 1500,
'blog_upload_space' => '100',
'fileupload_maxk' => '1500',
),
),
);
+38 -38
View File
@@ -203,18 +203,18 @@ class Tests_Admin_includesScreen extends WP_UnitTestCase {
$GLOBALS['hook_suffix'] = $hook['path'];
set_current_screen();
$this->assertEquals( $screen->id, $current_screen->id, $hook_name );
$this->assertEquals( $screen->base, $current_screen->base, $hook_name );
$this->assertSame( $screen->id, $current_screen->id, $hook_name );
$this->assertSame( $screen->base, $current_screen->base, $hook_name );
if ( isset( $screen->action ) ) {
$this->assertEquals( $screen->action, $current_screen->action, $hook_name );
$this->assertSame( $screen->action, $current_screen->action, $hook_name );
}
if ( isset( $screen->post_type ) ) {
$this->assertEquals( $screen->post_type, $current_screen->post_type, $hook_name );
$this->assertSame( $screen->post_type, $current_screen->post_type, $hook_name );
} else {
$this->assertEmpty( $current_screen->post_type, $hook_name );
}
if ( isset( $screen->taxonomy ) ) {
$this->assertEquals( $screen->taxonomy, $current_screen->taxonomy, $hook_name );
$this->assertSame( $screen->taxonomy, $current_screen->taxonomy, $hook_name );
}
$this->assertTrue( $current_screen->in_admin() );
@@ -237,48 +237,48 @@ class Tests_Admin_includesScreen extends WP_UnitTestCase {
function test_post_type_as_hookname() {
$screen = convert_to_screen( 'page' );
$this->assertEquals( $screen->post_type, 'page' );
$this->assertEquals( $screen->base, 'post' );
$this->assertEquals( $screen->id, 'page' );
$this->assertSame( $screen->post_type, 'page' );
$this->assertSame( $screen->base, 'post' );
$this->assertSame( $screen->id, 'page' );
$this->assertTrue( $screen->is_block_editor );
}
function test_post_type_with_special_suffix_as_hookname() {
register_post_type( 'value-add' );
$screen = convert_to_screen( 'value-add' ); // The '-add' part is key.
$this->assertEquals( $screen->post_type, 'value-add' );
$this->assertEquals( $screen->base, 'post' );
$this->assertEquals( $screen->id, 'value-add' );
$this->assertSame( $screen->post_type, 'value-add' );
$this->assertSame( $screen->base, 'post' );
$this->assertSame( $screen->id, 'value-add' );
$this->assertFalse( $screen->is_block_editor ); // Post types do not support `show_in_rest` by default.
$screen = convert_to_screen( 'edit-value-add' ); // The '-add' part is key.
$this->assertEquals( $screen->post_type, 'value-add' );
$this->assertEquals( $screen->base, 'edit' );
$this->assertEquals( $screen->id, 'edit-value-add' );
$this->assertSame( $screen->post_type, 'value-add' );
$this->assertSame( $screen->base, 'edit' );
$this->assertSame( $screen->id, 'edit-value-add' );
$this->assertFalse( $screen->is_block_editor ); // Post types do not support `show_in_rest` by default.
}
function test_taxonomy_with_special_suffix_as_hookname() {
register_taxonomy( 'old-or-new', 'post' );
$screen = convert_to_screen( 'edit-old-or-new' ); // The '-new' part is key.
$this->assertEquals( $screen->taxonomy, 'old-or-new' );
$this->assertEquals( $screen->base, 'edit-tags' );
$this->assertEquals( $screen->id, 'edit-old-or-new' );
$this->assertSame( $screen->taxonomy, 'old-or-new' );
$this->assertSame( $screen->base, 'edit-tags' );
$this->assertSame( $screen->id, 'edit-old-or-new' );
$this->assertFalse( $screen->is_block_editor );
}
function test_post_type_with_edit_prefix() {
register_post_type( 'edit-some-thing' );
$screen = convert_to_screen( 'edit-some-thing' );
$this->assertEquals( $screen->post_type, 'edit-some-thing' );
$this->assertEquals( $screen->base, 'post' );
$this->assertEquals( $screen->id, 'edit-some-thing' );
$this->assertSame( $screen->post_type, 'edit-some-thing' );
$this->assertSame( $screen->base, 'post' );
$this->assertSame( $screen->id, 'edit-some-thing' );
$this->assertFalse( $screen->is_block_editor ); // Post types do not support `show_in_rest` by default.
$screen = convert_to_screen( 'edit-edit-some-thing' );
$this->assertEquals( $screen->post_type, 'edit-some-thing' );
$this->assertEquals( $screen->base, 'edit' );
$this->assertEquals( $screen->id, 'edit-edit-some-thing' );
$this->assertSame( $screen->post_type, 'edit-some-thing' );
$this->assertSame( $screen->base, 'edit' );
$this->assertSame( $screen->id, 'edit-edit-some-thing' );
$this->assertFalse( $screen->is_block_editor ); // Post types do not support `show_in_rest` by default.
}
@@ -288,36 +288,36 @@ class Tests_Admin_includesScreen extends WP_UnitTestCase {
// Sorry, core wins here.
$screen = convert_to_screen( 'edit-comments' );
$this->assertEquals( $screen->base, 'edit-comments' );
$this->assertSame( $screen->base, 'edit-comments' );
// The post type wins here. convert_to_screen( $post_type ) is only relevant for meta boxes anyway.
$screen = convert_to_screen( 'comments' );
$this->assertEquals( $screen->base, 'post' );
$this->assertSame( $screen->base, 'post' );
// Core wins.
$screen = convert_to_screen( 'edit-tags' );
$this->assertEquals( $screen->base, 'edit-tags' );
$this->assertSame( $screen->base, 'edit-tags' );
$screen = convert_to_screen( 'tags' );
$this->assertEquals( $screen->base, 'post' );
$this->assertSame( $screen->base, 'post' );
}
function test_help_tabs() {
$tab = __FUNCTION__;
$tab_args = array(
'id' => $tab,
'title' => 'Help!',
'id' => $tab,
'content' => 'Some content',
'callback' => false,
);
$screen = get_current_screen();
$screen->add_help_tab( $tab_args );
$this->assertEquals(
$this->assertSame(
$screen->get_help_tab( $tab ),
array(
'id' => $tab,
'title' => 'Help!',
'id' => $tab,
'content' => 'Some content',
'callback' => false,
'priority' => 10,
@@ -331,7 +331,7 @@ class Tests_Admin_includesScreen extends WP_UnitTestCase {
$this->assertNull( $screen->get_help_tab( $tab ) );
$screen->remove_help_tabs();
$this->assertEquals( $screen->get_help_tabs(), array() );
$this->assertSame( $screen->get_help_tabs(), array() );
}
/**
@@ -380,18 +380,18 @@ class Tests_Admin_includesScreen extends WP_UnitTestCase {
$this->assertequals( $screen->get_help_tab( $tab_1 ), $tab_1_args );
$screen->add_help_tab( $tab_2_args );
$this->assertEquals( $screen->get_help_tab( $tab_2 ), $tab_2_args );
$this->assertSame( $screen->get_help_tab( $tab_2 ), $tab_2_args );
$screen->add_help_tab( $tab_3_args );
$this->assertEquals( $screen->get_help_tab( $tab_3 ), $tab_3_args );
$this->assertSame( $screen->get_help_tab( $tab_3 ), $tab_3_args );
$screen->add_help_tab( $tab_4_args );
// Priority is added with the default for future calls.
$tab_4_args['priority'] = 10;
$this->assertEquals( $screen->get_help_tab( $tab_4 ), $tab_4_args );
$this->assertSame( $screen->get_help_tab( $tab_4 ), $tab_4_args );
$tabs = $screen->get_help_tabs();
$this->assertEquals( 4, count( $tabs ) );
$this->assertSame( 4, count( $tabs ) );
$this->assertArrayHasKey( $tab_1, $tabs );
$this->assertArrayHasKey( $tab_2, $tabs );
$this->assertArrayHasKey( $tab_3, $tabs );
@@ -426,7 +426,7 @@ class Tests_Admin_includesScreen extends WP_UnitTestCase {
$this->assertSame( 0, count( $screen->get_help_tabs() ) );
$screen->remove_help_tabs();
$this->assertEquals( array(), $screen->get_help_tabs() );
$this->assertSame( array(), $screen->get_help_tabs() );
}
/**
@@ -443,7 +443,7 @@ class Tests_Admin_includesScreen extends WP_UnitTestCase {
$screen = get_current_screen();
$screen->add_option( $option, $option_args );
$this->assertEquals( $screen->get_option( $option ), $option_args );
$this->assertSame( $screen->get_option( $option ), $option_args );
$options = $screen->get_options();
$this->assertArrayHasKey( $option, $options );
@@ -452,7 +452,7 @@ class Tests_Admin_includesScreen extends WP_UnitTestCase {
$this->assertNull( $screen->get_option( $option ) );
$screen->remove_options();
$this->assertEquals( $screen->get_options(), array() );
$this->assertSame( $screen->get_options(), array() );
}
function test_in_admin() {
+2 -2
View File
@@ -95,7 +95,7 @@ class Tests_Admin_includesTheme extends WP_UnitTestCase {
),
get_page_templates( null, 'post' )
);
$this->assertEquals( array(), get_page_templates( null, 'bar' ) );
$this->assertSame( array(), get_page_templates( null, 'bar' ) );
}
/**
@@ -166,7 +166,7 @@ class Tests_Admin_includesTheme extends WP_UnitTestCase {
get_page_templates()
);
$this->assertEquals( array(), get_page_templates( null, 'bar' ) );
$this->assertSame( array(), get_page_templates( null, 'bar' ) );
}
/**