You are here

protected function PathProcessorTest::setUp in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 core/tests/Drupal/Tests/Core/PathProcessor/PathProcessorTest.php \Drupal\Tests\Core\PathProcessor\PathProcessorTest::setUp()

Overrides UnitTestCase::setUp

File

core/tests/Drupal/Tests/Core/PathProcessor/PathProcessorTest.php, line 43
Contains \Drupal\Tests\Core\PathProcessor\PathProcessorTest.

Class

PathProcessorTest
Tests processing of the inbound path.

Namespace

Drupal\Tests\Core\PathProcessor

Code

protected function setUp() {

  // Set up some languages to be used by the language-based path processor.
  $languages = array();
  foreach (array(
    'en',
    'fr',
  ) as $langcode) {
    $language = new Language(array(
      'id' => $langcode,
    ));
    $languages[$langcode] = $language;
  }
  $this->languages = $languages;

  // Create a stub configuration.
  $language_prefixes = array_keys($this->languages);
  $config = array(
    'url' => array(
      'prefixes' => array_combine($language_prefixes, $language_prefixes),
    ),
  );

  // Create a URL-based language negotiation method definition.
  $method_definitions = array(
    LanguageNegotiationUrl::METHOD_ID => array(
      'class' => '\\Drupal\\language\\Plugin\\LanguageNegotiation\\LanguageNegotiationUrl',
      'weight' => 9,
    ),
  );

  // Create a URL-based language negotiation method.
  $method_instance = new LanguageNegotiationUrl($config);

  // Create a language manager stub.
  $language_manager = $this
    ->getMockBuilder('Drupal\\language\\ConfigurableLanguageManagerInterface')
    ->getMock();
  $language_manager
    ->expects($this
    ->any())
    ->method('getCurrentLanguage')
    ->will($this
    ->returnValue($languages['en']));
  $language_manager
    ->expects($this
    ->any())
    ->method('getLanguages')
    ->will($this
    ->returnValue($this->languages));
  $language_manager
    ->expects($this
    ->any())
    ->method('getLanguageTypes')
    ->will($this
    ->returnValue(array(
    LanguageInterface::TYPE_INTERFACE,
  )));
  $language_manager
    ->expects($this
    ->any())
    ->method('getNegotiationMethods')
    ->will($this
    ->returnValue($method_definitions));
  $language_manager
    ->expects($this
    ->any())
    ->method('getNegotiationMethodInstance')
    ->will($this
    ->returnValue($method_instance));
  $method_instance
    ->setLanguageManager($language_manager);
  $this->languageManager = $language_manager;
}