You are here

public function SchedulerRulesEventsTest::testRulesEventsUnpublish in Scheduler 8

Same name and namespace in other branches
  1. 2.x tests/src/Functional/SchedulerRulesEventsTest.php \Drupal\Tests\scheduler\Functional\SchedulerRulesEventsTest::testRulesEventsUnpublish()

Tests the three events related to unpublishing a node.

File

tests/src/Functional/SchedulerRulesEventsTest.php, line 155

Class

SchedulerRulesEventsTest
Tests the six events that Scheduler provides for use in Rules module.

Namespace

Drupal\Tests\scheduler\Functional

Code

public function testRulesEventsUnpublish() {
  $assert = $this
    ->assertSession();

  // Create a node with an unpublish-on date, and check that only event 4 is
  // triggered.
  $edit = [
    'title[0][value]' => 'Create node with unpublish-on date',
    'unpublish_on[0][value][date]' => date('Y-m-d', time() + 3),
    'unpublish_on[0][value][time]' => date('H:i:s', time() + 3),
    'body[0][value]' => $this
      ->randomString(30),
  ];
  $this
    ->drupalPostForm('node/add/' . $this->type, $edit, 'Save');
  $node = $this
    ->drupalGetNodeByTitle($edit['title[0][value]']);
  $assert
    ->pageTextNotContains($this->message[1]);
  $assert
    ->pageTextNotContains($this->message[2]);
  $assert
    ->pageTextNotContains($this->message[3]);
  $assert
    ->pageTextContains($this->message[4]);
  $assert
    ->pageTextNotContains($this->message[5]);
  $assert
    ->pageTextNotContains($this->message[6]);

  // Edit this node and check that only event 5 is triggered.
  $edit = [
    'title[0][value]' => 'Edit node with unpublish-on date',
    'body[0][value]' => $this
      ->randomString(30),
  ];
  $this
    ->drupalPostForm('node/' . $node
    ->id() . '/edit', $edit, 'Save');
  $assert
    ->pageTextNotContains($this->message[1]);
  $assert
    ->pageTextNotContains($this->message[2]);
  $assert
    ->pageTextNotContains($this->message[3]);
  $assert
    ->pageTextNotContains($this->message[4]);
  $assert
    ->pageTextContains($this->message[5]);
  $assert
    ->pageTextNotContains($this->message[6]);

  // Delay to ensure that the date entered is now in the past so that the node
  // will be processed during cron, and assert that only event 6 is triggered.
  sleep(5);
  $this
    ->cronRun();
  $this
    ->drupalGet('admin/reports/dblog');
  $assert
    ->pageTextNotContains($this->message[1]);
  $assert
    ->pageTextNotContains($this->message[2]);
  $assert
    ->pageTextNotContains($this->message[3]);
  $assert
    ->pageTextNotContains($this->message[4]);
  $assert
    ->pageTextNotContains($this->message[5]);
  $assert
    ->pageTextContains($this->message[6]);
}