You are here

protected function ShareMessageTestBase::assertShareButtonHelper in Share Message 8

Helper for assertShareButtons and assertNoShareButtons.

Parameters

array $sharemessage: The edit array of a ShareMessage as passed to drupalPostForm().

string $icon_style: The specified default_icon_style option (addthis_16x16_style or addthis_32x32_style)

bool $addthis_attributes: (optional) FALSE if this markup should not contain its AddThis attributes, TRUE if it should. Defaults to FALSE.

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 markup should not exist, FALSE if it should. Defaults to TRUE.

Return value

bool TRUE on pass, FALSE on fail.

2 calls to ShareMessageTestBase::assertShareButtonHelper()
ShareMessageTestBase::assertNoShareButtons in tests/src/Functional/ShareMessageTestBase.php
Passes if the markup of the share links wrapper is NOT found on the loaded page.
ShareMessageTestBase::assertShareButtons in tests/src/Functional/ShareMessageTestBase.php
Passes if the markup of the share links wrapper IS found on the loaded page.

File

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

Class

ShareMessageTestBase

Namespace

Drupal\Tests\sharemessage\Functional

Code

protected function assertShareButtonHelper($sharemessage, $icon_style = 'addthis_16x16_style', $addthis_attributes = FALSE, $message = '', $not_exists = TRUE) {
  $raw_html_icon_style = '<div class="addthis_toolbox addthis_default_style ' . $icon_style . '"';
  if ($addthis_attributes) {

    // If you are logged out, please do not go to the front page, as the path
    // varies depending on whether you are logged in or not (the front page is
    // '/user', which then redirects away).
    // Enable the module 'filter' and use drupalGet('filter/tips') instead.
    $raw_html_icon_style .= isset($sharemessage['share_url']) ? ' addthis:url="' . $sharemessage['share_url'] . '"' : ' addthis:url="' . $this
      ->getUrl() . '"';
    $raw_html_icon_style .= isset($sharemessage['title']) ? ' addthis:title="' . $sharemessage['title'] . '"' : ' addthis:title=""';
    $raw_html_icon_style .= isset($sharemessage['message_long']) ? ' addthis:description="' . $sharemessage['message_long'] . '"' : ' addthis:description=""';
  }
  $raw_html_icon_style .= '>';
  if (!$message) {
    if (!$not_exists) {
      $message = new FormattableMarkup('Icon style "@raw_html_icon_style" found.', [
        '@raw_html_icon_style' => $raw_html_icon_style,
      ]);
    }
    else {
      $message = new FormattableMarkup('Icon style "@raw_html_icon_style" not found.', [
        '@raw_html_icon_style' => $raw_html_icon_style,
      ]);
    }
  }
  if (isset($this->renderedEntity)) {
    return $not_exists ? $this
      ->assertNotContains($raw_html_icon_style, $this->renderedEntity, $message) : $this
      ->assertContains($raw_html_icon_style, $this->renderedEntity, $message);
  }
  if ($not_exists) {
    return $this
      ->assertSession()
      ->responseNotContains($raw_html_icon_style, $message);
  }
  else {
    return $this
      ->assertSession()
      ->responseContains($raw_html_icon_style, $message);
  }
}