From 77d5a3d2e9a27bfb5945dda64ffd40418cbaa9ad Mon Sep 17 00:00:00 2001 From: Mateusz Uzdowski Date: Fri, 7 Feb 2014 14:43:26 +1300 Subject: [PATCH] NEW Add generic checks for fields being enabled/disabled. --- .../BehatExtension/Context/BasicContext.php | 37 +++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/src/SilverStripe/BehatExtension/Context/BasicContext.php b/src/SilverStripe/BehatExtension/Context/BasicContext.php index 9ce09bd..9a2407c 100644 --- a/src/SilverStripe/BehatExtension/Context/BasicContext.php +++ b/src/SilverStripe/BehatExtension/Context/BasicContext.php @@ -498,4 +498,41 @@ JS; public function setDatetimeFormat($format) { $this->datetimeFormat = $format; } + + /** + * Checks that field with specified in|name|label|value is disabled. + * Example: Then the field "Email" should be disabled + * Example: Then the "Email" field should be disabled + * + * @Then /^the "(?P(?:[^"]|\\")*)" field should be disabled/ + * @Then /^the field "(?P(?:[^"]|\\")*)" should be disabled/ + */ + public function stepFieldShouldBeDisabled($field) { + $page = $this->getSession()->getPage(); + $fieldElement = $page->findField($field); + assertNotNull($fieldElement, sprintf("Field '%s' not found", $field)); + + $disabledAttribute = $fieldElement->getAttribute('disabled'); + + assertNotNull($disabledAttribute, sprintf("Failed asserting field '%s' is disabled", $field)); + } + + /** + * Checks that checkbox with specified in|name|label|value is enabled. + * Example: Then the field "Email" should be enabled + * Example: Then the "Email" field should be enabled + * + * @Then /^the "(?P(?:[^"]|\\")*)" field should be enabled/ + * @Then /^the field "(?P(?:[^"]|\\")*)" should be enabled/ + */ + public function stepFieldShouldBeEnabled($field) { + $page = $this->getSession()->getPage(); + $fieldElement = $page->findField($field); + assertNotNull($fieldElement, sprintf("Field '%s' not found", $field)); + + $disabledAttribute = $fieldElement->getAttribute('disabled'); + + assertNull($disabledAttribute, sprintf("Failed asserting field '%s' is enabled", $field)); + } + }