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