diff --git a/core/modules/system/src/Tests/Routing/RouteNormalizerTest.php b/core/tests/Drupal/FunctionalTests/Routing/RouteNormalizerTest.php similarity index 63% rename from core/modules/system/src/Tests/Routing/RouteNormalizerTest.php rename to core/tests/Drupal/FunctionalTests/Routing/RouteNormalizerTest.php index 2f70d72..f97619c 100644 --- a/core/modules/system/src/Tests/Routing/RouteNormalizerTest.php +++ b/core/tests/Drupal/FunctionalTests/Routing/RouteNormalizerTest.php @@ -5,12 +5,12 @@ * Contains \Drupal\system\Tests\Routing\RouteNormalizerTest. */ -namespace Drupal\system\Tests\Routing; +namespace Drupal\FunctionalTests\Routing; use Drupal\Component\Utility\UrlHelper; use Drupal\Core\Url; use Drupal\language\Plugin\LanguageNegotiation\LanguageNegotiationUrl; -use Drupal\simpletest\WebTestBase; +use Drupal\Tests\BrowserTestBase; /** * Tests the route normalizer functionality. @@ -19,7 +19,7 @@ * * @see \Drupal\Core\EventSubscriber\RouteNormalizerRequestSubscriber */ -class RouteNormalizerTest extends WebTestBase { +class RouteNormalizerTest extends BrowserTestBase { /** * Modules to enable. @@ -37,50 +37,55 @@ public function testRedirects() { // Test front page redirect. $front_page_path = '/user/login'; - $this->config('system.site')->set('page.front', $front_page_path)->save(); + \Drupal::configFactory() + ->getEditable('system.site') + ->set('page.front', $front_page_path) + ->save(); $this->drupalGet(Url::fromUri('base:' . $front_page_path)); - $this->assertNotEqual($this->redirectCount, 0); - $this->assertUrl(Url::fromRoute('')); + $this->assertSame(Url::fromRoute('')->setAbsolute()->toString(), $this->getSession()->getCurrentUrl()); // Test path alias redirect. $this->drupalLogin($this->drupalCreateUser([ 'administer url aliases', ])); + $this->drupalGet(Url::fromRoute('path.admin_add')); $edit = [ 'source' => '/user/password', 'alias' => '/my-cool/password/recovery/page', ]; - $this->drupalPostForm('admin/config/search/path/add', $edit, t('Save')); + $this->submitForm($edit, t('Save')); $this->drupalGet(Url::fromUri('base:' . $edit['source'])); - $this->assertNotEqual($this->redirectCount, 0); - $this->assertUrl(Url::fromUri('base:' . $edit['alias'])); + $this->assertSame(Url::fromUri('base:' . $edit['alias'])->setAbsolute()->toString(), $this->getSession()->getCurrentUrl()); // Test language redirect. $this->drupalLogin($this->drupalCreateUser([ 'administer languages', ])); // We need more than one language to make the redirect work. + $this->drupalGet(Url::fromRoute('language.add')); $edit = [ 'predefined_langcode' => 'fr', ]; - $this->drupalPostForm('admin/config/regional/language/add', $edit, t('Add language')); + $this->submitForm($edit, t('Add language')); + $this->drupalGet(Url::fromRoute('language.negotiation')); $edit = [ 'language_interface[enabled][language-url]' => 1, ]; - $this->drupalPostForm('admin/config/regional/language/detection', $edit, t('Save settings')); + $this->submitForm($edit, t('Save settings')); + $this->drupalGet(Url::fromRoute('language.negotiation_url')); $edit = [ 'language_negotiation_url_part' => LanguageNegotiationUrl::CONFIG_PATH_PREFIX, 'prefix[en]' => 'en', 'prefix[fr]' => 'fr', ]; - $this->drupalPostForm('admin/config/regional/language/detection/url', $edit, t('Save configuration')); + $this->submitForm($edit, t('Save configuration')); $this->rebuildContainer(); $url = Url::fromUri('base:/admin/config/regional/language')->setAbsolute()->toString(); $prefix_count = substr_count($url, '/en/'); $this->drupalGet($url); - $this->assertNotEqual($this->redirectCount, 0); - $this->assertTrue(substr_count($this->url, '/en/') == $prefix_count + 1, 'The default language path prefix was added to the final URL.'); - $this->assertTrue(strpos($this->url, '/admin/config/regional/language') !== FALSE, 'Path preserved.'); + $current_url = $this->getSession()->getCurrentUrl(); + $this->assertSame($prefix_count + 1, substr_count($current_url, '/en/'), 'The path prefix of the default language was added to the final URL.'); + $this->assertContains('/admin/config/regional/language', $current_url, 'Path preserved.'); // Test a redirect having special characters in source/destination paths. /** @var \Drupal\Core\Menu\MenuLinkManagerInterface $menu_link_manager */ @@ -91,14 +96,14 @@ public function testRedirects() { $this->drupalLogin($this->drupalCreateUser([ 'administer url aliases', ])); + $this->drupalGet(Url::fromRoute('path.admin_add')); $edit = [ 'source' => '/' . $exotic_path, 'alias' => '/' . $exotic_path . rawurlencode(rawurlencode('#%&+/?')), ]; - $this->drupalPostForm('admin/config/search/path/add', $edit, t('Save')); + $this->submitForm($edit, t('Save')); $this->drupalGet($exotic_path, ['alias' => TRUE]); - $this->assertNotEqual($this->redirectCount, 0); - $this->assertTrue(strpos($this->url, UrlHelper::encodePath($edit['alias'])) !== FALSE, 'Redirected to the alias.'); + $this->assertContains(UrlHelper::encodePath($edit['alias']), $this->getSession()->getCurrentUrl(), 'Redirected to the alias.'); } }