You are here

public function MessageDigestSubContext::assertDigestNotContains in Message Digest 8

Checks that the digest for a user does not contain a certain message.

Example table: @codingStandardsIgnoreStart | mail_subject | The content titled "My content" has been deleted | | mail_body | The "My content" page was deleted by an administrator. | @codingStandardsIgnoreEnd

@Then the :interval digest for :username should not contain the following message for the :label :entity_type: @Then the :interval digest for :username should not contain the following message:

Parameters

\Behat\Gherkin\Node\TableNode $table: A table containing the expected content of the different view modes for the message that should not be present.

string $interval: The digest interval, e.g. 'daily' or 'weekly'.

string $username: The name of the user for which the message is intended.

string $label: Optional label of an entity that is related to the message.

string $entity_type: Optional entity type of an entity that is related to the message.

File

./message_digest.behat.inc, line 100
Contains \MessageDigestSubContext.

Class

MessageDigestSubContext
Behat step definitions for the Message Digest module.

Code

public function assertDigestNotContains(TableNode $table, $interval, $username, $label = NULL, $entity_type = NULL) {

  // Check that the passed table contains valid view modes.
  $rows = $table
    ->getRowsHash();
  $view_modes = array_keys($rows);
  $notifier = $this
    ->getMessageDigestNotifierForInterval($interval);
  $this
    ->assertNotifierViewModes($notifier, $view_modes);
  $user = user_load_by_name($username);
  $messages = $this
    ->getUserMessagesByNotifier($notifier, $user
    ->id(), $entity_type, $label);
  foreach ($messages as $message) {
    $found_view_modes = [];
    foreach ($rows as $view_mode => $expected_content) {
      $actual_content = $this
        ->getRenderedMessage($message, $view_mode);
      if (strpos($actual_content, $expected_content) !== FALSE) {
        $found_view_modes[] = $view_mode;
      }
    }
    if (empty(array_diff($view_modes, $found_view_modes))) {

      // We found the message.
      $exception_message = !empty($entity_type) && !empty($label) ? "The message for the '{$label}' {$entity_type} was unexpectedly found in the {$interval} digest for {$username}." : "The message was unexpectedly found in the {$interval} digest for {$username}.";
      throw new \RuntimeException($exception_message);
    }
  }
}