Skip to content

Commit

Permalink
Merge pull request #9 from Brille24/behat_fix
Browse files Browse the repository at this point in the history
Behat fix
  • Loading branch information
JakobTolkemit authored Aug 13, 2018
2 parents 1811b16 + d33c5fd commit 6301afe
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -159,8 +159,8 @@ Feature: Configuring validators
Then the customer option group "Some Group" should have conditions:
| option | comparator | value | error_message |
| Text Option | equal | 5 | Oops |
| Select Option | in_set | Value-1, Value-3 | |
| Boolean Option | equal | true | |
| Select Option | in_set | Value-1, Value-3 | Oops |
| Boolean Option | equal | true | Oops |

@ui
Scenario: Multiple constraints are saved correctly
Expand All @@ -187,10 +187,10 @@ Feature: Configuring validators
And I save my changes

Then the customer option group "Some Group" should have constraints:
| option | comparator | value | error_message |
| Text Option | equal | 5 | Oops |
| Select Option | in_set | "Value-1, Value-3" | |
| Boolean Option | equal | true | |
| option | comparator | value | error_message |
| Text Option | equal | 5 | Oops |
| Select Option | in_set | "Value-1, Value-3" | Oops |
| Boolean Option | equal | true | Oops |

@ui
Scenario: Saving multiple validators
Expand Down Expand Up @@ -223,10 +223,10 @@ Feature: Configuring validators
And I save my changes

Then the customer option group "Some Group" should have conditions:
| condition_option | condition_comparator | condition_value | error_message |
| Text Option | lesser | 10 | msg 1 |
| Number Option | equal | 10 | msg 2 |
| option | comparator | value | error_message |
| Text Option | lesser | 10 | msg 1 |
| Number Option | equal | 10 | msg 2 |

And the customer option group "Some Group" should have constraints:
| option | comparator | value | error_message |
| Text Option | greater | 10 | msg 3 |
And the customer option group "Some Group" should have constraints:
| option | comparator | value | error_message |
| Text Option | greater | 10 | msg 3 |
5 changes: 4 additions & 1 deletion src/Form/Validator/ValueType.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,8 @@ function ($modelData) use ($options) {
if ($modelData !== null
&& is_array($modelData)
&& array_key_exists('type', $modelData)
&& $modelData['type'] === $newConfig['type']) {
&& $modelData['type'] === $newConfig['type']
) {
$modelData = $modelData['value'];
$result = $modelData;
}
Expand All @@ -60,6 +61,8 @@ function ($modelData) use ($options) {
if (isset($modelData['timezone'])) {
$result->setTimezone(new \DateTimeZone($modelData['timezone']));
}
} else {
$result = $modelData;
}
}

Expand Down
25 changes: 22 additions & 3 deletions tests/Behat/Context/Admin/CustomerOptionGroupsContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -399,26 +399,45 @@ function (ValidatorInterface $validator) use ($conditionType): array {
$flatConditionsToCheck = array_merge($flatConditionsToCheck, $conditionsArray);
}

$result = false;
$result = true;

foreach ($table->getHash() as $row) {
foreach ($row as $key => $value) {
$row[$key] = str_replace('"', '', $value);
}

$hasCondition = false;

foreach ($flatConditionsToCheck as $condition) {
/** @var CustomerOptionInterface $customerOption */
$customerOption = $condition->getCustomerOption();

if ($customerOption->getName() == $row['option']) {
$optionName = $customerOption->getName();

if ($optionName == $row['option']) {
$val = $this->prepareValue($row['value'], $customerOption->getType());

if (CustomerOptionTypeEnum::isSelect($customerOption->getType())) {
foreach ($val as $key => $value) {
$val[$key] = strtolower($value);
}
}

$sameComp = $condition->getComparator() == $row['comparator'];
$sameVal = $this->values_are_equal(
$condition->getValue()['value'], $val, $customerOption->getType()
);

if ($sameComp && $sameVal) {
$expectedMessage = $row['error_message'];
$result = $condition->getValidator()->getErrorMessage()->getMessage() === $expectedMessage;
if ($condition->getValidator()->getErrorMessage()->getMessage() === $expectedMessage) {
$hasCondition = true;
}
}
}
}

$result = $result && $hasCondition;
}

Assert::true($result, 'The validator does not contain the condition');
Expand Down

0 comments on commit 6301afe

Please sign in to comment.