View source
<?php
namespace Drupal\Tests\scheduler\Functional;
class SchedulerValidationTest extends SchedulerBrowserTestBase {
public function testValidationDuringEdit($entityTypeId, $bundle) {
$this
->drupalLogin($this->adminUser);
$this
->entityTypeObject($entityTypeId)
->setThirdPartySetting('scheduler', 'unpublish_required', TRUE)
->save();
$entity = $this
->createEntity($entityTypeId, $bundle, [
'status' => FALSE,
]);
$edit = [
'publish_on[0][value][date]' => date('Y-m-d', strtotime('+1 day', $this->requestTime)),
'publish_on[0][value][time]' => date('H:i:s', strtotime('+1 day', $this->requestTime)),
];
$this
->drupalGet($entity
->toUrl('edit-form'));
$this
->submitForm($edit, 'Save');
$this
->assertSession()
->pageTextContains("If you set a 'publish on' date then you must also set an 'unpublish on' date.");
$this
->assertSession()
->pageTextNotMatches('/has been (updated|successfully saved)/');
$entity = $this
->createEntity($entityTypeId, $bundle, [
'status' => FALSE,
]);
$edit = [
'status[value]' => TRUE,
];
$this
->drupalGet($entity
->toUrl('edit-form'));
$this
->submitForm($edit, 'Save');
$this
->assertSession()
->pageTextContains("Either you must set an 'unpublish on' date or save this node as unpublished.");
$this
->assertSession()
->pageTextNotMatches('/has been (updated|successfully saved)/');
$entity = $this
->createEntity($entityTypeId, $bundle, [
'status' => FALSE,
]);
$edit = [
'publish_on[0][value][date]' => $this->dateFormatter
->format($this->requestTime + 7200, 'custom', 'Y-m-d'),
'publish_on[0][value][time]' => $this->dateFormatter
->format($this->requestTime + 7200, 'custom', 'H:i:s'),
'unpublish_on[0][value][date]' => $this->dateFormatter
->format($this->requestTime + 1800, 'custom', 'Y-m-d'),
'unpublish_on[0][value][time]' => $this->dateFormatter
->format($this->requestTime + 1800, 'custom', 'H:i:s'),
];
$this
->drupalGet($entity
->toUrl('edit-form'));
$this
->submitForm($edit, 'Save');
$this
->assertSession()
->pageTextContains("The 'unpublish on' date must be later than the 'publish on' date.");
$this
->assertSession()
->pageTextNotMatches('/has been (updated|successfully saved)/');
}
}