You are here

protected function LanguageNegotiationUrlTest::setUp in Drupal 9

Same name in this branch
  1. 9 core/modules/language/tests/src/Functional/LanguageNegotiationUrlTest.php \Drupal\Tests\language\Functional\LanguageNegotiationUrlTest::setUp()
  2. 9 core/modules/language/tests/src/Unit/LanguageNegotiationUrlTest.php \Drupal\Tests\language\Unit\LanguageNegotiationUrlTest::setUp()
Same name and namespace in other branches
  1. 8 core/modules/language/tests/src/Unit/LanguageNegotiationUrlTest.php \Drupal\Tests\language\Unit\LanguageNegotiationUrlTest::setUp()

Overrides UnitTestCase::setUp

File

core/modules/language/tests/src/Unit/LanguageNegotiationUrlTest.php, line 25

Class

LanguageNegotiationUrlTest
@coversDefaultClass \Drupal\language\Plugin\LanguageNegotiation\LanguageNegotiationUrl @group language

Namespace

Drupal\Tests\language\Unit

Code

protected function setUp() : void {

  // Set up some languages to be used by the language-based path processor.
  $language_de = $this
    ->createMock('\\Drupal\\Core\\Language\\LanguageInterface');
  $language_de
    ->expects($this
    ->any())
    ->method('getId')
    ->will($this
    ->returnValue('de'));
  $language_en = $this
    ->createMock('\\Drupal\\Core\\Language\\LanguageInterface');
  $language_en
    ->expects($this
    ->any())
    ->method('getId')
    ->will($this
    ->returnValue('en'));
  $languages = [
    'de' => $language_de,
    'en' => $language_en,
  ];
  $this->languages = $languages;

  // Create a language manager stub.
  $language_manager = $this
    ->getMockBuilder('Drupal\\language\\ConfigurableLanguageManagerInterface')
    ->getMock();
  $language_manager
    ->expects($this
    ->any())
    ->method('getLanguages')
    ->will($this
    ->returnValue($languages));
  $this->languageManager = $language_manager;

  // Create a user stub.
  $this->user = $this
    ->getMockBuilder('Drupal\\Core\\Session\\AccountInterface')
    ->getMock();
  $cache_contexts_manager = $this
    ->getMockBuilder('Drupal\\Core\\Cache\\Context\\CacheContextsManager')
    ->disableOriginalConstructor()
    ->getMock();
  $cache_contexts_manager
    ->method('assertValidTokens')
    ->willReturn(TRUE);
  $container = new ContainerBuilder();
  $container
    ->set('cache_contexts_manager', $cache_contexts_manager);
  \Drupal::setContainer($container);
}