Mercurial > hg > isophonics-drupal-site
comparison core/modules/system/src/Tests/Path/UrlAliasFixtures.php @ 0:4c8ae668cc8c
Initial import (non-working)
author | Chris Cannam |
---|---|
date | Wed, 29 Nov 2017 16:09:58 +0000 |
parents | |
children | 129ea1e6d783 |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:4c8ae668cc8c |
---|---|
1 <?php | |
2 | |
3 namespace Drupal\system\Tests\Path; | |
4 | |
5 use Drupal\Core\Database\Connection; | |
6 use Drupal\Core\Path\AliasStorage; | |
7 | |
8 /** | |
9 * Utility methods to generate sample data, database configuration, etc. | |
10 */ | |
11 class UrlAliasFixtures { | |
12 | |
13 /** | |
14 * Create the tables required for the sample data. | |
15 * | |
16 * @param \Drupal\Core\Database\Connection $connection | |
17 * The connection to use to create the tables. | |
18 */ | |
19 public function createTables(Connection $connection) { | |
20 $tables = $this->tableDefinition(); | |
21 $schema = $connection->schema(); | |
22 | |
23 foreach ($tables as $name => $table) { | |
24 $schema->dropTable($name); | |
25 $schema->createTable($name, $table); | |
26 } | |
27 } | |
28 | |
29 /** | |
30 * Drop the tables used for the sample data. | |
31 * | |
32 * @param \Drupal\Core\Database\Connection $connection | |
33 * The connection to use to drop the tables. | |
34 */ | |
35 public function dropTables(Connection $connection) { | |
36 $tables = $this->tableDefinition(); | |
37 $schema = $connection->schema(); | |
38 | |
39 foreach ($tables as $name => $table) { | |
40 $schema->dropTable($name); | |
41 } | |
42 } | |
43 | |
44 /** | |
45 * Returns an array of URL aliases for testing. | |
46 * | |
47 * @return array of URL alias definitions. | |
48 */ | |
49 public function sampleUrlAliases() { | |
50 return [ | |
51 [ | |
52 'source' => '/node/1', | |
53 'alias' => '/alias_for_node_1_en', | |
54 'langcode' => 'en' | |
55 ], | |
56 [ | |
57 'source' => '/node/2', | |
58 'alias' => '/alias_for_node_2_en', | |
59 'langcode' => 'en' | |
60 ], | |
61 [ | |
62 'source' => '/node/1', | |
63 'alias' => '/alias_for_node_1_fr', | |
64 'langcode' => 'fr' | |
65 ], | |
66 [ | |
67 'source' => '/node/1', | |
68 'alias' => '/alias_for_node_1_und', | |
69 'langcode' => 'und' | |
70 ] | |
71 ]; | |
72 } | |
73 | |
74 | |
75 /** | |
76 * Returns the table definition for the URL alias fixtures. | |
77 * | |
78 * @return array | |
79 * Table definitions. | |
80 */ | |
81 public function tableDefinition() { | |
82 $tables = []; | |
83 | |
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(); | |
90 | |
91 $tables['url_alias'] = AliasStorage::schemaDefinition(); | |
92 $tables['key_value'] = $schema['key_value']; | |
93 | |
94 return $tables; | |
95 } | |
96 | |
97 } |