Mercurial > hg > cmmr2012-drupal-site
diff core/tests/Drupal/FunctionalTests/Update/UpdatePathTestBaseTest.php @ 5:12f9dff5fda9 tip
Update to Drupal core 8.7.1
author | Chris Cannam |
---|---|
date | Thu, 09 May 2019 15:34:47 +0100 |
parents | a9cd425dd02b |
children |
line wrap: on
line diff
--- a/core/tests/Drupal/FunctionalTests/Update/UpdatePathTestBaseTest.php Thu Feb 28 13:11:55 2019 +0000 +++ b/core/tests/Drupal/FunctionalTests/Update/UpdatePathTestBaseTest.php Thu May 09 15:34:47 2019 +0100 @@ -4,6 +4,7 @@ use Drupal\Component\Utility\Html; use Drupal\Component\Render\FormattableMarkup; +use Drupal\Core\Database\Database; /** * Tests the update path base class. @@ -32,6 +33,9 @@ * Tests that the database was properly loaded. */ public function testDatabaseLoaded() { + // Set a value in the cache to prove caches are cleared. + \Drupal::service('cache.default')->set(__CLASS__, 'Test'); + foreach (['user', 'node', 'system', 'update_test_schema'] as $module) { $this->assertEqual(drupal_get_installed_schema_version($module), 8000, new FormattableMarkup('Module @module schema is 8000', ['@module' => $module])); } @@ -69,17 +73,21 @@ $this->assertEqual('on', $database->query("SHOW standard_conforming_strings")->fetchField()); $this->assertEqual('escape', $database->query("SHOW bytea_output")->fetchField()); } + // Ensure the test runners cache has been cleared. + $this->assertFalse(\Drupal::service('cache.default')->get(__CLASS__)); } /** * Test that updates are properly run. */ public function testUpdateHookN() { + $connection = Database::getConnection(); + // Increment the schema version. \Drupal::state()->set('update_test_schema_version', 8001); $this->runUpdates(); - $select = \Drupal::database()->select('watchdog'); + $select = $connection->select('watchdog'); $select->orderBy('wid', 'DESC'); $select->range(0, 5); $select->fields('watchdog', ['message']); @@ -92,7 +100,86 @@ // Ensure schema has changed. $this->assertEqual(drupal_get_installed_schema_version('update_test_schema', TRUE), 8001); // Ensure the index was added for column a. - $this->assertTrue(db_index_exists('update_test_schema_table', 'test'), 'Version 8001 of the update_test_schema module is installed.'); + $this->assertTrue($connection->schema()->indexExists('update_test_schema_table', 'test'), 'Version 8001 of the update_test_schema module is installed.'); + } + + /** + * Tests that path aliases are not processed during database updates. + */ + public function testPathAliasProcessing() { + // Add a path alias for the '/admin' system path. + $database = \Drupal::database(); + $database->insert('url_alias') + ->fields(['source', 'alias', 'langcode']) + ->values([ + 'source' => '/admin/structure', + 'alias' => '/admin-structure-alias', + 'langcode' => 'und', + ]) + ->execute(); + + // Increment the schema version. + \Drupal::state()->set('update_test_schema_version', 8002); + $this->runUpdates(); + + // Check that the alias defined earlier is not used during the update + // process. + $this->assertSession()->linkByHrefExists('/admin/structure'); + $this->assertSession()->linkByHrefNotExists('/admin-structure-alias'); + + $account = $this->createUser(['administer site configuration', 'access administration pages', 'access site reports']); + $this->drupalLogin($account); + + // Go to the status report page and check that the alias is used. + $this->drupalGet('admin/reports/status'); + $this->assertSession()->linkByHrefNotExists('/admin/structure'); + $this->assertSession()->linkByHrefExists('/admin-structure-alias'); + } + + /** + * Tests that test running environment is updated when module list changes. + * + * @see update_test_schema_update_8003() + */ + public function testModuleListChange() { + // Set a value in the cache to prove caches are cleared. + \Drupal::service('cache.default')->set(__CLASS__, 'Test'); + + // Ensure that modules are installed and uninstalled as expected prior to + // running updates. + $extension_config = $this->config('core.extension')->get(); + $this->assertArrayHasKey('page_cache', $extension_config['module']); + $this->assertArrayNotHasKey('module_test', $extension_config['module']); + + $module_list = \Drupal::moduleHandler()->getModuleList(); + $this->assertArrayHasKey('page_cache', $module_list); + $this->assertArrayNotHasKey('module_test', $module_list); + + $namespaces = \Drupal::getContainer()->getParameter('container.namespaces'); + $this->assertArrayHasKey('Drupal\page_cache', $namespaces); + $this->assertArrayNotHasKey('Drupal\module_test', $namespaces); + + // Increment the schema version so that update_test_schema_update_8003() + // runs. + \Drupal::state()->set('update_test_schema_version', 8003); + $this->runUpdates(); + + // Ensure that test running environment has been updated with the changes to + // the module list. + $extension_config = $this->config('core.extension')->get(); + $this->assertArrayNotHasKey('page_cache', $extension_config['module']); + $this->assertArrayHasKey('module_test', $extension_config['module']); + + $module_list = \Drupal::moduleHandler()->getModuleList(); + $this->assertArrayNotHasKey('page_cache', $module_list); + $this->assertArrayHasKey('module_test', $module_list); + + $namespaces = \Drupal::getContainer()->getParameter('container.namespaces'); + $this->assertArrayNotHasKey('Drupal\page_cache', $namespaces); + $this->assertArrayHasKey('Drupal\module_test', $namespaces); + + // Ensure the test runners cache has been cleared. + $this->assertFalse(\Drupal::service('cache.default')->get(__CLASS__)); } }