public function SchedulerBasicTest::testPublishingAndUnpublishing in Scheduler 2.x
Same name and namespace in other branches
- 8 tests/src/Functional/SchedulerBasicTest.php \Drupal\Tests\scheduler\Functional\SchedulerBasicTest::testPublishingAndUnpublishing()
Tests basic scheduling of content.
File
- tests/
src/ Functional/ SchedulerBasicTest.php, line 15
Class
- SchedulerBasicTest
- Tests the modules primary function - publishing and unpublishing content.
Namespace
Drupal\Tests\scheduler\FunctionalCode
public function testPublishingAndUnpublishing() {
// Login is required here before creating the publish_on date and time
// values so that $this->dateFormatter can utilise the current users
// timezone. The constraints receive values which have been converted using
// the users timezone so they need to be consistent.
$this
->drupalLogin($this->schedulerUser);
// Create node values. Set time to one hour in the future.
$edit = [
'title[0][value]' => 'Publish This Node',
'publish_on[0][value][date]' => $this->dateFormatter
->format(time() + 3600, 'custom', 'Y-m-d'),
'publish_on[0][value][time]' => $this->dateFormatter
->format(time() + 3600, 'custom', 'H:i:s'),
];
$this
->helpTestScheduler($edit);
// Remove publish_on and set unpublish_on, then run basic tests again.
$edit['unpublish_on[0][value][date]'] = $edit['publish_on[0][value][date]'];
$edit['unpublish_on[0][value][time]'] = $edit['publish_on[0][value][time]'];
unset($edit['publish_on[0][value][date]']);
unset($edit['publish_on[0][value][time]']);
// Need a new title for the new node, as we identify the node by title.
$edit['title[0][value]'] = 'Unpublish This Node';
$this
->helpTestScheduler($edit);
}