You are here

class SocialMessageContext in Open Social 10.0.x

Same name and namespace in other branches
  1. 10.3.x tests/behat/features/bootstrap/SocialMessageContext.php \Drupal\social\Behat\SocialMessageContext
  2. 10.1.x tests/behat/features/bootstrap/SocialMessageContext.php \Drupal\social\Behat\SocialMessageContext
  3. 10.2.x tests/behat/features/bootstrap/SocialMessageContext.php \Drupal\social\Behat\SocialMessageContext

Provides step-definitions for interacting with Drupal messages.

Hierarchy

  • class \Drupal\social\Behat\SocialMessageContext extends \Drupal\DrupalExtension\Context\MessageContext

Expanded class hierarchy of SocialMessageContext

1 string reference to 'SocialMessageContext'
behat.yml in tests/behat/config/behat.yml
tests/behat/config/behat.yml

File

tests/behat/features/bootstrap/SocialMessageContext.php, line 12

Namespace

Drupal\social\Behat
View source
class SocialMessageContext extends MessageContext {

  /**
   * Checks if the current page contains the given success message
   *
   * @param $message
   *   string The text to be checked
   * @param $region
   *   string The region
   *
   * @Then I should see the success message( containing) :message in the :region( region)
   */
  public function assertRegionSuccessMessage($message, $region) {
    $this
      ->_assertRegion($message, 'success_message_selector', "The page '%s' does not contain any success messages", "The page '%s' does not contain the success message '%s'", $region);
  }

  /**
   * Internal callback to check for a specific message in a given context.
   *
   * @param $message
   *   string The message to be checked
   * @param $selectorId
   *   string CSS selector name
   * @param $exceptionMsgNone
   *   string The message being thrown when no message is contained, string
   *   should contain one '%s' as a placeholder for the current URL
   * @param $exceptionMsgMissing
   *   string The message being thrown when the message is not contained, string
   *   should contain two '%s' as placeholders for the current URL and the message.
   * @param $region
   *   string The region
   *
   * @throws \Behat\Mink\Exception\ExpectationException
   *   Thrown when the expected message is not present in the page.
   */
  private function _assertRegion($message, $selectorId, $exceptionMsgNone, $exceptionMsgMissing, $region) {
    $session = $this
      ->getSession();
    $regionObj = $session
      ->getPage()
      ->find('region', $region);
    $selector = $this
      ->getDrupalSelector($selectorId);
    $selectorObjects = $regionObj
      ->findAll('css', $selector);
    if (empty($selectorObjects)) {
      throw new ExpectationException(sprintf($exceptionMsgNone, $session
        ->getCurrentUrl()), $session
        ->getDriver());
    }
    foreach ($selectorObjects as $selectorObject) {
      if (strpos(trim($selectorObject
        ->getText()), $message) !== FALSE) {
        return;
      }
    }
    throw new ExpectationException(sprintf($exceptionMsgMissing, $session
      ->getCurrentUrl(), $message), $session
      ->getDriver());
  }

}

Members

Namesort descending Modifiers Type Description Overrides
SocialMessageContext::assertRegionSuccessMessage public function Checks if the current page contains the given success message
SocialMessageContext::_assertRegion private function Internal callback to check for a specific message in a given context.