private function LocaleUrlRewritingTest::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 LocaleUrlRewritingTest::checkUrl()
LocaleUrlRewritingTest::testUrlRewritingEdgeCases in drupal/modules/locale/locale.test
Check that disabled or non-installed languages are not considered.

File

drupal/modules/locale/locale.test, line 2658
Tests for locale.module.

Class

LocaleUrlRewritingTest
Test that URL rewriting works as expected.

Code

private function checkUrl($language, $message1, $message2) {
  $options = array(
    'language' => $language,
  );
  $base_path = trim(base_path(), '/');
  $rewritten_path = trim(str_replace(array(
    '?q=',
    $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 the right one from
  // the language object so we can always check the prefixed URL.
  if ($this
    ->assertNotEqual($language->prefix, $prefix, $message1)) {
    $prefix = $language->prefix;
  }
  $this
    ->drupalGet("{$prefix}/{$path}");
  $this
    ->assertResponse(404, $message2);
}