LanguageNegotiationUrl example

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

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

    $cacheability = new BubbleableMetadata();
    $options = [];
    $method->processOutbound('foo', $options$request$cacheability);
    $expected_cacheability = new BubbleableMetadata();
    if ($expected_langcode) {
      $this->assertSame($prefix . '/', $options['prefix']);
      
// Create a language negotiator stub.     $negotiator = $this->getMockBuilder('Drupal\language\LanguageNegotiatorInterface')
      ->getMock();
    $negotiator->expects($this->any())
      ->method('getNegotiationMethods')
      ->willReturn([
        LanguageNegotiationUrl::METHOD_ID => [
          'class' => 'Drupal\language\Plugin\LanguageNegotiation\LanguageNegotiationUrl',
          'weight' => 9,
        ],
      ]);
    $method = new LanguageNegotiationUrl();
    $method->setConfig($config_factory_stub);
    $method->setLanguageManager($this->languageManager);
    $negotiator->expects($this->any())
      ->method('getNegotiationMethodInstance')
      ->willReturn($method);

    // Create a user stub.     $current_user = $this->getMockBuilder('Drupal\Core\Session\AccountInterface')
      ->getMock();

    // Create a config event subscriber stub.
Home | Imprint | This part of the site doesn't use cookies.