1<?php
2
3namespace Drupal\Tests\language\Functional;
4
5use Drupal\Core\StringTranslation\StringTranslationTrait;
6use Drupal\Tests\BrowserTestBase;
7
8/**
9 * @coversDefaultClass \Drupal\language\Plugin\LanguageNegotiation\LanguageNegotiationUrl
10 * @group language
11 */
12class LanguageNegotiationUrlTest extends BrowserTestBase {
13
14  use StringTranslationTrait;
15
16  /**
17   * {@inheritdoc}
18   */
19  public static $modules = [
20    'language',
21    'node',
22    'path',
23  ];
24
25  /**
26   * {@inheritdoc}
27   */
28  protected $defaultTheme = 'stark';
29
30  /**
31   * @var \Drupal\user\Entity\User
32   */
33  protected $user;
34
35  /**
36   * {@inheritdoc}
37   */
38  protected function setUp() {
39    parent::setUp();
40
41    // Create an Article node type.
42    if ($this->profile != 'standard') {
43      $this->drupalCreateContentType(['type' => 'article']);
44    }
45
46    $this->user = $this->drupalCreateUser([
47      'administer languages',
48      'access administration pages',
49      'view the administration theme',
50      'administer nodes',
51      'create article content',
52      'create url aliases',
53    ]);
54    $this->drupalLogin($this->user);
55
56    $this->drupalPostForm('admin/config/regional/language/add', ['predefined_langcode' => 'de'], $this->t('Add language'));
57  }
58
59  /**
60   * @covers ::processInbound
61   */
62  public function testDomain() {
63    // Check if paths that contain language prefixes can be reached when
64    // language is taken from the domain.
65    $edit = [
66      'language_negotiation_url_part' => 'domain',
67      'prefix[en]' => 'eng',
68      'prefix[de]' => 'de',
69      'domain[en]' => $_SERVER['HTTP_HOST'],
70      'domain[de]' => "de.$_SERVER[HTTP_HOST]",
71    ];
72    $this->drupalPostForm('admin/config/regional/language/detection/url', $edit, $this->t('Save configuration'));
73
74    $nodeValues = [
75      'title[0][value]' => 'Test',
76      'path[0][alias]' => '/eng/test',
77    ];
78    $this->drupalPostForm('node/add/article', $nodeValues, $this->t('Save'));
79    $this->assertSession()->statusCodeEquals(200);
80  }
81
82}
83