public function SchedulerApiTest::testAllowedUnpublishing in Scheduler 8
Covers hook_scheduler_allow_unpublishing()
This hook can allow or deny the unpublishing of individual nodes. This test is simpler than the test sequence for allowed publishing, because the past date 'publish' option is not applicable.
File
- tests/
src/ Functional/ SchedulerApiTest.php, line 125
Class
- SchedulerApiTest
- Tests the API of the Scheduler module.
Namespace
Drupal\Tests\scheduler\FunctionalCode
public function testAllowedUnpublishing() {
$this
->drupalLogin($this->webUser);
// Check the 'approved for unpublishing' field is shown on the node form.
$this
->drupalGet('node/add/' . $this->customName);
$this
->assertSession()
->fieldExists('edit-field-approved-unpublishing-value');
// Check that the message is shown when scheduling a node for unpublishing
// which is not yet allowed to be unpublished.
$edit = [
'title[0][value]' => 'Set unpublish-on date without approval',
'unpublish_on[0][value][date]' => date('Y-m-d', time() + 3),
'unpublish_on[0][value][time]' => date('H:i:s', time() + 3),
];
$this
->drupalPostForm('node/add/' . $this->customName, $edit, 'Save');
$this
->assertSession()
->pageTextContains('is scheduled for unpublishing, but will not be unpublished until approved.');
// Create a node that is scheduled but not approved for unpublication. Then
// simulate a cron run, and check that the node is still published.
$node = $this
->createUnapprovedNode('unpublish_on');
scheduler_cron();
$this->nodeStorage
->resetCache([
$node
->id(),
]);
$node = $this->nodeStorage
->load($node
->id());
$this
->assertTrue($node
->isPublished(), 'An unapproved node is not unpublished during cron processing.');
// Create a node, then approve it for unpublishing, simulate a cron run and
// check that the node is now unpublished.
$node = $this
->createUnapprovedNode('unpublish_on');
$this
->approveNode($node
->id(), 'field_approved_unpublishing');
$this
->assertTrue($node
->isPublished(), 'A new approved node is initially published.');
scheduler_cron();
$this->nodeStorage
->resetCache([
$node
->id(),
]);
$node = $this->nodeStorage
->load($node
->id());
$this
->assertFalse($node
->isPublished(), 'An approved node is unpublished during cron processing.');
// Show the dblog messages.
$this
->drupalLogin($this->adminUser);
$this
->drupalGet('admin/reports/dblog');
}