Skip to content

Commit

Permalink
Merge pull request #527 from idimopoulos/assert_not_region_button
Browse files Browse the repository at this point in the history
Provide a step to check that a button is not in a region.
  • Loading branch information
pfrenssen authored Feb 6, 2019
2 parents 3836ccb + d3db9fc commit be7f3c5
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 0 deletions.
4 changes: 4 additions & 0 deletions features/blackbox.feature
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,10 @@ Feature: Test DrupalContext
Given I am on the homepage
Then I should see the "Search" button in the "navigation"

Scenario: Button not in region
Given I am on the homepage
Then I should not see the "Search" button in the "right header" region

Scenario: Find an element in a region
Given I am on the homepage
Then I should see the "h1" element in the "left header"
Expand Down
24 changes: 24 additions & 0 deletions src/Drupal/DrupalExtension/Context/MarkupContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,30 @@ public function assertRegionButton($button, $region)
}
}

/**
* Asserts that a button does not exists in a region.
*
* @Then I should not see the button :button in the :region( region)
* @Then I should not see the :button button in the :region( region)
*
* @param $button
* string The id|name|title|alt|value of the button
* @param $region
* string The region in which the button should not be found
*
* @throws \Exception
* If region is not found or the button is found within the region.
*/
public function assertNotRegionButton($button, $region)
{
$regionObj = $this->getRegion($region);

$buttonObj = $regionObj->findButton($button);
if (!empty($buttonObj)) {
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()));
}
}

/**
* @Then I( should) see the :tag element in the :region( region)
*/
Expand Down

0 comments on commit be7f3c5

Please sign in to comment.