You are here

protected function ShareMessageTestBase::assertOGTagsHelper in Share Message 8

Helper for assertOGTags and assertNoOGTags.

Parameters

string $property: The OG tag property, for example "og:title" (WITHOUT any kind of quotes).

string $value: The value/content of the related OG tag property.

string $message: (optional) A message to display with the assertion. Do not translate messages: use \Drupal\Component\Utility\SafeMarkup::format() to embed variables in the message text, not t(). If left blank, a default message will be displayed.

bool $not_exists: (optional) TRUE if this OG tag should not be rendered, FALSE if it should. Defaults to TRUE.

Return value

bool TRUE on pass, FALSE on fail.

2 calls to ShareMessageTestBase::assertOGTagsHelper()
ShareMessageTestBase::assertNoOGTags in tests/src/Functional/ShareMessageTestBase.php
Passes if the markup of the OG meta tags is NOT found on the loaded page.
ShareMessageTestBase::assertOGTags in tests/src/Functional/ShareMessageTestBase.php
Passes if the markup of the OG meta tags IS found on the loaded page.

File

tests/src/Functional/ShareMessageTestBase.php, line 251

Class

ShareMessageTestBase

Namespace

Drupal\Tests\sharemessage\Functional

Code

protected function assertOGTagsHelper($property, $value, $message = '', $not_exists = TRUE) {
  $meta_tag = '<meta property="' . $property . '" content="' . Xss::filter($value) . '" />';
  if (!$message) {
    if (!$not_exists) {
      $message = new FormattableMarkup('OG tag "@meta_tag" found.', [
        '@meta_tag' => $meta_tag,
      ]);
    }
    else {
      $message = new FormattableMarkup('OG tag "@meta_tag" not found or has not the expected content.', [
        '@meta_tag' => $meta_tag,
      ]);
    }
  }
  if ($not_exists) {
    return $this
      ->assertNoRaw($meta_tag, $message);
  }
  else {
    return $this
      ->assertRaw($meta_tag, $message);
  }
}