Chris@0
|
1 <?php
|
Chris@0
|
2
|
Chris@0
|
3 namespace Drupal\FunctionalTests\Update;
|
Chris@0
|
4
|
Chris@0
|
5 use Drupal\Component\Utility\Html;
|
Chris@17
|
6 use Drupal\Component\Render\FormattableMarkup;
|
Chris@18
|
7 use Drupal\Core\Database\Database;
|
Chris@0
|
8
|
Chris@0
|
9 /**
|
Chris@0
|
10 * Tests the update path base class.
|
Chris@0
|
11 *
|
Chris@0
|
12 * @group Update
|
Chris@17
|
13 * @group legacy
|
Chris@0
|
14 */
|
Chris@0
|
15 class UpdatePathTestBaseTest extends UpdatePathTestBase {
|
Chris@0
|
16
|
Chris@0
|
17 /**
|
Chris@0
|
18 * {@inheritdoc}
|
Chris@0
|
19 */
|
Chris@0
|
20 protected static $modules = ['update_test_schema'];
|
Chris@0
|
21
|
Chris@0
|
22 /**
|
Chris@0
|
23 * {@inheritdoc}
|
Chris@0
|
24 */
|
Chris@0
|
25 protected function setDatabaseDumpFiles() {
|
Chris@0
|
26 $this->databaseDumpFiles = [
|
Chris@0
|
27 __DIR__ . '/../../../../modules/system/tests/fixtures/update/drupal-8.bare.standard.php.gz',
|
Chris@0
|
28 __DIR__ . '/../../../../modules/system/tests/fixtures/update/drupal-8.update-test-schema-enabled.php',
|
Chris@0
|
29 ];
|
Chris@0
|
30 }
|
Chris@0
|
31
|
Chris@0
|
32 /**
|
Chris@0
|
33 * Tests that the database was properly loaded.
|
Chris@0
|
34 */
|
Chris@0
|
35 public function testDatabaseLoaded() {
|
Chris@18
|
36 // Set a value in the cache to prove caches are cleared.
|
Chris@18
|
37 \Drupal::service('cache.default')->set(__CLASS__, 'Test');
|
Chris@18
|
38
|
Chris@0
|
39 foreach (['user', 'node', 'system', 'update_test_schema'] as $module) {
|
Chris@17
|
40 $this->assertEqual(drupal_get_installed_schema_version($module), 8000, new FormattableMarkup('Module @module schema is 8000', ['@module' => $module]));
|
Chris@0
|
41 }
|
Chris@0
|
42
|
Chris@0
|
43 // Ensure that all {router} entries can be unserialized. If they cannot be
|
Chris@0
|
44 // unserialized a notice will be thrown by PHP.
|
Chris@0
|
45
|
Chris@0
|
46 $result = \Drupal::database()->query("SELECT name, route from {router}")->fetchAllKeyed(0, 1);
|
Chris@0
|
47 // For the purpose of fetching the notices and displaying more helpful error
|
Chris@0
|
48 // messages, let's override the error handler temporarily.
|
Chris@0
|
49 set_error_handler(function ($severity, $message, $filename, $lineno) {
|
Chris@0
|
50 throw new \ErrorException($message, 0, $severity, $filename, $lineno);
|
Chris@0
|
51 });
|
Chris@0
|
52 foreach ($result as $route_name => $route) {
|
Chris@0
|
53 try {
|
Chris@0
|
54 unserialize($route);
|
Chris@0
|
55 }
|
Chris@0
|
56 catch (\Exception $e) {
|
Chris@0
|
57 $this->fail(sprintf('Error "%s" while unserializing route %s', $e->getMessage(), Html::escape($route_name)));
|
Chris@0
|
58 }
|
Chris@0
|
59 }
|
Chris@0
|
60 restore_error_handler();
|
Chris@0
|
61
|
Chris@0
|
62 // Before accessing the site we need to run updates first or the site might
|
Chris@0
|
63 // be broken.
|
Chris@0
|
64 $this->runUpdates();
|
Chris@0
|
65 $this->assertEqual(\Drupal::config('system.site')->get('name'), 'Site-Install');
|
Chris@0
|
66 $this->drupalGet('<front>');
|
Chris@0
|
67 $this->assertText('Site-Install');
|
Chris@0
|
68
|
Chris@0
|
69 // Ensure that the database tasks have been run during set up. Neither MySQL
|
Chris@0
|
70 // nor SQLite make changes that are testable.
|
Chris@0
|
71 $database = $this->container->get('database');
|
Chris@0
|
72 if ($database->driver() == 'pgsql') {
|
Chris@0
|
73 $this->assertEqual('on', $database->query("SHOW standard_conforming_strings")->fetchField());
|
Chris@0
|
74 $this->assertEqual('escape', $database->query("SHOW bytea_output")->fetchField());
|
Chris@0
|
75 }
|
Chris@18
|
76 // Ensure the test runners cache has been cleared.
|
Chris@18
|
77 $this->assertFalse(\Drupal::service('cache.default')->get(__CLASS__));
|
Chris@0
|
78 }
|
Chris@0
|
79
|
Chris@0
|
80 /**
|
Chris@0
|
81 * Test that updates are properly run.
|
Chris@0
|
82 */
|
Chris@0
|
83 public function testUpdateHookN() {
|
Chris@18
|
84 $connection = Database::getConnection();
|
Chris@18
|
85
|
Chris@0
|
86 // Increment the schema version.
|
Chris@0
|
87 \Drupal::state()->set('update_test_schema_version', 8001);
|
Chris@0
|
88 $this->runUpdates();
|
Chris@0
|
89
|
Chris@18
|
90 $select = $connection->select('watchdog');
|
Chris@0
|
91 $select->orderBy('wid', 'DESC');
|
Chris@0
|
92 $select->range(0, 5);
|
Chris@0
|
93 $select->fields('watchdog', ['message']);
|
Chris@0
|
94
|
Chris@0
|
95 $container_cannot_be_saved_messages = array_filter(iterator_to_array($select->execute()), function ($row) {
|
Chris@0
|
96 return strpos($row->message, 'Container cannot be saved to cache.') !== FALSE;
|
Chris@0
|
97 });
|
Chris@0
|
98 $this->assertEqual([], $container_cannot_be_saved_messages);
|
Chris@0
|
99
|
Chris@0
|
100 // Ensure schema has changed.
|
Chris@0
|
101 $this->assertEqual(drupal_get_installed_schema_version('update_test_schema', TRUE), 8001);
|
Chris@0
|
102 // Ensure the index was added for column a.
|
Chris@18
|
103 $this->assertTrue($connection->schema()->indexExists('update_test_schema_table', 'test'), 'Version 8001 of the update_test_schema module is installed.');
|
Chris@18
|
104 }
|
Chris@18
|
105
|
Chris@18
|
106 /**
|
Chris@18
|
107 * Tests that path aliases are not processed during database updates.
|
Chris@18
|
108 */
|
Chris@18
|
109 public function testPathAliasProcessing() {
|
Chris@18
|
110 // Add a path alias for the '/admin' system path.
|
Chris@18
|
111 $database = \Drupal::database();
|
Chris@18
|
112 $database->insert('url_alias')
|
Chris@18
|
113 ->fields(['source', 'alias', 'langcode'])
|
Chris@18
|
114 ->values([
|
Chris@18
|
115 'source' => '/admin/structure',
|
Chris@18
|
116 'alias' => '/admin-structure-alias',
|
Chris@18
|
117 'langcode' => 'und',
|
Chris@18
|
118 ])
|
Chris@18
|
119 ->execute();
|
Chris@18
|
120
|
Chris@18
|
121 // Increment the schema version.
|
Chris@18
|
122 \Drupal::state()->set('update_test_schema_version', 8002);
|
Chris@18
|
123 $this->runUpdates();
|
Chris@18
|
124
|
Chris@18
|
125 // Check that the alias defined earlier is not used during the update
|
Chris@18
|
126 // process.
|
Chris@18
|
127 $this->assertSession()->linkByHrefExists('/admin/structure');
|
Chris@18
|
128 $this->assertSession()->linkByHrefNotExists('/admin-structure-alias');
|
Chris@18
|
129
|
Chris@18
|
130 $account = $this->createUser(['administer site configuration', 'access administration pages', 'access site reports']);
|
Chris@18
|
131 $this->drupalLogin($account);
|
Chris@18
|
132
|
Chris@18
|
133 // Go to the status report page and check that the alias is used.
|
Chris@18
|
134 $this->drupalGet('admin/reports/status');
|
Chris@18
|
135 $this->assertSession()->linkByHrefNotExists('/admin/structure');
|
Chris@18
|
136 $this->assertSession()->linkByHrefExists('/admin-structure-alias');
|
Chris@18
|
137 }
|
Chris@18
|
138
|
Chris@18
|
139 /**
|
Chris@18
|
140 * Tests that test running environment is updated when module list changes.
|
Chris@18
|
141 *
|
Chris@18
|
142 * @see update_test_schema_update_8003()
|
Chris@18
|
143 */
|
Chris@18
|
144 public function testModuleListChange() {
|
Chris@18
|
145 // Set a value in the cache to prove caches are cleared.
|
Chris@18
|
146 \Drupal::service('cache.default')->set(__CLASS__, 'Test');
|
Chris@18
|
147
|
Chris@18
|
148 // Ensure that modules are installed and uninstalled as expected prior to
|
Chris@18
|
149 // running updates.
|
Chris@18
|
150 $extension_config = $this->config('core.extension')->get();
|
Chris@18
|
151 $this->assertArrayHasKey('page_cache', $extension_config['module']);
|
Chris@18
|
152 $this->assertArrayNotHasKey('module_test', $extension_config['module']);
|
Chris@18
|
153
|
Chris@18
|
154 $module_list = \Drupal::moduleHandler()->getModuleList();
|
Chris@18
|
155 $this->assertArrayHasKey('page_cache', $module_list);
|
Chris@18
|
156 $this->assertArrayNotHasKey('module_test', $module_list);
|
Chris@18
|
157
|
Chris@18
|
158 $namespaces = \Drupal::getContainer()->getParameter('container.namespaces');
|
Chris@18
|
159 $this->assertArrayHasKey('Drupal\page_cache', $namespaces);
|
Chris@18
|
160 $this->assertArrayNotHasKey('Drupal\module_test', $namespaces);
|
Chris@18
|
161
|
Chris@18
|
162 // Increment the schema version so that update_test_schema_update_8003()
|
Chris@18
|
163 // runs.
|
Chris@18
|
164 \Drupal::state()->set('update_test_schema_version', 8003);
|
Chris@18
|
165 $this->runUpdates();
|
Chris@18
|
166
|
Chris@18
|
167 // Ensure that test running environment has been updated with the changes to
|
Chris@18
|
168 // the module list.
|
Chris@18
|
169 $extension_config = $this->config('core.extension')->get();
|
Chris@18
|
170 $this->assertArrayNotHasKey('page_cache', $extension_config['module']);
|
Chris@18
|
171 $this->assertArrayHasKey('module_test', $extension_config['module']);
|
Chris@18
|
172
|
Chris@18
|
173 $module_list = \Drupal::moduleHandler()->getModuleList();
|
Chris@18
|
174 $this->assertArrayNotHasKey('page_cache', $module_list);
|
Chris@18
|
175 $this->assertArrayHasKey('module_test', $module_list);
|
Chris@18
|
176
|
Chris@18
|
177 $namespaces = \Drupal::getContainer()->getParameter('container.namespaces');
|
Chris@18
|
178 $this->assertArrayNotHasKey('Drupal\page_cache', $namespaces);
|
Chris@18
|
179 $this->assertArrayHasKey('Drupal\module_test', $namespaces);
|
Chris@18
|
180
|
Chris@18
|
181 // Ensure the test runners cache has been cleared.
|
Chris@18
|
182 $this->assertFalse(\Drupal::service('cache.default')->get(__CLASS__));
|
Chris@0
|
183 }
|
Chris@0
|
184
|
Chris@0
|
185 }
|