public function SchedulerRevisioningTest::testAlterCreationDate in Scheduler 8
Same name and namespace in other branches
- 2.x tests/src/Functional/SchedulerRevisioningTest.php \Drupal\Tests\scheduler\Functional\SchedulerRevisioningTest::testAlterCreationDate()
Tests the 'touch' option to alter the node created date during publishing.
File
- tests/
src/ Functional/ SchedulerRevisioningTest.php, line 126
Class
- SchedulerRevisioningTest
- Tests revision options when Scheduler publishes or unpublishes content.
Namespace
Drupal\Tests\scheduler\FunctionalCode
public function testAlterCreationDate() {
// Ensure nodes with past dates will be scheduled not published immediately.
$this->nodetype
->setThirdPartySetting('scheduler', 'publish_past_date', 'schedule')
->save();
// Create a node with a 'created' date two days in the past.
$created = strtotime('-2 day', $this->requestTime);
$settings = [
'type' => $this->type,
'created' => $created,
'status' => FALSE,
];
$node = $this
->drupalCreateNode($settings);
// Show that the node is not published.
$this
->assertFalse($node
->isPublished(), 'The node is not published.');
// Schedule the node for publishing and run cron.
$node = $this
->schedule($node, 'publish');
// Get the created date from the node and check that it has not changed.
$created_after_cron = $node->created->value;
$this
->assertTrue($node
->isPublished(), 'The node has been published.');
$this
->assertEquals($created, $created_after_cron, 'The node creation date is not changed by default.');
// Set option to change the created date to match the publish_on date.
$this->nodetype
->setThirdPartySetting('scheduler', 'publish_touch', TRUE)
->save();
// Schedule the node again and run cron.
$node = $this
->schedule($node, 'publish');
// Check that the created date has changed to match the publish_on date.
$created_after_cron = $node->created->value;
$this
->assertEquals(strtotime('-5 hour', $this->requestTime), $created_after_cron, "With 'touch' option set, the node creation date is changed to match the publishing date.");
}