3 namespace Drupal\system\Tests\Path;
5 use Drupal\Core\Database\Connection;
6 use Drupal\Core\Path\AliasStorage;
9 * Utility methods to generate sample data, database configuration, etc.
11 class UrlAliasFixtures {
14 * Create the tables required for the sample data.
16 * @param \Drupal\Core\Database\Connection $connection
17 * The connection to use to create the tables.
19 public function createTables(Connection $connection) {
20 $tables = $this->tableDefinition();
21 $schema = $connection->schema();
23 foreach ($tables as $name => $table) {
24 $schema->dropTable($name);
25 $schema->createTable($name, $table);
30 * Drop the tables used for the sample data.
32 * @param \Drupal\Core\Database\Connection $connection
33 * The connection to use to drop the tables.
35 public function dropTables(Connection $connection) {
36 $tables = $this->tableDefinition();
37 $schema = $connection->schema();
39 foreach ($tables as $name => $table) {
40 $schema->dropTable($name);
45 * Returns an array of URL aliases for testing.
47 * @return array of URL alias definitions.
49 public function sampleUrlAliases() {
52 'source' => '/node/1',
53 'alias' => '/alias_for_node_1_en',
57 'source' => '/node/2',
58 'alias' => '/alias_for_node_2_en',
62 'source' => '/node/1',
63 'alias' => '/alias_for_node_1_fr',
67 'source' => '/node/1',
68 'alias' => '/alias_for_node_1_und',
76 * Returns the table definition for the URL alias fixtures.
81 public function tableDefinition() {
84 // Prime the drupal_get_filename() cache with the location of the system
85 // module as its location is known and shouldn't change.
86 // @todo Remove as part of https://www.drupal.org/node/2186491
87 drupal_get_filename('module', 'system', 'core/modules/system/system.info.yml');
88 module_load_install('system');
89 $schema = system_schema();
91 $tables['url_alias'] = AliasStorage::schemaDefinition();
92 $tables['key_value'] = $schema['key_value'];