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