You are here

public function ScheduledTransitionLocalTaskTest::testTabTitleByTranslation in Scheduled Transitions 2.x

Same name and namespace in other branches
  1. 8 tests/src/Functional/ScheduledTransitionLocalTaskTest.php \Drupal\Tests\scheduled_transitions\Functional\ScheduledTransitionLocalTaskTest::testTabTitleByTranslation()

Tests local task tab title depending on viewed translation.

File

tests/src/Functional/ScheduledTransitionLocalTaskTest.php, line 60

Class

ScheduledTransitionLocalTaskTest
Tests the text displayed in local task [tab].

Namespace

Drupal\Tests\scheduled_transitions\Functional

Code

public function testTabTitleByTranslation() {
  ConfigurableLanguage::createFromLangcode('de')
    ->save();
  ConfigurableLanguage::createFromLangcode('fr')
    ->save();
  $languageNegotiator = \Drupal::service('language_negotiator');
  $languageNegotiator
    ->saveConfiguration('language_content', [
    LanguageNegotiationUrl::METHOD_ID => 1,
  ]);

  // Rebuild so container picks up new languages and enabled negotiator
  // plugins.
  $this
    ->rebuildContainer();
  $workflow = $this
    ->createEditorialWorkflow();
  $workflow
    ->getTypePlugin()
    ->addEntityTypeAndBundle('st_entity_test', 'st_entity_test');
  $workflow
    ->save();
  $this
    ->enabledBundles([
    [
      'st_entity_test',
      'st_entity_test',
    ],
  ]);
  $entity = TestEntity::create([
    'type' => 'st_entity_test',
  ]);
  $de = $entity
    ->addTranslation('de');
  $fr = $entity
    ->addTranslation('fr');
  $de->name = 'deName';
  $fr->name = 'frName';
  $entity
    ->save();
  $author = User::create([
    'uid' => 2,
    'name' => $this
      ->randomMachineName(),
  ]);
  $author
    ->save();
  $scheduledTransition = ScheduledTransition::create([
    'entity' => $entity,
    'entity_revision_id' => 1,
    // Transition 'de'.
    'entity_revision_langcode' => 'de',
    'author' => $author,
    'workflow' => $workflow
      ->id(),
    'moderation_state' => 'published',
    'transition_on' => (new \DateTime('2 Feb 2018 11am'))
      ->getTimestamp(),
  ]);
  $scheduledTransition
    ->save();
  $currentUser = $this
    ->drupalCreateUser([
    'administer st_entity_test entities',
    'use editorial transition create_new_draft',
    'view scheduled transitions st_entity_test st_entity_test',
  ]);
  $this
    ->drupalLogin($currentUser);

  // No transitions for default language.
  $this
    ->drupalGet($entity
    ->toUrl());
  $this
    ->assertSession()
    ->statusCodeEquals(200);
  $this
    ->assertSession()
    ->elementTextContains('css', 'nav.tabs', 'Scheduled transitions (0)');

  // No transitions for 'de' language.
  $this
    ->drupalGet($entity
    ->getTranslation('de')
    ->toUrl());
  $this
    ->assertSession()
    ->statusCodeEquals(200);
  $this
    ->assertSession()
    ->elementTextContains('css', 'nav.tabs', 'Scheduled transitions (1)');

  // No transitions for 'fr' language.
  $this
    ->drupalGet($entity
    ->getTranslation('fr')
    ->toUrl());
  $this
    ->assertSession()
    ->statusCodeEquals(200);
  $this
    ->assertSession()
    ->elementTextContains('css', 'nav.tabs', 'Scheduled transitions (0)');
}