You are here

protected function SchedulerMultilingualTest::setUp in Scheduler 8

Same name and namespace in other branches
  1. 2.x tests/src/Functional/SchedulerMultilingualTest.php \Drupal\Tests\scheduler\Functional\SchedulerMultilingualTest::setUp()

Overrides SchedulerBrowserTestBase::setUp

File

tests/src/Functional/SchedulerMultilingualTest.php, line 38

Class

SchedulerMultilingualTest
Tests the scheduling functions for node translations.

Namespace

Drupal\Tests\scheduler\Functional

Code

protected function setUp() : void {
  parent::setUp();

  // Create a user with the required translation permissions.
  // 'administer languages' for url admin/config/regional/content-language.
  // 'administer content translation' to show the list of content fields at
  // url admin/config/regional/content-language.
  // 'create content translations' for the 'translations' tab on node pages
  // url node/*/translations.
  // 'translate any entity' for the 'add translation' link on the translations
  // page, url node/*/translations/add/.
  $this->translatorUser = $this
    ->drupalCreateUser([
    'administer languages',
    'administer content translation',
    'create content translations',
    'translate any entity',
  ]);

  // Get the additional role already assigned to the scheduler admin user
  // created in SchedulerBrowserTestBase and add this role to the translator
  // user, to avoid switching between users throughout this test.
  $admin_roles = $this->adminUser
    ->getRoles();

  // Key 0 is 'authenticated' role. Key 1 is the first real role.
  $this->translatorUser
    ->addRole($admin_roles[1]);
  $this->translatorUser
    ->save();
  $this
    ->drupalLogin($this->translatorUser);

  // Allow scheduler dates in the past to be published on next cron run.
  $this->nodetype
    ->setThirdPartySetting('scheduler', 'publish_past_date', 'schedule')
    ->save();

  // Enable the content type for translation.
  $this->container
    ->get('content_translation.manager')
    ->setEnabled('node', $this->type, TRUE);

  // Make three additional languages available. 'en' is added here as the last
  // code and it should not be defined as a configurable language.
  $langcodes = [
    'am',
    'bg',
    'ca',
    'en',
  ];
  ConfigurableLanguage::createFromLangcode($langcodes[0])
    ->save();
  ConfigurableLanguage::createFromLangcode($langcodes[1])
    ->save();
  ConfigurableLanguage::createFromLangcode($langcodes[2])
    ->save();

  // Get the language names and store for later use.
  $languages = \Drupal::languageManager()
    ->getLanguages();
  foreach ($langcodes as $key => $code) {
    $this->languages[$key] = [
      'code' => $code,
      'name' => $languages[$code]
        ->getName(),
    ];
  }
}