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@0
|
6 use Drupal\Component\Utility\SafeMarkup;
|
Chris@0
|
7
|
Chris@0
|
8 /**
|
Chris@0
|
9 * Tests the update path base class.
|
Chris@0
|
10 *
|
Chris@0
|
11 * @group Update
|
Chris@0
|
12 */
|
Chris@0
|
13 class UpdatePathTestBaseTest extends UpdatePathTestBase {
|
Chris@0
|
14
|
Chris@0
|
15 /**
|
Chris@0
|
16 * {@inheritdoc}
|
Chris@0
|
17 */
|
Chris@0
|
18 protected static $modules = ['update_test_schema'];
|
Chris@0
|
19
|
Chris@0
|
20 /**
|
Chris@0
|
21 * {@inheritdoc}
|
Chris@0
|
22 */
|
Chris@0
|
23 protected function setDatabaseDumpFiles() {
|
Chris@0
|
24 $this->databaseDumpFiles = [
|
Chris@0
|
25 __DIR__ . '/../../../../modules/system/tests/fixtures/update/drupal-8.bare.standard.php.gz',
|
Chris@0
|
26 __DIR__ . '/../../../../modules/system/tests/fixtures/update/drupal-8.update-test-schema-enabled.php',
|
Chris@0
|
27 ];
|
Chris@0
|
28 }
|
Chris@0
|
29
|
Chris@0
|
30 /**
|
Chris@0
|
31 * Tests that the database was properly loaded.
|
Chris@0
|
32 */
|
Chris@0
|
33 public function testDatabaseLoaded() {
|
Chris@0
|
34 foreach (['user', 'node', 'system', 'update_test_schema'] as $module) {
|
Chris@0
|
35 $this->assertEqual(drupal_get_installed_schema_version($module), 8000, SafeMarkup::format('Module @module schema is 8000', ['@module' => $module]));
|
Chris@0
|
36 }
|
Chris@0
|
37
|
Chris@0
|
38 // Ensure that all {router} entries can be unserialized. If they cannot be
|
Chris@0
|
39 // unserialized a notice will be thrown by PHP.
|
Chris@0
|
40
|
Chris@0
|
41 $result = \Drupal::database()->query("SELECT name, route from {router}")->fetchAllKeyed(0, 1);
|
Chris@0
|
42 // For the purpose of fetching the notices and displaying more helpful error
|
Chris@0
|
43 // messages, let's override the error handler temporarily.
|
Chris@0
|
44 set_error_handler(function ($severity, $message, $filename, $lineno) {
|
Chris@0
|
45 throw new \ErrorException($message, 0, $severity, $filename, $lineno);
|
Chris@0
|
46 });
|
Chris@0
|
47 foreach ($result as $route_name => $route) {
|
Chris@0
|
48 try {
|
Chris@0
|
49 unserialize($route);
|
Chris@0
|
50 }
|
Chris@0
|
51 catch (\Exception $e) {
|
Chris@0
|
52 $this->fail(sprintf('Error "%s" while unserializing route %s', $e->getMessage(), Html::escape($route_name)));
|
Chris@0
|
53 }
|
Chris@0
|
54 }
|
Chris@0
|
55 restore_error_handler();
|
Chris@0
|
56
|
Chris@0
|
57 // Before accessing the site we need to run updates first or the site might
|
Chris@0
|
58 // be broken.
|
Chris@0
|
59 $this->runUpdates();
|
Chris@0
|
60 $this->assertEqual(\Drupal::config('system.site')->get('name'), 'Site-Install');
|
Chris@0
|
61 $this->drupalGet('<front>');
|
Chris@0
|
62 $this->assertText('Site-Install');
|
Chris@0
|
63
|
Chris@0
|
64 // Ensure that the database tasks have been run during set up. Neither MySQL
|
Chris@0
|
65 // nor SQLite make changes that are testable.
|
Chris@0
|
66 $database = $this->container->get('database');
|
Chris@0
|
67 if ($database->driver() == 'pgsql') {
|
Chris@0
|
68 $this->assertEqual('on', $database->query("SHOW standard_conforming_strings")->fetchField());
|
Chris@0
|
69 $this->assertEqual('escape', $database->query("SHOW bytea_output")->fetchField());
|
Chris@0
|
70 }
|
Chris@0
|
71 }
|
Chris@0
|
72
|
Chris@0
|
73 /**
|
Chris@0
|
74 * Test that updates are properly run.
|
Chris@0
|
75 */
|
Chris@0
|
76 public function testUpdateHookN() {
|
Chris@0
|
77 // Increment the schema version.
|
Chris@0
|
78 \Drupal::state()->set('update_test_schema_version', 8001);
|
Chris@0
|
79 $this->runUpdates();
|
Chris@0
|
80
|
Chris@0
|
81 $select = \Drupal::database()->select('watchdog');
|
Chris@0
|
82 $select->orderBy('wid', 'DESC');
|
Chris@0
|
83 $select->range(0, 5);
|
Chris@0
|
84 $select->fields('watchdog', ['message']);
|
Chris@0
|
85
|
Chris@0
|
86 $container_cannot_be_saved_messages = array_filter(iterator_to_array($select->execute()), function ($row) {
|
Chris@0
|
87 return strpos($row->message, 'Container cannot be saved to cache.') !== FALSE;
|
Chris@0
|
88 });
|
Chris@0
|
89 $this->assertEqual([], $container_cannot_be_saved_messages);
|
Chris@0
|
90
|
Chris@0
|
91 // Ensure schema has changed.
|
Chris@0
|
92 $this->assertEqual(drupal_get_installed_schema_version('update_test_schema', TRUE), 8001);
|
Chris@0
|
93 // Ensure the index was added for column a.
|
Chris@0
|
94 $this->assertTrue(db_index_exists('update_test_schema_table', 'test'), 'Version 8001 of the update_test_schema module is installed.');
|
Chris@0
|
95 }
|
Chris@0
|
96
|
Chris@0
|
97 }
|