You are here

public function SchedulerRulesEventsTest::testRulesEventsUnpublish in Scheduler 2.x

Same name and namespace in other branches
  1. 8 tests/src/Functional/SchedulerRulesEventsTest.php \Drupal\Tests\scheduler\Functional\SchedulerRulesEventsTest::testRulesEventsUnpublish()

Tests the three events related to unpublishing an entity.

@dataProvider dataStandardEntityTypes()

File

tests/src/Functional/SchedulerRulesEventsTest.php, line 182

Class

SchedulerRulesEventsTest
Tests the six events that Scheduler provides for use in Rules module.

Namespace

Drupal\Tests\scheduler\Functional

Code

public function testRulesEventsUnpublish($entityTypeId, $bundle) {

  // Create an entity with an unpublish-on date, and check that only event 4
  // is triggered.
  $titleField = $entityTypeId == 'media' ? 'name' : 'title';
  $title = 'E. Create with unpublish-on date';
  $edit = [
    "{$titleField}[0][value]" => $title,
    'unpublish_on[0][value][date]' => date('Y-m-d', time() + 5),
    'unpublish_on[0][value][time]' => date('H:i:s', time() + 5),
  ];
  $this
    ->drupalGet($this
    ->entityAddUrl($entityTypeId, $bundle));
  $this
    ->submitForm($edit, 'Save');
  $this
    ->checkMessages($entityTypeId, [
    4,
  ]);

  // Edit the entity and check that only event 5 is triggered.
  $entity = $this
    ->getEntityByTitle($entityTypeId, $title);
  $this
    ->drupalGet($entity
    ->toUrl('edit-form'));
  $this
    ->submitForm([
    "{$titleField}[0][value]" => 'F. Edit with unpublish-on date',
  ], 'Save');
  $this
    ->checkMessages($entityTypeId, [
    5,
  ]);

  // Delay to ensure that the dates are in the past so that the entity will be
  // processed during cron, and check that only event 6 is triggered.
  sleep(6);
  $this
    ->cronRun();
  $this
    ->drupalGet($entity
    ->toUrl());
  $this
    ->checkMessages($entityTypeId, [
    6,
  ]);
}