You are here

public function ScheduledTransitionListTest::testList in Scheduled Transitions 8

Same name and namespace in other branches
  1. 2.x tests/src/Functional/ScheduledTransitionListTest.php \Drupal\Tests\scheduled_transitions\Functional\ScheduledTransitionListTest::testList()

Tests list.

File

tests/src/Functional/ScheduledTransitionListTest.php, line 39

Class

ScheduledTransitionListTest
Tests the non-views global list.

Namespace

Drupal\Tests\scheduled_transitions\Functional

Code

public function testList() {
  $currentUser = $this
    ->drupalCreateUser([
    'view all scheduled transitions',
  ]);
  $this
    ->drupalLogin($currentUser);
  $url = Url::fromRoute('entity.scheduled_transition.collection');
  $this
    ->drupalGet($url);
  $this
    ->assertSession()
    ->statusCodeEquals(200);
  $this
    ->assertSession()
    ->pageTextContains('There are no scheduled transitions yet.');
  $workflow = $this
    ->createEditorialWorkflow();
  $workflow
    ->getTypePlugin()
    ->addEntityTypeAndBundle('entity_test_revlog', 'entity_test_revlog');
  $workflow
    ->save();
  $entityLabel = $this
    ->randomMachineName();
  $author = User::create([
    'name' => $this
      ->randomMachineName(),
  ]);
  $author
    ->save();
  $entity = EntityTestWithRevisionLog::create([
    'type' => 'entity_test_revlog',
  ]);
  $entity->name = $entityLabel;
  $entity->moderation_state = 'draft';
  $entity
    ->save();
  $this
    ->assertEquals(1, $entity
    ->getRevisionId());
  $newState = 'published';
  $date = new \DateTime('2 Feb 2018 11am');
  $scheduledTransition = ScheduledTransition::create([
    'entity' => $entity,
    'entity_revision_id' => 1,
    'author' => $author,
    'workflow' => $workflow
      ->id(),
    'moderation_state' => $newState,
    'transition_on' => $date
      ->getTimestamp(),
  ]);
  $scheduledTransition
    ->save();
  $this
    ->drupalGet($url);
  $this
    ->assertSession()
    ->statusCodeEquals(200);
  $tableRows = $this
    ->cssSelect('table tbody tr');
  $this
    ->assertCount(1, $tableRows);
  $row1 = $this
    ->cssSelect('table tbody tr:nth-child(1)');
  $td1 = $row1[0]
    ->find('css', 'td:nth-child(1)');
  $this
    ->assertEquals($entityLabel, $td1
    ->getText());
  $td2 = $row1[0]
    ->find('css', 'td:nth-child(2)');
  $this
    ->assertEquals('Fri, 02/02/2018 - 11:00', $td2
    ->getText());
}