Skip to content

Commit

Permalink
ibx-1481_added_field_group_limitation_parser (#241)
Browse files Browse the repository at this point in the history
added hasClass assert to ElementAssert

added additional hasClass configuration

fixed hasClass assert message
  • Loading branch information
tomaszszopinski authored Jan 24, 2022
1 parent c4d61c1 commit 45c1081
Show file tree
Hide file tree
Showing 6 changed files with 61 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/bundle/Resources/config/services/limitation_parsers.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
1 change: 1 addition & 0 deletions src/lib/API/Context/ContentTypeContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -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,
]);

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?php

/**
* @copyright Copyright (C) Ibexa AS. All rights reserved.
* @license For full copyright and license information view LICENSE file distributed with this source code.
*/
declare(strict_types=1);

namespace EzSystems\Behat\API\Context\LimitationParser;

use eZ\Publish\API\Repository\Values\User\Limitation;
use Ibexa\Platform\Contracts\Permissions\Repository\Values\User\Limitation\FieldGroupLimitation;

class FieldGroupLimitationParser implements LimitationParserInterface
{
public function supports(string $limitationType): bool
{
return \in_array(strtolower($limitationType), ['fieldgroup', 'field group']);
}

public function parse(string $limitationValues): Limitation
{
$limitations = explode(',', $limitationValues);

return new FieldGroupLimitation(
['limitationValues' => $limitations]
);
}
}
9 changes: 9 additions & 0 deletions src/lib/Browser/Assert/Debug/Interactive/ElementAssert.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
}
18 changes: 18 additions & 0 deletions src/lib/Browser/Assert/ElementAssert.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
2 changes: 2 additions & 0 deletions src/lib/Browser/Assert/ElementAssertInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

0 comments on commit 45c1081

Please sign in to comment.