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@18: // Set a value in the cache to prove caches are cleared. Chris@18: \Drupal::service('cache.default')->set(__CLASS__, 'Test'); Chris@18: Chris@0: foreach (['user', 'node', 'system', 'update_test_schema'] as $module) { Chris@17: $this->assertEqual(drupal_get_installed_schema_version($module), 8000, new FormattableMarkup('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@18: // Ensure the test runners cache has been cleared. Chris@18: $this->assertFalse(\Drupal::service('cache.default')->get(__CLASS__)); Chris@0: } Chris@0: Chris@0: /** Chris@0: * Test that updates are properly run. Chris@0: */ Chris@0: public function testUpdateHookN() { Chris@18: $connection = Database::getConnection(); Chris@18: Chris@0: // Increment the schema version. Chris@0: \Drupal::state()->set('update_test_schema_version', 8001); Chris@0: $this->runUpdates(); Chris@0: Chris@18: $select = $connection->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@18: $this->assertTrue($connection->schema()->indexExists('update_test_schema_table', 'test'), 'Version 8001 of the update_test_schema module is installed.'); Chris@18: } Chris@18: Chris@18: /** Chris@18: * Tests that path aliases are not processed during database updates. Chris@18: */ Chris@18: public function testPathAliasProcessing() { Chris@18: // Add a path alias for the '/admin' system path. Chris@18: $database = \Drupal::database(); Chris@18: $database->insert('url_alias') Chris@18: ->fields(['source', 'alias', 'langcode']) Chris@18: ->values([ Chris@18: 'source' => '/admin/structure', Chris@18: 'alias' => '/admin-structure-alias', Chris@18: 'langcode' => 'und', Chris@18: ]) Chris@18: ->execute(); Chris@18: Chris@18: // Increment the schema version. Chris@18: \Drupal::state()->set('update_test_schema_version', 8002); Chris@18: $this->runUpdates(); Chris@18: Chris@18: // Check that the alias defined earlier is not used during the update Chris@18: // process. Chris@18: $this->assertSession()->linkByHrefExists('/admin/structure'); Chris@18: $this->assertSession()->linkByHrefNotExists('/admin-structure-alias'); Chris@18: Chris@18: $account = $this->createUser(['administer site configuration', 'access administration pages', 'access site reports']); Chris@18: $this->drupalLogin($account); Chris@18: Chris@18: // Go to the status report page and check that the alias is used. Chris@18: $this->drupalGet('admin/reports/status'); Chris@18: $this->assertSession()->linkByHrefNotExists('/admin/structure'); Chris@18: $this->assertSession()->linkByHrefExists('/admin-structure-alias'); Chris@18: } Chris@18: Chris@18: /** Chris@18: * Tests that test running environment is updated when module list changes. Chris@18: * Chris@18: * @see update_test_schema_update_8003() Chris@18: */ Chris@18: public function testModuleListChange() { Chris@18: // Set a value in the cache to prove caches are cleared. Chris@18: \Drupal::service('cache.default')->set(__CLASS__, 'Test'); Chris@18: Chris@18: // Ensure that modules are installed and uninstalled as expected prior to Chris@18: // running updates. Chris@18: $extension_config = $this->config('core.extension')->get(); Chris@18: $this->assertArrayHasKey('page_cache', $extension_config['module']); Chris@18: $this->assertArrayNotHasKey('module_test', $extension_config['module']); Chris@18: Chris@18: $module_list = \Drupal::moduleHandler()->getModuleList(); Chris@18: $this->assertArrayHasKey('page_cache', $module_list); Chris@18: $this->assertArrayNotHasKey('module_test', $module_list); Chris@18: Chris@18: $namespaces = \Drupal::getContainer()->getParameter('container.namespaces'); Chris@18: $this->assertArrayHasKey('Drupal\page_cache', $namespaces); Chris@18: $this->assertArrayNotHasKey('Drupal\module_test', $namespaces); Chris@18: Chris@18: // Increment the schema version so that update_test_schema_update_8003() Chris@18: // runs. Chris@18: \Drupal::state()->set('update_test_schema_version', 8003); Chris@18: $this->runUpdates(); Chris@18: Chris@18: // Ensure that test running environment has been updated with the changes to Chris@18: // the module list. Chris@18: $extension_config = $this->config('core.extension')->get(); Chris@18: $this->assertArrayNotHasKey('page_cache', $extension_config['module']); Chris@18: $this->assertArrayHasKey('module_test', $extension_config['module']); Chris@18: Chris@18: $module_list = \Drupal::moduleHandler()->getModuleList(); Chris@18: $this->assertArrayNotHasKey('page_cache', $module_list); Chris@18: $this->assertArrayHasKey('module_test', $module_list); Chris@18: Chris@18: $namespaces = \Drupal::getContainer()->getParameter('container.namespaces'); Chris@18: $this->assertArrayNotHasKey('Drupal\page_cache', $namespaces); Chris@18: $this->assertArrayHasKey('Drupal\module_test', $namespaces); Chris@18: Chris@18: // Ensure the test runners cache has been cleared. Chris@18: $this->assertFalse(\Drupal::service('cache.default')->get(__CLASS__)); Chris@0: } Chris@0: Chris@0: }