You are here

public function SchedulerRulesEventsTest::testRulesEventsPublish in Scheduler 8

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

Tests the three events related to publishing a node.

File

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

Class

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

Namespace

Drupal\Tests\scheduler\Functional

Code

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

  // Create a node with a publish-on date, and check that only event 1 is
  // triggered.
  $edit = [
    'title[0][value]' => 'Create node with publish-on date',
    'publish_on[0][value][date]' => date('Y-m-d', time() + 3),
    'publish_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
    ->pageTextContains($this->message[1]);
  $assert
    ->pageTextNotContains($this->message[2]);
  $assert
    ->pageTextNotContains($this->message[3]);
  $assert
    ->pageTextNotContains($this->message[4]);
  $assert
    ->pageTextNotContains($this->message[5]);
  $assert
    ->pageTextNotContains($this->message[6]);

  // Edit this node and check that only event 2 is triggered.
  $edit = [
    'title[0][value]' => 'Edit node with publish-on date',
    'body[0][value]' => $this
      ->randomString(30),
  ];
  $this
    ->drupalPostForm('node/' . $node
    ->id() . '/edit', $edit, 'Save');
  $assert
    ->pageTextNotContains($this->message[1]);
  $assert
    ->pageTextContains($this->message[2]);
  $assert
    ->pageTextNotContains($this->message[3]);
  $assert
    ->pageTextNotContains($this->message[4]);
  $assert
    ->pageTextNotContains($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 3 is triggered.
  sleep(5);
  $this
    ->cronRun();
  $this
    ->drupalGet('admin/reports/dblog');
  $assert
    ->pageTextNotContains($this->message[1]);
  $assert
    ->pageTextNotContains($this->message[2]);
  $assert
    ->pageTextContains($this->message[3]);
  $assert
    ->pageTextNotContains($this->message[4]);
  $assert
    ->pageTextNotContains($this->message[5]);
  $assert
    ->pageTextNotContains($this->message[6]);
}