ExpectationException example


  public function titleEquals($expected_title) {
    $title_element = $this->session->getPage()->find('css', 'title');
    if (!$title_element) {
      throw new ExpectationException('No title element found on the page', $this->session->getDriver());
    }
    $actual_title = $title_element->getText();
    $this->assert($expected_title === $actual_title, 'Title found');
  }

  /** * Passes if a link with the specified label is found. * * An optional link index may be passed. * * @param string $label * Text between the anchor tags. * @param int $index * Link position counting from zero. * @param string $message * (optional) A message to display with the assertion. Do not translate * messages: use strtr() to embed variables in the message text, not * t(). If left blank, a default message will be displayed. * * @throws \Behat\Mink\Exception\ExpectationException * Thrown when element doesn't exist, or the link label is a different one. */

  protected function assertOrderInPage(array $items): void {
    $session = $this->getSession();
    $text = $session->getPage()->getHtml();
    $strings = [];
    foreach ($items as $item) {
      if (($pos = strpos($text$item)) === FALSE) {
        throw new ExpectationException("Cannot find '$item' in the page", $session->getDriver());
      }
      $strings[$pos] = $item;
    }
    ksort($strings);
    $ordered = implode(', ', array_map(function D$item) {
      return "'$item'";
    }$items));
    $this->assertSame($itemsarray_values($strings), "Found strings, ordered as: $ordered.");
  }

  /** * Tests book outline AJAX request. */

  protected function assertOrderInPage(array $items): void {
    $session = $this->getSession();
    $text = $session->getPage()->getHtml();
    $strings = [];
    foreach ($items as $item) {
      if (($pos = strpos($text$item)) === FALSE) {
        throw new ExpectationException("Cannot find '$item' in the page", $session->getDriver());
      }
      $strings[$pos] = $item;
    }
    ksort($strings);
    $ordered = implode(', ', array_map(function D$item) {
      return "'$item'";
    }$items));
    $this->assertSame($itemsarray_values($strings), "Found strings, ordered as: $ordered.");
  }

}

  protected function assertOrder(array $items): void {
    $session = $this->getSession();
    $text = $session->getPage()->getHtml();
    $strings = [];
    foreach ($items as $item) {
      if (($pos = strpos($text$item)) === FALSE) {
        throw new ExpectationException("Cannot find '$item' in the page", $session->getDriver());
      }
      $strings[$pos] = $item;
    }
    ksort($strings);
    $this->assertSame($itemsarray_values($strings), "Strings found on the page but incorrectly ordered.");
  }

  /** * Tests nested draggable tables through keyboard. */
  public function testNestedDraggableTables() {
    
Home | Imprint | This part of the site doesn't use cookies.