Chris@0: databaseDumpFiles = [ Chris@0: __DIR__ . '/../../../../modules/system/tests/fixtures/update/drupal-8.bare.standard.php.gz', Chris@0: __DIR__ . '/../../../../modules/system/tests/fixtures/update/drupal-8.update-test-schema-enabled.php', Chris@0: ]; Chris@0: } Chris@0: Chris@0: /** Chris@0: * Tests that the database was properly loaded. Chris@0: */ Chris@0: public function testDatabaseLoaded() { Chris@0: foreach (['user', 'node', 'system', 'update_test_schema'] as $module) { Chris@0: $this->assertEqual(drupal_get_installed_schema_version($module), 8000, SafeMarkup::format('Module @module schema is 8000', ['@module' => $module])); Chris@0: } Chris@0: Chris@0: // Ensure that all {router} entries can be unserialized. If they cannot be Chris@0: // unserialized a notice will be thrown by PHP. Chris@0: Chris@0: $result = \Drupal::database()->query("SELECT name, route from {router}")->fetchAllKeyed(0, 1); Chris@0: // For the purpose of fetching the notices and displaying more helpful error Chris@0: // messages, let's override the error handler temporarily. Chris@0: set_error_handler(function ($severity, $message, $filename, $lineno) { Chris@0: throw new \ErrorException($message, 0, $severity, $filename, $lineno); Chris@0: }); Chris@0: foreach ($result as $route_name => $route) { Chris@0: try { Chris@0: unserialize($route); Chris@0: } Chris@0: catch (\Exception $e) { Chris@0: $this->fail(sprintf('Error "%s" while unserializing route %s', $e->getMessage(), Html::escape($route_name))); Chris@0: } Chris@0: } Chris@0: restore_error_handler(); Chris@0: Chris@0: // Before accessing the site we need to run updates first or the site might Chris@0: // be broken. Chris@0: $this->runUpdates(); Chris@0: $this->assertEqual(\Drupal::config('system.site')->get('name'), 'Site-Install'); Chris@0: $this->drupalGet(''); Chris@0: $this->assertText('Site-Install'); Chris@0: Chris@0: // Ensure that the database tasks have been run during set up. Neither MySQL Chris@0: // nor SQLite make changes that are testable. Chris@0: $database = $this->container->get('database'); Chris@0: if ($database->driver() == 'pgsql') { Chris@0: $this->assertEqual('on', $database->query("SHOW standard_conforming_strings")->fetchField()); Chris@0: $this->assertEqual('escape', $database->query("SHOW bytea_output")->fetchField()); Chris@0: } Chris@0: } Chris@0: Chris@0: /** Chris@0: * Test that updates are properly run. Chris@0: */ Chris@0: public function testUpdateHookN() { Chris@0: // Increment the schema version. Chris@0: \Drupal::state()->set('update_test_schema_version', 8001); Chris@0: $this->runUpdates(); Chris@0: Chris@0: $select = \Drupal::database()->select('watchdog'); Chris@0: $select->orderBy('wid', 'DESC'); Chris@0: $select->range(0, 5); Chris@0: $select->fields('watchdog', ['message']); Chris@0: Chris@0: $container_cannot_be_saved_messages = array_filter(iterator_to_array($select->execute()), function ($row) { Chris@0: return strpos($row->message, 'Container cannot be saved to cache.') !== FALSE; Chris@0: }); Chris@0: $this->assertEqual([], $container_cannot_be_saved_messages); Chris@0: Chris@0: // Ensure schema has changed. Chris@0: $this->assertEqual(drupal_get_installed_schema_version('update_test_schema', TRUE), 8001); Chris@0: // Ensure the index was added for column a. Chris@0: $this->assertTrue(db_index_exists('update_test_schema_table', 'test'), 'Version 8001 of the update_test_schema module is installed.'); Chris@0: } Chris@0: Chris@0: }