public function SchedulerHooksLegacyTest::testAllowedUnpublishing in Scheduler 2.x
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/ SchedulerHooksLegacyTest.php, line 242
Class
- SchedulerHooksLegacyTest
- Tests the legacy API hook functions 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
->drupalGet("node/add/{$this->customName}");
$this
->submitForm($edit, 'Save');
$this
->assertSession()
->pageTextMatches('/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(), "Unapproved '{$node->label()}' should not be 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(), "New approved '{$node->label()}' should initially remain published.");
scheduler_cron();
$this->nodeStorage
->resetCache([
$node
->id(),
]);
$node = $this->nodeStorage
->load($node
->id());
$this
->assertFalse($node
->isPublished(), "Approved '{$node->label()}' should be unpublished during cron processing.");
// Show the dblog messages.
$this
->drupalLogin($this->adminUser);
$this
->drupalGet('admin/reports/dblog');
}