public function ScheduledTransitionRescheduleFormTest::testLatestOptionPreselected in Scheduled Transitions 2.x
Same name and namespace in other branches
- 8 tests/src/Functional/ScheduledTransitionRescheduleFormTest.php \Drupal\Tests\scheduled_transitions\Functional\ScheduledTransitionRescheduleFormTest::testLatestOptionPreselected()
Test rescheduling.
File
- tests/
src/ Functional/ ScheduledTransitionRescheduleFormTest.php, line 48
Class
- ScheduledTransitionRescheduleFormTest
- Tests the route to reschedule a transition.
Namespace
Drupal\Tests\scheduled_transitions\FunctionalCode
public function testLatestOptionPreselected() {
$this
->enabledBundles([
[
'st_entity_test',
'st_entity_test',
],
]);
$workflow = $this
->createEditorialWorkflow();
$workflow
->getTypePlugin()
->addEntityTypeAndBundle('st_entity_test', 'st_entity_test');
$workflow
->save();
$author = User::create([
'name' => $this
->randomMachineName(),
]);
$author
->save();
$currentUser = $this
->drupalCreateUser([
'administer st_entity_test entities',
'use editorial transition create_new_draft',
'use editorial transition publish',
'use editorial transition archive',
Permissions::rescheduleScheduledTransitionsPermission('st_entity_test', 'st_entity_test'),
]);
$this
->drupalLogin($currentUser);
$entity = ScheduledTransitionsTestEntity::create([
'type' => 'st_entity_test',
]);
$entity
->save();
$date = new \DateTime('2 Feb 2018 11am');
/** @var \Drupal\scheduled_transitions\Entity\ScheduledTransitionInterface $scheduledTransition */
$scheduledTransition = ScheduledTransition::create([
'entity' => $entity,
'entity_revision_id' => $entity
->getRevisionId(),
'author' => $author,
'workflow' => $workflow
->id(),
'moderation_state' => 'published',
'transition_on' => $date
->getTimestamp(),
]);
$scheduledTransition
->save();
$this
->drupalGet($scheduledTransition
->toUrl('reschedule-form'));
$this
->assertSession()
->fieldValueEquals('current_date[date]', '2018-02-02');
$this
->assertSession()
->fieldValueEquals('current_date[time]', '11:00:00');
$this
->assertSession()
->fieldValueEquals('date[date]', '2018-02-02');
$this
->assertSession()
->fieldValueEquals('date[time]', '11:00:00');
$edit = [
'date[date]' => '2018-10-21',
'date[time]' => '14:00:00',
];
$this
->drupalPostForm(NULL, $edit, 'Reschedule transition');
$this
->assertSession()
->pageTextContains('Rescheduled transition for Sun, 10/21/2018 - 14:00');
// Reload ST.
$expectedDate = (new \DateTime('2018-10-21 2pm'))
->getTimestamp();
$scheduledTransition = ScheduledTransition::load($scheduledTransition
->id());
$this
->assertEquals($scheduledTransition
->getTransitionTime(), $expectedDate);
}