You are here

public function SchedulerDeleteNodeTest::testDeleteNodeWhenSchedulingIsRequired in Scheduler 8

Tests the deletion of a scheduled node.

Check that it is possible to delete a node that does not have a publishing date set, when scheduled publishing is required. Likewise for unpublishing.

See also

https://drupal.org/node/1614880

File

tests/src/Functional/SchedulerDeleteNodeTest.php, line 23

Class

SchedulerDeleteNodeTest
Tests deletion of nodes enabled for Scheduler.

Namespace

Drupal\Tests\scheduler\Functional

Code

public function testDeleteNodeWhenSchedulingIsRequired() {

  // Log in.
  $this
    ->drupalLogin($this->adminUser);

  // Create a published and an unpublished node, both without scheduled dates.
  $published_node = $this
    ->drupalCreateNode([
    'type' => $this->type,
    'status' => 1,
  ]);
  $unpublished_node = $this
    ->drupalCreateNode([
    'type' => $this->type,
    'status' => 0,
  ]);

  // Make scheduled publishing and unpublishing required.
  $this->nodetype
    ->setThirdPartySetting('scheduler', 'publish_required', TRUE)
    ->setThirdPartySetting('scheduler', 'unpublish_required', TRUE)
    ->save();

  // Check that deleting the nodes does not throw form validation errors.
  $this
    ->drupalGet('node/' . $published_node
    ->id() . '/edit');
  $this
    ->clickLink('Delete');

  // The text 'error message' is used in a header h2 html tag which is
  // normally made hidden from browsers but will be in the page source.
  // It is also good when testing for the absense of something to also test
  // for the presence of text, hence the second assertion for each check.
  $this
    ->assertSession()
    ->pageTextNotContains('Error message');
  $this
    ->assertSession()
    ->pageTextContains('Are you sure you want to delete the content');

  // Do the same test for the unpublished node.
  $this
    ->drupalGet('node/' . $unpublished_node
    ->id() . '/edit');
  $this
    ->clickLink('Delete');
  $this
    ->assertSession()
    ->pageTextNotContains('Error message');
  $this
    ->assertSession()
    ->pageTextContains('Are you sure you want to delete the content');
}