Changeset 42343 for trunk/tests/phpunit/tests/dbdelta.php
- Timestamp:
- 11/30/2017 11:09:33 PM (8 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/tests/phpunit/tests/dbdelta.php
r41818 r42343 82 82 83 83 $expected = array( 84 "{$wpdb->prefix}dbdelta_create_test" => "Created table {$wpdb->prefix}dbdelta_create_test" 84 "{$wpdb->prefix}dbdelta_create_test" => "Created table {$wpdb->prefix}dbdelta_create_test", 85 85 ); 86 86 … … 88 88 89 89 $this->assertEquals( 90 "{$wpdb->prefix}dbdelta_create_test" 91 , $wpdb->get_var( 90 "{$wpdb->prefix}dbdelta_create_test", $wpdb->get_var( 92 91 $wpdb->prepare( 93 'SHOW TABLES LIKE %s' 94 , $wpdb->esc_like( "{$wpdb->prefix}dbdelta_create_test" ) 92 'SHOW TABLES LIKE %s', $wpdb->esc_like( "{$wpdb->prefix}dbdelta_create_test" ) 95 93 ) 96 94 ) … … 145 143 array( 146 144 "{$wpdb->prefix}dbdelta_test.id" 147 => "Changed type of {$wpdb->prefix}dbdelta_test.id from bigint(20) to int(11)" 148 ) 149 , $updates 145 => "Changed type of {$wpdb->prefix}dbdelta_test.id from bigint(20) to int(11)", 146 ), $updates 150 147 ); 151 148 } … … 174 171 array( 175 172 "{$wpdb->prefix}dbdelta_test.extra_col" 176 => "Added column {$wpdb->prefix}dbdelta_test.extra_col" 177 ) 178 , $updates 173 => "Added column {$wpdb->prefix}dbdelta_test.extra_col", 174 ), $updates 179 175 ); 180 176 181 177 $this->assertTableHasColumn( 'column_1', $wpdb->prefix . 'dbdelta_test' ); 182 $this->assertTableHasPrimaryKey( 'id' 178 $this->assertTableHasPrimaryKey( 'id', $wpdb->prefix . 'dbdelta_test' ); 183 179 } 184 180 … … 227 223 KEY compound_key (id,column_1($this->max_index_length)) 228 224 ) 229 " 230 , false // Don't execute. 225 ", false // Don't execute. 231 226 ); 232 227 … … 234 229 array( 235 230 "{$wpdb->prefix}dbdelta_test.extra_col" 236 => "Added column {$wpdb->prefix}dbdelta_test.extra_col" 237 ) 238 , $updates 231 => "Added column {$wpdb->prefix}dbdelta_test.extra_col", 232 ), $updates 239 233 ); 240 234 … … 245 239 * Test inserting into the database 246 240 */ 247 public function test_insert_into_table() {241 public function test_insert_into_table() { 248 242 global $wpdb; 249 243 … … 253 247 254 248 $this->assertEquals( 255 array( ) 256 , $insert 257 ); 258 259 $this->assertTableRowHasValue( 'column_1', 'wcphilly2015', $wpdb->prefix . 'dbdelta_test' ); 249 array(), $insert 250 ); 251 252 $this->assertTableRowHasValue( 'column_1', 'wcphilly2015', $wpdb->prefix . 'dbdelta_test' ); 260 253 261 254 } … … 263 256 /** 264 257 * Test that FULLTEXT indexes are detected. 258 * 265 259 * @ticket 14445 266 260 */ … … 301 295 302 296 $expected = (object) array( 303 $column => $value297 $column => $value, 304 298 ); 305 299 … … 329 323 * @param string $table The database table name. 330 324 */ 331 protected function assertTableHasPrimaryKey( $column 325 protected function assertTableHasPrimaryKey( $column, $table ) { 332 326 global $wpdb; 333 327 334 328 $table_indices = $wpdb->get_results( "SHOW INDEX FROM {$table}" ); 335 329 336 $this->assertCount( 1, wp_list_filter( $table_indices, array( 'Key_name' => 'PRIMARY' , 'Column_name' => $column ) , 'AND' ) ); 330 $this->assertCount( 331 1, wp_list_filter( 332 $table_indices, array( 333 'Key_name' => 'PRIMARY', 334 'Column_name' => $column, 335 ), 'AND' 336 ) 337 ); 337 338 } 338 339 … … 383 384 384 385 if ( 191 != $index->Sub_part ) { 385 $this->markTestSkipped( "This test requires the index to be truncated.");386 $this->markTestSkipped( 'This test requires the index to be truncated.' ); 386 387 } 387 388 … … 407 408 FULLTEXT KEY fulltext_key (column_1) 408 409 ) ENGINE=MyISAM 409 ", false ); 410 ", false 411 ); 410 412 411 413 $this->assertSame( array(), $result ); … … 430 432 FULLTEXT KEY fulltext_key (column_1) 431 433 ) ENGINE=MyISAM 432 ", false ); 434 ", false 435 ); 433 436 434 437 $this->assertSame( array(), $result ); … … 453 456 FULLTEXT KEY fulltext_key (column_1) 454 457 ) ENGINE=MyISAM 455 ", false ); 458 ", false 459 ); 456 460 457 461 $this->assertSame( 458 462 array( 459 463 "{$wpdb->prefix}dbdelta_test.column_2" 460 => "Changed type of {$wpdb->prefix}dbdelta_test.column_2 from text to bigtext" 461 ), $result ); 464 => "Changed type of {$wpdb->prefix}dbdelta_test.column_2 from text to bigtext", 465 ), $result 466 ); 462 467 } 463 468 … … 480 485 FULLTEXT KEY fulltext_key (column_1) 481 486 ) ENGINE=MyISAM 482 ", false ); 487 ", false 488 ); 483 489 484 490 $this->assertSame( 485 491 array( 486 492 "{$wpdb->prefix}dbdelta_test.column_3" 487 => "Changed type of {$wpdb->prefix}dbdelta_test.column_3 from blob to mediumblob" 488 ), $result ); 493 => "Changed type of {$wpdb->prefix}dbdelta_test.column_3 from blob to mediumblob", 494 ), $result 495 ); 489 496 } 490 497 … … 553 560 $updates = dbDelta( $schema, false ); 554 561 555 $this->assertSame( array( 556 "{$wpdb->prefix}spatial_index_test.spatial_value2" => "Added column {$wpdb->prefix}spatial_index_test.spatial_value2", 557 "Added index {$wpdb->prefix}spatial_index_test SPATIAL KEY `spatial_key2` (`spatial_value2`)" 558 ), $updates ); 562 $this->assertSame( 563 array( 564 "{$wpdb->prefix}spatial_index_test.spatial_value2" => "Added column {$wpdb->prefix}spatial_index_test.spatial_value2", 565 "Added index {$wpdb->prefix}spatial_index_test SPATIAL KEY `spatial_key2` (`spatial_value2`)", 566 ), $updates 567 ); 559 568 560 569 $wpdb->query( "DROP TABLE IF EXISTS {$wpdb->prefix}spatial_index_test" ); … … 580 589 $updates = dbDelta( $schema ); 581 590 582 $table_indices = $wpdb->get_results( "SHOW INDEX FROM {$wpdb->prefix}dbdelta_test2" );591 $table_indices = $wpdb->get_results( "SHOW INDEX FROM {$wpdb->prefix}dbdelta_test2" ); 583 592 $compound_key_index = wp_list_filter( $table_indices, array( 'Key_name' => 'compound_key' ) ); 584 593 … … 614 623 $table_indices = $wpdb->get_results( "SHOW INDEX FROM {$wpdb->prefix}dbdelta_test" ); 615 624 616 $this->assertCount( 2, wp_list_filter( $table_indices, array( 'Key_name' => 'compound_key2' ) 625 $this->assertCount( 2, wp_list_filter( $table_indices, array( 'Key_name' => 'compound_key2' ), 'AND' ) ); 617 626 618 627 $this->assertSame( 619 628 array( 620 629 "{$wpdb->prefix}dbdelta_test.references" => "Added column {$wpdb->prefix}dbdelta_test.references", 621 0 => "Added index {$wpdb->prefix}dbdelta_test KEY `compound_key2` (`id`,`references`($this->max_index_length))",630 0 => "Added index {$wpdb->prefix}dbdelta_test KEY `compound_key2` (`id`,`references`($this->max_index_length))", 622 631 ), 623 632 $updates … … 844 853 FULLTEXT KEY FULLtext_kEY (column_1) 845 854 ) ENGINE=MyISAM 846 ", false ); 855 ", false 856 ); 847 857 848 858 $this->assertEmpty( $updates ); … … 867 877 FULLTEXT KEY fulltext_key (column_1) 868 878 ) ENGINE=MyISAM 869 ", false ); 879 ", false 880 ); 870 881 871 882 $this->assertEmpty( $updates ); … … 891 902 FULLTEXT KEY fulltext_key (column_1) 892 903 ) ENGINE=MyISAM 893 " ); 894 895 $this->assertSame( array( 896 "Added index {$wpdb->prefix}dbdelta_test KEY `changing_key_length` (`column_1`(20))" 897 ), $updates ); 904 " 905 ); 906 907 $this->assertSame( 908 array( 909 "Added index {$wpdb->prefix}dbdelta_test KEY `changing_key_length` (`column_1`(20))", 910 ), $updates 911 ); 898 912 899 913 $updates = dbDelta( … … 910 924 FULLTEXT KEY fulltext_key (column_1) 911 925 ) ENGINE=MyISAM 912 " ); 926 " 927 ); 913 928 914 929 $this->assertEmpty( $updates ); … … 927 942 FULLTEXT KEY fulltext_key (column_1) 928 943 ) ENGINE=MyISAM 929 " ); 944 " 945 ); 930 946 931 947 $this->assertEmpty( $updates ); … … 944 960 FULLTEXT KEY fulltext_key (column_1) 945 961 ) ENGINE=MyISAM 946 " ); 962 " 963 ); 947 964 948 965 $this->assertEmpty( $updates );
Note: See TracChangeset
for help on using the changeset viewer.