public function SchedulerDrushTest::testDrushCronPublishing in Scheduler 2.x
Same name and namespace in other branches
- 8 tests/src/Functional/SchedulerDrushTest.php \Drupal\Tests\scheduler\Functional\SchedulerDrushTest::testDrushCronPublishing()
Tests scheduled publishing and unpublishing of entities via Drush.
@dataProvider dataStandardEntityTypes()
File
- tests/
src/ Functional/ SchedulerDrushTest.php, line 47
Class
- SchedulerDrushTest
- Tests the Drush commands provided by Scheduler.
Namespace
Drupal\Tests\scheduler\FunctionalCode
public function testDrushCronPublishing($entityTypeId, $bundle) {
// Create an entity which is scheduled for publishing.
$title1 = $this
->randomMachineName(20) . ' for publishing';
$entity = $this
->createEntity($entityTypeId, $bundle, [
'title' => $title1,
'publish_on' => strtotime('-3 hours'),
]);
// Create an entity which is scheduled for unpublishing.
$title2 = $this
->randomMachineName(20) . ' for unpublishing';
$entity = $this
->createEntity($entityTypeId, $bundle, [
'title' => $title2,
'unpublish_on' => strtotime('-2 hours'),
]);
// Run Scheduler's drush cron command and check that the expected publishing
// and unpublishing messages are found.
$this
->drush('scheduler:cron');
$messages = $this
->getErrorOutput();
$bundle_field = $entity
->getEntityType()
->get('entity_keys')['bundle'];
$type_label = $entity->{$bundle_field}->entity
->label();
$this
->assertStringContainsString(sprintf('%s: scheduled publishing of %s', $type_label, $title1), $messages, 'Scheduled publishing message not found', TRUE);
$this
->assertStringContainsString(sprintf('%s: scheduled unpublishing of %s', $type_label, $title2), $messages, 'Scheduled unpublishing message not found', TRUE);
}