Mercurial > hg > cmmr2012-drupal-site
comparison core/tests/Drupal/FunctionalTests/Update/UpdatePathTestBaseTest.php @ 5:12f9dff5fda9 tip
Update to Drupal core 8.7.1
author | Chris Cannam |
---|---|
date | Thu, 09 May 2019 15:34:47 +0100 |
parents | a9cd425dd02b |
children |
comparison
equal
deleted
inserted
replaced
4:a9cd425dd02b | 5:12f9dff5fda9 |
---|---|
2 | 2 |
3 namespace Drupal\FunctionalTests\Update; | 3 namespace Drupal\FunctionalTests\Update; |
4 | 4 |
5 use Drupal\Component\Utility\Html; | 5 use Drupal\Component\Utility\Html; |
6 use Drupal\Component\Render\FormattableMarkup; | 6 use Drupal\Component\Render\FormattableMarkup; |
7 use Drupal\Core\Database\Database; | |
7 | 8 |
8 /** | 9 /** |
9 * Tests the update path base class. | 10 * Tests the update path base class. |
10 * | 11 * |
11 * @group Update | 12 * @group Update |
30 | 31 |
31 /** | 32 /** |
32 * Tests that the database was properly loaded. | 33 * Tests that the database was properly loaded. |
33 */ | 34 */ |
34 public function testDatabaseLoaded() { | 35 public function testDatabaseLoaded() { |
36 // Set a value in the cache to prove caches are cleared. | |
37 \Drupal::service('cache.default')->set(__CLASS__, 'Test'); | |
38 | |
35 foreach (['user', 'node', 'system', 'update_test_schema'] as $module) { | 39 foreach (['user', 'node', 'system', 'update_test_schema'] as $module) { |
36 $this->assertEqual(drupal_get_installed_schema_version($module), 8000, new FormattableMarkup('Module @module schema is 8000', ['@module' => $module])); | 40 $this->assertEqual(drupal_get_installed_schema_version($module), 8000, new FormattableMarkup('Module @module schema is 8000', ['@module' => $module])); |
37 } | 41 } |
38 | 42 |
39 // Ensure that all {router} entries can be unserialized. If they cannot be | 43 // Ensure that all {router} entries can be unserialized. If they cannot be |
67 $database = $this->container->get('database'); | 71 $database = $this->container->get('database'); |
68 if ($database->driver() == 'pgsql') { | 72 if ($database->driver() == 'pgsql') { |
69 $this->assertEqual('on', $database->query("SHOW standard_conforming_strings")->fetchField()); | 73 $this->assertEqual('on', $database->query("SHOW standard_conforming_strings")->fetchField()); |
70 $this->assertEqual('escape', $database->query("SHOW bytea_output")->fetchField()); | 74 $this->assertEqual('escape', $database->query("SHOW bytea_output")->fetchField()); |
71 } | 75 } |
76 // Ensure the test runners cache has been cleared. | |
77 $this->assertFalse(\Drupal::service('cache.default')->get(__CLASS__)); | |
72 } | 78 } |
73 | 79 |
74 /** | 80 /** |
75 * Test that updates are properly run. | 81 * Test that updates are properly run. |
76 */ | 82 */ |
77 public function testUpdateHookN() { | 83 public function testUpdateHookN() { |
84 $connection = Database::getConnection(); | |
85 | |
78 // Increment the schema version. | 86 // Increment the schema version. |
79 \Drupal::state()->set('update_test_schema_version', 8001); | 87 \Drupal::state()->set('update_test_schema_version', 8001); |
80 $this->runUpdates(); | 88 $this->runUpdates(); |
81 | 89 |
82 $select = \Drupal::database()->select('watchdog'); | 90 $select = $connection->select('watchdog'); |
83 $select->orderBy('wid', 'DESC'); | 91 $select->orderBy('wid', 'DESC'); |
84 $select->range(0, 5); | 92 $select->range(0, 5); |
85 $select->fields('watchdog', ['message']); | 93 $select->fields('watchdog', ['message']); |
86 | 94 |
87 $container_cannot_be_saved_messages = array_filter(iterator_to_array($select->execute()), function ($row) { | 95 $container_cannot_be_saved_messages = array_filter(iterator_to_array($select->execute()), function ($row) { |
90 $this->assertEqual([], $container_cannot_be_saved_messages); | 98 $this->assertEqual([], $container_cannot_be_saved_messages); |
91 | 99 |
92 // Ensure schema has changed. | 100 // Ensure schema has changed. |
93 $this->assertEqual(drupal_get_installed_schema_version('update_test_schema', TRUE), 8001); | 101 $this->assertEqual(drupal_get_installed_schema_version('update_test_schema', TRUE), 8001); |
94 // Ensure the index was added for column a. | 102 // Ensure the index was added for column a. |
95 $this->assertTrue(db_index_exists('update_test_schema_table', 'test'), 'Version 8001 of the update_test_schema module is installed.'); | 103 $this->assertTrue($connection->schema()->indexExists('update_test_schema_table', 'test'), 'Version 8001 of the update_test_schema module is installed.'); |
104 } | |
105 | |
106 /** | |
107 * Tests that path aliases are not processed during database updates. | |
108 */ | |
109 public function testPathAliasProcessing() { | |
110 // Add a path alias for the '/admin' system path. | |
111 $database = \Drupal::database(); | |
112 $database->insert('url_alias') | |
113 ->fields(['source', 'alias', 'langcode']) | |
114 ->values([ | |
115 'source' => '/admin/structure', | |
116 'alias' => '/admin-structure-alias', | |
117 'langcode' => 'und', | |
118 ]) | |
119 ->execute(); | |
120 | |
121 // Increment the schema version. | |
122 \Drupal::state()->set('update_test_schema_version', 8002); | |
123 $this->runUpdates(); | |
124 | |
125 // Check that the alias defined earlier is not used during the update | |
126 // process. | |
127 $this->assertSession()->linkByHrefExists('/admin/structure'); | |
128 $this->assertSession()->linkByHrefNotExists('/admin-structure-alias'); | |
129 | |
130 $account = $this->createUser(['administer site configuration', 'access administration pages', 'access site reports']); | |
131 $this->drupalLogin($account); | |
132 | |
133 // Go to the status report page and check that the alias is used. | |
134 $this->drupalGet('admin/reports/status'); | |
135 $this->assertSession()->linkByHrefNotExists('/admin/structure'); | |
136 $this->assertSession()->linkByHrefExists('/admin-structure-alias'); | |
137 } | |
138 | |
139 /** | |
140 * Tests that test running environment is updated when module list changes. | |
141 * | |
142 * @see update_test_schema_update_8003() | |
143 */ | |
144 public function testModuleListChange() { | |
145 // Set a value in the cache to prove caches are cleared. | |
146 \Drupal::service('cache.default')->set(__CLASS__, 'Test'); | |
147 | |
148 // Ensure that modules are installed and uninstalled as expected prior to | |
149 // running updates. | |
150 $extension_config = $this->config('core.extension')->get(); | |
151 $this->assertArrayHasKey('page_cache', $extension_config['module']); | |
152 $this->assertArrayNotHasKey('module_test', $extension_config['module']); | |
153 | |
154 $module_list = \Drupal::moduleHandler()->getModuleList(); | |
155 $this->assertArrayHasKey('page_cache', $module_list); | |
156 $this->assertArrayNotHasKey('module_test', $module_list); | |
157 | |
158 $namespaces = \Drupal::getContainer()->getParameter('container.namespaces'); | |
159 $this->assertArrayHasKey('Drupal\page_cache', $namespaces); | |
160 $this->assertArrayNotHasKey('Drupal\module_test', $namespaces); | |
161 | |
162 // Increment the schema version so that update_test_schema_update_8003() | |
163 // runs. | |
164 \Drupal::state()->set('update_test_schema_version', 8003); | |
165 $this->runUpdates(); | |
166 | |
167 // Ensure that test running environment has been updated with the changes to | |
168 // the module list. | |
169 $extension_config = $this->config('core.extension')->get(); | |
170 $this->assertArrayNotHasKey('page_cache', $extension_config['module']); | |
171 $this->assertArrayHasKey('module_test', $extension_config['module']); | |
172 | |
173 $module_list = \Drupal::moduleHandler()->getModuleList(); | |
174 $this->assertArrayNotHasKey('page_cache', $module_list); | |
175 $this->assertArrayHasKey('module_test', $module_list); | |
176 | |
177 $namespaces = \Drupal::getContainer()->getParameter('container.namespaces'); | |
178 $this->assertArrayNotHasKey('Drupal\page_cache', $namespaces); | |
179 $this->assertArrayHasKey('Drupal\module_test', $namespaces); | |
180 | |
181 // Ensure the test runners cache has been cleared. | |
182 $this->assertFalse(\Drupal::service('cache.default')->get(__CLASS__)); | |
96 } | 183 } |
97 | 184 |
98 } | 185 } |