Make WordPress Core

Changeset 33175


Ignore:
Timestamp:
07/12/2015 05:28:15 PM (9 years ago)
Author:
jorbin
Message:

Add dbDelta insert test

Test to make sure that dbDelta properly inserts a value into the DB.

Props tryon, jtsternberg, ebinnion, JPry, avnarun, kevkoeh, salcode.
Fixes #29020.

File:
1 edited

Legend:

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

    r32770 r33175  
    231231    }
    232232
     233    /**
     234     * Test inserting into the database
     235     */
     236    public function test_insert_into_table(){
     237        global $wpdb;
     238
     239        $insert = dbDelta(
     240            "INSERT INTO {$wpdb->prefix}dbdelta_test (column_1) VALUES ('wcphilly2015')"
     241        );
     242
     243        $this->assertEquals(
     244            array( )
     245            , $insert
     246        );
     247
     248        $this->assertTableRowHasValue( 'column_1', 'wcphilly2015',  $wpdb->prefix . 'dbdelta_test' );
     249
     250    }
     251   
    233252    //
    234253    // Assertions.
    235254    //
     255
     256    /**
     257     * Assert that a table has a row with a value in a field.
     258     *
     259     * @param string $column The field name.
     260     * @param string $value  The field value.
     261     * @param string $table  The database table name.
     262     */
     263    protected function assertTableRowHasValue( $column, $value, $table ) {
     264
     265        global $wpdb;
     266
     267        $table_row = $wpdb->get_row( "select $column from {$table} where $column = '$value'" );
     268
     269        $expected = (object) array(
     270            $column => $value
     271        );
     272
     273        $this->assertEquals( $expected, $table_row );
     274    }
    236275
    237276    /**
Note: See TracChangeset for help on using the changeset viewer.