protected function SchedulerBasicTest::helpTestScheduler in Scheduler 8
Same name and namespace in other branches
- 2.x tests/src/Functional/SchedulerBasicTest.php \Drupal\Tests\scheduler\Functional\SchedulerBasicTest::helpTestScheduler()
Helper function for testPublishingAndUnpublishing().
Schedules content, runs cron and asserts status.
1 call to SchedulerBasicTest::helpTestScheduler()
- SchedulerBasicTest::testPublishingAndUnpublishing in tests/
src/ Functional/ SchedulerBasicTest.php - Tests basic scheduling of content.
File
- tests/
src/ Functional/ SchedulerBasicTest.php, line 45
Class
- SchedulerBasicTest
- Tests the modules primary function - publishing and unpublishing content.
Namespace
Drupal\Tests\scheduler\FunctionalCode
protected function helpTestScheduler($edit) {
$this
->drupalPostForm('node/add/' . $this->type, $edit, 'Save');
// Verify that the node was created.
$node = $this
->drupalGetNodeByTitle($edit['title[0][value]']);
$this
->assertNotEmpty($node, sprintf('"%s" was created sucessfully.', $edit['title[0][value]']));
if (empty($node)) {
$this
->assertTrue(FALSE, 'Test halted because node was not created.');
return;
}
// Assert that the node is correctly published or unpublished.
if (isset($edit['publish_on[0][value][date]'])) {
$key = 'publish_on';
$this
->assertFalse($node
->isPublished(), 'Node is unpublished before Cron');
}
else {
$key = 'unpublish_on';
$this
->assertTrue($node
->isPublished(), 'Node is published before Cron');
}
// Modify the scheduler field data to a time in the past, then run cron.
$node->{$key} = $this->requestTime - 1;
$node
->save();
$this
->cronRun();
// Refresh the node cache and check the node status.
$this->nodeStorage
->resetCache([
$node
->id(),
]);
$node = $this->nodeStorage
->load($node
->id());
if ($key == 'publish_on') {
$this
->assertTrue($node
->isPublished(), 'Node is published after Cron');
}
else {
$this
->assertFalse($node
->isPublished(), 'Node is unpublished after Cron');
}
}