View source
<?php
namespace Drupal\Tests\scheduler\Functional;
class SchedulerValidationTest extends SchedulerBrowserTestBase {
public function testValidationDuringEdit() {
$this
->drupalLogin($this->adminUser);
$this->nodetype
->setThirdPartySetting('scheduler', 'unpublish_required', TRUE)
->save();
$node = $this
->drupalCreateNode([
'type' => $this->type,
'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('node/' . $node
->id() . '/edit');
$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()
->pageTextNotContains(sprintf('%s %s has been updated.', $this->typeName, $node->title->value));
$node = $this
->drupalCreateNode([
'type' => $this->type,
'status' => FALSE,
]);
$edit = [
'status[value]' => TRUE,
];
$this
->drupalPostForm('node/' . $node
->id() . '/edit', $edit, 'Save');
$this
->assertSession()
->pageTextContains("Either you must set an 'unpublish on' date or save this node as unpublished.");
$this
->assertSession()
->pageTextNotContains(sprintf('%s %s has been updated.', $this->typeName, $node->title->value));
$node = $this
->drupalCreateNode([
'type' => $this->type,
'status' => FALSE,
]);
$edit = [
'publish_on[0][value][date]' => $this->dateFormatter
->format($this->requestTime + 8100, 'custom', 'Y-m-d'),
'publish_on[0][value][time]' => $this->dateFormatter
->format($this->requestTime + 8100, '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
->drupalPostForm('node/' . $node
->id() . '/edit', $edit, 'Save');
$this
->assertSession()
->pageTextContains("The 'unpublish on' date must be later than the 'publish on' date.");
$this
->assertSession()
->pageTextNotContains(sprintf('%s %s has been updated.', $this->typeName, $node->title->value));
}
}