Look at LanguageUrlRewritingTest.php

and the function definition for 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.
   *
   * @param string $language
   *   The language prefix, e.g. 'es'.                          <<<< THIS LINE IS  WRONG!!!!
   * @param string $message1
   *   Message to display in assertion that language prefixes are not added.
   * @param string $message2
   *   The message to display confirming prefixed URL is not working.
   */
  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)), '/');

$language is used to form an options array :-

$options = [
'language' => $language,
'script' => ''
];

which is passed to the common.inc function url()
the annotations in this function comments leads me to this page

https://api.drupal.org/api/drupal/core!lib!Drupal!Core!Routing!UrlGenera...

so far so good. So quoting from this document the language key in the array should be a language object not a string!!!!

'language': An optional language object. If the path being linked to is internal to the site, $options['language'] is used to look up the alias for the URL. If $options['language'] is omitted, the language will be obtained from \Drupal::languageManager()->getCurrentLanguage(LanguageInterface::TYPE_URL).

For confirmation of this mistake please look at this functions usage. A language object $non_exising and NOT a string is passed in when the function is used.


function testUrlRewritingEdgeCases() {
// Check URL rewriting with a non-installed language.
$non_existing = \Drupal::languageManager()->getDefaultLanguage();
$non_existing->id = $this->randomMachineName();
$this->checkUrl($non_existing, 'Path language is ignored if language is not installed.', 'URL language negotiation does not work with non-installed languages');

// Check that URL rewriting is not applied to subrequests.
$this->drupalGet('language_test/subrequest');
$this->assertText($this->web_user->getUsername(), 'Page correctly retrieved');
}

CommentFileSizeAuthor
#6 languageParam-6.patch776 bytesmartin107
languageParam-0.patch775 bytesmartin107
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

martin107’s picture

Issue summary: View changes
Status: Active » Needs review

Status: Needs review » Needs work

The last submitted patch, languageParam-0.patch, failed testing.

swentel’s picture

Version: 8.1.x-dev » 8.0.x-dev
martin107’s picture

Status: Needs work » Needs review

@swentel, sorry for the noise :(

Lets see what testbot make of this comment only patch when the the branch is correct

jhodgdon’s picture

Status: Needs review » Needs work

Looks like your conclusions are correct, and thanks for filing/investigating!

Small problem in the patch: the second line (description) should end in .

martin107’s picture

FileSize
776 bytes

Thanks, my mistake - full stop added.

jhodgdon’s picture

Status: Needs work » Reviewed & tested by the community

Thanks! I checked this over again, and delved deep into the code. It does indeed appear that users of $options['language'] in url-generating functions expect it to be a language object, not a language code, and that is what this parameter is passed into.

alexpott’s picture

Status: Reviewed & tested by the community » Fixed

Committed 33a3ed6 and pushed to 8.0.x. Thanks!

  • alexpott committed 33a3ed6 on 8.0.x
    Issue #2337911 by martin107: LanguageUrlRewritingTest checkUrl $language...

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.