function PathLanguageTest::setUp

Same name in other branches
  1. 9 core/modules/path/tests/src/Functional/PathLanguageTest.php \Drupal\Tests\path\Functional\PathLanguageTest::setUp()
  2. 8.9.x core/modules/path/tests/src/Functional/PathLanguageTest.php \Drupal\Tests\path\Functional\PathLanguageTest::setUp()
  3. 10 core/modules/path/tests/src/Functional/PathLanguageTest.php \Drupal\Tests\path\Functional\PathLanguageTest::setUp()

Overrides PathTestBase::setUp

File

core/modules/path/tests/src/Functional/PathLanguageTest.php, line 47

Class

PathLanguageTest
Confirm that paths work with translated nodes.

Namespace

Drupal\Tests\path\Functional

Code

protected function setUp() : void {
    parent::setUp();
    $permissions = [
        'access administration pages',
        'administer content translation',
        'administer content types',
        'administer languages',
        'administer url aliases',
        'create content translations',
        'create page content',
        'create url aliases',
        'edit any page content',
        'translate any entity',
    ];
    // Create and log in user.
    $this->webUser = $this->drupalCreateUser($permissions);
    $this->drupalLogin($this->webUser);
    // Enable French language.
    static::createLanguageFromLangcode('fr');
    // Enable URL language detection and selection.
    $this->container
        ->get('language_negotiator')
        ->saveConfiguration(LanguageInterface::TYPE_URL, [
        LanguageNegotiationUrl::METHOD_ID => 1,
    ]);
    // Enable translation for page node.
    static::enableContentTranslation('node', 'page');
    static::setFieldTranslatable('node', 'page', 'body', TRUE);
    $definitions = \Drupal::service('entity_field.manager')->getFieldDefinitions('node', 'page');
    $this->assertTrue($definitions['path']->isTranslatable(), 'Node path is translatable.');
    $this->assertTrue($definitions['body']->isTranslatable(), 'Node body is translatable.');
}

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