Make WordPress Core

Ticket #29020: 29020.4.diff

File 29020.4.diff, 1.3 KB (added by tryon, 10 years ago)

Insert test

  • tests/phpunit/tests/dbdelta.php

     
    230230                $this->assertTableHasNotColumn( 'extra_col', $wpdb->prefix . 'dbdelta_test' );
    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        //
    236255
    237256        /**
     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        }
     275
     276        /**
    238277         * Assert that a table has a column.
    239278         *
    240279         * @param string $column The field name.