You are here

public function ScheduledTransitionEntityTransitionsFormTest::testTransitionsByPageLanguage in Scheduled Transitions 2.x

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

Tests transitions appear on list according to page context language.

Transitions irrelevant to the language context must not show.

Language by route context is automatically enabled when installing language.module with the 'URL' (Language from the URL (Path prefix or domain) negotiator method plugin.

File

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

Class

ScheduledTransitionEntityTransitionsFormTest
Tests the route which shows all transitions for an entity.

Namespace

Drupal\Tests\scheduled_transitions\Functional

Code

public function testTransitionsByPageLanguage() {
  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',
    ],
  ]);
  $currentUser = $this
    ->drupalCreateUser([
    'administer st_entity_test entities',
    'use editorial transition create_new_draft',
    'use editorial transition publish',
    'use editorial transition archive',
    Permissions::viewScheduledTransitionsPermission('st_entity_test', 'st_entity_test'),
  ]);
  $this
    ->drupalLogin($currentUser);
  $entity = TestEntity::create([
    'type' => 'st_entity_test',
  ]);
  $entity->name = 'defaultName';
  $de = $entity
    ->addTranslation('de');
  $fr = $entity
    ->addTranslation('fr');
  $de->name = 'deName';
  $fr->name = 'frName';
  $entity
    ->save();
  $author = User::create([
    '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();
  $defaultUrl = $entity
    ->toUrl(RouteProvider::LINK_TEMPLATE);
  $this
    ->drupalGet($defaultUrl);
  $this
    ->assertSession()
    ->addressEquals('/st_entity_test/1/scheduled-transitions');
  $this
    ->assertSession()
    ->pageTextContains('There are no scheduled transitions for defaultName');
  $deUrl = $entity
    ->getTranslation('de')
    ->toUrl(RouteProvider::LINK_TEMPLATE);
  $this
    ->drupalGet($deUrl);
  $this
    ->assertSession()
    ->addressEquals('/de/st_entity_test/1/scheduled-transitions');
  $this
    ->assertSession()
    ->pageTextNotContains('There are no scheduled transitions for deName');
  $this
    ->assertSession()
    ->elementTextContains('css', 'table tr:nth-child(1) > td:nth-child(2)', 'Draft');
  $this
    ->assertSession()
    ->elementTextContains('css', 'table tr:nth-child(1) > td:nth-child(3)', 'Published');
  $this
    ->assertSession()
    ->elementTextContains('css', 'table tr:nth-child(1) > td:nth-child(5)', $author
    ->label());
  $frUrl = $entity
    ->getTranslation('fr')
    ->toUrl(RouteProvider::LINK_TEMPLATE);
  $this
    ->drupalGet($frUrl);
  $this
    ->assertSession()
    ->addressEquals('/fr/st_entity_test/1/scheduled-transitions');
  $this
    ->assertSession()
    ->pageTextContains('There are no scheduled transitions for frName');
}