Code Duplication    Length = 8-11 lines in 12 locations

src/Drupal/DrupalExtension/Context/MarkupContext.php 4 locations

@@ 51-59 (lines=9) @@
48
   * @throws \Exception
49
   *   If region or button within it cannot be found.
50
   */
51
    public function assertRegionButton($button, $region)
52
    {
53
        $regionObj = $this->getRegion($region);
54
55
        $buttonObj = $regionObj->findButton($button);
56
        if (empty($buttonObj)) {
57
            throw new \Exception(sprintf("The button '%s' was not found in the region '%s' on the page %s", $button, $region, $this->getSession()->getCurrentUrl()));
58
        }
59
    }
60
61
    /**
62
     * Asserts that a button does not exists in a region.
@@ 75-83 (lines=9) @@
72
     * @throws \Exception
73
     *   If region is not found or the button is found within the region.
74
     */
75
    public function assertNotRegionButton($button, $region)
76
    {
77
        $regionObj = $this->getRegion($region);
78
79
        $buttonObj = $regionObj->findButton($button);
80
        if (!empty($buttonObj)) {
81
            throw new \Exception(sprintf("The button '%s' was found in the region '%s' on the page %s but should not", $button, $region, $this->getSession()->getCurrentUrl()));
82
        }
83
    }
84
85
  /**
86
   * @Then I( should) see the :tag element in the :region( region)
@@ 88-96 (lines=9) @@
85
  /**
86
   * @Then I( should) see the :tag element in the :region( region)
87
   */
88
    public function assertRegionElement($tag, $region)
89
    {
90
        $regionObj = $this->getRegion($region);
91
        $elements = $regionObj->findAll('css', $tag);
92
        if (!empty($elements)) {
93
            return;
94
        }
95
        throw new \Exception(sprintf('The element "%s" was not found in the "%s" region on the page %s', $tag, $region, $this->getSession()->getCurrentUrl()));
96
    }
97
98
  /**
99
   * @Then I( should) not see the :tag element in the :region( region)
@@ 101-108 (lines=8) @@
98
  /**
99
   * @Then I( should) not see the :tag element in the :region( region)
100
   */
101
    public function assertNotRegionElement($tag, $region)
102
    {
103
        $regionObj = $this->getRegion($region);
104
        $result = $regionObj->findAll('css', $tag);
105
        if (!empty($result)) {
106
            throw new \Exception(sprintf('The element "%s" was found in the "%s" region on the page %s', $tag, $region, $this->getSession()->getCurrentUrl()));
107
        }
108
    }
109
110
  /**
111
   * @Then I( should) not see :text in the :tag element in the :region( region)

src/Drupal/DrupalExtension/Context/MinkContext.php 8 locations

@@ 360-367 (lines=8) @@
357
   * @Then I (should ) see the button :button
358
   * @Then I (should ) see the :button button
359
   */
360
    public function assertButton($button)
361
    {
362
        $element = $this->getSession()->getPage();
363
        $buttonObj = $element->findButton($button);
364
        if (empty($buttonObj)) {
365
            throw new \Exception(sprintf("The button '%s' was not found on the page %s", $button, $this->getSession()->getCurrentUrl()));
366
        }
367
    }
368
369
  /**
370
   * @Then I should not see the button :button
@@ 373-380 (lines=8) @@
370
   * @Then I should not see the button :button
371
   * @Then I should not see the :button button
372
   */
373
    public function assertNotButton($button)
374
    {
375
        $element = $this->getSession()->getPage();
376
        $buttonObj = $element->findButton($button);
377
        if (!empty($buttonObj)) {
378
            throw new \Exception(sprintf("The button '%s' was found on the page %s", $button, $this->getSession()->getCurrentUrl()));
379
        }
380
    }
381
382
  /**
383
   * @When I follow/click :link in the :region( region)
@@ 388-398 (lines=11) @@
385
   * @throws \Exception
386
   *   If region or link within it cannot be found.
387
   */
388
    public function assertRegionLinkFollow($link, $region)
389
    {
390
        $regionObj = $this->getRegion($region);
391
392
        // Find the link within the region
393
        $linkObj = $regionObj->findLink($link);
394
        if (empty($linkObj)) {
395
            throw new \Exception(sprintf('The link "%s" was not found in the region "%s" on the page %s', $link, $region, $this->getSession()->getCurrentUrl()));
396
        }
397
        $linkObj->click();
398
    }
399
400
  /**
401
   * Checks, if a button with id|name|title|alt|value exists or not and pressess the same
@@ 413-422 (lines=10) @@
410
   * @throws \Exception
411
   *   If region or button within it cannot be found.
412
   */
413
    public function assertRegionPressButton($button, $region)
414
    {
415
        $regionObj = $this->getRegion($region);
416
417
        $buttonObj = $regionObj->findButton($button);
418
        if (empty($buttonObj)) {
419
            throw new \Exception(sprintf("The button '%s' was not found in the region '%s' on the page %s", $button, $region, $this->getSession()->getCurrentUrl()));
420
        }
421
        $regionObj->pressButton($button);
422
    }
423
424
  /**
425
   * Fills in a form field with id|name|title|alt|value in the specified region.
@@ 474-482 (lines=9) @@
471
   * @throws \Exception
472
   *   If region or link within it cannot be found.
473
   */
474
    public function assertLinkRegion($link, $region)
475
    {
476
        $regionObj = $this->getRegion($region);
477
478
        $result = $regionObj->findLink($link);
479
        if (empty($result)) {
480
            throw new \Exception(sprintf('No link to "%s" in the "%s" region on the page %s', $link, $region, $this->getSession()->getCurrentUrl()));
481
        }
482
    }
483
484
  /**
485
   * @Then I should not see the link :link in the :region( region)
@@ 490-498 (lines=9) @@
487
   * @throws \Exception
488
   *   If region or link within it cannot be found.
489
   */
490
    public function assertNotLinkRegion($link, $region)
491
    {
492
        $regionObj = $this->getRegion($region);
493
494
        $result = $regionObj->findLink($link);
495
        if (!empty($result)) {
496
            throw new \Exception(sprintf('Link to "%s" in the "%s" region on the page %s', $link, $region, $this->getSession()->getCurrentUrl()));
497
        }
498
    }
499
500
  /**
501
   * @Then I should see( the text) :text in the :region( region)
@@ 506-515 (lines=10) @@
503
   * @throws \Exception
504
   *   If region or text within it cannot be found.
505
   */
506
    public function assertRegionText($text, $region)
507
    {
508
        $regionObj = $this->getRegion($region);
509
510
        // Find the text within the region
511
        $regionText = $regionObj->getText();
512
        if (strpos($regionText, $text) === false) {
513
            throw new \Exception(sprintf("The text '%s' was not found in the region '%s' on the page %s", $text, $region, $this->getSession()->getCurrentUrl()));
514
        }
515
    }
516
517
  /**
518
   * @Then I should not see( the text) :text in the :region( region)
@@ 523-532 (lines=10) @@
520
   * @throws \Exception
521
   *   If region or text within it cannot be found.
522
   */
523
    public function assertNotRegionText($text, $region)
524
    {
525
        $regionObj = $this->getRegion($region);
526
527
        // Find the text within the region.
528
        $regionText = $regionObj->getText();
529
        if (strpos($regionText, $text) !== false) {
530
            throw new \Exception(sprintf('The text "%s" was found in the region "%s" on the page %s', $text, $region, $this->getSession()->getCurrentUrl()));
531
        }
532
    }
533
534
  /**
535
   * @Then I (should )see the text :text