opnform/tests/Unit/Service/Forms/FormLogicPropertyResolverTe...

111 lines
3.9 KiB
PHP
Raw Normal View History

2022-09-20 19:59:52 +00:00
<?php
2024-02-23 10:54:12 +00:00
2022-09-20 19:59:52 +00:00
use App\Service\Forms\FormLogicPropertyResolver;
it('can validate form logic property resolver', function ($property, $formData, $expectedResult) {
$isRequired = FormLogicPropertyResolver::isRequired($property, $formData);
expect($isRequired)->toBe($expectedResult);
})->with([
[
[
2024-02-23 10:54:12 +00:00
'id' => 'title',
'name' => 'Name',
2022-09-20 19:59:52 +00:00
'type' => 'text',
'hidden' => false,
'required' => true,
'logic' => [
2024-02-23 10:54:12 +00:00
'conditions' => [
'operatorIdentifier' => 'and',
'children' => [
2022-09-20 19:59:52 +00:00
[
2024-02-23 10:54:12 +00:00
'identifier' => 'user',
'value' => [
'operator' => 'is_not_empty',
'property_meta' => [
'id' => '93ea3198-353f-440b-8dc9-2ac9a7bee124',
'type' => 'select',
2022-09-20 19:59:52 +00:00
],
2024-02-23 10:54:12 +00:00
'value' => true,
],
],
],
2022-09-20 19:59:52 +00:00
],
2024-02-23 10:54:12 +00:00
'actions' => ['make-it-optional'],
],
2022-09-20 19:59:52 +00:00
],
2024-02-23 10:54:12 +00:00
['93ea3198-353f-440b-8dc9-2ac9a7bee124' => ['One']],
false,
2022-09-20 19:59:52 +00:00
],
[
[
2024-02-23 10:54:12 +00:00
'id' => 'title',
'name' => 'Name',
2022-09-20 19:59:52 +00:00
'type' => 'text',
'hidden' => false,
'required' => true,
'logic' => [
2024-02-23 10:54:12 +00:00
'conditions' => [
'operatorIdentifier' => 'and',
'children' => [
2022-09-20 19:59:52 +00:00
[
2024-02-23 10:54:12 +00:00
'identifier' => 'user',
'value' => [
'operator' => 'is_not_empty',
'property_meta' => [
'id' => '93ea3198-353f-440b-8dc9-2ac9a7bee124',
'type' => 'select',
2022-09-20 19:59:52 +00:00
],
2024-02-23 10:54:12 +00:00
'value' => true,
],
],
],
2022-09-20 19:59:52 +00:00
],
2024-02-23 10:54:12 +00:00
'actions' => ['make-it-optional'],
],
2022-09-20 19:59:52 +00:00
],
2024-02-23 10:54:12 +00:00
['93ea3198-353f-440b-8dc9-2ac9a7bee124' => []],
true,
2022-09-20 19:59:52 +00:00
],
[
[
2024-02-23 10:54:12 +00:00
'id' => 'title',
'name' => 'Name',
2022-09-20 19:59:52 +00:00
'type' => 'text',
'hidden' => false,
'required' => true,
'logic' => [
2024-02-23 10:54:12 +00:00
'conditions' => [
'operatorIdentifier' => 'or',
'children' => [
2022-09-20 19:59:52 +00:00
[
2024-02-23 10:54:12 +00:00
'identifier' => 'user',
'value' => [
'operator' => 'is_not_empty',
'property_meta' => [
'id' => '93ea3198-353f-440b-8dc9-2ac9a7bee124',
'type' => 'select',
2022-09-20 19:59:52 +00:00
],
2024-02-23 10:54:12 +00:00
'value' => true,
],
2022-09-20 19:59:52 +00:00
],
[
2024-02-23 10:54:12 +00:00
'identifier' => 'email',
'value' => [
'operator' => 'contains',
'property_meta' => [
'id' => '93ea3198-353f-440b-8dc9-2ac9a7bee222',
'type' => 'email',
2022-09-20 19:59:52 +00:00
],
2024-02-23 10:54:12 +00:00
'value' => 'abc',
],
],
],
2022-09-20 19:59:52 +00:00
],
2024-02-23 10:54:12 +00:00
'actions' => ['make-it-optional'],
],
2022-09-20 19:59:52 +00:00
],
2024-02-23 10:54:12 +00:00
['93ea3198-353f-440b-8dc9-2ac9a7bee124' => [], '93ea3198-353f-440b-8dc9-2ac9a7bee222' => ['abc']],
false,
],
]);