View source
<?php
namespace Drupal\Tests\scheduler\Functional;
class SchedulerMessageTest extends SchedulerBrowserTestBase {
public function testConfirmationMessage($entityTypeId, $bundle) {
$this
->drupalLogin($this->schedulerUser);
$titleField = $entityTypeId == 'media' ? 'name' : 'title';
$publish_on = strtotime('+ 1 day 5 hours');
$unpublish_on = strtotime('+ 2 day 7 hours');
$publish_on_formatted = $this->dateFormatter
->format($publish_on, 'long');
$unpublish_on_formatted = $this->dateFormatter
->format($unpublish_on, 'long');
$title1 = 'Test 1 - ' . $this
->randomString(10);
$title2 = 'Test 2 - ' . $this
->randomString(10);
$title3 = 'Test 3 - ' . $this
->randomString(10);
$edit = [
"{$titleField}[0][value]" => $title1,
'publish_on[0][value][date]' => date('Y-m-d', $publish_on),
'publish_on[0][value][time]' => date('H:i:s', $publish_on),
];
$add_url = $this
->entityAddUrl($entityTypeId, $bundle);
$this
->drupalGet($add_url);
$this
->submitForm($edit, 'Save');
$entity1 = $this
->getEntityByTitle($entityTypeId, $title1);
$this
->assertSession()
->pageTextContains(sprintf('%s is scheduled to be published %s', $title1, $publish_on_formatted));
$edit = [
"{$titleField}[0][value]" => $title2,
'unpublish_on[0][value][date]' => date('Y-m-d', $unpublish_on),
'unpublish_on[0][value][time]' => date('H:i:s', $unpublish_on),
];
$this
->drupalGet($add_url);
$this
->submitForm($edit, 'Save');
$entity2 = $this
->getEntityByTitle($entityTypeId, $title2);
$this
->assertSession()
->pageTextContains(sprintf('%s is scheduled to be unpublished %s', $title2, $unpublish_on_formatted));
$edit = [
"{$titleField}[0][value]" => $title3,
'publish_on[0][value][date]' => date('Y-m-d', $publish_on),
'publish_on[0][value][time]' => date('H:i:s', $publish_on),
'unpublish_on[0][value][date]' => date('Y-m-d', $unpublish_on),
'unpublish_on[0][value][time]' => date('H:i:s', $unpublish_on),
];
$this
->drupalGet($add_url);
$this
->submitForm($edit, 'Save');
$entity3 = $this
->getEntityByTitle($entityTypeId, $title3);
$this
->assertSession()
->pageTextContains(sprintf('%s is scheduled to be published %s and unpublished %s', $title3, $publish_on_formatted, $unpublish_on_formatted));
$this
->entityTypeObject($entityTypeId, $bundle)
->setThirdPartySetting('scheduler', 'show_message_after_update', FALSE)
->save();
$this
->drupalGet($entity1
->toUrl('edit-form'));
$this
->submitForm([], 'Save');
$this
->assertSession()
->pageTextNotContains('is scheduled to be published');
$this
->drupalGet($entity2
->toUrl('edit-form'));
$this
->submitForm([], 'Save');
$this
->assertSession()
->pageTextNotContains('is scheduled to be unpublished');
$this
->drupalGet($entity3
->toUrl('edit-form'));
$this
->submitForm([], 'Save');
$this
->assertSession()
->pageTextNotContains('is scheduled to be published');
$this
->entityTypeObject($entityTypeId, $bundle)
->setThirdPartySetting('scheduler', 'show_message_after_update', TRUE)
->save();
$this
->drupalGet($entity1
->toUrl('edit-form'));
$this
->submitForm([], 'Save');
$this
->assertSession()
->pageTextContains(sprintf('%s is scheduled to be published %s', $title1, $publish_on_formatted));
$this
->drupalGet($entity2
->toUrl('edit-form'));
$this
->submitForm([], 'Save');
$this
->assertSession()
->pageTextContains(sprintf('%s is scheduled to be unpublished %s', $title2, $unpublish_on_formatted));
$this
->drupalGet($entity3
->toUrl('edit-form'));
$this
->submitForm([], 'Save');
$this
->assertSession()
->pageTextContains(sprintf('%s is scheduled to be published %s and unpublished %s', $title3, $publish_on_formatted, $unpublish_on_formatted));
}
}