comparison core/modules/language/tests/src/Functional/LanguageUrlRewritingTest.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
comparison
equal deleted inserted replaced
4:a9cd425dd02b 5:12f9dff5fda9
59 $non_existing = new Language(['id' => $this->randomMachineName()]); 59 $non_existing = new Language(['id' => $this->randomMachineName()]);
60 $this->checkUrl($non_existing, 'Path language is ignored if language is not installed.', 'URL language negotiation does not work with non-installed languages'); 60 $this->checkUrl($non_existing, 'Path language is ignored if language is not installed.', 'URL language negotiation does not work with non-installed languages');
61 61
62 // Check that URL rewriting is not applied to subrequests. 62 // Check that URL rewriting is not applied to subrequests.
63 $this->drupalGet('language_test/subrequest'); 63 $this->drupalGet('language_test/subrequest');
64 $this->assertText($this->webUser->getUsername(), 'Page correctly retrieved'); 64 $this->assertText($this->webUser->getAccountName(), 'Page correctly retrieved');
65 } 65 }
66 66
67 /** 67 /**
68 * Check URL rewriting for the given language. 68 * Check URL rewriting for the given language.
69 * 69 *
79 * The message to display confirming prefixed URL is not working. 79 * The message to display confirming prefixed URL is not working.
80 */ 80 */
81 private function checkUrl(LanguageInterface $language, $message1, $message2) { 81 private function checkUrl(LanguageInterface $language, $message1, $message2) {
82 $options = ['language' => $language, 'script' => '']; 82 $options = ['language' => $language, 'script' => ''];
83 $base_path = trim(base_path(), '/'); 83 $base_path = trim(base_path(), '/');
84 $rewritten_path = trim(str_replace($base_path, '', \Drupal::url('<front>', [], $options)), '/'); 84 $rewritten_path = trim(str_replace($base_path, '', Url::fromRoute('<front>', [], $options)->toString()), '/');
85 $segments = explode('/', $rewritten_path, 2); 85 $segments = explode('/', $rewritten_path, 2);
86 $prefix = $segments[0]; 86 $prefix = $segments[0];
87 $path = isset($segments[1]) ? $segments[1] : $prefix; 87 $path = isset($segments[1]) ? $segments[1] : $prefix;
88 88
89 // If the rewritten URL has not a language prefix we pick a random prefix so 89 // If the rewritten URL has not a language prefix we pick a random prefix so
123 // Reset static caching. 123 // Reset static caching.
124 $this->container->get('language_manager')->reset(); 124 $this->container->get('language_manager')->reset();
125 125
126 // In case index.php is part of the URLs, we need to adapt the asserted 126 // In case index.php is part of the URLs, we need to adapt the asserted
127 // URLs as well. 127 // URLs as well.
128 $index_php = strpos(\Drupal::url('<front>', [], ['absolute' => TRUE]), 'index.php') !== FALSE; 128 $index_php = strpos(Url::fromRoute('<front>', [], ['absolute' => TRUE])->toString(), 'index.php') !== FALSE;
129 129
130 $request = Request::createFromGlobals(); 130 $request = Request::createFromGlobals();
131 $server = $request->server->all(); 131 $server = $request->server->all();
132 $request = $this->prepareRequestForGenerator(TRUE, ['HTTP_HOST' => $server['HTTP_HOST'] . ':88']); 132 $request = $this->prepareRequestForGenerator(TRUE, ['HTTP_HOST' => $server['HTTP_HOST'] . ':88']);
133 133