Completed
Push — 1.0.x ( 0a17d9...7f19ee )
by Antonio
06:30
created

VisibilityContext::iShouldSeeTheField()   B

Complexity

Conditions 5
Paths 6

Size

Total Lines 17
Code Lines 9

Duplication

Lines 17
Ratio 100 %

Importance

Changes 0
Metric Value
dl 17
loc 17
rs 8.8571
c 0
b 0
f 0
cc 5
eloc 9
nc 6
nop 1
1
<?php
2
3
namespace NuvoleWeb\Drupal\DrupalExtension\Context;
4
5
use Behat\Mink\Exception\UnsupportedDriverActionException;
6
7
/**
8
 * Class VisibilityContext.
9
 *
10
 * @package NuvoleWeb\Drupal\DrupalExtension\Context
11
 */
12
class VisibilityContext extends RawMinkContext {
13
14
  /**
15
   * Assert presence of given field on the page.
16
   *
17
   * @Then I should see the field :field
18
   */
19 View Code Duplication
  public function iShouldSeeTheField($field) {
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
20
    $element = $this->getSession()->getPage();
21
    $result = $element->findField($field);
22
    try {
23
      if ($result && !$result->isVisible()) {
24
        throw new \Exception(sprintf("No field '%s' on the page %s", $field, $this->getSession()->getCurrentUrl()));
25
      }
26
    }
27
    catch (UnsupportedDriverActionException $e) {
28
      // We catch the UnsupportedDriverActionException exception in case
29
      // this step is not being performed by a driver that supports javascript.
30
      // All other exceptions are valid.
31
    }
32
    if (empty($result)) {
33
      throw new \Exception(sprintf("No field '%s' on the page %s", $field, $this->getSession()->getCurrentUrl()));
34
    }
35
  }
36
37
  /**
38
   * Assert absence of given field.
39
   *
40
   * @Then I should not see the field :field
41
   */
42 View Code Duplication
  public function iShouldNotSeeTheField($field) {
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
43
    $element = $this->getSession()->getPage();
44
    $result = $element->findField($field);
45
    try {
46
      if ($result && $result->isVisible()) {
47
        throw new \Exception(sprintf("The field '%s' was present on the page %s and was not supposed to be", $field, $this->getSession()->getCurrentUrl()));
48
      }
49
    }
50
    catch (UnsupportedDriverActionException $e) {
51
      // We catch the UnsupportedDriverActionException exception in case
52
      // this step is not being performed by a driver that supports javascript.
53
      // All other exceptions are valid.
54
      if ($result) {
55
        throw new \Exception(sprintf("The field '%s' was present on the page %s and was not supposed to be", $field, $this->getSession()->getCurrentUrl()));
56
      }
57
    }
58
  }
59
60
}
61