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() {
$title1 = $this
->randomMachineName(20);
$this
->drupalCreateNode([
'title' => $title1,
'type' => $this->type,
'publish_on' => strtotime('-3 hours'),
]);
$title2 = $this
->randomMachineName(20);
$this
->drupalCreateNode([
'title' => $title2,
'type' => $this->type,
'unpublish_on' => strtotime('-2 hours'),
]);
$this
->drush('scheduler:cron');
$messages = $this
->getErrorOutput();
$this
->assertStringContainsString(sprintf('%s: scheduled publishing of %s', $this->typeName, $title1), $messages, 'Scheduled publishing message not found', TRUE);
$this
->assertStringContainsString(sprintf('%s: scheduled unpublishing of %s', $this->typeName, $title2), $messages, 'Scheduled unpublishing message not found', TRUE);
}
}