Chris@0
|
1 <?php
|
Chris@0
|
2
|
Chris@0
|
3 namespace Drupal\system\Tests\Path;
|
Chris@0
|
4
|
Chris@0
|
5 use Drupal\Core\Database\Connection;
|
Chris@0
|
6 use Drupal\Core\Path\AliasStorage;
|
Chris@0
|
7
|
Chris@0
|
8 /**
|
Chris@0
|
9 * Utility methods to generate sample data, database configuration, etc.
|
Chris@0
|
10 */
|
Chris@0
|
11 class UrlAliasFixtures {
|
Chris@0
|
12
|
Chris@0
|
13 /**
|
Chris@0
|
14 * Create the tables required for the sample data.
|
Chris@0
|
15 *
|
Chris@0
|
16 * @param \Drupal\Core\Database\Connection $connection
|
Chris@0
|
17 * The connection to use to create the tables.
|
Chris@0
|
18 */
|
Chris@0
|
19 public function createTables(Connection $connection) {
|
Chris@0
|
20 $tables = $this->tableDefinition();
|
Chris@0
|
21 $schema = $connection->schema();
|
Chris@0
|
22
|
Chris@0
|
23 foreach ($tables as $name => $table) {
|
Chris@0
|
24 $schema->dropTable($name);
|
Chris@0
|
25 $schema->createTable($name, $table);
|
Chris@0
|
26 }
|
Chris@0
|
27 }
|
Chris@0
|
28
|
Chris@0
|
29 /**
|
Chris@0
|
30 * Drop the tables used for the sample data.
|
Chris@0
|
31 *
|
Chris@0
|
32 * @param \Drupal\Core\Database\Connection $connection
|
Chris@0
|
33 * The connection to use to drop the tables.
|
Chris@0
|
34 */
|
Chris@0
|
35 public function dropTables(Connection $connection) {
|
Chris@0
|
36 $tables = $this->tableDefinition();
|
Chris@0
|
37 $schema = $connection->schema();
|
Chris@0
|
38
|
Chris@0
|
39 foreach ($tables as $name => $table) {
|
Chris@0
|
40 $schema->dropTable($name);
|
Chris@0
|
41 }
|
Chris@0
|
42 }
|
Chris@0
|
43
|
Chris@0
|
44 /**
|
Chris@0
|
45 * Returns an array of URL aliases for testing.
|
Chris@0
|
46 *
|
Chris@0
|
47 * @return array of URL alias definitions.
|
Chris@0
|
48 */
|
Chris@0
|
49 public function sampleUrlAliases() {
|
Chris@0
|
50 return [
|
Chris@0
|
51 [
|
Chris@0
|
52 'source' => '/node/1',
|
Chris@0
|
53 'alias' => '/alias_for_node_1_en',
|
Chris@17
|
54 'langcode' => 'en',
|
Chris@0
|
55 ],
|
Chris@0
|
56 [
|
Chris@0
|
57 'source' => '/node/2',
|
Chris@0
|
58 'alias' => '/alias_for_node_2_en',
|
Chris@17
|
59 'langcode' => 'en',
|
Chris@0
|
60 ],
|
Chris@0
|
61 [
|
Chris@0
|
62 'source' => '/node/1',
|
Chris@0
|
63 'alias' => '/alias_for_node_1_fr',
|
Chris@17
|
64 'langcode' => 'fr',
|
Chris@0
|
65 ],
|
Chris@0
|
66 [
|
Chris@0
|
67 'source' => '/node/1',
|
Chris@0
|
68 'alias' => '/alias_for_node_1_und',
|
Chris@17
|
69 'langcode' => 'und',
|
Chris@17
|
70 ],
|
Chris@0
|
71 ];
|
Chris@0
|
72 }
|
Chris@0
|
73
|
Chris@0
|
74 /**
|
Chris@0
|
75 * Returns the table definition for the URL alias fixtures.
|
Chris@0
|
76 *
|
Chris@0
|
77 * @return array
|
Chris@0
|
78 * Table definitions.
|
Chris@0
|
79 */
|
Chris@0
|
80 public function tableDefinition() {
|
Chris@0
|
81 $tables = [];
|
Chris@0
|
82
|
Chris@0
|
83 // Prime the drupal_get_filename() cache with the location of the system
|
Chris@0
|
84 // module as its location is known and shouldn't change.
|
Chris@0
|
85 // @todo Remove as part of https://www.drupal.org/node/2186491
|
Chris@0
|
86 drupal_get_filename('module', 'system', 'core/modules/system/system.info.yml');
|
Chris@0
|
87 module_load_install('system');
|
Chris@0
|
88 $schema = system_schema();
|
Chris@0
|
89
|
Chris@0
|
90 $tables['url_alias'] = AliasStorage::schemaDefinition();
|
Chris@0
|
91 $tables['key_value'] = $schema['key_value'];
|
Chris@0
|
92
|
Chris@0
|
93 return $tables;
|
Chris@0
|
94 }
|
Chris@0
|
95
|
Chris@0
|
96 }
|