private function LanguageUrlRewritingTest::checkUrl

Check URL rewriting for the given language.

The test is performed with a fixed URL (the default front page) to simply check that language prefixes are not added to it and that the prefixed URL is actually not working.

Parameters

string $language: The language prefix, e.g. 'es'.

string $message1: Message to display in assertion that language prefixes are not added.

string $message2: The message to display confirming prefixed URL is not working.

1 call to LanguageUrlRewritingTest::checkUrl()
LanguageUrlRewritingTest::testUrlRewritingEdgeCases in drupal/core/modules/language/lib/Drupal/language/Tests/LanguageUrlRewritingTest.php
Check that non-installed languages are not considered.

File

drupal/core/modules/language/lib/Drupal/language/Tests/LanguageUrlRewritingTest.php, line 82
Definition of Drupal\language\Tests\LanguageUrlRewritingTest.

Class

LanguageUrlRewritingTest
Test that URL rewriting works as expected.

Namespace

Drupal\language\Tests

Code

private function checkUrl($language, $message1, $message2) {
  $options = array(
    'language' => $language,
    'script' => '',
  );
  $base_path = trim(base_path(), '/');
  $rewritten_path = trim(str_replace($base_path, '', url('node', $options)), '/');
  $segments = explode('/', $rewritten_path, 2);
  $prefix = $segments[0];
  $path = isset($segments[1]) ? $segments[1] : $prefix;

  // If the rewritten URL has not a language prefix we pick a random prefix so
  // we can always check the prefixed URL.
  $prefixes = language_negotiation_url_prefixes();
  $stored_prefix = isset($prefixes[$language->langcode]) ? $prefixes[$language->langcode] : $this
    ->randomName();
  if ($this
    ->assertNotEqual($stored_prefix, $prefix, $message1)) {
    $prefix = $stored_prefix;
  }
  $this
    ->drupalGet("{$prefix}/{$path}");
  $this
    ->assertResponse(404, $message2);
}