LanguageNegotiationUrlTest.php

Same filename in this branch
  1. 8.9.x core/modules/language/tests/src/Unit/LanguageNegotiationUrlTest.php
Same filename in other branches
  1. 9 core/modules/language/tests/src/Unit/LanguageNegotiationUrlTest.php
  2. 9 core/modules/language/tests/src/Functional/LanguageNegotiationUrlTest.php
  3. 10 core/modules/language/tests/src/Unit/LanguageNegotiationUrlTest.php
  4. 10 core/modules/language/tests/src/Functional/LanguageNegotiationUrlTest.php
  5. 11.x core/modules/language/tests/src/Unit/LanguageNegotiationUrlTest.php
  6. 11.x core/modules/language/tests/src/Functional/LanguageNegotiationUrlTest.php

Namespace

Drupal\Tests\language\Functional

File

core/modules/language/tests/src/Functional/LanguageNegotiationUrlTest.php

View source
<?php

namespace Drupal\Tests\language\Functional;

use Drupal\Core\StringTranslation\StringTranslationTrait;
use Drupal\Tests\BrowserTestBase;

/**
 * @coversDefaultClass \Drupal\language\Plugin\LanguageNegotiation\LanguageNegotiationUrl
 * @group language
 */
class LanguageNegotiationUrlTest extends BrowserTestBase {
    use StringTranslationTrait;
    
    /**
     * {@inheritdoc}
     */
    public static $modules = [
        'language',
        'node',
        'path',
    ];
    
    /**
     * {@inheritdoc}
     */
    protected $defaultTheme = 'stark';
    
    /**
     * @var \Drupal\user\Entity\User
     */
    protected $user;
    
    /**
     * {@inheritdoc}
     */
    protected function setUp() {
        parent::setUp();
        // Create an Article node type.
        if ($this->profile != 'standard') {
            $this->drupalCreateContentType([
                'type' => 'article',
            ]);
        }
        $this->user = $this->drupalCreateUser([
            'administer languages',
            'access administration pages',
            'view the administration theme',
            'administer nodes',
            'create article content',
            'create url aliases',
        ]);
        $this->drupalLogin($this->user);
        $this->drupalPostForm('admin/config/regional/language/add', [
            'predefined_langcode' => 'de',
        ], $this->t('Add language'));
    }
    
    /**
     * @covers ::processInbound
     */
    public function testDomain() {
        // Check if paths that contain language prefixes can be reached when
        // language is taken from the domain.
        $edit = [
            'language_negotiation_url_part' => 'domain',
            'prefix[en]' => 'eng',
            'prefix[de]' => 'de',
            'domain[en]' => $_SERVER['HTTP_HOST'],
            'domain[de]' => "de.{$_SERVER['HTTP_HOST']}",
        ];
        $this->drupalPostForm('admin/config/regional/language/detection/url', $edit, $this->t('Save configuration'));
        $nodeValues = [
            'title[0][value]' => 'Test',
            'path[0][alias]' => '/eng/test',
        ];
        $this->drupalPostForm('node/add/article', $nodeValues, $this->t('Save'));
        $this->assertSession()
            ->statusCodeEquals(200);
    }

}

Classes

Title Deprecated Summary
LanguageNegotiationUrlTest @coversDefaultClass \Drupal\language\Plugin\LanguageNegotiation\LanguageNegotiationUrl @group language

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.