Pull merge.
[yaffs-website] / web / core / modules / system / src / Tests / Path / UrlAliasFixtures.php
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    * Returns the table definition for the URL alias fixtures.
76    *
77    * @return array
78    *   Table definitions.
79    */
80   public function tableDefinition() {
81     $tables = [];
82
83     // Prime the drupal_get_filename() cache with the location of the system
84     // module as its location is known and shouldn't change.
85     // @todo Remove as part of https://www.drupal.org/node/2186491
86     drupal_get_filename('module', 'system', 'core/modules/system/system.info.yml');
87     module_load_install('system');
88     $schema = system_schema();
89
90     $tables['url_alias'] = AliasStorage::schemaDefinition();
91     $tables['key_value'] = $schema['key_value'];
92
93     return $tables;
94   }
95
96 }