You are here

protected function WorkbenchEmailTestBase::assertNeedsReviewNotifications in Workbench Email 2.x

Same name and namespace in other branches
  1. 8 tests/src/Functional/WorkbenchEmailTestBase.php \Drupal\Tests\workbench_email\Functional\WorkbenchEmailTestBase::assertNeedsReviewNotifications()

Assert notifications sent for needs review.

Parameters

\Drupal\node\NodeInterface $node: Node updated.

1 call to WorkbenchEmailTestBase::assertNeedsReviewNotifications()
WorkbenchEmailTestBase::testEndToEnd in tests/src/Functional/WorkbenchEmailTestBase.php
Test administration.

File

tests/src/Functional/WorkbenchEmailTestBase.php, line 417

Class

WorkbenchEmailTestBase
Defines a base class for workbench email tests.

Namespace

Drupal\Tests\workbench_email\Functional

Code

protected function assertNeedsReviewNotifications(NodeInterface $node) {

  // Check mail goes to approvers.
  $captured_emails = $this->container
    ->get('state')
    ->get('system.test_mail_collector') ?: [];

  // Should only be two emails.
  $this
    ->assertCount(2, $captured_emails);
  $last = end($captured_emails);
  $prev = prev($captured_emails);
  $mails = [
    $last['to'],
    $prev['to'],
  ];
  sort($mails);
  $expected = [
    $this->approver1
      ->getEmail(),
    $this->approver2
      ->getEmail(),
  ];
  sort($expected);
  $this
    ->assertEquals($expected, $mails);

  // The node id text is added to the email subject in the
  // workbench_email_test_mail_alter() function.
  // We check that it is set here.
  $this
    ->assertEquals(sprintf('Content needs review: %s (node id: %s)', $node
    ->label(), $node
    ->id()), preg_replace('/\\s+/', ' ', $last['subject']));
  $this
    ->assertEquals(sprintf('Content needs review: %s (node id: %s)', $node
    ->label(), $node
    ->id()), preg_replace('/\\s+/', ' ', $prev['subject']));
  $this
    ->assertEquals($this->editor
    ->getEmail(), $last['reply-to']);
  $this
    ->assertEquals($this->editor
    ->getEmail(), $prev['reply-to']);
  $this
    ->assertStringContainsString(sprintf('Content with title %s needs review. You can view it at', $node
    ->label()), preg_replace('/\\s+/', ' ', $prev['body']));
  $this
    ->assertStringContainsString(sprintf('Content with title %s needs review. You can view it at', $node
    ->label()), preg_replace('/\\s+/', ' ', $last['body']));

  // Check that empty tokens are removed.
  $this
    ->assertStringNotContainsString('[node:field_does_not_exist]', preg_replace('/\\s+/', ' ', $prev['body']));
  $this
    ->assertStringNotContainsString('[node:field_does_not_exist]', preg_replace('/\\s+/', ' ', $last['body']));
  $this
    ->assertStringContainsString($node
    ->toUrl('canonical', [
    'absolute' => TRUE,
  ])
    ->toString(), preg_replace('/\\s+/', ' ', $prev['body']));
  $this
    ->assertStringContainsString($node
    ->toUrl('canonical', [
    'absolute' => TRUE,
  ])
    ->toString(), preg_replace('/\\s+/', ' ', $last['body']));
}