WordPress.org

Make WordPress Core


Ignore:
Timestamp:
07/08/2019 12:55:20 AM (2 years ago)
Author:
pento
Message:

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.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/tests/db.php

    r45603 r45607  
    2424    public static function setUpBeforeClass() {
    2525        parent::setUpBeforeClass();
    26         self::$_wpdb = new wpdb_exposed_methods_for_testing();
     26        self::$_wpdb = new WpdbExposedMethodsForTesting();
    2727    }
    2828
     
    347347
    348348    public function filter_allowed_incompatible_sql_mode( $modes ) {
    349         $pos = array_search( 'ONLY_FULL_GROUP_BY', $modes );
     349        $pos = array_search( 'ONLY_FULL_GROUP_BY', $modes, true );
    350350        $this->assertGreaterThanOrEqual( 0, $pos );
    351351
     
    366366        $id = 0;
    367367        // This, obviously, is an incorrect prepare.
     368        // phpcs:ignore WordPress.DB.PreparedSQL.InterpolatedNotPrepared
    368369        $prepared = $wpdb->prepare( "SELECT * FROM $wpdb->users WHERE id = $id", $id );
    369370        $this->assertEquals( "SELECT * FROM $wpdb->users WHERE id = 0", $prepared );
     
    383384        global $wpdb;
    384385
     386        // phpcs:ignore WordPress.PHP.NoSilencedErrors.Discouraged
    385387        $prepared = @$wpdb->prepare( "SELECT * FROM $wpdb->users WHERE id = %d AND user_login = %s", 1, array( 'admin' ) );
    386388        $this->assertEquals( "SELECT * FROM $wpdb->users WHERE id = 1 AND user_login = ''", $prepared );
    387389
     390        // phpcs:ignore WordPress.PHP.NoSilencedErrors.Discouraged
    388391        $prepared = @$wpdb->prepare( "SELECT * FROM $wpdb->users WHERE id = %d AND user_login = %s", array( 1 ), 'admin' );
    389392        $this->assertEquals( "SELECT * FROM $wpdb->users WHERE id = 0 AND user_login = 'admin'", $prepared );
     
    403406        global $wpdb;
    404407
     408        // phpcs:ignore WordPress.PHP.NoSilencedErrors.Discouraged
    405409        $prepared = @$wpdb->prepare( "SELECT * FROM $wpdb->users WHERE id = %d AND user_login = %s", array( 1, array( 'admin' ) ) );
    406410        $this->assertEquals( "SELECT * FROM $wpdb->users WHERE id = 1 AND user_login = ''", $prepared );
    407411
     412        // phpcs:ignore WordPress.PHP.NoSilencedErrors.Discouraged
    408413        $prepared = @$wpdb->prepare( "SELECT * FROM $wpdb->users WHERE id = %d AND user_login = %s", array( array( 1 ), 'admin' ) );
    409414        $this->assertEquals( "SELECT * FROM $wpdb->users WHERE id = 0 AND user_login = 'admin'", $prepared );
     
    421426        array_unshift( $args, $query );
    422427
     428        // phpcs:ignore WordPress.PHP.NoSilencedErrors.Discouraged
    423429        $prepared = @call_user_func_array( array( $wpdb, 'prepare' ), $args );
    424430        $this->assertEquals( $expected, $prepared );
     
    588594        $wpdb->last_result = $last_result;
    589595
     596        // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared
    590597        $result = $wpdb->get_col( $query, $column );
    591598
     
    10441051        }
    10451052
    1046         if ( ! in_array( $expected_charset, array( 'utf8', 'utf8mb4', 'latin1' ) ) ) {
     1053        if ( ! in_array( $expected_charset, array( 'utf8', 'utf8mb4', 'latin1' ), true ) ) {
    10471054            $this->markTestSkipped( 'This test only works with utf8, utf8mb4 or latin1 character sets' );
    10481055        }
     
    11171124        );
    11181125
    1119         $row = $wpdb->get_row( "SELECT * FROM $wpdb->postmeta WHERE meta_key='$key'" );
     1126        $row = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM $wpdb->postmeta WHERE meta_key=%s", $key ) );
    11201127
    11211128        $this->assertNull( $row->meta_value );
     
    11401147        );
    11411148
    1142         $row = $wpdb->get_row( "SELECT * FROM $wpdb->postmeta WHERE meta_key='$key'" );
     1149        $row = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM $wpdb->postmeta WHERE meta_key=%s", $key ) );
    11431150
    11441151        $this->assertSame( $value, $row->meta_value );
     
    11551162        );
    11561163
    1157         $row = $wpdb->get_row( "SELECT * FROM $wpdb->postmeta WHERE meta_key='$key'" );
     1164        $row = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM $wpdb->postmeta WHERE meta_key=%s", $key ) );
    11581165
    11591166        $this->assertNull( $row->meta_value );
     
    11781185        );
    11791186
    1180         $row = $wpdb->get_row( "SELECT * FROM $wpdb->postmeta WHERE meta_key='$key'" );
     1187        $row = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM $wpdb->postmeta WHERE meta_key=%s", $key ) );
    11811188
    11821189        $this->assertNull( $row->meta_value );
     
    11931200        );
    11941201
    1195         $row = $wpdb->get_row( "SELECT * FROM $wpdb->postmeta WHERE meta_key='$key'" );
     1202        $row = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM $wpdb->postmeta WHERE meta_key=%s", $key ) );
    11961203
    11971204        $this->assertSame( $value, $row->meta_value );
     
    12161223        );
    12171224
    1218         $row = $wpdb->get_row( "SELECT * FROM $wpdb->postmeta WHERE meta_key='$key'" );
     1225        $row = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM $wpdb->postmeta WHERE meta_key=%s", $key ) );
    12191226
    12201227        $this->assertNull( $row->meta_value );
     
    12291236        );
    12301237
    1231         $row = $wpdb->get_row( "SELECT * FROM $wpdb->postmeta WHERE meta_key='$key'" );
     1238        $row = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM $wpdb->postmeta WHERE meta_key=%s", $key ) );
    12321239
    12331240        $this->assertNull( $row );
     
    15731580        $sql = str_replace( '{ESCAPE}', $escape, $sql );
    15741581
     1582        // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared
    15751583        $actual = $wpdb->prepare( $sql, $values );
    15761584
     
    16541662        $wpdb->query( "CREATE TABLE {$wpdb->prefix}test_placeholder( a VARCHAR(100) );" );
    16551663        $sql = $wpdb->prepare( "INSERT INTO {$wpdb->prefix}test_placeholder VALUES(%s)", $value );
     1664
     1665        // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared
    16561666        $wpdb->query( $sql );
    16571667
     
    16681678
    16691679        $sql = $wpdb->prepare( ' %s %1$c ', 'foo' );
     1680        // phpcs:ignore WordPress.DB.PreparedSQL.InterpolatedNotPrepared
    16701681        $sql = $wpdb->prepare( " $sql %s ", 'foo' );
    16711682
Note: See TracChangeset for help on using the changeset viewer.