Révision 01dfd3b5
Ajouté par Assos Assos il y a plus de 3 ans
drupal7/modules/simpletest/tests/schema.test | ||
---|---|---|
381 | 381 |
|
382 | 382 |
db_drop_field($table_name, $field_name); |
383 | 383 |
} |
384 |
|
|
385 |
/** |
|
386 |
* Tests the findTables() method. |
|
387 |
*/ |
|
388 |
public function testFindTables() { |
|
389 |
// We will be testing with three tables, two of them using the default |
|
390 |
// prefix and the third one with an individually specified prefix. |
|
391 |
|
|
392 |
// Set up a new connection with different connection info. |
|
393 |
$connection_info = Database::getConnectionInfo(); |
|
394 |
|
|
395 |
// Add per-table prefix to the second table. |
|
396 |
$new_connection_info = $connection_info['default']; |
|
397 |
$new_connection_info['prefix']['test_2_table'] = $new_connection_info['prefix']['default'] . '_shared_'; |
|
398 |
Database::addConnectionInfo('test', 'default', $new_connection_info); |
|
399 |
|
|
400 |
Database::setActiveConnection('test'); |
|
401 |
|
|
402 |
// Create the tables. |
|
403 |
$table_specification = array( |
|
404 |
'description' => 'Test table.', |
|
405 |
'fields' => array( |
|
406 |
'id' => array( |
|
407 |
'type' => 'int', |
|
408 |
'default' => NULL, |
|
409 |
), |
|
410 |
), |
|
411 |
); |
|
412 |
Database::getConnection()->schema()->createTable('test_1_table', $table_specification); |
|
413 |
Database::getConnection()->schema()->createTable('test_2_table', $table_specification); |
|
414 |
Database::getConnection()->schema()->createTable('the_third_table', $table_specification); |
|
415 |
|
|
416 |
// Check the "all tables" syntax. |
|
417 |
$tables = Database::getConnection()->schema()->findTablesD8('%'); |
|
418 |
sort($tables); |
|
419 |
$expected = array( |
|
420 |
'test_1_table', |
|
421 |
// This table uses a per-table prefix, yet it is returned as un-prefixed. |
|
422 |
'test_2_table', |
|
423 |
'the_third_table', |
|
424 |
); |
|
425 |
|
|
426 |
$this->assertTrue(!array_diff($expected, $tables), 'All tables were found.'); |
|
427 |
|
|
428 |
// Check the restrictive syntax. |
|
429 |
$tables = Database::getConnection()->schema()->findTablesD8('test_%'); |
|
430 |
sort($tables); |
|
431 |
$expected = array( |
|
432 |
'test_1_table', |
|
433 |
'test_2_table', |
|
434 |
); |
|
435 |
$this->assertEqual($tables, $expected, 'Two tables were found.'); |
|
436 |
|
|
437 |
// Go back to the initial connection. |
|
438 |
Database::setActiveConnection('default'); |
|
439 |
} |
|
384 | 440 |
} |
Formats disponibles : Unified diff
Udpate to 7.77