From c6e3b84c48286ecfcc0f9641999a851bb310dba3 Mon Sep 17 00:00:00 2001 From: Aaron Jorbin Date: Sun, 12 Jul 2015 17:28:15 +0000 Subject: [PATCH] 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. git-svn-id: https://develop.svn.wordpress.org/trunk@33175 602fd350-edb4-49c9-b593-d223f7449a82 --- tests/phpunit/tests/dbdelta.php | 39 +++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/tests/phpunit/tests/dbdelta.php b/tests/phpunit/tests/dbdelta.php index 7dbb96abcf..51bedb101c 100755 --- a/tests/phpunit/tests/dbdelta.php +++ b/tests/phpunit/tests/dbdelta.php @@ -230,10 +230,49 @@ class Tests_dbDelta extends WP_UnitTestCase { $this->assertTableHasNotColumn( 'extra_col', $wpdb->prefix . 'dbdelta_test' ); } + /** + * Test inserting into the database + */ + public function test_insert_into_table(){ + global $wpdb; + + $insert = dbDelta( + "INSERT INTO {$wpdb->prefix}dbdelta_test (column_1) VALUES ('wcphilly2015')" + ); + + $this->assertEquals( + array( ) + , $insert + ); + + $this->assertTableRowHasValue( 'column_1', 'wcphilly2015', $wpdb->prefix . 'dbdelta_test' ); + + } + // // Assertions. // + /** + * Assert that a table has a row with a value in a field. + * + * @param string $column The field name. + * @param string $value The field value. + * @param string $table The database table name. + */ + protected function assertTableRowHasValue( $column, $value, $table ) { + + global $wpdb; + + $table_row = $wpdb->get_row( "select $column from {$table} where $column = '$value'" ); + + $expected = (object) array( + $column => $value + ); + + $this->assertEquals( $expected, $table_row ); + } + /** * Assert that a table has a column. *