diff --git a/core/lib/Drupal/Core/Routing/CachedUrlGenerator.php b/core/lib/Drupal/Core/Routing/CachedUrlGenerator.php index 5de0e67..9f0b960 100644 --- a/core/lib/Drupal/Core/Routing/CachedUrlGenerator.php +++ b/core/lib/Drupal/Core/Routing/CachedUrlGenerator.php @@ -90,7 +90,7 @@ public function __construct(UrlGeneratorInterface $url_generator, CacheBackendIn /** * Clears the caches of the URL generator. */ - public function clear() { + public function clearCache() { $this->cachedUrls = array(); $this->cache->delete($this->cacheKey); } diff --git a/core/lib/Drupal/Core/Routing/UrlGenerator.php b/core/lib/Drupal/Core/Routing/UrlGenerator.php index ac5d5c8..c45ab6e 100644 --- a/core/lib/Drupal/Core/Routing/UrlGenerator.php +++ b/core/lib/Drupal/Core/Routing/UrlGenerator.php @@ -370,4 +370,10 @@ protected function getRoute($name) { return $route; } + /** + * {@inheritdoc} + */ + public function clearCache() { + // Nothing to do in this class. + } } diff --git a/core/lib/Drupal/Core/Routing/UrlGeneratorInterface.php b/core/lib/Drupal/Core/Routing/UrlGeneratorInterface.php index 62fe1ef..e526474 100644 --- a/core/lib/Drupal/Core/Routing/UrlGeneratorInterface.php +++ b/core/lib/Drupal/Core/Routing/UrlGeneratorInterface.php @@ -199,4 +199,8 @@ public function setBasePath($path); */ public function setScriptPath($path); + /** + * Clears the caches of the URL generator. + */ + public function clearCache(); } diff --git a/core/modules/language/lib/Drupal/language/Tests/LanguageListTest.php b/core/modules/language/lib/Drupal/language/Tests/LanguageListTest.php index 4870f57..46c39bf 100644 --- a/core/modules/language/lib/Drupal/language/Tests/LanguageListTest.php +++ b/core/modules/language/lib/Drupal/language/Tests/LanguageListTest.php @@ -46,7 +46,8 @@ function testLanguageList() { ); $this->drupalPost('admin/config/regional/language/add', $edit, t('Add language')); $this->assertText('French', 'Language added successfully.'); - $this->assertEqual($this->getUrl(), url('admin/config/regional/language', array('absolute' => TRUE)), 'Correct page redirection.'); + // Check for correct page redirection. + $this->assertEqual($this->getUrl(), url('admin/config/regional/language', array('absolute' => TRUE))); // Add custom language. $langcode = 'xx'; @@ -58,7 +59,8 @@ function testLanguageList() { 'direction' => '0', ); $this->drupalPost('admin/config/regional/language/add', $edit, t('Add custom language')); - $this->assertEqual($this->getUrl(), url('admin/config/regional/language', array('absolute' => TRUE)), 'Correct page redirection.'); + // Check for correct page redirection. + $this->assertEqual($this->getUrl(), url('admin/config/regional/language', array('absolute' => TRUE))); $this->assertRaw('"edit-languages-' . $langcode .'-weight"', 'Language code found.'); $this->assertText(t($name), 'Test language added.'); @@ -71,12 +73,16 @@ function testLanguageList() { 'site_default_language' => $langcode, ); $this->drupalPost(NULL, $edit, t('Save configuration')); + // Clear cached urls in the local process too. + $this->container->get('url_generator')->clearCache(); $this->assertNoOptionSelected('edit-site-default-language', 'en', 'Default language updated.'); - $this->assertEqual($this->getUrl(), url($path, array('absolute' => TRUE)), 'Correct page redirection.'); + // Check for correct page redirection. + $this->assertEqual($this->getUrl(), url($path, array('absolute' => TRUE))); // Ensure we can't delete the default language. $this->drupalGet('admin/config/regional/language/delete/' . $langcode); - $this->assertEqual($this->getUrl(), url('admin/config/regional/language', array('absolute' => TRUE)), 'Correct page redirection.'); + // Check for correct page redirection. + $this->assertEqual($this->getUrl(), url('admin/config/regional/language', array('absolute' => TRUE))); $this->assertText(t('The default language cannot be deleted.'), 'Failed to delete the default language.'); // Ensure 'Edit' link works. @@ -89,13 +95,16 @@ function testLanguageList() { ); $this->drupalPost('admin/config/regional/language/edit/' . $langcode, $edit, t('Save language')); $this->assertRaw($name, 'The language has been updated.'); - $this->assertEqual($this->getUrl(), url('admin/config/regional/language', array('absolute' => TRUE)), 'Correct page redirection.'); + // Check for correct page redirection. + $this->assertEqual($this->getUrl(), url('admin/config/regional/language', array('absolute' => TRUE))); // Change back the default language. $edit = array( 'site_default_language' => 'en', ); $this->drupalPost($path, $edit, t('Save configuration')); + // Clear cached urls in the local process too. + $this->container->get('url_generator')->clearCache(); // Ensure 'delete' link works. $this->drupalGet('admin/config/regional/language'); $this->clickLink(t('Delete')); @@ -104,7 +113,8 @@ function testLanguageList() { $this->drupalGet('admin/config/regional/language/delete/' . $langcode); // First test the 'cancel' link. $this->clickLink(t('Cancel')); - $this->assertEqual($this->getUrl(), url('admin/config/regional/language', array('absolute' => TRUE)), 'Correct page redirection.'); + // Check for correct page redirection. + $this->assertEqual($this->getUrl(), url('admin/config/regional/language', array('absolute' => TRUE))); $this->assertRaw($name, 'The language was not deleted.'); // Delete the language for real. This a confirm form, we do not need any // fields changed. @@ -112,7 +122,8 @@ function testLanguageList() { // We need raw here because %language and %langcode will add HTML. $t_args = array('%language' => $name, '%langcode' => $langcode); $this->assertRaw(t('The %language (%langcode) language has been removed.', $t_args), 'The test language has been removed.'); - $this->assertEqual($this->getUrl(), url('admin/config/regional/language', array('absolute' => TRUE)), 'Correct page redirection.'); + // Check for correct page redirection. + $this->assertEqual($this->getUrl(), url('admin/config/regional/language', array('absolute' => TRUE))); // Verify that language is no longer found. $this->drupalGet('admin/config/regional/language/delete/' . $langcode); $this->assertResponse(404, 'Language no longer found.'); @@ -121,6 +132,8 @@ function testLanguageList() { $languages = language_list(); $language_count = $this->container->get('state')->get('language_count') ?: 1; $this->assertEqual($language_count, count($languages), 'Language count is correct.'); + // Clear cached urls in the local process too. + $this->container->get('url_generator')->clearCache(); // Delete French. $this->drupalPost('admin/config/regional/language/delete/fr', array(), t('Delete')); // Get the count of languages. @@ -129,7 +142,8 @@ function testLanguageList() { // We need raw here because %language and %langcode will add HTML. $t_args = array('%language' => 'French', '%langcode' => 'fr'); $this->assertRaw(t('The %language (%langcode) language has been removed.', $t_args), 'Disabled language has been removed.'); - $this->assertEqual($this->getUrl(), url('admin/config/regional/language', array('absolute' => TRUE)), 'Correct page redirection.'); + // Check for correct page redirection. + $this->assertEqual($this->getUrl(), url('admin/config/regional/language', array('absolute' => TRUE))); // Verify that language is no longer found. $this->drupalGet('admin/config/regional/language/delete/fr'); $this->assertResponse(404, 'Language no longer found.'); @@ -149,7 +163,10 @@ function testLanguageList() { 'direction' => '0', ); $this->drupalPost('admin/config/regional/language/add', $edit, t('Add custom language')); - $this->assertEqual($this->getUrl(), url('admin/config/regional/language', array('absolute' => TRUE)), 'Correct page redirection.'); + // Clear cached urls in the local process too. + $this->container->get('url_generator')->clearCache(); + // Check for correct page redirection. + $this->assertEqual($this->getUrl(), url('admin/config/regional/language', array('absolute' => TRUE))); $this->assertText($name, 'Name found.'); // Check if we can change the default language. @@ -161,8 +178,11 @@ function testLanguageList() { 'site_default_language' => $langcode, ); $this->drupalPost(NULL, $edit, t('Save configuration')); + // Clear cached urls in the local process too. + $this->container->get('url_generator')->clearCache(); $this->assertNoOptionSelected('edit-site-default-language', 'en', 'Default language updated.'); - $this->assertEqual($this->getUrl(), url($path, array('absolute' => TRUE)), 'Correct page redirection.'); + // Check for correct page redirection. + $this->assertEqual($this->getUrl(), url($path, array('absolute' => TRUE))); $this->drupalPost('admin/config/regional/language/delete/en', array(), t('Delete')); // We need raw here because %language and %langcode will add HTML. diff --git a/core/modules/simpletest/lib/Drupal/simpletest/WebTestBase.php b/core/modules/simpletest/lib/Drupal/simpletest/WebTestBase.php index 8d907ac..06dcef9 100644 --- a/core/modules/simpletest/lib/Drupal/simpletest/WebTestBase.php +++ b/core/modules/simpletest/lib/Drupal/simpletest/WebTestBase.php @@ -3403,10 +3403,8 @@ protected function prepareRequestForGenerator($clean_urls = TRUE, $override_serv $request = Request::create($request_path, 'GET', array(), array(), array(), $server); $generator->setRequest($request); - // Ensure to clear some internal caches of the URL generator. - if ($generator instanceof CachedUrlGenerator) { - $generator->clear(); - } + // Ensure any internal caches of the URL generator are cleared. + $generator->clearCache(); return $request; } diff --git a/core/modules/system/lib/Drupal/system/Form/RegionalForm.php b/core/modules/system/lib/Drupal/system/Form/RegionalForm.php index 52f5db5..f47a104 100644 --- a/core/modules/system/lib/Drupal/system/Form/RegionalForm.php +++ b/core/modules/system/lib/Drupal/system/Form/RegionalForm.php @@ -166,9 +166,7 @@ public function submitForm(array &$form, array &$form_state) { ->set('timezone.user.default', $form_state['values']['user_default_timezone']) ->save(); - if (method_exists($this->urlGenerator, 'clear')) { - $this->urlGenerator->clear(); - } + $this->urlGenerator->clearCache(); parent::submitForm($form, $form_state); }