You are here

public function SchedulerRulesEventsTest::checkMessages in Scheduler 2.x

Check the presence or absence of expected message texts on the page.

Parameters

string $entityTypeId: The entity type being tested.

array $expectedMessages: The ids of the messages that should be showing on the current page. All other messsages should not be displayed.

4 calls to SchedulerRulesEventsTest::checkMessages()
SchedulerRulesEventsTest::testRulesEventsBoth in tests/src/Functional/SchedulerRulesEventsTest.php
Tests all six events related to publishing and unpublishing an entity.
SchedulerRulesEventsTest::testRulesEventsNone in tests/src/Functional/SchedulerRulesEventsTest.php
Tests that no events are triggered when there are no scheduling dates.
SchedulerRulesEventsTest::testRulesEventsPublish in tests/src/Functional/SchedulerRulesEventsTest.php
Tests the three events related to publishing an entity.
SchedulerRulesEventsTest::testRulesEventsUnpublish in tests/src/Functional/SchedulerRulesEventsTest.php
Tests the three events related to unpublishing an entity.

File

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

Class

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

Namespace

Drupal\Tests\scheduler\Functional

Code

public function checkMessages(string $entityTypeId = NULL, array $expectedMessages = []) {

  // Add the required entity offset to each message id in the expected array.
  $offset = [
    'node' => 0,
    'media' => 6,
    'commerce_product' => 12,
  ];
  array_walk($expectedMessages, function (&$item) use ($offset, $entityTypeId) {
    $item = $item + $offset[$entityTypeId];
  });

  // Check that all the expected messages are shown.
  foreach ($expectedMessages as $i) {
    $this
      ->assertSession()
      ->pageTextContains($this->message[$i]);
  }

  // Check that none of the other messages are shown.
  $notExpecting = array_diff(array_keys($this->message), $expectedMessages);
  foreach ($notExpecting as $i) {
    $this
      ->assertSession()
      ->pageTextNotContains($this->message[$i]);
  }
}