From 45c1081c9b240593382ce2b6f9ea761ea300799c Mon Sep 17 00:00:00 2001 From: tomaszszopinski <59650405+tomaszszopinski@users.noreply.github.com> Date: Mon, 24 Jan 2022 13:31:46 +0100 Subject: [PATCH] ibx-1481_added_field_group_limitation_parser (#241) added hasClass assert to ElementAssert added additional hasClass configuration fixed hasClass assert message --- .../config/services/limitation_parsers.yaml | 2 ++ src/lib/API/Context/ContentTypeContext.php | 1 + .../FieldGroupLimitationParser.php | 29 +++++++++++++++++++ .../Debug/Interactive/ElementAssert.php | 9 ++++++ src/lib/Browser/Assert/ElementAssert.php | 18 ++++++++++++ .../Browser/Assert/ElementAssertInterface.php | 2 ++ 6 files changed, 61 insertions(+) create mode 100644 src/lib/API/Context/LimitationParser/FieldGroupLimitationParser.php diff --git a/src/bundle/Resources/config/services/limitation_parsers.yaml b/src/bundle/Resources/config/services/limitation_parsers.yaml index e4306ebf..294f7dd7 100644 --- a/src/bundle/Resources/config/services/limitation_parsers.yaml +++ b/src/bundle/Resources/config/services/limitation_parsers.yaml @@ -12,6 +12,8 @@ services: arguments: - '@ezpublish.api.service.content_type' + EzSystems\Behat\API\Context\LimitationParser\FieldGroupLimitationParser: ~ + EzSystems\Behat\API\Context\LimitationParser\LocationLimitationParser: arguments: - '@ezpublish.api.service.url_alias' diff --git a/src/lib/API/Context/ContentTypeContext.php b/src/lib/API/Context/ContentTypeContext.php index d2a1caa6..290b9db5 100644 --- a/src/lib/API/Context/ContentTypeContext.php +++ b/src/lib/API/Context/ContentTypeContext.php @@ -56,6 +56,7 @@ private function parseFieldDefinitions(TableNode $fieldDetails): array 'isRequired' => $this->parseBool($fieldData['Required']), 'isTranslatable' => $this->parseBool($fieldData['Translatable']), 'isSearchable' => $this->parseBool($fieldData['Searchable']), + 'fieldGroup' => array_key_exists('Category', $fieldData) ? $fieldData['Category'] : null, 'fieldSettings' => array_key_exists('Settings', $fieldData) ? $this->parseFieldSettings($fieldTypeIdentifier, $fieldData['Settings']) : null, ]); diff --git a/src/lib/API/Context/LimitationParser/FieldGroupLimitationParser.php b/src/lib/API/Context/LimitationParser/FieldGroupLimitationParser.php new file mode 100644 index 00000000..67f52414 --- /dev/null +++ b/src/lib/API/Context/LimitationParser/FieldGroupLimitationParser.php @@ -0,0 +1,29 @@ + $limitations] + ); + } +} diff --git a/src/lib/Browser/Assert/Debug/Interactive/ElementAssert.php b/src/lib/Browser/Assert/Debug/Interactive/ElementAssert.php index f619fcca..eddfddf8 100644 --- a/src/lib/Browser/Assert/Debug/Interactive/ElementAssert.php +++ b/src/lib/Browser/Assert/Debug/Interactive/ElementAssert.php @@ -51,4 +51,13 @@ public function isVisible(): ElementInterface return $this->startInteractiveSessionOnException($exception, true); } } + + public function hasClass(string $expectedClass): ElementInterface + { + try { + return $this->baseElementAssert->hasClass($expectedClass); + } catch (ExpectationFailedException $exception) { + return $this->startInteractiveSessionOnException($exception, true); + } + } } diff --git a/src/lib/Browser/Assert/ElementAssert.php b/src/lib/Browser/Assert/ElementAssert.php index 33f61d15..37a3ecd1 100644 --- a/src/lib/Browser/Assert/ElementAssert.php +++ b/src/lib/Browser/Assert/ElementAssert.php @@ -83,4 +83,22 @@ public function isVisible(): ElementInterface return $this->element; } + + public function hasClass(string $expectedClass): ElementInterface + { + $actualClass = $this->element->getAttribute('class'); + + Assert::assertTrue($this->element->hasClass($expectedClass), + sprintf( + "Failed asserting that element with %s locator '%s': '%s' has '%s' class, instead class is '%s'", + $this->locator->getType(), + $this->locator->getIdentifier(), + $this->locator->getSelector(), + $expectedClass, + $actualClass + ) + ); + + return $this->element; + } } diff --git a/src/lib/Browser/Assert/ElementAssertInterface.php b/src/lib/Browser/Assert/ElementAssertInterface.php index de608295..b4d00683 100644 --- a/src/lib/Browser/Assert/ElementAssertInterface.php +++ b/src/lib/Browser/Assert/ElementAssertInterface.php @@ -17,4 +17,6 @@ public function textEquals(string $expectedText): ElementInterface; public function textContains(string $expectedTextFragment): ElementInterface; public function isVisible(): ElementInterface; + + public function hasClass(string $expectedClass): ElementInterface; }