You are here

protected function LanguageAccessTestBase::setUp in Language access 8

Overrides BrowserTestBase::setUp

3 calls to LanguageAccessTestBase::setUp()
LanguageAccessAdminTest::setUp in tests/src/Functional/LanguageAccessAdminTest.php
LanguageAccessSimpleSitemapTest::setUp in tests/src/Functional/LanguageAccessSimpleSitemapTest.php
LanguageAccessTest::setUp in tests/src/Functional/LanguageAccessTest.php
3 methods override LanguageAccessTestBase::setUp()
LanguageAccessAdminTest::setUp in tests/src/Functional/LanguageAccessAdminTest.php
LanguageAccessSimpleSitemapTest::setUp in tests/src/Functional/LanguageAccessSimpleSitemapTest.php
LanguageAccessTest::setUp in tests/src/Functional/LanguageAccessTest.php

File

tests/src/Functional/LanguageAccessTestBase.php, line 58

Class

LanguageAccessTestBase
Base class used to simplify language access testing.

Namespace

Drupal\Tests\language_access\Functional

Code

protected function setUp() : void {
  parent::setUp();
  $this
    ->drupalCreateContentType([
    'type' => 'page',
  ]);
  $this
    ->config('system.site')
    ->set('page.front', '/node')
    ->save();

  // Create NL language.
  ConfigurableLanguage::createFromLangcode('nl')
    ->save();

  // Set the language path prefixes.
  $this
    ->config('language.negotiation')
    ->set('url', [
    'source' => 'path_prefix',
    'prefixes' => [
      'en' => 'en',
      'nl' => 'nl',
    ],
  ])
    ->save();

  // Turn on content translation for pages.
  $config = ContentLanguageSettings::loadByEntityTypeBundle('node', 'page');
  $config
    ->setDefaultLangcode('en')
    ->setLanguageAlterable(TRUE)
    ->save();
  $node = $this
    ->drupalCreateNode([
    'type' => 'page',
    'path' => '/test-en',
  ]);
  $node
    ->addTranslation('nl', [
    'title' => $this
      ->randomMachineName(),
    'path' => '/test-nl',
  ])
    ->save();

  // Access to the default language.
  $this->roleStorage = $this->container
    ->get('entity_type.manager')
    ->getStorage('user_role');
  $authenticated_role = $this->roleStorage
    ->load('authenticated');
  $authenticated_role
    ->revokePermission('access language en');
  $authenticated_role
    ->save();
  $this->userEn = $this
    ->createUser([
    'access language en',
  ]);
  $this->userNl = $this
    ->createUser([
    'access language nl',
  ]);
}