public function MetaInformationTest::testArticleScheduling in Thunder 8.4
Same name and namespace in other branches
- 8.5 tests/src/FunctionalJavascript/MetaInformationTest.php \Drupal\Tests\thunder\FunctionalJavascript\MetaInformationTest::testArticleScheduling()
- 8.2 tests/src/FunctionalJavascript/MetaInformationTest.php \Drupal\Tests\thunder\FunctionalJavascript\MetaInformationTest::testArticleScheduling()
- 8.3 tests/src/FunctionalJavascript/MetaInformationTest.php \Drupal\Tests\thunder\FunctionalJavascript\MetaInformationTest::testArticleScheduling()
- 6.2.x tests/src/FunctionalJavascript/MetaInformationTest.php \Drupal\Tests\thunder\FunctionalJavascript\MetaInformationTest::testArticleScheduling()
- 6.0.x tests/src/FunctionalJavascript/MetaInformationTest.php \Drupal\Tests\thunder\FunctionalJavascript\MetaInformationTest::testArticleScheduling()
- 6.1.x tests/src/FunctionalJavascript/MetaInformationTest.php \Drupal\Tests\thunder\FunctionalJavascript\MetaInformationTest::testArticleScheduling()
Test Scheduling of Article.
File
- tests/
src/ FunctionalJavascript/ MetaInformationTest.php, line 233
Class
- MetaInformationTest
- Testing of Meta Information.
Namespace
Drupal\Tests\thunder\FunctionalJavascriptCode
public function testArticleScheduling() {
$articleId = 10;
// Create article with published 2 days ago, unpublish tomorrow.
$startTimestamp = strtotime('-2 days');
$endTimestamp = strtotime('+1 day');
$fieldValues = [
'publish_on[0][value][date]' => date('Y-m-d', $startTimestamp),
'publish_on[0][value][time]' => date('H:i:s', $startTimestamp),
'unpublish_on[0][value][date]' => date('Y-m-d', $endTimestamp),
'unpublish_on[0][value][time]' => date('H:i:s', $endTimestamp),
'publish_state[0]' => 'published',
'unpublish_state[0]' => 'unpublished',
];
$this
->createArticleWithFields($fieldValues);
// Check that Article is unpublished.
$this
->drupalGet('node/' . $articleId);
$this
->assertSession()
->elementExists('xpath', '//div[@class="content"]/article[contains(@class, "node--unpublished")]');
$this
->runCron();
// Check that Article is published.
$this
->drupalGet('node/' . $articleId);
$this
->assertSession()
->elementNotExists('xpath', '//div[@class="content"]/article[contains(@class, "node--unpublished")]');
// Check that Article is published.
$this
->drupalGet('node/' . $articleId . '/edit');
$page = $this
->getSession()
->getPage();
// Edit article and set un-publish date same as publish date.
$unPublishDiffSeconds = 5;
$unPublishTimestamp = strtotime("+{$unPublishDiffSeconds} seconds");
$unPublishFieldValues = [
'unpublish_on[0][value][date]' => date('Y-m-d', $unPublishTimestamp),
'unpublish_on[0][value][time]' => date('H:i:s', $unPublishTimestamp),
'unpublish_state[0]' => 'unpublished',
];
$this
->expandAllTabs();
$this
->setFieldValues($page, $unPublishFieldValues);
$this
->clickSave();
// Check that Article is published.
$this
->drupalGet('node/' . $articleId);
$this
->assertSession()
->elementNotExists('xpath', '//div[@class="content"]/article[contains(@class, "node--unpublished")]');
// Wait sufficient time before cron is executed.
sleep($unPublishDiffSeconds + 2);
$this
->runCron();
// Check that Article is unpublished.
$this
->drupalGet('node/' . $articleId);
$this
->assertSession()
->elementExists('xpath', '//div[@class="content"]/article[contains(@class, "node--unpublished")]');
}