| | 277 | /** |
| | 278 | * @ticket 34872 |
| | 279 | * |
| | 280 | * @dataProvider data_provider_schema_indexes |
| | 281 | * |
| | 282 | * @param string $schema The table schema. |
| | 283 | */ |
| | 284 | public function test_no_duplicate_indexes( $schema ) { |
| | 285 | |
| | 286 | // Run once to create the table and indexes. |
| | 287 | $updates = dbDelta( $schema ); |
| | 288 | |
| | 289 | $this->assertCount( 1, $updates ); |
| | 290 | $this->assertEquals( |
| | 291 | array( 'wptests_dbdelta_test_2' => 'Created table wptests_dbdelta_test_2' ) |
| | 292 | , $updates |
| | 293 | ); |
| | 294 | |
| | 295 | // Run again. Nothing should happen. |
| | 296 | $updates = dbDelta( $schema ); |
| | 297 | |
| | 298 | $this->assertSame( array(), $updates ); |
| | 299 | } |
| | 300 | |
| | 301 | /** |
| | 302 | * Provides sets of table schemas to test index detection. |
| | 303 | * |
| | 304 | * @return array |
| | 305 | */ |
| | 306 | public function data_provider_schema_indexes() { |
| | 307 | |
| | 308 | global $wpdb; |
| | 309 | |
| | 310 | return array( |
| | 311 | 'named' => array( |
| | 312 | "CREATE TABLE {$wpdb->prefix}dbdelta_test_2 ( |
| | 313 | id bigint(20) NOT NULL AUTO_INCREMENT, |
| | 314 | KEY id (id) |
| | 315 | )" |
| | 316 | ), |
| | 317 | 'unnamed' => array( |
| | 318 | "CREATE TABLE {$wpdb->prefix}dbdelta_test_2 ( |
| | 319 | id bigint(20) NOT NULL AUTO_INCREMENT, |
| | 320 | KEY (id) |
| | 321 | )" |
| | 322 | ), |
| | 323 | 'primary' => array( |
| | 324 | "CREATE TABLE {$wpdb->prefix}dbdelta_test_2 ( |
| | 325 | id bigint(20) NOT NULL AUTO_INCREMENT, |
| | 326 | PRIMARY KEY (id) |
| | 327 | )" |
| | 328 | ), |
| | 329 | 'primary_extra_space' => array( |
| | 330 | "CREATE TABLE {$wpdb->prefix}dbdelta_test_2 ( |
| | 331 | id bigint(20) NOT NULL AUTO_INCREMENT, |
| | 332 | PRIMARY KEY (id) |
| | 333 | )" |
| | 334 | ), |
| | 335 | ); |
| | 336 | } |
| | 337 | |