PositionContext::shouldPrecede()   A
last analyzed

Complexity

Conditions 4
Paths 4

Size

Total Lines 14
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 14
rs 9.2
c 0
b 0
f 0
cc 4
eloc 10
nc 4
nop 2
1
<?php
2
3
namespace NuvoleWeb\Drupal\DrupalExtension\Context;
4
5
use Behat\Mink\Exception\ExpectationException;
6
7
/**
8
 * Class PositionContext.
9
 *
10
 * @package NuvoleWeb\Drupal\DrupalExtension\Context
11
 */
12
class PositionContext extends RawMinkContext {
13
14
  /**
15
   * Assert first element precedes second one.
16
   *
17
   * @Then :first should precede :second
18
   */
19
  public function shouldPrecede($first, $second) {
20
    $page = $this->getSession()->getPage()->getText();
21
    $pos1 = strpos($page, $first);
22
    if ($pos1 === FALSE) {
23
      throw new ExpectationException("Text not found: '$first'.", $this->getSession());
24
    }
25
    $pos2 = strpos($page, $second);
26
    if ($pos2 === FALSE) {
27
      throw new ExpectationException("Text not found: '$second'.", $this->getSession());
28
    }
29
    if ($pos2 < $pos1) {
30
      throw new \Exception("Text '$first' does not precede text '$second'.");
31
    }
32
  }
33
34
}
35