You are here

class MessageDigestTest in Message Digest 8

Kernel tests for Message Digest.

@group message_digest

Hierarchy

Expanded class hierarchy of MessageDigestTest

File

tests/src/Kernel/MessageDigestTest.php, line 14

Namespace

Drupal\Tests\message_digest\Kernel
View source
class MessageDigestTest extends DigestTestBase {

  /**
   * Tests the plugin deriver for daily and weekly digests.
   */
  public function testDigestNotifierPluginsExist() {
    $count = 0;
    foreach ($this->notifierManager
      ->getDefinitions() as $plugin_id => $plugin_definition) {
      if ($plugin_definition['provider'] === 'message_digest') {
        $dummy = Message::create([
          'template' => 'foo',
        ]);

        // Ensure the plugin can be instantiated.
        $this->notifierManager
          ->createInstance($plugin_id, [], $dummy);
        $count++;
      }
    }
    $this
      ->assertEquals(2, $count, 'There are 2 digest notifiers.');
  }

  /**
   * Tests the notifier sending and delivery.
   *
   * @param bool $reference_entity
   *   Whether or not an entity should be referenced in the message digest that
   *   is being sent.
   * @param string $expected_subject
   *   The expected subject for the email that is being sent.
   *
   * @dataProvider providerTestNotifierDelivery
   */
  public function testNotifierDelivery($reference_entity, $expected_subject) {

    // Set the site name, so we can check that it is used in the subject of the
    // digest e-mail.
    $this
      ->config('system.site')
      ->set('name', 'Test site')
      ->save();
    $template = $this
      ->createMessageTemplate('foo', 'Foo', 'Foo, foo', [
      'Test message',
    ]);
    $dummy = Message::create([
      'template' => $template
        ->id(),
    ]);

    /** @var \Drupal\message_digest\Plugin\Notifier\DigestInterface $digest_notifier */
    $digest_notifier = $this->notifierManager
      ->createInstance('message_digest:daily', [], $dummy);
    $configuration = [];

    // If we are referencing an entity, create a test user and reference it in
    // the message digest.
    if ($reference_entity) {
      $referenced_user = $this
        ->createUser([], 'Test user');
      $configuration = [
        'entity_type' => 'user',
        'entity_id' => $referenced_user
          ->id(),
      ];
    }

    // Create a recipient and send the message.
    $account = $this
      ->createUser();
    $dummy
      ->setOwner($account);
    $dummy
      ->save();
    $this->notifierSender
      ->send($dummy, $configuration, $digest_notifier
      ->getPluginId());
    $result = $this->container
      ->get('database')
      ->select('message_digest', 'm')
      ->fields('m')
      ->execute()
      ->fetchAllAssoc('id');
    $this
      ->assertEquals(1, count($result));
    foreach ($result as $row) {
      $this
        ->assertEquals($account
        ->id(), $row->receiver);
      $this
        ->assertEquals($digest_notifier
        ->getPluginId(), $row->notifier);
    }

    // Now deliver the message.
    $this
      ->sendDigests();
    $this
      ->assertMail('subject', $expected_subject, 'Expected email subject is set.');
    $this
      ->assertMail('body', "Test message\n\n", 'Expected email body is set.');
    $this
      ->assertMail('id', 'message_digest_digest', 'Expected email key is set.');
    $this
      ->assertMail('to', $account
      ->getEmail(), 'Expected email recipient is set.');

    // Verify that the aggregate alter hook was called.
    // @see message_digest_test_message_digest_aggregate_alter()
    $this
      ->assertTrue($this->container
      ->get('state')
      ->get('message_digest_test_message_digest_aggregate_alter', FALSE));

    // Verify that hook_message_digest_view_mode_alter() has been called.
    // @see message_digest_test_message_digest_view_mode_alter().
    $this
      ->assertTrue($this->container
      ->get('state')
      ->get('message_digest_test_message_digest_view_mode_alter', FALSE));
  }

  /**
   * Data provider for ::testNotifierDelivery().
   *
   * @return array
   *   An array of test data, each test case an array with two elements:
   *   - A boolean indicating whether or not an entity should be referenced.
   *   - The expected subject of the message digest e-mail that is sent.
   */
  public function providerTestNotifierDelivery() {
    return [
      // Test case that does not reference an entity. In this case the site name
      // should be mentioned in the message subject.
      [
        FALSE,
        'Test site message digest',
      ],
      // Test case that references an entity. In this case the name of the
      // entity should be mentioned in the message subject. We are using a user
      // entity to test this case.
      [
        TRUE,
        'Test user message digest',
      ],
    ];
  }

  /**
   * Tests message aggregation.
   */
  public function testNotifierAggregation() {

    // Send several messages.
    $template = $this
      ->createMessageTemplate('foo', 'Foo', 'Foo, foo', []);
    $account = $this
      ->createUser();
    $message_1 = Message::create([
      'template' => $template
        ->id(),
    ]);
    $message_2 = Message::create([
      'template' => $template
        ->id(),
    ]);

    /** @var \Drupal\message_digest\Plugin\Notifier\DigestInterface $digest_notifier */
    $digest_notifier = $this->notifierManager
      ->createInstance('message_digest:weekly', [], $message_1);
    $message_1
      ->setOwner($account);
    $message_1
      ->save();
    $message_2
      ->setOwner($account);
    $message_2
      ->save();
    $this->notifierSender
      ->send($message_1, [], $digest_notifier
      ->getPluginId());
    $this->notifierSender
      ->send($message_2, [], $digest_notifier
      ->getPluginId());
    $result = $this->container
      ->get('database')
      ->select('message_digest', 'm')
      ->fields('m')
      ->execute()
      ->fetchAllAssoc('id');
    $this
      ->assertEquals(2, count($result));
    foreach ($result as $row) {
      $this
        ->assertEquals($account
        ->id(), $row->receiver);
      $this
        ->assertEquals($digest_notifier
        ->getPluginId(), $row->notifier);
    }

    // Aggregate and mark processed.
    $start_time = $digest_notifier
      ->getEndTime();
    $recipients = $digest_notifier
      ->getRecipients();
    $this
      ->assertEquals(1, count($recipients));
    foreach ($recipients as $uid) {
      $results = $digest_notifier
        ->aggregate($uid, $start_time);
      $digest_notifier
        ->setLastSent();
      $expected = [
        '' => [
          '' => [
            $message_1
              ->id(),
            $message_2
              ->id(),
          ],
        ],
      ];
      $this
        ->assertSame($expected, $results);
    }

    // Since this has been marked as sent, the notifier should return FALSE
    // for processing again.
    $this
      ->assertFalse($digest_notifier
      ->processDigest());

    // Set last sent time to 8 days in the past.
    $last_run = strtotime('-8 days', $this->container
      ->get('datetime.time')
      ->getRequestTime());
    $this->container
      ->get('state')
      ->set($digest_notifier
      ->getPluginId() . '_last_run', $last_run);
    $results = $digest_notifier
      ->aggregate($account
      ->id(), $start_time);
    $this
      ->assertSame($expected, $results);

    // Aggregate should not return any results once marked sent.
    $digest_notifier
      ->markSent($account, $message_2
      ->id());
    $this
      ->assertEmpty($digest_notifier
      ->getRecipients());
  }

  /**
   * Test grouping by entity type, and ID.
   */
  public function testDigestGrouping() {
    $template = $this
      ->createMessageTemplate('foo', 'Foo', 'Foo, foo', []);
    $account = $this
      ->createUser();

    // Send several messages w/o grouping.
    $global_messages = [];
    foreach (range(1, 3) as $i) {
      $message = Message::create([
        'template' => $template
          ->id(),
      ]);
      $message
        ->setOwner($account);
      $message
        ->save();
      $global_messages[$i] = $message;
      $digest_notifier = $this->notifierManager
        ->createInstance('message_digest:weekly', [], $message);
      $this->notifierSender
        ->send($message, [], $digest_notifier
        ->getPluginId());
    }

    // Now send some grouped by entity type.
    $configuration = [
      'entity_type' => 'foo',
      'entity_id' => 'bar',
    ];
    $grouped_messages = [];
    foreach (range(1, 3) as $i) {
      $message = Message::create([
        'template' => $template
          ->id(),
      ]);
      $message
        ->setOwner($account);
      $message
        ->save();
      $grouped_messages[$i] = $message;

      /** @var \Drupal\message_digest\Plugin\Notifier\DigestInterface $digest_notifier */
      $digest_notifier = $this->notifierManager
        ->createInstance('message_digest:weekly', $configuration, $message);
      $this->notifierSender
        ->send($message, $configuration, $digest_notifier
        ->getPluginId());
    }

    // Aggregate and mark processed.
    $results = $digest_notifier
      ->aggregate($account
      ->id(), $digest_notifier
      ->getEndTime());
    $digest_notifier
      ->setLastSent();
    $expected = [
      '' => [
        '' => [
          '1',
          '2',
          '3',
        ],
      ],
      'foo' => [
        'bar' => [
          '4',
          '5',
          '6',
        ],
      ],
    ];
    $this
      ->assertSame($expected, $results);
  }

  /**
   * Returns some message text, including HTML.
   *
   * @return array
   *   An array of message text.
   */
  protected function getMessageText() {
    $text = [];

    // Subject.
    $text[] = [
      'value' => 'Test subject',
      'format' => 'filtered_html',
    ];

    // Body.
    $text[] = [
      'value' => '<div class="foo-bar">Some sweet <a href="[site:url]">message</a>.',
      'format' => 'full_html',
    ];
    return $text;
  }

  /**
   * Tests sending with an entity_id and no type.
   */
  public function testInvalidEntityType() {
    $configuration = [
      'entity_id' => 42,
    ];
    $template = $this
      ->createMessageTemplate('foo', 'Foo', 'Foo, foo', []);
    $message = Message::create([
      'template' => $template
        ->id(),
    ]);
    $digest_notifier = $this->notifierManager
      ->createInstance('message_digest:weekly', $configuration, $message);
    $this
      ->expectException(InvalidDigestGroupingException::class);
    $this
      ->expectExceptionMessage('Tried to create a message digest without both entity_type () and entity_id (42). These either both need to be empty, or have values.');
    $this->notifierSender
      ->send($message, $configuration, $digest_notifier
      ->getPluginId());
  }

  /**
   * Tests sending with an entity_type and no ID.
   */
  public function testInvalidEntityId() {
    $configuration = [
      'entity_type' => 'foo',
    ];
    $template = $this
      ->createMessageTemplate('foo', 'Foo', 'Foo, foo', []);
    $message = Message::create([
      'template' => $template
        ->id(),
    ]);
    $digest_notifier = $this->notifierManager
      ->createInstance('message_digest:weekly', $configuration, $message);
    $this
      ->expectException(InvalidDigestGroupingException::class);
    $this
      ->expectExceptionMessage('Tried to create a message digest without both entity_type (foo) and entity_id (). These either both need to be empty, or have values.');
    $this->notifierSender
      ->send($message, $configuration, $digest_notifier
      ->getPluginId());
  }

  /**
   * Test old message purging.
   */
  public function testMessageCleanup() {
    $template = $this
      ->createMessageTemplate('foo', 'Foo', 'Foo, foo', []);
    $account = $this
      ->createUser();
    $messages = [];

    // Send 10 messages.
    foreach (range(1, 10) as $i) {
      $message = Message::create([
        'template' => $template
          ->id(),
      ]);
      $message
        ->setOwner($account);
      $message
        ->save();
      $digest_notifier = $this->notifierManager
        ->createInstance('message_digest:weekly', [], $message);
      $this->notifierSender
        ->send($message, [], $digest_notifier
        ->getPluginId());
      $messages[$i] = $message;
    }
    $digest = $digest_notifier
      ->aggregate($account
      ->id(), $digest_notifier
      ->getEndTime());
    $this
      ->assertEquals(10, count($digest['']['']));
    $digest_notifier
      ->markSent($account, $messages[10]
      ->id());

    // Delete 5 messages.
    foreach (range(1, 5) as $i) {
      $messages[$i]
        ->delete();
    }
    $this->digestManager
      ->cleanupOldMessages();
    $result = $this->container
      ->get('database')
      ->select('message_digest', 'md')
      ->fields('md')
      ->execute()
      ->fetchAllAssoc('id');
    $this
      ->assertEquals(5, count($result));
    foreach ($result as $row) {
      $this
        ->assertGreaterThan(5, $row->mid);
    }
  }

  /**
   * Tests that the message_digest table is cleaned up when deleting entities.
   */
  public function testOrphanedEntityReferences() {
    $template = $this
      ->createMessageTemplate('foo', 'Foo', 'Foo, foo', []);

    // Create 3 test users and send 3 messages, one to each user.
    $users = $messages = [];
    for ($i = 0; $i < 3; $i++) {
      $user = $this
        ->createUser();
      $message = Message::create([
        'template' => $template
          ->id(),
      ]);
      $message
        ->setOwner($user);
      $message
        ->save();
      $digest_notifier = $this->notifierManager
        ->createInstance('message_digest:weekly', [], $message);
      $this->notifierSender
        ->send($message, [], $digest_notifier
        ->getPluginId());
      $users[$i] = $user;
      $messages[$i] = $message;
    }

    // There should be 3 message digests.
    $this
      ->assertRowCount(3);

    // Delete one of the messages and verify that the corresponding message
    // digest is cleaned up.
    $orphaned_message_id = $messages[0]
      ->id();
    $messages[0]
      ->delete();
    $this
      ->assertRowCount(2);
    foreach ($this
      ->getAllMessageDigests() as $digest) {
      if ($digest->mid == $orphaned_message_id) {
        $this
          ->fail('When a message is deleted its corresponding message digest is cleaned up.');
      }
    }

    // Delete one of the users and verify that the corresponding message digest
    // is cleaned up.
    $orphaned_user_id = $users[1]
      ->id();
    $users[1]
      ->delete();
    $this
      ->assertRowCount(1);
    foreach ($this
      ->getAllMessageDigests() as $digest) {
      if ($digest->receiver == $orphaned_user_id) {
        $this
          ->fail('When a user is deleted its corresponding message digest is cleaned up.');
      }
    }
  }

  /**
   * Tests the message digest manager processing.
   */
  public function testManagerProcessing() {
    $this->digestManager
      ->processDigests();
    $request_time = $this->container
      ->get('datetime.time')
      ->getRequestTime();
    $this
      ->assertEquals($request_time, $this->container
      ->get('state')
      ->get('message_digest:daily_last_run'));
    $this
      ->assertEquals($request_time, $this->container
      ->get('state')
      ->get('message_digest:weekly_last_run'));
    $this
      ->assertEmpty($this
      ->getMails());

    // Actually add some messages now, and reset last sent time.
    $last_run = strtotime('-8 days', $this->container
      ->get('datetime.time')
      ->getRequestTime());
    $this->container
      ->get('state')
      ->set('message_digest:weekly_last_run', $last_run);
    $template = $this
      ->createMessageTemplate('foo', 'Foo', 'Foo, foo', $this
      ->getMessageText());
    $account = $this
      ->createUser();
    $messages = [];

    // Send 10 messages.
    foreach (range(1, 10) as $i) {
      $message = Message::create([
        'template' => $template
          ->id(),
      ]);
      $message
        ->setOwner($account);
      $message
        ->save();
      $digest_notifier = $this->notifierManager
        ->createInstance('message_digest:weekly', [], $message);
      $this->notifierSender
        ->send($message, [], $digest_notifier
        ->getPluginId());
      $messages[$i] = $message;
    }

    // Ensure cron function actually calls the process method.
    $this->container
      ->get('cron')
      ->run();
    $emails = $this
      ->getMails();
    $this
      ->assertEquals(1, count($emails));
    $this
      ->assertMail('to', $account
      ->getEmail());

    // Since the core mail service converts HTML to text, that should be be the
    // case here too.
    $expected = MailFormatHelper::wrapMail(MailFormatHelper::htmlToText("  <div>\n    <div>\n  Test subject\n</div>\n\n  </div>\n  <div>\n    <div>\n  <div class=\"foo-bar\">Some sweet <a href=\"http://localhost/\">message</a>.\n</div>\n\n  </div>\n<hr />  <div>\n    <div>\n  Test subject\n</div>\n\n  </div>\n  <div>\n    <div>\n  <div class=\"foo-bar\">Some sweet <a href=\"http://localhost/\">message</a>.\n</div>\n\n  </div>\n<hr />  <div>\n    <div>\n  Test subject\n</div>\n\n  </div>\n  <div>\n    <div>\n  <div class=\"foo-bar\">Some sweet <a href=\"http://localhost/\">message</a>.\n</div>\n\n  </div>\n<hr />  <div>\n    <div>\n  Test subject\n</div>\n\n  </div>\n  <div>\n    <div>\n  <div class=\"foo-bar\">Some sweet <a href=\"http://localhost/\">message</a>.\n</div>\n\n  </div>\n<hr />  <div>\n    <div>\n  Test subject\n</div>\n\n  </div>\n  <div>\n    <div>\n  <div class=\"foo-bar\">Some sweet <a href=\"http://localhost/\">message</a>.\n</div>\n\n  </div>\n<hr />  <div>\n    <div>\n  Test subject\n</div>\n\n  </div>\n  <div>\n    <div>\n  <div class=\"foo-bar\">Some sweet <a href=\"http://localhost/\">message</a>.\n</div>\n\n  </div>\n<hr />  <div>\n    <div>\n  Test subject\n</div>\n\n  </div>\n  <div>\n    <div>\n  <div class=\"foo-bar\">Some sweet <a href=\"http://localhost/\">message</a>.\n</div>\n\n  </div>\n<hr />  <div>\n    <div>\n  Test subject\n</div>\n\n  </div>\n  <div>\n    <div>\n  <div class=\"foo-bar\">Some sweet <a href=\"http://localhost/\">message</a>.\n</div>\n\n  </div>\n<hr />  <div>\n    <div>\n  Test subject\n</div>\n\n  </div>\n  <div>\n    <div>\n  <div class=\"foo-bar\">Some sweet <a href=\"http://localhost/\">message</a>.\n</div>\n\n  </div>\n<hr />  <div>\n    <div>\n  Test subject\n</div>\n\n  </div>\n  <div>\n    <div>\n  <div class=\"foo-bar\">Some sweet <a href=\"http://localhost/\">message</a>.\n</div>\n\n  </div>\n\n"));
    $email = reset($emails);
    $this
      ->assertEquals($expected, $email['body']);
  }

  /**
   * Checks that message digest plugins can be correctly serialized.
   */
  public function testDigestSerialization() {
    foreach ([
      'daily',
      'weekly',
    ] as $interval) {
      $plugin_id = "message_digest:{$interval}";
      $dummy = Message::create([
        'template' => 'foo',
      ]);

      /** @var \Drupal\message_digest\Plugin\Notifier\DigestInterface $notifier */
      $notifier = $this->notifierManager
        ->createInstance($plugin_id, [], $dummy);

      /** @var \Drupal\message_digest\Plugin\Notifier\DigestInterface $unserialized_notifier */
      $unserialized_notifier = unserialize(serialize($notifier));
      $this
        ->assertEquals($plugin_id, $unserialized_notifier
        ->getPluginId());
    }
  }

  /**
   * Tests that a message is not sent if its owner has been deleted.
   */
  public function testOrphanedMessage() {

    // Create a test user.
    $user = $this
      ->createUser();

    // Create a test message owned by the test user.
    $template = $this
      ->createMessageTemplate('foo', 'Foo', 'Foo, foo', []);
    $message = Message::create([
      'template' => $template
        ->id(),
    ]);

    /** @var \Drupal\message_digest\Plugin\Notifier\DigestInterface $digest_notifier */
    $digest_notifier = $this->notifierManager
      ->createInstance('message_digest:daily', [], $message);
    $message
      ->setOwner($user);
    $message
      ->save();

    // Delete the user.
    $user
      ->delete();

    // Deliver the message and send out the digests.
    $this->notifierSender
      ->send($message, [], $digest_notifier
      ->getPluginId());
    $this
      ->sendDigests();

    // Check that no mails have been sent.
    $this
      ->assertEmpty($this
      ->getMails());
  }

  /**
   * Returns all rows from the message_digest table.
   *
   * @return array
   *   An array of all table rows, keyed by ID.
   *
   * @throws \Exception
   *   Thrown when the database connection is not available on the container.
   */
  protected function getAllMessageDigests() {
    return $this->container
      ->get('database')
      ->select('message_digest', 'm')
      ->fields('m')
      ->execute()
      ->fetchAllAssoc('id');
  }

  /**
   * Checks that the message_digest table contains the expected number of rows.
   *
   * @param int $expected_count
   *   The expected number of rows.
   *
   * @throws \Exception
   *   Thrown when the database connection is not available on the container.
   */
  protected function assertRowCount($expected_count) {
    $this
      ->assertEquals($expected_count, count($this
      ->getAllMessageDigests()));
  }

}

Members

Namesort descending Modifiers Type Description Overrides
AssertContentTrait::$content protected property The current raw content.
AssertContentTrait::$drupalSettings protected property The drupalSettings value from the current raw $content.
AssertContentTrait::$elements protected property The XML structure parsed from the current raw $content. 1
AssertContentTrait::$plainTextContent protected property The plain-text content of raw $content (text nodes).
AssertContentTrait::assertEscaped protected function Passes if the raw text IS found escaped on the loaded page, fail otherwise.
AssertContentTrait::assertField protected function Asserts that a field exists with the given name or ID.
AssertContentTrait::assertFieldById protected function Asserts that a field exists with the given ID and value.
AssertContentTrait::assertFieldByName protected function Asserts that a field exists with the given name and value.
AssertContentTrait::assertFieldByXPath protected function Asserts that a field exists in the current page by the given XPath.
AssertContentTrait::assertFieldChecked protected function Asserts that a checkbox field in the current page is checked.
AssertContentTrait::assertFieldsByValue protected function Asserts that a field exists in the current page with a given Xpath result.
AssertContentTrait::assertLink protected function Passes if a link with the specified label is found.
AssertContentTrait::assertLinkByHref protected function Passes if a link containing a given href (part) is found.
AssertContentTrait::assertNoDuplicateIds protected function Asserts that each HTML ID is used for just a single element.
AssertContentTrait::assertNoEscaped protected function Passes if the raw text IS NOT found escaped on the loaded page, fail otherwise.
AssertContentTrait::assertNoField protected function Asserts that a field does not exist with the given name or ID.
AssertContentTrait::assertNoFieldById protected function Asserts that a field does not exist with the given ID and value.
AssertContentTrait::assertNoFieldByName protected function Asserts that a field does not exist with the given name and value.
AssertContentTrait::assertNoFieldByXPath protected function Asserts that a field does not exist or its value does not match, by XPath.
AssertContentTrait::assertNoFieldChecked protected function Asserts that a checkbox field in the current page is not checked.
AssertContentTrait::assertNoLink protected function Passes if a link with the specified label is not found.
AssertContentTrait::assertNoLinkByHref protected function Passes if a link containing a given href (part) is not found.
AssertContentTrait::assertNoLinkByHrefInMainRegion protected function Passes if a link containing a given href is not found in the main region.
AssertContentTrait::assertNoOption protected function Asserts that a select option in the current page does not exist.
AssertContentTrait::assertNoOptionSelected protected function Asserts that a select option in the current page is not checked.
AssertContentTrait::assertNoPattern protected function Triggers a pass if the perl regex pattern is not found in raw content.
AssertContentTrait::assertNoRaw protected function Passes if the raw text is NOT found on the loaded page, fail otherwise.
AssertContentTrait::assertNoText protected function Passes if the page (with HTML stripped) does not contains the text.
AssertContentTrait::assertNoTitle protected function Pass if the page title is not the given string.
AssertContentTrait::assertNoUniqueText protected function Passes if the text is found MORE THAN ONCE on the text version of the page.
AssertContentTrait::assertOption protected function Asserts that a select option in the current page exists.
AssertContentTrait::assertOptionByText protected function Asserts that a select option with the visible text exists.
AssertContentTrait::assertOptionSelected protected function Asserts that a select option in the current page is checked.
AssertContentTrait::assertOptionSelectedWithDrupalSelector protected function Asserts that a select option in the current page is checked.
AssertContentTrait::assertOptionWithDrupalSelector protected function Asserts that a select option in the current page exists.
AssertContentTrait::assertPattern protected function Triggers a pass if the Perl regex pattern is found in the raw content.
AssertContentTrait::assertRaw protected function Passes if the raw text IS found on the loaded page, fail otherwise.
AssertContentTrait::assertText protected function Passes if the page (with HTML stripped) contains the text.
AssertContentTrait::assertTextHelper protected function Helper for assertText and assertNoText.
AssertContentTrait::assertTextPattern protected function Asserts that a Perl regex pattern is found in the plain-text content.
AssertContentTrait::assertThemeOutput protected function Asserts themed output.
AssertContentTrait::assertTitle protected function Pass if the page title is the given string.
AssertContentTrait::assertUniqueText protected function Passes if the text is found ONLY ONCE on the text version of the page.
AssertContentTrait::assertUniqueTextHelper protected function Helper for assertUniqueText and assertNoUniqueText.
AssertContentTrait::buildXPathQuery protected function Builds an XPath query.
AssertContentTrait::constructFieldXpath protected function Helper: Constructs an XPath for the given set of attributes and value.
AssertContentTrait::cssSelect protected function Searches elements using a CSS selector in the raw content.
AssertContentTrait::getAllOptions protected function Get all option elements, including nested options, in a select.
AssertContentTrait::getDrupalSettings protected function Gets the value of drupalSettings for the currently-loaded page.
AssertContentTrait::getRawContent protected function Gets the current raw content.
AssertContentTrait::getSelectedItem protected function Get the selected value from a select field.
AssertContentTrait::getTextContent protected function Retrieves the plain-text content from the current raw content.
AssertContentTrait::getUrl protected function Get the current URL from the cURL handler. 1
AssertContentTrait::parse protected function Parse content returned from curlExec using DOM and SimpleXML.
AssertContentTrait::removeWhiteSpace protected function Removes all white-space between HTML tags from the raw content.
AssertContentTrait::setDrupalSettings protected function Sets the value of drupalSettings for the currently-loaded page.
AssertContentTrait::setRawContent protected function Sets the raw content (e.g. HTML).
AssertContentTrait::xpath protected function Performs an xpath search on the contents of the internal browser.
AssertHelperTrait::castSafeStrings protected static function Casts MarkupInterface objects into strings.
AssertLegacyTrait::assert protected function Deprecated Scheduled for removal in Drupal 10.0.0. Use self::assertTrue() instead.
AssertLegacyTrait::assertEqual protected function Deprecated Scheduled for removal in Drupal 10.0.0. Use self::assertEquals() instead.
AssertLegacyTrait::assertIdentical protected function Deprecated Scheduled for removal in Drupal 10.0.0. Use self::assertSame() instead.
AssertLegacyTrait::assertIdenticalObject protected function Deprecated Scheduled for removal in Drupal 10.0.0. Use self::assertEquals() instead.
AssertLegacyTrait::assertNotEqual protected function Deprecated Scheduled for removal in Drupal 10.0.0. Use self::assertNotEquals() instead.
AssertLegacyTrait::assertNotIdentical protected function Deprecated Scheduled for removal in Drupal 10.0.0. Use self::assertNotSame() instead.
AssertLegacyTrait::pass protected function Deprecated Scheduled for removal in Drupal 10.0.0. Use self::assertTrue() instead.
AssertLegacyTrait::verbose protected function
AssertMailTrait::assertMail protected function Asserts that the most recently sent email message has the given value.
AssertMailTrait::assertMailPattern protected function Asserts that the most recently sent email message has the pattern in it.
AssertMailTrait::assertMailString protected function Asserts that the most recently sent email message has the string in it.
AssertMailTrait::getMails protected function Gets an array containing all emails sent during this test case.
AssertMailTrait::verboseEmail protected function Outputs to verbose the most recent $count emails sent.
ConfigTestTrait::configImporter protected function Returns a ConfigImporter object to import test configuration.
ConfigTestTrait::copyConfig protected function Copies configuration objects from source storage to target storage.
DigestTestBase::$digestManager protected property The message digest manager.
DigestTestBase::$modules public static property Modules to enable. Overrides KernelTestBase::$modules 1
DigestTestBase::$notifierManager protected property Message notifier plugin manager.
DigestTestBase::$notifierSender protected property The message notify sender service.
DigestTestBase::sendDigests protected function Helper method to process and deliver digests.
DigestTestBase::setUp public function Overrides KernelTestBase::setUp
KernelTestBase::$backupGlobals protected property Back up and restore any global variables that may be changed by tests.
KernelTestBase::$backupStaticAttributes protected property Back up and restore static class properties that may be changed by tests.
KernelTestBase::$backupStaticAttributesBlacklist protected property Contains a few static class properties for performance.
KernelTestBase::$classLoader protected property
KernelTestBase::$configImporter protected property @todo Move into Config test base class. 7
KernelTestBase::$configSchemaCheckerExclusions protected static property An array of config object names that are excluded from schema checking.
KernelTestBase::$container protected property
KernelTestBase::$databasePrefix protected property
KernelTestBase::$preserveGlobalState protected property Do not forward any global state from the parent process to the processes that run the actual tests.
KernelTestBase::$root protected property The app root.
KernelTestBase::$runTestInSeparateProcess protected property Kernel tests are run in separate processes because they allow autoloading of code from extensions. Running the test in a separate process isolates this behavior from other tests. Subclasses should not override this property.
KernelTestBase::$siteDirectory protected property
KernelTestBase::$strictConfigSchema protected property Set to TRUE to strict check all configuration saved. 6
KernelTestBase::$vfsRoot protected property The virtual filesystem root directory.
KernelTestBase::assertPostConditions protected function 1
KernelTestBase::bootEnvironment protected function Bootstraps a basic test environment.
KernelTestBase::bootKernel private function Bootstraps a kernel for a test.
KernelTestBase::config protected function Configuration accessor for tests. Returns non-overridden configuration.
KernelTestBase::disableModules protected function Disables modules for this test.
KernelTestBase::enableModules protected function Enables modules for this test.
KernelTestBase::getConfigSchemaExclusions protected function Gets the config schema exclusions for this test.
KernelTestBase::getDatabaseConnectionInfo protected function Returns the Database connection info to be used for this test. 1
KernelTestBase::getDatabasePrefix public function
KernelTestBase::getExtensionsForModules private function Returns Extension objects for $modules to enable.
KernelTestBase::getModulesToEnable private static function Returns the modules to enable for this test.
KernelTestBase::initFileCache protected function Initializes the FileCache component.
KernelTestBase::installConfig protected function Installs default configuration for a given list of modules.
KernelTestBase::installEntitySchema protected function Installs the storage schema for a specific entity type.
KernelTestBase::installSchema protected function Installs database tables from a module schema definition.
KernelTestBase::isTestInIsolation Deprecated protected function Returns whether the current test method is running in a separate process.
KernelTestBase::prepareTemplate protected function
KernelTestBase::register public function Registers test-specific services. Overrides ServiceProviderInterface::register 26
KernelTestBase::render protected function Renders a render array. 1
KernelTestBase::setInstallProfile protected function Sets the install profile and rebuilds the container to update it.
KernelTestBase::setSetting protected function Sets an in-memory Settings variable.
KernelTestBase::setUpBeforeClass public static function 1
KernelTestBase::setUpFilesystem protected function Sets up the filesystem, so things like the file directory. 2
KernelTestBase::stop protected function Stops test execution.
KernelTestBase::tearDown protected function 6
KernelTestBase::tearDownCloseDatabaseConnection public function @after
KernelTestBase::vfsDump protected function Dumps the current state of the virtual filesystem to STDOUT.
KernelTestBase::__get Deprecated public function BC: Automatically resolve former KernelTestBase class properties.
KernelTestBase::__sleep public function Prevents serializing any properties.
MessageDigestTest::assertRowCount protected function Checks that the message_digest table contains the expected number of rows.
MessageDigestTest::getAllMessageDigests protected function Returns all rows from the message_digest table.
MessageDigestTest::getMessageText protected function Returns some message text, including HTML.
MessageDigestTest::providerTestNotifierDelivery public function Data provider for ::testNotifierDelivery().
MessageDigestTest::testDigestGrouping public function Test grouping by entity type, and ID.
MessageDigestTest::testDigestNotifierPluginsExist public function Tests the plugin deriver for daily and weekly digests.
MessageDigestTest::testDigestSerialization public function Checks that message digest plugins can be correctly serialized.
MessageDigestTest::testInvalidEntityId public function Tests sending with an entity_type and no ID.
MessageDigestTest::testInvalidEntityType public function Tests sending with an entity_id and no type.
MessageDigestTest::testManagerProcessing public function Tests the message digest manager processing.
MessageDigestTest::testMessageCleanup public function Test old message purging.
MessageDigestTest::testNotifierAggregation public function Tests message aggregation.
MessageDigestTest::testNotifierDelivery public function Tests the notifier sending and delivery.
MessageDigestTest::testOrphanedEntityReferences public function Tests that the message_digest table is cleaned up when deleting entities.
MessageDigestTest::testOrphanedMessage public function Tests that a message is not sent if its owner has been deleted.
MessageTemplateCreateTrait::createMessageTemplate protected function Helper function to create and save a message template entity.
PhpunitCompatibilityTrait::getMock Deprecated public function Returns a mock object for the specified class using the available method.
PhpunitCompatibilityTrait::setExpectedException Deprecated public function Compatibility layer for PHPUnit 6 to support PHPUnit 4 code.
RandomGeneratorTrait::$randomGenerator protected property The random generator.
RandomGeneratorTrait::getRandomGenerator protected function Gets the random generator for the utility methods.
RandomGeneratorTrait::randomMachineName protected function Generates a unique random string containing letters and numbers. 1
RandomGeneratorTrait::randomObject public function Generates a random PHP object.
RandomGeneratorTrait::randomString public function Generates a pseudo-random string of ASCII characters of codes 32 to 126.
RandomGeneratorTrait::randomStringValidate public function Callback for random string validation.
StorageCopyTrait::replaceStorageContents protected static function Copy the configuration from one storage to another and remove stale items.
TestRequirementsTrait::checkModuleRequirements private function Checks missing module requirements.
TestRequirementsTrait::checkRequirements protected function Check module requirements for the Drupal use case. 1
TestRequirementsTrait::getDrupalRoot protected static function Returns the Drupal root directory.
UserCreationTrait::checkPermissions protected function Checks whether a given list of permission names is valid.
UserCreationTrait::createAdminRole protected function Creates an administrative role.
UserCreationTrait::createRole protected function Creates a role with specified permissions.
UserCreationTrait::createUser protected function Create a user with a given set of permissions.
UserCreationTrait::grantPermissions protected function Grant permissions to a user role.
UserCreationTrait::setCurrentUser protected function Switch the current logged in user.
UserCreationTrait::setUpCurrentUser protected function Creates a random user account and sets it as current user.