public function SchedulerRulesEventsTest::testRulesEventsPublish in Scheduler 2.x
Same name and namespace in other branches
- 8 tests/src/Functional/SchedulerRulesEventsTest.php \Drupal\Tests\scheduler\Functional\SchedulerRulesEventsTest::testRulesEventsPublish()
Tests the three events related to publishing an entity.
@dataProvider dataStandardEntityTypes()
File
- tests/
src/ Functional/ SchedulerRulesEventsTest.php, line 147
Class
- SchedulerRulesEventsTest
- Tests the six events that Scheduler provides for use in Rules module.
Namespace
Drupal\Tests\scheduler\FunctionalCode
public function testRulesEventsPublish($entityTypeId, $bundle) {
// Allow dates in the past.
$this
->entityTypeObject($entityTypeId, $bundle)
->setThirdPartySetting('scheduler', 'publish_past_date', 'schedule')
->save();
// Create an entity with a publish-on date, and check that only event 1 is
// triggered.
$titleField = $entityTypeId == 'media' ? 'name' : 'title';
$title = 'C. Create with publish-on date';
$edit = [
"{$titleField}[0][value]" => $title,
'publish_on[0][value][date]' => date('Y-m-d', time() - 60),
'publish_on[0][value][time]' => date('H:i:s', time() - 60),
];
$this
->drupalGet($this
->entityAddUrl($entityTypeId, $bundle));
$this
->submitForm($edit, 'Save');
$this
->checkMessages($entityTypeId, [
1,
]);
// Edit the entity and check that only event 2 is triggered.
$entity = $this
->getEntityByTitle($entityTypeId, $title);
$this
->drupalGet($entity
->toUrl('edit-form'));
$this
->submitForm([
"{$titleField}[0][value]" => 'D. Edit with publish-on date',
], 'Save');
$this
->checkMessages($entityTypeId, [
2,
]);
// Run cron and check that only event 3 is triggered.
$this
->cronRun();
$this
->drupalGet($entity
->toUrl());
$this
->checkMessages($entityTypeId, [
3,
]);
}