View source
<?php
namespace Drupal\Tests\scheduler\Functional;
use Drush\TestTraits\DrushTestTrait;
class SchedulerDrushTest extends SchedulerBrowserTestBase {
use DrushTestTrait;
public function testDrushCronMessages() {
$this
->drush('scheduler:cron');
$messages = $this
->getErrorOutput();
$this
->assertStringContainsString('Lightweight cron run activated by drush command', $messages, 'Starting dblog message not found', TRUE);
$this
->assertStringContainsString('Lightweight cron run completed', $messages, 'Ending dblog message not found', TRUE);
$this
->assertStringContainsString('Message: Scheduler lightweight cron completed', $messages, 'Drush message not found', TRUE);
$this
->drush('sch:cron', [], [
'nomsg' => TRUE,
]);
$messages = $this
->getErrorOutput();
$this
->assertStringNotContainsString('Message: Scheduler lightweight cron completed', $messages, '--nomsg parameter did not work', TRUE);
$this
->drush('sch-cron', [], [
'nolog' => TRUE,
]);
$messages = $this
->getErrorOutput();
$this
->assertStringNotContainsString('Lightweight cron run activated by drush command', $messages, '--nolog parameter did not work for starting message', TRUE);
$this
->assertStringNotContainsString('Lightweight cron run completed', $messages, '--nolog parameter did not work for ending message', TRUE);
}
public function testDrushCronPublishing($entityTypeId, $bundle) {
$title1 = $this
->randomMachineName(20) . ' for publishing';
$entity = $this
->createEntity($entityTypeId, $bundle, [
'title' => $title1,
'publish_on' => strtotime('-3 hours'),
]);
$title2 = $this
->randomMachineName(20) . ' for unpublishing';
$entity = $this
->createEntity($entityTypeId, $bundle, [
'title' => $title2,
'unpublish_on' => strtotime('-2 hours'),
]);
$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);
}
public function testDrushEntityUpdate() {
$this
->drush('scheduler:entity-update');
$messages = $this
->getErrorOutput();
$this
->assertStringContainsString('Scheduler entity update - nothing to update', $messages, 'Error! Entity update message not found', TRUE);
}
}