Verified Commit f0288721 authored by Dave Long's avatar Dave Long
Browse files

Issue #3385550 by lauriii, Gauravvvv, sboden, Shabbir, longwave: Language...

Issue #3385550 by lauriii, Gauravvvv, sboden, Shabbir, longwave: Language negotiation breaks updating Drupal 9 to 10
parent c4ae1976
Loading
Loading
Loading
Loading
Loading
+1 −4
Original line number Diff line number Diff line
@@ -130,10 +130,7 @@ public function processOutbound($path, &$options = [], Request $request = NULL,
    }
    $languages = array_flip(array_keys($this->languageManager->getLanguages()));
    // Language can be passed as an option, or we go for current URL language.
    if (!isset($options['language']) || ($options['language'] instanceof LanguageInterface && in_array($options['language']->getId(), [
      LanguageInterface::LANGCODE_NOT_SPECIFIED,
      LanguageInterface::LANGCODE_NOT_APPLICABLE,
    ]))) {
    if (!isset($options['language']) || ($options['language'] instanceof LanguageInterface && $options['language']->getId() == LanguageInterface::LANGCODE_NOT_SPECIFIED)) {
      $language_url = $this->languageManager->getCurrentLanguage(LanguageInterface::TYPE_URL);
      $options['language'] = $language_url;
    }
+65 −0
Original line number Diff line number Diff line
@@ -156,6 +156,71 @@ public function providerTestPathPrefix() {
    return $path_prefix_configuration;
  }

  /**
   * Tests outbound path processing for neutral languages.
   *
   * @dataProvider providerNeutralLanguages
   */
  public function testNeutralLanguages($langcode, $expected_langcode) {
    if ($expected_langcode) {
      $this->languageManager->expects($this->once())
        ->method('getCurrentLanguage')
        ->willReturn($this->languages['en']);
    }

    $config = $this->getConfigFactoryStub([
      'language.negotiation' => [
        'url' => [
          'source' => LanguageNegotiationUrl::CONFIG_PATH_PREFIX,
          'prefixes' => [
            'de' => 'de',
            'en' => 'en',
          ],
        ],
      ],
    ]);

    $request = Request::create('/foo', 'GET');
    $method = new LanguageNegotiationUrl();
    $method->setLanguageManager($this->languageManager);
    $method->setConfig($config);
    $method->setCurrentUser($this->user);
    $this->assertNull($method->getLangcode($request));

    $language = $this->createMock(LanguageInterface::class);
    $language->expects($this->any())
      ->method('getId')
      ->willReturn($langcode);
    $cacheability = new BubbleableMetadata();
    $options = [
      'language' => $language,
    ];
    $method->processOutbound('foo', $options, $request, $cacheability);
    $expected_cacheability = new BubbleableMetadata();
    if ($expected_langcode) {
      $this->assertSame($expected_langcode . '/', $options['prefix']);
      $expected_cacheability->setCacheContexts(['languages:' . LanguageInterface::TYPE_URL]);
    }
    else {
      $this->assertFalse(isset($options['prefix']));
    }
    $this->assertEquals($expected_cacheability, $cacheability);
  }

  /**
   * Provides data for the neutral language test.
   *
   * @return array
   *   An array of data for checking path prefix negotiation for neutral
   *   languages.
   */
  public function providerNeutralLanguages() {
    return [
      [LanguageInterface::LANGCODE_NOT_APPLICABLE, NULL],
      [LanguageInterface::LANGCODE_NOT_SPECIFIED, 'en'],
    ];
  }

  /**
   * Tests domain language negotiation and outbound path processing.
   *
+0 −1
Original line number Diff line number Diff line
@@ -602,7 +602,6 @@ public function testDetailsTitleIsNotEscaped() {
  public function testUrlPrefixOnLanguageNeutralContent() {
    $this->drupalLogin($this->administrator);
    $neutral_langcodes = [
      LanguageInterface::LANGCODE_NOT_APPLICABLE,
      LanguageInterface::LANGCODE_NOT_SPECIFIED,
    ];
    foreach ($neutral_langcodes as $langcode) {