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