Coding Standards: Fix the remaining issues in /tests.

All PHP files in `/tests` now conform to the PHP coding standards, or have exceptions appropriately marked.

Travis now also runs `phpcs` on the `/tests` directory, any future changes to these files must conform entirely to the WordPress PHP coding standards. 🎉

See #47632.



git-svn-id: https://develop.svn.wordpress.org/trunk@45607 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Gary Pendergast
2019-07-08 00:55:20 +00:00
parent 431bc58a48
commit c6c78490e2
91 changed files with 435 additions and 320 deletions
+4 -4
View File
@@ -102,8 +102,8 @@ class Tests_Admin_includesPlugin extends WP_UnitTestCase {
$plugin = $this->_create_plugin( null, 'list_files_test_plugin.php', $plugin_dir );
$sub_dir = trailingslashit( dirname( $plugin[1] ) ) . 'subdir';
@mkdir( $sub_dir );
@file_put_contents( $sub_dir . '/subfile.php', '<?php // Silence.' );
mkdir( $sub_dir );
file_put_contents( $sub_dir . '/subfile.php', '<?php // Silence.' );
$plugin_files = get_plugin_files( plugin_basename( $plugin[1] ) );
$expected = array(
@@ -415,7 +415,7 @@ class Tests_Admin_includesPlugin extends WP_UnitTestCase {
}
}
@closedir( $mu_plugins );
closedir( $mu_plugins );
foreach ( $files_to_move as $file_to_move ) {
$f = rename( WPMU_PLUGIN_DIR . '/' . $file_to_move, $mu_bu_dir . '/' . $file_to_move );
@@ -442,7 +442,7 @@ class Tests_Admin_includesPlugin extends WP_UnitTestCase {
}
}
@closedir( $mu_plugins );
closedir( $mu_plugins );
foreach ( $files_to_move as $file_to_move ) {
rename( $mu_bu_dir . '/' . $file_to_move, WPMU_PLUGIN_DIR . '/' . $file_to_move );
@@ -28,6 +28,7 @@ class Tests_Admin_Includes_Schema extends WP_UnitTestCase {
$charset_collate = $wpdb->get_charset_collate();
$max_index_length = 191;
// phpcs:disable WordPress.DB.PreparedSQL.InterpolatedNotPrepared
$wpdb->query(
"
CREATE TABLE {$options} (
@@ -66,6 +67,7 @@ class Tests_Admin_Includes_Schema extends WP_UnitTestCase {
) {$charset_collate}
"
);
// phpcs:enable
}
/**
@@ -78,9 +80,11 @@ class Tests_Admin_Includes_Schema extends WP_UnitTestCase {
$blogmeta = self::$blogmeta;
$sitemeta = self::$sitemeta;
// phpcs:disable WordPress.DB.PreparedSQL.InterpolatedNotPrepared
$wpdb->query( "DROP TABLE IF EXISTS {$options}" );
$wpdb->query( "DROP TABLE IF EXISTS {$blogmeta}" );
$wpdb->query( "DROP TABLE IF EXISTS {$sitemeta}" );
// phpcs:enable
}
/**
+1 -1
View File
@@ -744,7 +744,7 @@ class Tests_AdminBar extends WP_UnitTestCase {
$nodes = $wp_admin_bar->get_nodes();
foreach ( $this->get_my_sites_network_menu_items() as $id => $cap ) {
if ( in_array( $cap, $network_user_caps ) ) {
if ( in_array( $cap, $network_user_caps, true ) ) {
$this->assertTrue( isset( $nodes[ $id ] ), sprintf( 'Menu item %1$s must display for a user with the %2$s cap.', $id, $cap ) );
} else {
$this->assertFalse( isset( $nodes[ $id ] ), sprintf( 'Menu item %1$s must not display for a user without the %2$s cap.', $id, $cap ) );
+2 -2
View File
@@ -52,7 +52,7 @@ class Tests_Ajax_CustomizeMenus extends WP_Ajax_UnitTestCase {
*/
function test_ajax_load_available_items_cap_check( $role, $expected_results ) {
if ( 'administrator' != $role ) {
if ( 'administrator' !== $role ) {
// If we're not an admin, we should get a wp_die(-1).
$this->setExpectedException( 'WPAjaxDieStopException' );
}
@@ -441,7 +441,7 @@ class Tests_Ajax_CustomizeMenus extends WP_Ajax_UnitTestCase {
*/
function test_ajax_search_available_items_caps_check( $role, $expected_results ) {
if ( 'administrator' != $role ) {
if ( 'administrator' !== $role ) {
// If we're not an admin, we should get a wp_die(-1).
$this->setExpectedException( 'WPAjaxDieStopException' );
}
+4 -4
View File
@@ -94,11 +94,11 @@ class Tests_Ajax_DeleteComment extends WP_Ajax_UnitTestCase {
$this->assertLessThanOrEqual( time(), (int) $xml->response[0]->comment[0]->supplemental[0]->time[0] );
// trash, spam, delete should make the total go down
if ( in_array( $action, array( 'trash', 'spam', 'delete' ) ) ) {
if ( in_array( $action, array( 'trash', 'spam', 'delete' ), true ) ) {
$total = $_POST['_total'] - 1;
// unspam, untrash should make the total go up
} elseif ( in_array( $action, array( 'untrash', 'unspam' ) ) ) {
} elseif ( in_array( $action, array( 'untrash', 'unspam' ), true ) ) {
$total = $_POST['_total'] + 1;
}
@@ -108,7 +108,7 @@ class Tests_Ajax_DeleteComment extends WP_Ajax_UnitTestCase {
// Check for either possible total
$message = sprintf( 'returned value: %1$d $total: %2$d $recalc_total: %3$d', (int) $xml->response[0]->comment[0]->supplemental[0]->total[0], $total, $recalc_total );
$this->assertTrue( in_array( (int) $xml->response[0]->comment[0]->supplemental[0]->total[0], array( $total, $recalc_total ) ), $message );
$this->assertTrue( in_array( (int) $xml->response[0]->comment[0]->supplemental[0]->total[0], array( $total, $recalc_total ), true ), $message );
}
/**
@@ -243,7 +243,7 @@ class Tests_Ajax_DeleteComment extends WP_Ajax_UnitTestCase {
$this->_last_response = '';
// Force delete the comment
if ( 'delete' == $action ) {
if ( 'delete' === $action ) {
wp_delete_comment( $comment->comment_ID, true );
}
+2 -2
View File
@@ -89,7 +89,7 @@ class Tests_Ajax_DimComment extends WP_Ajax_UnitTestCase {
// Check the status
$current = wp_get_comment_status( $comment->comment_ID );
if ( in_array( $prev_status, array( 'unapproved', 'spam' ) ) ) {
if ( in_array( $prev_status, array( 'unapproved', 'spam' ), true ) ) {
$this->assertEquals( 'approved', $current );
} else {
$this->assertEquals( 'unapproved', $current );
@@ -103,7 +103,7 @@ class Tests_Ajax_DimComment extends WP_Ajax_UnitTestCase {
$total = $_POST['_total'] - 1;
// Check for either possible total
$this->assertTrue( in_array( (int) $xml->response[0]->comment[0]->supplemental[0]->total[0], array( $total, $recalc_total ) ) );
$this->assertTrue( in_array( (int) $xml->response[0]->comment[0]->supplemental[0]->total[0], array( $total, $recalc_total ), true ) );
}
/**
+1 -1
View File
@@ -96,7 +96,7 @@ class Tests_Ajax_EditComment extends WP_Ajax_UnitTestCase {
$comment = array_pop( $comments );
// Manually update the comment_post_ID, because wp_update_comment() will prevent it.
$wpdb->query( "UPDATE {$wpdb->comments} SET comment_post_ID=0 WHERE comment_ID={$comment->comment_ID}" );
$wpdb->update( $wpdb->comments, array( 'comment_post_ID' => 0 ), array( 'comment_ID' => $comment->comment_ID ) );
clean_comment_cache( $comment->comment_ID );
// Set up a default request
+1 -1
View File
@@ -85,7 +85,7 @@ class Tests_Ajax_Response extends WP_UnitTestCase {
$headers = xdebug_get_headers();
ob_end_clean();
$this->assertTrue( in_array( 'Content-Type: text/xml; charset=' . get_option( 'blog_charset' ), $headers ) );
$this->assertTrue( in_array( 'Content-Type: text/xml; charset=' . get_option( 'blog_charset' ), $headers, true ) );
}
/**
+1 -1
View File
@@ -22,7 +22,7 @@ class Tests_Basic extends WP_UnitTestCase {
$package_json = json_decode( $package_json, true );
list( $version ) = explode( '-', $GLOBALS['wp_version'] );
// package.json uses x.y.z, so fill cleaned $wp_version for .0 releases
if ( 1 == substr_count( $version, '.' ) ) {
if ( 1 === substr_count( $version, '.' ) ) {
$version .= '.0';
}
$this->assertEquals( $version, $package_json['version'], "package.json's version needs to be updated to $version." );
+3 -3
View File
@@ -672,7 +672,7 @@ class Tests_Comment extends WP_UnitTestCase {
// Check to see if a notification email was sent to the moderator `admin@example.org`.
if ( isset( $GLOBALS['phpmailer']->mock_sent )
&& ! empty( $GLOBALS['phpmailer']->mock_sent )
&& WP_TESTS_EMAIL == $GLOBALS['phpmailer']->mock_sent[0]['to'][0][0]
&& WP_TESTS_EMAIL === $GLOBALS['phpmailer']->mock_sent[0]['to'][0][0]
) {
$email_sent_when_comment_added = true;
reset_phpmailer_instance();
@@ -700,7 +700,7 @@ class Tests_Comment extends WP_UnitTestCase {
// Check to see if a notification email was sent to the post author `test@test.com`.
if ( isset( $GLOBALS['phpmailer']->mock_sent )
&& ! empty( $GLOBALS['phpmailer']->mock_sent )
&& 'test@test.com' == $GLOBALS['phpmailer']->mock_sent[0]['to'][0][0]
&& 'test@test.com' === $GLOBALS['phpmailer']->mock_sent[0]['to'][0][0]
) {
$email_sent_when_comment_approved = true;
} else {
@@ -722,7 +722,7 @@ class Tests_Comment extends WP_UnitTestCase {
// Check to see if a notification email was sent to the post author `test@test.com`.
if ( isset( $GLOBALS['phpmailer']->mock_sent ) &&
! empty( $GLOBALS['phpmailer']->mock_sent ) &&
'test@test.com' == $GLOBALS['phpmailer']->mock_sent[0]['to'][0][0] ) {
'test@test.com' === $GLOBALS['phpmailer']->mock_sent[0]['to'][0][0] ) {
$email_sent_when_comment_added = true;
reset_phpmailer_instance();
} else {
+2 -2
View File
@@ -54,10 +54,10 @@ class Comment_Callback_Test {
}
public function comment( $comment, $args, $depth ) {
if ( 1 == $depth ) {
if ( 1 === $depth ) {
$this->test_walker->assertTrue( $this->walker->has_children );
$this->test_walker->assertTrue( $args['has_children'] ); // Back compat
} elseif ( 2 == $depth ) {
} elseif ( 2 === $depth ) {
$this->test_walker->assertFalse( $this->walker->has_children );
$this->test_walker->assertFalse( $args['has_children'] ); // Back compat
}
+4 -4
View File
@@ -125,10 +125,10 @@ EOT;
'string',
$heredoc,
// object data
new classA(),
// undefined data
new ClassA(),
// phpcs:ignore WordPress.PHP.NoSilencedErrors.Discouraged -- intentionally undefined data
@$undefined_var,
// unset data
// phpcs:ignore WordPress.PHP.NoSilencedErrors.Discouraged -- intentionally unset data
@$unset_var,
);
$outputs = array(
@@ -315,7 +315,7 @@ EOT;
}
/* used in test_mb_substr_phpcore */
class classA {
class ClassA {
public function __toString() {
return 'Class A object';
}
+1 -1
View File
@@ -2668,7 +2668,7 @@ class Tests_WP_Customize_Manager extends WP_UnitTestCase {
*/
function filter_customize_dynamic_setting_args_for_test_dynamic_settings( $setting_args, $setting_id ) {
$this->assertInternalType( 'string', $setting_id );
if ( in_array( $setting_id, array( 'foo', 'bar' ) ) ) {
if ( in_array( $setting_id, array( 'foo', 'bar' ), true ) ) {
$setting_args = array( 'default' => "dynamic_{$setting_id}_default" );
}
return $setting_args;
@@ -386,7 +386,7 @@ class Test_WP_Customize_Nav_Menu_Item_Setting extends WP_UnitTestCase {
$menu_items = wp_get_nav_menu_items( $secondary_menu_id );
$db_ids = wp_list_pluck( $menu_items, 'db_id' );
$this->assertContains( $item_id, $db_ids );
$i = array_search( $item_id, $db_ids );
$i = array_search( $item_id, $db_ids, true );
$updated_item = $menu_items[ $i ];
$post_value['post_status'] = $post_value['status'];
unset( $post_value['status'] );
@@ -676,7 +676,7 @@ class Test_WP_Customize_Nav_Menu_Item_Setting extends WP_UnitTestCase {
$menu_items = wp_get_nav_menu_items( $secondary_menu_id );
$db_ids = wp_list_pluck( $menu_items, 'db_id' );
$this->assertContains( $item_id, $db_ids );
$i = array_search( $item_id, $db_ids );
$i = array_search( $item_id, $db_ids, true );
$updated_item = $menu_items[ $i ];
$post_value['post_status'] = $post_value['status'];
unset( $post_value['status'] );
@@ -224,7 +224,7 @@ class Test_WP_Customize_Nav_Menu_Setting extends WP_UnitTestCase {
$menus = wp_get_nav_menus();
$menus_ids = wp_list_pluck( $menus, 'term_id' );
$i = array_search( $menu_id, $menus_ids );
$i = array_search( $menu_id, $menus_ids, true );
$this->assertInternalType( 'int', $i, 'Update-previewed menu does not appear in wp_get_nav_menus()' );
$filtered_menu = $menus[ $i ];
$this->assertEquals( 'Name 2 \\o/', $filtered_menu->name );
@@ -269,7 +269,7 @@ class Test_WP_Customize_Nav_Menu_Setting extends WP_UnitTestCase {
$menus = wp_get_nav_menus();
$menus_ids = wp_list_pluck( $menus, 'term_id' );
$i = array_search( $menu_id, $menus_ids );
$i = array_search( $menu_id, $menus_ids, true );
$this->assertInternalType( 'int', $i, 'Insert-previewed menu was not injected into wp_get_nav_menus()' );
$filtered_menu = $menus[ $i ];
$this->assertEquals( 'New Menu Name 1 \\o/', $filtered_menu->name );
+1 -1
View File
@@ -1014,7 +1014,7 @@ class Tests_WP_Date_Query extends WP_UnitTestCase {
// Invalid values.
$days_of_year = array( -1, 0, 367 );
foreach ( $days_of_year as $day_of_year ) {
$this->assertFalse( @$this->q->validate_date_values( array( 'dayofyear' => $day_of_year ) ) );
$this->assertFalse( $this->q->validate_date_values( array( 'dayofyear' => $day_of_year ) ) );
}
}
+21 -10
View File
@@ -23,7 +23,7 @@ class Tests_DB extends WP_UnitTestCase {
public static function setUpBeforeClass() {
parent::setUpBeforeClass();
self::$_wpdb = new wpdb_exposed_methods_for_testing();
self::$_wpdb = new WpdbExposedMethodsForTesting();
}
/**
@@ -346,7 +346,7 @@ class Tests_DB extends WP_UnitTestCase {
}
public function filter_allowed_incompatible_sql_mode( $modes ) {
$pos = array_search( 'ONLY_FULL_GROUP_BY', $modes );
$pos = array_search( 'ONLY_FULL_GROUP_BY', $modes, true );
$this->assertGreaterThanOrEqual( 0, $pos );
if ( false === $pos ) {
@@ -365,6 +365,7 @@ class Tests_DB extends WP_UnitTestCase {
global $wpdb;
$id = 0;
// This, obviously, is an incorrect prepare.
// phpcs:ignore WordPress.DB.PreparedSQL.InterpolatedNotPrepared
$prepared = $wpdb->prepare( "SELECT * FROM $wpdb->users WHERE id = $id", $id );
$this->assertEquals( "SELECT * FROM $wpdb->users WHERE id = 0", $prepared );
}
@@ -382,9 +383,11 @@ class Tests_DB extends WP_UnitTestCase {
function test_prepare_sprintf_invalid_args() {
global $wpdb;
// phpcs:ignore WordPress.PHP.NoSilencedErrors.Discouraged
$prepared = @$wpdb->prepare( "SELECT * FROM $wpdb->users WHERE id = %d AND user_login = %s", 1, array( 'admin' ) );
$this->assertEquals( "SELECT * FROM $wpdb->users WHERE id = 1 AND user_login = ''", $prepared );
// phpcs:ignore WordPress.PHP.NoSilencedErrors.Discouraged
$prepared = @$wpdb->prepare( "SELECT * FROM $wpdb->users WHERE id = %d AND user_login = %s", array( 1 ), 'admin' );
$this->assertEquals( "SELECT * FROM $wpdb->users WHERE id = 0 AND user_login = 'admin'", $prepared );
}
@@ -402,9 +405,11 @@ class Tests_DB extends WP_UnitTestCase {
function test_prepare_vsprintf_invalid_args() {
global $wpdb;
// phpcs:ignore WordPress.PHP.NoSilencedErrors.Discouraged
$prepared = @$wpdb->prepare( "SELECT * FROM $wpdb->users WHERE id = %d AND user_login = %s", array( 1, array( 'admin' ) ) );
$this->assertEquals( "SELECT * FROM $wpdb->users WHERE id = 1 AND user_login = ''", $prepared );
// phpcs:ignore WordPress.PHP.NoSilencedErrors.Discouraged
$prepared = @$wpdb->prepare( "SELECT * FROM $wpdb->users WHERE id = %d AND user_login = %s", array( array( 1 ), 'admin' ) );
$this->assertEquals( "SELECT * FROM $wpdb->users WHERE id = 0 AND user_login = 'admin'", $prepared );
}
@@ -420,6 +425,7 @@ class Tests_DB extends WP_UnitTestCase {
// $query is the first argument to be passed to wpdb::prepare()
array_unshift( $args, $query );
// phpcs:ignore WordPress.PHP.NoSilencedErrors.Discouraged
$prepared = @call_user_func_array( array( $wpdb, 'prepare' ), $args );
$this->assertEquals( $expected, $prepared );
}
@@ -587,6 +593,7 @@ class Tests_DB extends WP_UnitTestCase {
$wpdb->last_result = $last_result;
// phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared
$result = $wpdb->get_col( $query, $column );
if ( $query ) {
@@ -1043,7 +1050,7 @@ class Tests_DB extends WP_UnitTestCase {
$expected_charset = $wpdb->get_col_charset( $wpdb->posts, 'post_content' );
}
if ( ! in_array( $expected_charset, array( 'utf8', 'utf8mb4', 'latin1' ) ) ) {
if ( ! in_array( $expected_charset, array( 'utf8', 'utf8mb4', 'latin1' ), true ) ) {
$this->markTestSkipped( 'This test only works with utf8, utf8mb4 or latin1 character sets' );
}
@@ -1116,7 +1123,7 @@ class Tests_DB extends WP_UnitTestCase {
array( '%s', '%s' )
);
$row = $wpdb->get_row( "SELECT * FROM $wpdb->postmeta WHERE meta_key='$key'" );
$row = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM $wpdb->postmeta WHERE meta_key=%s", $key ) );
$this->assertNull( $row->meta_value );
}
@@ -1139,7 +1146,7 @@ class Tests_DB extends WP_UnitTestCase {
array( '%s', '%s' )
);
$row = $wpdb->get_row( "SELECT * FROM $wpdb->postmeta WHERE meta_key='$key'" );
$row = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM $wpdb->postmeta WHERE meta_key=%s", $key ) );
$this->assertSame( $value, $row->meta_value );
@@ -1154,7 +1161,7 @@ class Tests_DB extends WP_UnitTestCase {
array( '%s', '%s' )
);
$row = $wpdb->get_row( "SELECT * FROM $wpdb->postmeta WHERE meta_key='$key'" );
$row = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM $wpdb->postmeta WHERE meta_key=%s", $key ) );
$this->assertNull( $row->meta_value );
}
@@ -1177,7 +1184,7 @@ class Tests_DB extends WP_UnitTestCase {
array( '%s', '%s' )
);
$row = $wpdb->get_row( "SELECT * FROM $wpdb->postmeta WHERE meta_key='$key'" );
$row = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM $wpdb->postmeta WHERE meta_key=%s", $key ) );
$this->assertNull( $row->meta_value );
@@ -1192,7 +1199,7 @@ class Tests_DB extends WP_UnitTestCase {
array( '%s', '%s' )
);
$row = $wpdb->get_row( "SELECT * FROM $wpdb->postmeta WHERE meta_key='$key'" );
$row = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM $wpdb->postmeta WHERE meta_key=%s", $key ) );
$this->assertSame( $value, $row->meta_value );
}
@@ -1215,7 +1222,7 @@ class Tests_DB extends WP_UnitTestCase {
array( '%s', '%s' )
);
$row = $wpdb->get_row( "SELECT * FROM $wpdb->postmeta WHERE meta_key='$key'" );
$row = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM $wpdb->postmeta WHERE meta_key=%s", $key ) );
$this->assertNull( $row->meta_value );
@@ -1228,7 +1235,7 @@ class Tests_DB extends WP_UnitTestCase {
array( '%s', '%s' )
);
$row = $wpdb->get_row( "SELECT * FROM $wpdb->postmeta WHERE meta_key='$key'" );
$row = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM $wpdb->postmeta WHERE meta_key=%s", $key ) );
$this->assertNull( $row );
}
@@ -1572,6 +1579,7 @@ class Tests_DB extends WP_UnitTestCase {
$sql = str_replace( '{ESCAPE}', $escape, $sql );
// phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared
$actual = $wpdb->prepare( $sql, $values );
$this->assertEquals( $expected, $actual );
@@ -1653,6 +1661,8 @@ class Tests_DB extends WP_UnitTestCase {
$wpdb->query( "CREATE TABLE {$wpdb->prefix}test_placeholder( a VARCHAR(100) );" );
$sql = $wpdb->prepare( "INSERT INTO {$wpdb->prefix}test_placeholder VALUES(%s)", $value );
// phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared
$wpdb->query( $sql );
$actual = $wpdb->get_var( "SELECT a FROM {$wpdb->prefix}test_placeholder" );
@@ -1667,6 +1677,7 @@ class Tests_DB extends WP_UnitTestCase {
global $wpdb;
$sql = $wpdb->prepare( ' %s %1$c ', 'foo' );
// phpcs:ignore WordPress.DB.PreparedSQL.InterpolatedNotPrepared
$sql = $wpdb->prepare( " $sql %s ", 'foo' );
$this->assertEquals( " 'foo' {$wpdb->placeholder_escape()}1\$c 'foo' ", $sql );
+1 -1
View File
@@ -27,7 +27,7 @@ class Tests_DB_Charset extends WP_UnitTestCase {
require_once( dirname( dirname( __FILE__ ) ) . '/db.php' );
self::$_wpdb = new wpdb_exposed_methods_for_testing();
self::$_wpdb = new WpdbExposedMethodsForTesting();
if ( self::$_wpdb->use_mysqli ) {
self::$server_info = mysqli_get_server_info( self::$_wpdb->dbh );
+31 -16
View File
@@ -33,18 +33,22 @@ class Tests_dbDelta extends WP_UnitTestCase {
// Forcing MyISAM, because InnoDB only started supporting FULLTEXT indexes in MySQL 5.7.
$wpdb->query(
"
CREATE TABLE {$wpdb->prefix}dbdelta_test (
id bigint(20) NOT NULL AUTO_INCREMENT,
column_1 varchar(255) NOT NULL,
column_2 text,
column_3 blob,
PRIMARY KEY (id),
KEY key_1 (column_1($this->max_index_length)),
KEY compound_key (id,column_1($this->max_index_length)),
FULLTEXT KEY fulltext_key (column_1)
) ENGINE=MyISAM
"
$wpdb->prepare(
"
CREATE TABLE {$wpdb->prefix}dbdelta_test (
id bigint(20) NOT NULL AUTO_INCREMENT,
column_1 varchar(255) NOT NULL,
column_2 text,
column_3 blob,
PRIMARY KEY (id),
KEY key_1 (column_1(%d)),
KEY compound_key (id,column_1(%d)),
FULLTEXT KEY fulltext_key (column_1)
) ENGINE=MyISAM
",
$this->max_index_length,
$this->max_index_length
)
);
parent::setUp();
@@ -299,6 +303,7 @@ class Tests_dbDelta extends WP_UnitTestCase {
protected function assertTableRowHasValue( $column, $value, $table ) {
global $wpdb;
// phpcs:ignore WordPress.DB.PreparedSQL.InterpolatedNotPrepared
$table_row = $wpdb->get_row( "select $column from {$table} where $column = '$value'" );
$expected = (object) array(
@@ -317,7 +322,8 @@ class Tests_dbDelta extends WP_UnitTestCase {
protected function assertTableHasColumn( $column, $table ) {
global $wpdb;
$table_fields = $wpdb->get_results( "DESCRIBE {$table}" );
// phpcs:ignore WordPress.DB.PreparedSQL.InterpolatedNotPrepared
$table_fields = $wpdb->get_results( "DESCRIBE $table" );
$this->assertCount( 1, wp_list_filter( $table_fields, array( 'Field' => $column ) ) );
}
@@ -333,7 +339,8 @@ class Tests_dbDelta extends WP_UnitTestCase {
protected function assertTableHasPrimaryKey( $column, $table ) {
global $wpdb;
$table_indices = $wpdb->get_results( "SHOW INDEX FROM {$table}" );
// phpcs:ignore WordPress.DB.PreparedSQL.InterpolatedNotPrepared
$table_indices = $wpdb->get_results( "SHOW INDEX FROM $table" );
$this->assertCount(
1,
@@ -358,7 +365,8 @@ class Tests_dbDelta extends WP_UnitTestCase {
global $wpdb;
$table_fields = $wpdb->get_results( "DESCRIBE {$table}" );
// phpcs:ignore WordPress.DB.PreparedSQL.InterpolatedNotPrepared
$table_fields = $wpdb->get_results( "DESCRIBE $table" );
$this->assertCount( 0, wp_list_filter( $table_fields, array( 'Field' => $column ) ) );
}
@@ -385,15 +393,18 @@ class Tests_dbDelta extends WP_UnitTestCase {
KEY a_key (a)
) ENGINE=InnoDB ROW_FORMAT=DYNAMIC";
// phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared
$wpdb->query( $create );
// phpcs:ignore WordPress.DB.PreparedSQL.InterpolatedNotPrepared
$index = $wpdb->get_row( "SHOW INDEXES FROM $table_name WHERE Key_name='a_key';" );
$actual = dbDelta( $create, false );
// phpcs:ignore WordPress.DB.PreparedSQL.InterpolatedNotPrepared
$wpdb->query( "DROP TABLE IF EXISTS $table_name;" );
if ( 191 != $index->Sub_part ) {
if ( 191 !== $index->Sub_part ) {
$this->markTestSkipped( 'This test requires the index to be truncated.' );
}
@@ -527,6 +538,7 @@ class Tests_dbDelta extends WP_UnitTestCase {
)
";
// phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared
$wpdb->query( $schema );
$updates = dbDelta( $schema, false );
@@ -556,6 +568,7 @@ class Tests_dbDelta extends WP_UnitTestCase {
) ENGINE=MyISAM;
";
// phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared
$wpdb->query( $schema );
$updates = dbDelta( $schema, false );
@@ -602,6 +615,7 @@ class Tests_dbDelta extends WP_UnitTestCase {
)
";
// phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared
$wpdb->query( $schema );
$updates = dbDelta( $schema );
@@ -998,6 +1012,7 @@ class Tests_dbDelta extends WP_UnitTestCase {
)
";
// phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared
$wpdb->query( $schema );
$schema_update = "
+2 -2
View File
@@ -13,7 +13,7 @@ class Tests_External_HTTP_Basic extends WP_UnitTestCase {
preg_match( '#Recommendations.*PHP</a> version <strong>([0-9.]*)#s', $readme, $matches );
$response = wp_remote_get( 'https://secure.php.net/supported-versions.php' );
if ( 200 != wp_remote_retrieve_response_code( $response ) ) {
if ( 200 !== wp_remote_retrieve_response_code( $response ) ) {
$this->fail( 'Could not contact PHP.net to check versions.' );
}
$php = wp_remote_retrieve_body( $response );
@@ -25,7 +25,7 @@ class Tests_External_HTTP_Basic extends WP_UnitTestCase {
preg_match( '#Recommendations.*MySQL</a> version <strong>([0-9.]*)#s', $readme, $matches );
$response = wp_remote_get( "https://dev.mysql.com/doc/relnotes/mysql/{$matches[1]}/en/" );
if ( 200 != wp_remote_retrieve_response_code( $response ) ) {
if ( 200 !== wp_remote_retrieve_response_code( $response ) ) {
$this->fail( 'Could not contact dev.MySQL.com to check versions.' );
}
$mysql = wp_remote_retrieve_body( $response );
+4 -3
View File
@@ -71,6 +71,7 @@ class Tests_Feeds_Atom extends WP_UnitTestCase {
// Nasty hack! In the future it would better to leverage do_feed( 'atom' ).
global $post;
try {
// phpcs:ignore WordPress.PHP.NoSilencedErrors.Discouraged
@require( ABSPATH . 'wp-includes/feed-atom.php' );
$out = ob_get_clean();
} catch ( Exception $e ) {
@@ -162,7 +163,7 @@ class Tests_Feeds_Atom extends WP_UnitTestCase {
// Link rel="alternate"
$link_alts = xml_find( $entries[ $key ]['child'], 'link' );
foreach ( $link_alts as $link_alt ) {
if ( 'alternate' == $link_alt['attributes']['rel'] ) {
if ( 'alternate' === $link_alt['attributes']['rel'] ) {
$this->assertEquals( get_permalink( $post ), $link_alt['attributes']['href'] );
}
}
@@ -185,7 +186,7 @@ class Tests_Feeds_Atom extends WP_UnitTestCase {
}
$categories = xml_find( $entries[ $key ]['child'], 'category' );
foreach ( $categories as $category ) {
$this->assertTrue( in_array( $category['attributes']['term'], $terms ) );
$this->assertTrue( in_array( $category['attributes']['term'], $terms, true ) );
}
unset( $terms );
@@ -198,7 +199,7 @@ class Tests_Feeds_Atom extends WP_UnitTestCase {
// Link rel="replies"
$link_replies = xml_find( $entries[ $key ]['child'], 'link' );
foreach ( $link_replies as $link_reply ) {
if ( 'replies' == $link_reply['attributes']['rel'] && 'application/atom+xml' == $link_reply['attributes']['type'] ) {
if ( 'replies' === $link_reply['attributes']['rel'] && 'application/atom+xml' === $link_reply['attributes']['type'] ) {
$this->assertEquals( get_post_comments_feed_link( $post->ID, 'atom' ), $link_reply['attributes']['href'] );
}
}
+1
View File
@@ -83,6 +83,7 @@ class Tests_Feeds_RSS2 extends WP_UnitTestCase {
// Nasty hack! In the future it would better to leverage do_feed( 'rss2' ).
global $post;
try {
// phpcs:ignore WordPress.PHP.NoSilencedErrors.Discouraged
@require( ABSPATH . 'wp-includes/feed-rss2.php' );
$out = ob_get_clean();
} catch ( Exception $e ) {
+2 -2
View File
@@ -208,7 +208,7 @@ class Tests_File extends WP_UnitTestCase {
$this->assertLessThan( 10, $time_taken, 'verify_file_signature() took longer than 10 seconds.' );
// Check to see if the system parameters prevent signature verifications.
if ( is_wp_error( $verify ) && 'signature_verification_unsupported' == $verify->get_error_code() ) {
if ( is_wp_error( $verify ) && 'signature_verification_unsupported' === $verify->get_error_code() ) {
$this->markTestSkipped( 'This system does not support Signature Verification.' );
}
@@ -228,7 +228,7 @@ class Tests_File extends WP_UnitTestCase {
$verify = verify_file_signature( $file, $expected_signature, 'WordPress' );
unlink( $file );
if ( is_wp_error( $verify ) && 'signature_verification_unsupported' == $verify->get_error_code() ) {
if ( is_wp_error( $verify ) && 'signature_verification_unsupported' === $verify->get_error_code() ) {
$this->markTestSkipped( 'This system does not support Signature Verification.' );
}
@@ -17,7 +17,7 @@ class Tests_Formatting_WPSpecialchars extends WP_UnitTestCase {
// Allowed entities should be unchanged
foreach ( $allowedentitynames as $ent ) {
if ( 'apos' == $ent ) {
if ( 'apos' === $ent ) {
// But for some reason, PHP doesn't allow &apos;
continue;
}
@@ -1576,7 +1576,7 @@ class Tests_Formatting_WPTexturize extends WP_UnitTestCase {
case '&#8216;':
return '!openq1!';
case '&#8217;':
if ( 'apostrophe' == $context ) {
if ( 'apostrophe' === $context ) {
return '!apos!';
} else {
return '!closeq1!';
@@ -2001,7 +2001,7 @@ String with a number followed by a single quote &#8216;Expendables 3&#8217; vest
case '&#8216;':
return '!q1!';
case '&#8217;':
if ( 'apostrophe' == $context ) {
if ( 'apostrophe' === $context ) {
return '!apos!';
} else {
return '!q1!';
+4 -4
View File
@@ -844,7 +844,7 @@ class Tests_Functions extends WP_UnitTestCase {
$charsets = mb_detect_order();
$old_charsets = $charsets;
if ( ! in_array( 'EUC-JP', $charsets ) ) {
if ( ! in_array( 'EUC-JP', $charsets, true ) ) {
$charsets[] = 'EUC-JP';
mb_detect_order( $charsets );
}
@@ -869,7 +869,7 @@ class Tests_Functions extends WP_UnitTestCase {
$charsets = mb_detect_order();
$old_charsets = $charsets;
if ( ! in_array( 'EUC-JP', $charsets ) ) {
if ( ! in_array( 'EUC-JP', $charsets, true ) ) {
$charsets[] = 'EUC-JP';
mb_detect_order( $charsets );
}
@@ -965,8 +965,8 @@ class Tests_Functions extends WP_UnitTestCase {
public function test_wp_ext2type() {
$extensions = wp_get_ext_types();
foreach ( $extensions as $type => $extensionList ) {
foreach ( $extensionList as $extension ) {
foreach ( $extensions as $type => $extension_list ) {
foreach ( $extension_list as $extension ) {
$this->assertEquals( $type, wp_ext2type( $extension ) );
$this->assertEquals( $type, wp_ext2type( strtoupper( $extension ) ) );
}
+1 -1
View File
@@ -135,7 +135,7 @@ class Test_Functions_Deprecated extends WP_UnitTestCase {
$key = 'file';
}
foreach ( $search as $v ) {
if ( $name == $v[ $key ] ) {
if ( $name === $v[ $key ] ) {
return $v;
}
}
+2 -2
View File
@@ -54,7 +54,7 @@ abstract class WP_HTTP_UnitTestCase extends WP_UnitTestCase {
// Disable all transports aside from this one.
foreach ( array( 'curl', 'streams', 'fsockopen' ) as $t ) {
remove_filter( "use_{$t}_transport", '__return_false' ); // Just strip them all
if ( $t != $this->transport ) {
if ( $t !== $this->transport ) {
add_filter( "use_{$t}_transport", '__return_false' ); // and add it back if need be..
}
}
@@ -247,7 +247,7 @@ abstract class WP_HTTP_UnitTestCase extends WP_UnitTestCase {
$headers[ $parts[0] ] = $parts[1];
}
$this->assertTrue( isset( $headers['test1'] ) && 'test' == $headers['test1'] );
$this->assertTrue( isset( $headers['test1'] ) && 'test' === $headers['test1'] );
$this->assertTrue( isset( $headers['test2'] ) && '0' === $headers['test2'] );
// cURL/HTTP Extension Note: Will never pass, cURL does not pass headers with an empty value.
// Should it be that empty headers with empty values are NOT sent?
+1 -1
View File
@@ -75,7 +75,7 @@ abstract class WP_Image_UnitTestCase extends WP_UnitTestCase {
protected function assertImageDimensions( $filename, $width, $height ) {
$detected_width = 0;
$detected_height = 0;
$image_size = @getimagesize( $filename );
$image_size = getimagesize( $filename );
if ( isset( $image_size[0] ) ) {
$detected_width = $image_size[0];
+2 -2
View File
@@ -55,7 +55,7 @@ class Tests_WP_Site_Icon extends WP_UnitTestCase {
$this->assertEquals( $sizes, $image_sizes );
// Remove custom size.
unset( $this->wp_site_icon->site_icon_sizes[ array_search( 321, $this->wp_site_icon->site_icon_sizes ) ] );
unset( $this->wp_site_icon->site_icon_sizes[ array_search( 321, $this->wp_site_icon->site_icon_sizes, true ) ] );
// Remove the filter we added
remove_filter( 'site_icon_image_sizes', array( $this, '_custom_test_sizes' ) );
}
@@ -95,7 +95,7 @@ class Tests_WP_Site_Icon extends WP_UnitTestCase {
$this->assertEquals( $sizes, $image_sizes );
// Remove custom size.
unset( $this->wp_site_icon->site_icon_sizes[ array_search( 321, $this->wp_site_icon->site_icon_sizes ) ] );
unset( $this->wp_site_icon->site_icon_sizes[ array_search( 321, $this->wp_site_icon->site_icon_sizes, true ) ] );
}
function test_create_attachment_object() {
+1
View File
@@ -28,6 +28,7 @@ class Tests_Import_Import extends WP_Import_UnitTestCase {
global $wpdb;
// crude but effective: make sure there's no residual data in the main tables
foreach ( array( 'posts', 'postmeta', 'comments', 'terms', 'term_taxonomy', 'term_relationships', 'users', 'usermeta' ) as $table ) {
// phpcs:ignore WordPress.DB.PreparedSQL.InterpolatedNotPrepared
$wpdb->query( "DELETE FROM {$wpdb->$table}" );
}
}
+7 -7
View File
@@ -148,7 +148,7 @@ EOF;
);
foreach ( $bad as $k => $x ) {
$result = wp_kses_bad_protocol( wp_kses_normalize_entities( $x ), wp_allowed_protocols() );
if ( ! empty( $result ) && $result != 'alert(1);' && $result != 'alert(1)' ) {
if ( ! empty( $result ) && 'alert(1);' !== $result && 'alert(1)' !== $result ) {
switch ( $k ) {
case 6:
$this->assertEquals( 'javascript&amp;#0000058alert(1);', $result );
@@ -183,7 +183,7 @@ EOF;
);
foreach ( $safe as $x ) {
$result = wp_kses_bad_protocol( wp_kses_normalize_entities( $x ), array( 'http', 'https', 'dummy' ) );
if ( $result != $x && $result != 'http://example.org/' ) {
if ( $result !== $x && 'http://example.org/' !== $result ) {
$this->fail( "wp_kses_bad_protocol incorrectly blocked $x" );
}
}
@@ -192,17 +192,17 @@ EOF;
public function test_hackers_attacks() {
$xss = simplexml_load_file( DIR_TESTDATA . '/formatting/xssAttacks.xml' );
foreach ( $xss->attack as $attack ) {
if ( in_array( $attack->name, array( 'IMG Embedded commands 2', 'US-ASCII encoding', 'OBJECT w/Flash 2', 'Character Encoding Example' ) ) ) {
if ( in_array( (string) $attack->name, array( 'IMG Embedded commands 2', 'US-ASCII encoding', 'OBJECT w/Flash 2', 'Character Encoding Example' ), true ) ) {
continue;
}
$code = (string) $attack->code;
if ( $code == 'See Below' ) {
if ( 'See Below' === $code ) {
continue;
}
if ( substr( $code, 0, 4 ) == 'perl' ) {
if ( substr( $code, 0, 4 ) === 'perl' ) {
$pos = strpos( $code, '"' ) + 1;
$code = substr( $code, $pos, strrpos( $code, '"' ) - $pos );
$code = str_replace( '\0', "\0", $code );
@@ -210,7 +210,7 @@ EOF;
$result = trim( wp_kses_data( $code ) );
if ( $result == '' || $result == 'XSS' || $result == 'alert("XSS");' || $result == "alert('XSS');" ) {
if ( in_array( $result, array( '', 'XSS', 'alert("XSS");', "alert('XSS');" ), true ) ) {
continue;
}
@@ -324,7 +324,7 @@ EOF;
}
function _wp_kses_allowed_html_filter( $html, $context ) {
if ( 'post' == $context ) {
if ( 'post' === $context ) {
return array( 'a' => array( 'href' => true ) );
} else {
return array( 'a' => array( 'href' => false ) );
+8 -8
View File
@@ -75,16 +75,16 @@ class Tests_L10n extends WP_UnitTestCase {
$this->assertEqualSets( $textdomains_expected, array_keys( $installed_translations ) );
$this->assertNotEmpty( $installed_translations['default']['en_GB'] );
$data_en_GB = $installed_translations['default']['en_GB'];
$this->assertEquals( '2016-10-26 00:01+0200', $data_en_GB['PO-Revision-Date'] );
$this->assertEquals( 'Development (4.4.x)', $data_en_GB['Project-Id-Version'] );
$this->assertEquals( 'Poedit 1.8.10', $data_en_GB['X-Generator'] );
$data_en_gb = $installed_translations['default']['en_GB'];
$this->assertEquals( '2016-10-26 00:01+0200', $data_en_gb['PO-Revision-Date'] );
$this->assertEquals( 'Development (4.4.x)', $data_en_gb['Project-Id-Version'] );
$this->assertEquals( 'Poedit 1.8.10', $data_en_gb['X-Generator'] );
$this->assertNotEmpty( $installed_translations['admin']['es_ES'] );
$data_es_ES = $installed_translations['admin']['es_ES'];
$this->assertEquals( '2016-10-25 18:29+0200', $data_es_ES['PO-Revision-Date'] );
$this->assertEquals( 'Administration', $data_es_ES['Project-Id-Version'] );
$this->assertEquals( 'Poedit 1.8.10', $data_es_ES['X-Generator'] );
$data_es_es = $installed_translations['admin']['es_ES'];
$this->assertEquals( '2016-10-25 18:29+0200', $data_es_es['PO-Revision-Date'] );
$this->assertEquals( 'Administration', $data_es_es['Project-Id-Version'] );
$this->assertEquals( 'Poedit 1.8.10', $data_es_es['X-Generator'] );
}
/**
@@ -175,15 +175,15 @@ class Tests_L10n_loadTextdomainJustInTime extends WP_UnitTestCase {
require_once DIR_TESTDATA . '/plugins/internationalized-plugin.php';
switch_to_locale( 'de_DE' );
$expected_de_DE = i18n_plugin_test();
$expected_de_de = i18n_plugin_test();
switch_to_locale( 'es_ES' );
$expected_es_ES = i18n_plugin_test();
$expected_es_es = i18n_plugin_test();
restore_current_locale();
$this->assertSame( 'Das ist ein Dummy Plugin', $expected_de_DE );
$this->assertSame( 'This is a dummy plugin', $expected_es_ES );
$this->assertSame( 'Das ist ein Dummy Plugin', $expected_de_de );
$this->assertSame( 'This is a dummy plugin', $expected_es_es );
}
/**
+6 -6
View File
@@ -86,25 +86,25 @@ class Tests_Locale_Switcher extends WP_UnitTestCase {
switch_to_locale( 'de_DE' );
$wp_locale_de_DE = clone $wp_locale;
$wp_locale_de_de = clone $wp_locale;
// Cleanup.
restore_previous_locale();
$this->assertEqualSetsWithIndex( $expected, $wp_locale_de_DE->number_format );
$this->assertEqualSetsWithIndex( $expected, $wp_locale_de_de->number_format );
}
public function test_switch_to_locale_en_US() {
switch_to_locale( 'en_GB' );
$locale_en_GB = get_locale();
$locale_en_gb = get_locale();
switch_to_locale( 'en_US' );
$locale_en_US = get_locale();
$locale_en_us = get_locale();
// Cleanup.
restore_current_locale();
$this->assertSame( 'en_GB', $locale_en_GB );
$this->assertSame( 'en_US', $locale_en_US );
$this->assertSame( 'en_GB', $locale_en_gb );
$this->assertSame( 'en_US', $locale_en_us );
}
public function test_switch_to_locale_multiple_times() {
+2
View File
@@ -8,9 +8,11 @@ class Test_Theme_File extends WP_UnitTestCase {
if ( ! function_exists( 'symlink' ) ) {
self::markTestSkipped( 'symlink() is not available.' );
}
// phpcs:ignore WordPress.PHP.NoSilencedErrors.Discouraged
if ( ! @symlink( DIR_TESTDATA . '/theme-file-parent', WP_CONTENT_DIR . '/themes/theme-file-parent' ) ) {
self::markTestSkipped( 'Could not create parent symlink.' );
}
// phpcs:ignore WordPress.PHP.NoSilencedErrors.Discouraged
if ( ! @symlink( DIR_TESTDATA . '/theme-file-child', WP_CONTENT_DIR . '/themes/theme-file-child' ) ) {
self::markTestSkipped( 'Could not create child symlink.' );
}
+5 -5
View File
@@ -1256,7 +1256,7 @@ EOF;
* @ticket 33016
*/
function filter_wp_embed_shortcode_custom( $content, $url ) {
if ( 'https://www.example.com/?video=1' == $url ) {
if ( 'https://www.example.com/?video=1' === $url ) {
$content = '@embed URL was replaced@';
}
return $content;
@@ -1446,7 +1446,7 @@ EOF;
foreach ( $image_meta['sizes'] as $name => $size ) {
// Whitelist the sizes that should be included so we pick up 'medium_large' in 4.4.
if ( in_array( $name, $intermediates ) ) {
if ( in_array( $name, $intermediates, true ) ) {
$expected .= $uploads_dir_url . $year_month . '/' . $size['file'] . ' ' . $size['width'] . 'w, ';
}
}
@@ -1491,7 +1491,7 @@ EOF;
foreach ( $image_meta['sizes'] as $name => $size ) {
// Whitelist the sizes that should be included so we pick up 'medium_large' in 4.4.
if ( in_array( $name, $intermediates ) ) {
if ( in_array( $name, $intermediates, true ) ) {
$expected .= $uploads_dir_url . $size['file'] . ' ' . $size['width'] . 'w, ';
}
}
@@ -1568,7 +1568,7 @@ EOF;
foreach ( $image_meta['sizes'] as $name => $size ) {
// Whitelist the sizes that should be included so we pick up 'medium_large' in 4.4.
if ( in_array( $name, $intermediates ) ) {
if ( in_array( $name, $intermediates, true ) ) {
$expected .= $uploads_dir_url . $year_month . '/' . $size['file'] . ' ' . $size['width'] . 'w, ';
}
}
@@ -1847,7 +1847,7 @@ EOF;
foreach ( $image_meta['sizes'] as $name => $size ) {
// Whitelist the sizes that should be included so we pick up 'medium_large' in 4.4.
if ( in_array( $name, $intermediates ) ) {
if ( in_array( $name, $intermediates, true ) ) {
$expected .= $uploads_dir . $year_month . '/' . $size['file'] . ' ' . $size['width'] . 'w, ';
}
}
+1
View File
@@ -370,6 +370,7 @@ class Tests_Meta extends WP_UnitTestCase {
$string_mid = "{$meta_id}.0";
// phpcs:ignore WordPress.PHP.StrictComparisons.LooseComparison -- intentional implicit casting check
$this->assertTrue( floor( $string_mid ) == $string_mid );
$this->assertNotEquals( false, get_metadata_by_mid( 'user', $string_mid ) );
$this->assertNotEquals( false, update_metadata_by_mid( 'user', $string_mid, 'meta_new_value_2' ) );
+1 -1
View File
@@ -505,7 +505,7 @@ class Tests_Meta_Register_Meta extends WP_UnitTestCase {
}
public function filter_get_object_subtype_for_customtype( $subtype, $object_id ) {
if ( $object_id % 2 === 1 ) {
if ( 1 === ( $object_id % 2 ) ) {
return 'odd';
}
+1 -1
View File
@@ -31,7 +31,7 @@ if ( is_multisite() ) :
wpmu_log_new_registrations( 1, 1 );
// currently there is no wrapper function for the registration_log
$reg_blog = $wpdb->get_col( "SELECT email FROM {$wpdb->registration_log} WHERE {$wpdb->registration_log}.blog_id = 1 AND IP LIKE '" . $ip . "'" );
$reg_blog = $wpdb->get_col( $wpdb->prepare( "SELECT email FROM {$wpdb->registration_log} WHERE {$wpdb->registration_log}.blog_id = 1 AND IP LIKE %s", $ip ) );
$this->assertEquals( $user->user_email, $reg_blog[ count( $reg_blog ) - 1 ] );
}
}
@@ -28,7 +28,7 @@ if ( is_multisite() ) :
// Our comparison of space relies on an initial value of 0. If a previous test has failed or if the
// src directory already contains a content directory with site content, then the initial expectation
// will be polluted. We create sites until an empty one is available.
while ( 0 != get_space_used() ) {
while ( 0 !== get_space_used() ) {
restore_current_blog();
$blog_id = self::factory()->blog->create();
switch_to_blog( $blog_id );
@@ -64,7 +64,7 @@ if ( is_multisite() ) :
// We don't rely on an initial value of 0 for space used, but should have a clean space available
// so that we can remove any uploaded files and directories without concern of a conflict with
// existing content directories in src.
while ( 0 != get_space_used() ) {
while ( 0 !== get_space_used() ) {
restore_current_blog();
$blog_id = self::factory()->blog->create();
switch_to_blog( $blog_id );
+20 -6
View File
@@ -166,16 +166,21 @@ if ( is_multisite() ) :
// Check existence of each database table for the created site.
foreach ( $wpdb->tables( 'blog', false ) as $table ) {
$suppress = $wpdb->suppress_errors();
$suppress = $wpdb->suppress_errors();
// phpcs:ignore WordPress.DB.PreparedSQL.InterpolatedNotPrepared
$table_fields = $wpdb->get_results( "DESCRIBE $prefix$table;" );
$wpdb->suppress_errors( $suppress );
// The table should exist.
$this->assertNotEmpty( $table_fields );
// And the table should not be empty, unless commentmeta, termmeta, or links.
// phpcs:ignore WordPress.DB.PreparedSQL.InterpolatedNotPrepared
$result = $wpdb->get_results( "SELECT * FROM $prefix$table LIMIT 1" );
if ( 'commentmeta' == $table || 'termmeta' == $table || 'links' == $table ) {
if ( 'commentmeta' === $table || 'termmeta' === $table || 'links' === $table ) {
$this->assertEmpty( $result );
} else {
$this->assertNotEmpty( $result );
@@ -244,8 +249,11 @@ if ( is_multisite() ) :
$prefix = $wpdb->get_blog_prefix( $blog_id );
foreach ( $wpdb->tables( 'blog', false ) as $table ) {
$suppress = $wpdb->suppress_errors();
$suppress = $wpdb->suppress_errors();
// phpcs:ignore WordPress.DB.PreparedSQL.InterpolatedNotPrepared
$table_fields = $wpdb->get_results( "DESCRIBE $prefix$table;" );
$wpdb->suppress_errors( $suppress );
$this->assertNotEmpty( $table_fields, $prefix . $table );
}
@@ -282,8 +290,11 @@ if ( is_multisite() ) :
$prefix = $wpdb->get_blog_prefix( $blog_id );
foreach ( $wpdb->tables( 'blog', false ) as $table ) {
$suppress = $wpdb->suppress_errors();
$suppress = $wpdb->suppress_errors();
// phpcs:ignore WordPress.DB.PreparedSQL.InterpolatedNotPrepared
$table_fields = $wpdb->get_results( "DESCRIBE $prefix$table;" );
$wpdb->suppress_errors( $suppress );
$this->assertEmpty( $table_fields );
}
@@ -320,8 +331,11 @@ if ( is_multisite() ) :
$prefix = $wpdb->get_blog_prefix( $blog_id );
foreach ( $wpdb->tables( 'blog', false ) as $table ) {
$suppress = $wpdb->suppress_errors();
$suppress = $wpdb->suppress_errors();
// phpcs:ignore WordPress.DB.PreparedSQL.InterpolatedNotPrepared
$table_fields = $wpdb->get_results( "DESCRIBE $prefix$table;" );
$wpdb->suppress_errors( $suppress );
$this->assertNotEmpty( $table_fields, $prefix . $table );
}
@@ -855,7 +869,7 @@ if ( is_multisite() ) :
* the testing of the filter and for a test which does not need the database.
*/
function _domain_exists_cb( $exists, $domain, $path, $site_id ) {
if ( 'foo' == $domain && 'bar/' == $path ) {
if ( 'foo' === $domain && 'bar/' === $path ) {
return 1234;
} else {
return null;
+1 -1
View File
@@ -121,7 +121,7 @@ class Test_oEmbed_Controller extends WP_UnitTestCase {
);
}
if ( $url === self::UNTRUSTED_PROVIDER_URL ) {
if ( self::UNTRUSTED_PROVIDER_URL === $url ) {
return array(
'response' => array(
'code' => 200,
+1 -1
View File
@@ -30,6 +30,6 @@ class Tests_oEmbed_HTTP_Headers extends WP_UnitTestCase {
$headers = xdebug_get_headers();
$this->assertTrue( in_array( 'Content-Type: text/xml; charset=' . get_option( 'blog_charset' ), $headers ) );
$this->assertTrue( in_array( 'Content-Type: text/xml; charset=' . get_option( 'blog_charset' ), $headers, true ) );
}
}
+1 -1
View File
@@ -178,7 +178,7 @@ class Tests_POMO_MO extends WP_UnitTestCase {
}
function test_overloaded_mb_functions() {
if ( ( ini_get( 'mbstring.func_overload' ) & 2 ) == 0 ) {
if ( ( ini_get( 'mbstring.func_overload' ) & 2 ) === 0 ) {
$this->markTestSkipped( __METHOD__ . ' only runs when mbstring.func_overload is enabled.' );
}
+8 -8
View File
@@ -60,7 +60,7 @@ class PluralFormsTest extends WP_UnitTestCase {
$plural_expressions = array();
foreach ( $locales as $slug => $locale ) {
$plural_expression = $locale->plural_expression;
if ( $plural_expression !== 'n != 1' ) {
if ( 'n != 1' !== $plural_expression ) {
$plural_expressions[] = array( $slug, $locale->nplurals, $plural_expression );
}
}
@@ -82,14 +82,14 @@ class PluralFormsTest extends WP_UnitTestCase {
$parenthesized = self::parenthesize_plural_expression( $expression );
$old_style = tests_make_plural_form_function( $nplurals, $parenthesized );
$pluralForms = new Plural_Forms( $expression );
$plural_forms = new Plural_Forms( $expression );
$generated_old = array();
$generated_new = array();
foreach ( range( 0, 200 ) as $i ) {
$generated_old[] = $old_style( $i );
$generated_new[] = $pluralForms->get( $i );
$generated_new[] = $plural_forms->get( $i );
}
$this->assertSame( $generated_old, $generated_new );
@@ -151,10 +151,10 @@ class PluralFormsTest extends WP_UnitTestCase {
* @dataProvider simple_provider
*/
public function test_simple( $expression, $expected ) {
$pluralForms = new Plural_Forms( $expression );
$actual = array();
$plural_forms = new Plural_Forms( $expression );
$actual = array();
foreach ( array_keys( $expected ) as $num ) {
$actual[ $num ] = $pluralForms->get( $num );
$actual[ $num ] = $plural_forms->get( $num );
}
$this->assertSame( $expected, $actual );
@@ -212,9 +212,9 @@ class PluralFormsTest extends WP_UnitTestCase {
*/
public function test_exceptions( $expression, $expected_exception, $call_get ) {
try {
$pluralForms = new Plural_Forms( $expression );
$plural_forms = new Plural_Forms( $expression );
if ( $call_get ) {
$pluralForms->get( 1 );
$plural_forms->get( 1 );
}
} catch ( Exception $e ) {
$this->assertEquals( $expected_exception, $e->getMessage() );
+2 -2
View File
@@ -95,7 +95,7 @@ class Tests_Post extends WP_UnitTestCase {
$this->assertEquals( 2, count( $tcache ) );
$tcache = wp_cache_get( $id, 'ctax_relationships' );
if ( 'cpt' == $post_type ) {
if ( 'cpt' === $post_type ) {
$this->assertInternalType( 'array', $tcache );
$this->assertEquals( 2, count( $tcache ) );
} else {
@@ -1008,7 +1008,7 @@ class Tests_Post extends WP_UnitTestCase {
*/
function test_utf8mb3_post_saves_with_emoji() {
global $wpdb;
$_wpdb = new wpdb_exposed_methods_for_testing();
$_wpdb = new WpdbExposedMethodsForTesting();
if ( 'utf8' !== $_wpdb->get_col_charset( $wpdb->posts, 'post_title' ) ) {
$this->markTestSkipped( 'This test is only useful with the utf8 character set' );
+1 -1
View File
@@ -95,7 +95,7 @@ class Tests_Post_Meta extends WP_UnitTestCase {
'another value',
);
sort( $expected );
$this->assertTrue( in_array( get_post_meta( self::$post_id, 'nonunique', true ), $expected ) );
$this->assertTrue( in_array( get_post_meta( self::$post_id, 'nonunique', true ), $expected, true ) );
$actual = get_post_meta( self::$post_id, 'nonunique', false );
sort( $actual );
$this->assertEquals( $expected, $actual );
+3 -3
View File
@@ -651,9 +651,9 @@ class Test_Nav_Menus extends WP_UnitTestCase {
);
$tag_id = self::factory()->tag->create();
$wpdb->query( "UPDATE $wpdb->posts SET ID=$new_id WHERE ID=$page_id" );
$wpdb->query( "UPDATE $wpdb->terms SET term_id=$new_id WHERE term_id=$tag_id" );
$wpdb->query( "UPDATE $wpdb->term_taxonomy SET term_id=$new_id WHERE term_id=$tag_id" );
$wpdb->update( $wpdb->posts, array( 'ID' => $new_id ), array( 'ID' => $page_id ) );
$wpdb->update( $wpdb->terms, array( 'term_id' => $new_id ), array( 'term_id' => $tag_id ) );
$wpdb->update( $wpdb->term_taxonomy, array( 'term_id' => $new_id ), array( 'term_id' => $tag_id ) );
update_option( 'page_on_front', $new_id );
+1 -1
View File
@@ -36,7 +36,7 @@ class Tests_Post_Objects extends WP_UnitTestCase {
$post = get_post( $id, ARRAY_N );
$this->assertInternalType( 'array', $post );
$this->assertFalse( isset( $post['post_type'] ) );
$this->assertTrue( in_array( 'post', $post ) );
$this->assertTrue( in_array( 'post', $post, true ) );
$post = get_post( $id );
$post = get_post( $post, ARRAY_A );
+5 -5
View File
@@ -71,7 +71,7 @@ class Tests_Post_Thumbnail_Template extends WP_UnitTestCase {
function test_update_post_thumbnail_cache() {
set_post_thumbnail( self::$post, self::$attachment_id );
$WP_Query = new WP_Query(
$query = new WP_Query(
array(
'post_type' => 'any',
'post__in' => array( self::$post->ID ),
@@ -79,11 +79,11 @@ class Tests_Post_Thumbnail_Template extends WP_UnitTestCase {
)
);
$this->assertFalse( $WP_Query->thumbnails_cached );
$this->assertFalse( $query->thumbnails_cached );
update_post_thumbnail_cache( $WP_Query );
update_post_thumbnail_cache( $query );
$this->assertTrue( $WP_Query->thumbnails_cached );
$this->assertTrue( $query->thumbnails_cached );
}
/**
@@ -392,7 +392,7 @@ class Tests_Post_Thumbnail_Template extends WP_UnitTestCase {
self::$different_post->ID => 'thumbnail',
);
$post = $which_post === 1 ? self::$different_post : self::$post;
$post = 1 === $which_post ? self::$different_post : self::$post;
add_filter( 'post_thumbnail_size', array( $this, 'filter_post_thumbnail_size' ), 10, 2 );
+2 -2
View File
@@ -305,9 +305,9 @@ class Tests_Post_Types extends WP_UnitTestCase {
)
);
$this->assertInternalType( 'int', array_search( 'bar', $wp->public_query_vars ) );
$this->assertInternalType( 'int', array_search( 'bar', $wp->public_query_vars, true ) );
$this->assertTrue( unregister_post_type( 'foo' ) );
$this->assertFalse( array_search( 'bar', $wp->public_query_vars ) );
$this->assertFalse( array_search( 'bar', $wp->public_query_vars, true ) );
}
/**
+5 -5
View File
@@ -78,7 +78,7 @@ class Tests_WP_Post_Type extends WP_UnitTestCase {
);
$post_type_object->add_rewrite_rules();
$this->assertFalse( in_array( 'foobar', $wp->public_query_vars ) );
$this->assertFalse( in_array( 'foobar', $wp->public_query_vars, true ) );
}
public function test_adds_query_var_if_public() {
@@ -98,10 +98,10 @@ class Tests_WP_Post_Type extends WP_UnitTestCase {
);
$post_type_object->add_rewrite_rules();
$in_array = in_array( 'foobar', $wp->public_query_vars );
$in_array = in_array( 'foobar', $wp->public_query_vars, true );
$post_type_object->remove_rewrite_rules();
$in_array_after = in_array( 'foobar', $wp->public_query_vars );
$in_array_after = in_array( 'foobar', $wp->public_query_vars, true );
$this->assertTrue( $in_array );
$this->assertFalse( $in_array_after );
@@ -128,8 +128,8 @@ class Tests_WP_Post_Type extends WP_UnitTestCase {
$post_type_object->remove_rewrite_rules();
$rewrite_tags_after = $wp_rewrite->rewritecode;
$this->assertNotFalse( array_search( "%$post_type%", $rewrite_tags ) );
$this->assertFalse( array_search( "%$post_type%", $rewrite_tags_after ) );
$this->assertNotFalse( array_search( "%$post_type%", $rewrite_tags, true ) );
$this->assertFalse( array_search( "%$post_type%", $rewrite_tags_after, true ) );
}
public function test_register_meta_boxes() {
+1 -1
View File
@@ -255,7 +255,7 @@ class Tests_REST_API extends WP_UnitTestCase {
*/
function test_rest_route_query_var() {
rest_api_init();
$this->assertTrue( in_array( 'rest_route', $GLOBALS['wp']->public_query_vars ) );
$this->assertTrue( in_array( 'rest_route', $GLOBALS['wp']->public_query_vars, true ) );
}
public function test_route_method() {
@@ -2491,7 +2491,7 @@ class WP_Test_REST_Posts_Controller extends WP_Test_REST_Post_Type_Controller_Te
}
public function revoke_assign_term( $caps, $cap, $user_id, $args ) {
if ( 'assign_term' === $cap && isset( $args[0] ) && $this->forbidden_cat == $args[0] ) {
if ( 'assign_term' === $cap && isset( $args[0] ) && $this->forbidden_cat === $args[0] ) {
$caps = array( 'do_not_allow' );
}
return $caps;
@@ -463,8 +463,8 @@ class Tests_REST_Request extends WP_UnitTestCase {
$data = $valid->get_error_data( 'rest_missing_callback_param' );
$this->assertTrue( in_array( 'someinteger', $data['params'] ) );
$this->assertTrue( in_array( 'someotherinteger', $data['params'] ) );
$this->assertTrue( in_array( 'someinteger', $data['params'], true ) );
$this->assertTrue( in_array( 'someotherinteger', $data['params'], true ) );
}
public function test_has_valid_params_validate_callback() {
+3 -2
View File
@@ -38,7 +38,8 @@ class Tests_Shortcode extends WP_UnitTestCase {
// [footag foo="bar"]
function _shortcode_footag( $atts ) {
return @"foo = {$atts['foo']}";
$foo = isset( $atts['foo'] ) ? $atts['foo'] : '';
return "foo = $foo";
}
// [bartag foo="bar"]
@@ -444,7 +445,7 @@ EOF;
// Filter shortcode atts in various ways
function _filter_atts2( $out, $pairs, $atts ) {
// If foo attribute equals "foo1", change it to be default value
if ( isset( $out['foo'] ) && 'foo1' == $out['foo'] ) {
if ( isset( $out['foo'] ) && 'foo1' === $out['foo'] ) {
$out['foo'] = $pairs['foo'];
}
+2 -2
View File
@@ -811,9 +811,9 @@ class Tests_Taxonomy extends WP_UnitTestCase {
register_taxonomy( 'foo', 'post', array( 'query_var' => 'bar' ) );
$this->assertInternalType( 'int', array_search( 'bar', $wp->public_query_vars ) );
$this->assertInternalType( 'int', array_search( 'bar', $wp->public_query_vars, true ) );
$this->assertTrue( unregister_taxonomy( 'foo' ) );
$this->assertFalse( array_search( 'bar', $wp->public_query_vars ) );
$this->assertFalse( array_search( 'bar', $wp->public_query_vars, true ) );
}
/**
+1 -1
View File
@@ -90,7 +90,7 @@ class Tests_Term_Cache extends WP_UnitTestCase {
$this->assertEquals( $children, count( $hierarchy, COUNT_RECURSIVE ) - count( $hierarchy ) );
}
if ( $i % 3 === 0 ) {
if ( 0 === ( $i % 3 ) ) {
$step = 1;
} else {
$step++;
+4 -4
View File
@@ -2474,9 +2474,9 @@ class Tests_Term_getTerms extends WP_UnitTestCase {
$this->assertEqualSets( array( $t1, $t2, $t3 ), wp_list_pluck( $found, 'term_id' ) );
foreach ( $found as $f ) {
if ( $t1 == $f->term_id ) {
if ( $t1 === $f->term_id ) {
$this->assertSame( 3, $f->count );
} elseif ( $t2 == $f->term_id ) {
} elseif ( $t2 === $f->term_id ) {
$this->assertSame( 2, $f->count );
} else {
$this->assertSame( 1, $f->count );
@@ -2547,9 +2547,9 @@ class Tests_Term_getTerms extends WP_UnitTestCase {
$this->assertEqualSets( array( $t1, $t2, $t3 ), wp_list_pluck( $found, 'term_id' ) );
foreach ( $found as $f ) {
if ( $t1 == $f->term_id ) {
if ( $t1 === $f->term_id ) {
$this->assertEquals( 1, $f->count );
} elseif ( $t2 == $f->term_id ) {
} elseif ( $t2 === $f->term_id ) {
$this->assertEquals( 2, $f->count );
} else {
$this->assertEquals( 1, $f->count );
+1 -1
View File
@@ -822,7 +822,7 @@ class Tests_Term_WpInsertTerm extends WP_UnitTestCase {
$cached_children = get_option( 'wptests_tax_children' );
$this->assertNotEmpty( $cached_children[ $t ] );
$this->assertTrue( in_array( $found['term_id'], $cached_children[ $t ] ) );
$this->assertTrue( in_array( $found['term_id'], $cached_children[ $t ], true ) );
}
/**
+5 -5
View File
@@ -22,7 +22,7 @@ class Tests_WP_Taxonomy extends WP_UnitTestCase {
$taxonomy_object = new WP_Taxonomy( $taxonomy, 'post' );
$taxonomy_object->add_rewrite_rules();
$this->assertFalse( in_array( 'foobar', $wp->public_query_vars ) );
$this->assertFalse( in_array( 'foobar', $wp->public_query_vars, true ) );
}
public function test_adds_query_var_if_public() {
@@ -43,10 +43,10 @@ class Tests_WP_Taxonomy extends WP_UnitTestCase {
);
$taxonomy_object->add_rewrite_rules();
$in_array = in_array( 'foobar', $wp->public_query_vars );
$in_array = in_array( 'foobar', $wp->public_query_vars, true );
$taxonomy_object->remove_rewrite_rules();
$in_array_after = in_array( 'foobar', $wp->public_query_vars );
$in_array_after = in_array( 'foobar', $wp->public_query_vars, true );
$this->assertTrue( $in_array );
$this->assertFalse( $in_array_after );
@@ -74,8 +74,8 @@ class Tests_WP_Taxonomy extends WP_UnitTestCase {
$taxonomy_object->remove_rewrite_rules();
$rewrite_tags_after = $wp_rewrite->rewritecode;
$this->assertNotFalse( array_search( "%$taxonomy%", $rewrite_tags ) );
$this->assertFalse( array_search( "%$taxonomy%", $rewrite_tags_after ) );
$this->assertNotFalse( array_search( "%$taxonomy%", $rewrite_tags, true ) );
$this->assertFalse( array_search( "%$taxonomy%", $rewrite_tags_after, true ) );
}
public function test_adds_ajax_callback() {
+1 -1
View File
@@ -685,7 +685,7 @@ class Tests_Term_WpUpdateTerm extends WP_UnitTestCase {
$cached_children = get_option( 'wptests_tax_children' );
$this->assertNotEmpty( $cached_children[ $t2 ] );
$this->assertTrue( in_array( $found['term_id'], $cached_children[ $t2 ] ) );
$this->assertTrue( in_array( $found['term_id'], $cached_children[ $t2 ], true ) );
}
/**
+1 -1
View File
@@ -243,7 +243,7 @@ class Tests_Theme extends WP_UnitTestCase {
for ( $i = 0; $i < 3; $i++ ) {
foreach ( $themes as $name => $theme ) {
// switch to this theme
if ( $i === 2 ) {
if ( 2 === $i ) {
switch_theme( $theme['Template'], $theme['Stylesheet'] );
} else {
switch_theme( $theme['Stylesheet'] );
+1 -1
View File
@@ -142,7 +142,7 @@ class Tests_Theme_Support extends WP_UnitTestCase {
}
function supports_foobar( $yesno, $args, $feature ) {
if ( $args[0] == $feature[0] ) {
if ( $args[0] === $feature[0] ) {
return true;
}
return false;
+2 -2
View File
@@ -145,7 +145,7 @@ class Tests_Theme_ThemeDir extends WP_UnitTestCase {
// Ignore themes in the default /themes directory.
foreach ( $themes as $theme_name => $theme ) {
if ( $theme->get_theme_root() != $this->theme_root ) {
if ( $theme->get_theme_root() !== $this->theme_root ) {
unset( $themes[ $theme_name ] );
}
}
@@ -209,7 +209,7 @@ class Tests_Theme_ThemeDir extends WP_UnitTestCase {
$this->assertFalse( empty( $theme ) );
$templates = $theme['Template Files'];
$this->assertTrue( in_array( $this->theme_root . '/page-templates/template-top-level.php', $templates ) );
$this->assertTrue( in_array( $this->theme_root . '/page-templates/template-top-level.php', $templates, true ) );
}
/**
+16 -16
View File
@@ -81,7 +81,7 @@ class Tests_User extends WP_UnitTestCase {
$found = array();
foreach ( $user_list as $user ) {
// only include the users we just created - there might be some others that existed previously
if ( in_array( $user->ID, $nusers ) ) {
if ( in_array( $user->ID, $nusers, true ) ) {
$found[] = $user->ID;
}
}
@@ -161,7 +161,7 @@ class Tests_User extends WP_UnitTestCase {
// for reasons unclear, the resulting array is indexed numerically; meta keys are not included anywhere.
// so we'll just check to make sure our values are included somewhere.
foreach ( $vals as $k => $v ) {
$this->assertTrue( isset( $out[ $k ] ) && $out[ $k ][0] == $v );
$this->assertTrue( isset( $out[ $k ] ) && $out[ $k ][0] === $v );
}
// delete one key and check again
$keys = array_keys( $vals );
@@ -170,10 +170,10 @@ class Tests_User extends WP_UnitTestCase {
$out = get_user_meta( self::$author_id );
// make sure that key is excluded from the results
foreach ( $vals as $k => $v ) {
if ( $k == $key_to_delete ) {
if ( $k === $key_to_delete ) {
$this->assertFalse( isset( $out[ $k ] ) );
} else {
$this->assertTrue( isset( $out[ $k ] ) && $out[ $k ][0] == $v );
$this->assertTrue( isset( $out[ $k ] ) && $out[ $k ][0] === $v );
}
}
}
@@ -599,7 +599,7 @@ class Tests_User extends WP_UnitTestCase {
$this->assertWPError( $id2 );
}
@update_user_meta( $id2, 'key', 'value' );
update_user_meta( $id2, 'key', 'value' );
$metas = array_keys( get_user_meta( 1 ) );
$this->assertNotContains( 'key', $metas );
@@ -1022,7 +1022,7 @@ class Tests_User extends WP_UnitTestCase {
)
);
$this->assertTrue( in_array( self::$contrib_id, $users ) );
$this->assertTrue( in_array( (string) self::$contrib_id, $users, true ) );
}
public function test_search_users_url() {
@@ -1033,7 +1033,7 @@ class Tests_User extends WP_UnitTestCase {
)
);
$this->assertTrue( in_array( self::$contrib_id, $users ) );
$this->assertTrue( in_array( (string) self::$contrib_id, $users, true ) );
}
public function test_search_users_email() {
@@ -1044,7 +1044,7 @@ class Tests_User extends WP_UnitTestCase {
)
);
$this->assertTrue( in_array( self::$contrib_id, $users ) );
$this->assertTrue( in_array( (string) self::$contrib_id, $users, true ) );
}
public function test_search_users_nicename() {
@@ -1055,7 +1055,7 @@ class Tests_User extends WP_UnitTestCase {
)
);
$this->assertTrue( in_array( self::$contrib_id, $users ) );
$this->assertTrue( in_array( (string) self::$contrib_id, $users, true ) );
}
public function test_search_users_display_name() {
@@ -1066,7 +1066,7 @@ class Tests_User extends WP_UnitTestCase {
)
);
$this->assertTrue( in_array( self::$contrib_id, $users ) );
$this->assertTrue( in_array( (string) self::$contrib_id, $users, true ) );
}
/**
@@ -1201,8 +1201,8 @@ class Tests_User extends WP_UnitTestCase {
* post author `blackburn@battlefield3.com` and and site admin `admin@example.org`.
*/
if ( ! empty( $GLOBALS['phpmailer']->mock_sent ) ) {
$was_admin_email_sent = ( isset( $GLOBALS['phpmailer']->mock_sent[0] ) && WP_TESTS_EMAIL == $GLOBALS['phpmailer']->mock_sent[0]['to'][0][0] );
$was_user_email_sent = ( isset( $GLOBALS['phpmailer']->mock_sent[1] ) && 'blackburn@battlefield3.com' == $GLOBALS['phpmailer']->mock_sent[1]['to'][0][0] );
$was_admin_email_sent = ( isset( $GLOBALS['phpmailer']->mock_sent[0] ) && WP_TESTS_EMAIL === $GLOBALS['phpmailer']->mock_sent[0]['to'][0][0] );
$was_user_email_sent = ( isset( $GLOBALS['phpmailer']->mock_sent[1] ) && 'blackburn@battlefield3.com' === $GLOBALS['phpmailer']->mock_sent[1]['to'][0][0] );
}
$this->assertTrue( $was_admin_email_sent );
@@ -1226,8 +1226,8 @@ class Tests_User extends WP_UnitTestCase {
* post author `blackburn@battlefield3.com` and and site admin `admin@example.org`.
*/
if ( ! empty( $GLOBALS['phpmailer']->mock_sent ) ) {
$was_admin_email_sent = ( isset( $GLOBALS['phpmailer']->mock_sent[0] ) && WP_TESTS_EMAIL == $GLOBALS['phpmailer']->mock_sent[0]['to'][0][0] );
$was_user_email_sent = ( isset( $GLOBALS['phpmailer']->mock_sent[1] ) && 'blackburn@battlefield3.com' == $GLOBALS['phpmailer']->mock_sent[1]['to'][0][0] );
$was_admin_email_sent = ( isset( $GLOBALS['phpmailer']->mock_sent[0] ) && WP_TESTS_EMAIL === $GLOBALS['phpmailer']->mock_sent[0]['to'][0][0] );
$was_user_email_sent = ( isset( $GLOBALS['phpmailer']->mock_sent[1] ) && 'blackburn@battlefield3.com' === $GLOBALS['phpmailer']->mock_sent[1]['to'][0][0] );
}
$this->assertTrue( $was_admin_email_sent );
@@ -1465,7 +1465,7 @@ class Tests_User extends WP_UnitTestCase {
do_action( 'personal_options_update' );
if ( ! empty( $GLOBALS['phpmailer']->mock_sent ) ) {
$was_confirmation_email_sent = ( isset( $GLOBALS['phpmailer']->mock_sent[0] ) && 'after@example.com' == $GLOBALS['phpmailer']->mock_sent[0]['to'][0][0] );
$was_confirmation_email_sent = ( isset( $GLOBALS['phpmailer']->mock_sent[0] ) && 'after@example.com' === $GLOBALS['phpmailer']->mock_sent[0]['to'][0][0] );
}
// A confirmation email is sent.
@@ -1502,7 +1502,7 @@ class Tests_User extends WP_UnitTestCase {
do_action( 'personal_options_update' );
if ( ! empty( $GLOBALS['phpmailer']->mock_sent ) ) {
$was_confirmation_email_sent = ( isset( $GLOBALS['phpmailer']->mock_sent[0] ) && 'after@example.com' == $GLOBALS['phpmailer']->mock_sent[0]['to'][0][0] );
$was_confirmation_email_sent = ( isset( $GLOBALS['phpmailer']->mock_sent[0] ) && 'after@example.com' === $GLOBALS['phpmailer']->mock_sent[0]['to'][0][0] );
}
// No confirmation email is sent.
+1 -1
View File
@@ -1546,7 +1546,7 @@ class Tests_User_Capabilities extends WP_UnitTestCase {
function _nullify_current_user() {
// Prevents fatal errors in ::tearDown()'s and other uses of restore_current_blog()
$function_stack = wp_debug_backtrace_summary( null, 0, false );
if ( in_array( 'restore_current_blog', $function_stack ) ) {
if ( in_array( 'restore_current_blog', $function_stack, true ) ) {
return;
}
$GLOBALS['current_user'] = null;
+9 -7
View File
@@ -53,7 +53,9 @@ class Tests_User_Query extends WP_UnitTestCase {
$users = new WP_User_Query();
$this->assertEquals( '', $users->get( 'fields' ) );
$this->assertEquals( '', @$users->query_vars['fields'] );
if ( isset( $users->query_vars['fields'] ) ) {
$this->assertEquals( '', $users->query_vars['fields'] );
}
$users->set( 'fields', 'all' );
@@ -1136,11 +1138,11 @@ class Tests_User_Query extends WP_UnitTestCase {
)
);
$foundCount = count( $q->get_results() );
$expectedCount = 10; // 13 total users minus 3 from query
$found_count = count( $q->get_results() );
$expected_count = 10; // 13 total users minus 3 from query
$this->assertContains( "AND user_nicename NOT IN ( 'peter','paul','mary' )", $q->query_where );
$this->assertEquals( $expectedCount, $foundCount );
$this->assertEquals( $expected_count, $found_count );
}
/**
@@ -1237,11 +1239,11 @@ class Tests_User_Query extends WP_UnitTestCase {
)
);
$foundCount = count( $q->get_results() );
$expectedCount = 10; // 13 total users minus 3 from query
$found_count = count( $q->get_results() );
$expected_count = 10; // 13 total users minus 3 from query
$this->assertContains( "AND user_login NOT IN ( '$user_login1','$user_login2','$user_login3' )", $q->query_where );
$this->assertEquals( $expectedCount, $foundCount );
$this->assertEquals( $expected_count, $found_count );
}
/**
+1 -1
View File
@@ -150,7 +150,7 @@ class Tests_Widgets extends WP_UnitTestCase {
$names = wp_list_pluck( $wp_registered_sidebars, 'name' );
for ( $i = 1; $i <= $num; $i++ ) {
if ( in_array( "$id_base $i", $names ) ) {
if ( in_array( "$id_base $i", $names, true ) ) {
$result[] = true;
}
}
+3 -3
View File
@@ -22,15 +22,15 @@ class Tests_WP extends WP_UnitTestCase {
$this->wp->add_query_var( 'test' );
$this->assertSame( $public_qv_count + 2, count( $this->wp->public_query_vars ) );
$this->assertTrue( in_array( 'test', $this->wp->public_query_vars ) );
$this->assertTrue( in_array( 'test2', $this->wp->public_query_vars ) );
$this->assertTrue( in_array( 'test', $this->wp->public_query_vars, true ) );
$this->assertTrue( in_array( 'test2', $this->wp->public_query_vars, true ) );
}
public function test_remove_query_var() {
$public_qv_count = count( $this->wp->public_query_vars );
$this->wp->add_query_var( 'test' );
$this->assertTrue( in_array( 'test', $this->wp->public_query_vars ) );
$this->assertTrue( in_array( 'test', $this->wp->public_query_vars, true ) );
$this->wp->remove_query_var( 'test' );
$this->assertSame( $public_qv_count, count( $this->wp->public_query_vars ) );
@@ -109,7 +109,7 @@ class Tests_XMLRPC_mw_getRecentPosts extends WP_XMLRPC_UnitTestCase {
$this->assertInternalType( 'string', $result['wp_post_thumbnail'] );
$this->assertStringMatchesFormat( '%d', $result['wp_post_thumbnail'] );
if ( ! empty( $result['wp_post_thumbnail'] ) || $result['postid'] == self::$post_id ) {
if ( ! empty( $result['wp_post_thumbnail'] ) || $result['postid'] === self::$post_id ) {
$attachment_id = get_post_meta( $result['postid'], '_thumbnail_id', true );
$this->assertEquals( $attachment_id, $result['wp_post_thumbnail'] );
+3 -3
View File
@@ -445,7 +445,7 @@ class Tests_XMLRPC_wp_editPost extends WP_XMLRPC_UnitTestCase {
$this->assertEquals( 1, count( get_post_meta( $post_id, 'enclosure' ) ) );
// For good measure, check that the expected value is in the array
$this->assertTrue( in_array( $enclosure_string, get_post_meta( $post_id, 'enclosure' ) ) );
$this->assertTrue( in_array( $enclosure_string, get_post_meta( $post_id, 'enclosure' ), true ) );
// Attempt to add a brand new enclosure via XML-RPC
$this->myxmlrpcserver->add_enclosure_if_new( $post_id, $new_enclosure );
@@ -455,10 +455,10 @@ class Tests_XMLRPC_wp_editPost extends WP_XMLRPC_UnitTestCase {
// Check that the new enclosure is in the enclosure meta
$new_enclosure_string = "{$new_enclosure['url']}\n{$new_enclosure['length']}\n{$new_enclosure['type']}\n";
$this->assertTrue( in_array( $new_enclosure_string, get_post_meta( $post_id, 'enclosure' ) ) );
$this->assertTrue( in_array( $new_enclosure_string, get_post_meta( $post_id, 'enclosure' ), true ) );
// Check that the old enclosure is in the enclosure meta
$this->assertTrue( in_array( $enclosure_string, get_post_meta( $post_id, 'enclosure' ) ) );
$this->assertTrue( in_array( $enclosure_string, get_post_meta( $post_id, 'enclosure' ), true ) );
}
/**
+3 -3
View File
@@ -55,8 +55,8 @@ class Tests_XMLRPC_wp_getPages extends WP_XMLRPC_UnitTestCase {
}
function remove_editor_edit_page_cap( $caps, $cap, $user_id, $args ) {
if ( in_array( $cap, array( 'edit_page', 'edit_others_pages' ) ) ) {
if ( $user_id == self::$editor_id && $args[0] == self::$post_id ) {
if ( in_array( $cap, array( 'edit_page', 'edit_others_pages' ), true ) ) {
if ( $user_id === self::$editor_id && $args[0] === self::$post_id ) {
return array( false );
}
}
@@ -78,7 +78,7 @@ class Tests_XMLRPC_wp_getPages extends WP_XMLRPC_UnitTestCase {
// WP#20629
$this->assertNotIXRError( $result );
if ( $result['page_id'] == self::$post_id ) {
if ( $result['page_id'] === self::$post_id ) {
$found_incapable = true;
break;
}
+2 -2
View File
@@ -121,9 +121,9 @@ class Tests_XMLRPC_wp_getTerms extends WP_XMLRPC_UnitTestCase {
$this->assertNotEquals( 0, count( $results ) );
foreach ( $results as $term ) {
if ( $term['term_id'] == $cat1 ) {
if ( $term['term_id'] === $cat1 ) {
break; // found cat1 first as expected
} elseif ( $term['term_id'] == $cat2 ) {
} elseif ( $term['term_id'] === $cat2 ) {
$this->assertFalse( false, 'Incorrect category ordering.' );
}
}