Skip to content

Commit c204339

Browse files
committed
Merge branch 'MAUT-11616' into development
2 parents 48fc416 + 367cd2e commit c204339

File tree

3 files changed

+47
-11
lines changed

3 files changed

+47
-11
lines changed

Form/Type/CampaignConditionFieldValueType.php

+15-10
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,20 @@ public function buildForm(FormBuilderInterface $builder, array $options): void
5252
$choices[$field->getLabel()] = $field->getId();
5353
}
5454

55+
$optionAttr = array_combine(
56+
array_map(fn ($field) => $field->getLabel(), $fields),
57+
array_map(
58+
function ($field) {
59+
return [
60+
'data-operators' => json_encode($field->getTypeObject()->getOperatorOptions()),
61+
'data-options' => json_encode($field->getChoices()),
62+
'data-field-type' => $field->getType(),
63+
];
64+
},
65+
$fields
66+
)
67+
);
68+
5569
$builder->add(
5670
'field',
5771
ChoiceType::class,
@@ -62,16 +76,7 @@ public function buildForm(FormBuilderInterface $builder, array $options): void
6276
'attr' => [
6377
'class' => 'form-control',
6478
],
65-
'choice_attr' => array_map(
66-
function ($field) {
67-
return [
68-
'data-operators' => json_encode($field->getTypeObject()->getOperatorOptions()),
69-
'data-options' => json_encode($field->getChoices()),
70-
'data-field-type' => $field->getType(),
71-
];
72-
},
73-
$fields
74-
),
79+
'choice_attr' => $optionAttr,
7580
]
7681
);
7782

Tests/Functional/EventListener/CampaignConditionTest.php

+31
Original file line numberDiff line numberDiff line change
@@ -67,4 +67,35 @@ public function testConditionForm(): void
6767
Assert::assertSame('=', $body['event']['properties']['properties']['operator']);
6868
Assert::assertSame('unicorn', $body['event']['properties']['properties']['value']);
6969
}
70+
71+
public function testVerifyDataOperatorAttrIsAvailableForFields(): void
72+
{
73+
$customObject = $this->createCustomObjectWithAllFields(self::$container, 'Campaign test object');
74+
$crawler = $this->client->request(
75+
Request::METHOD_GET,
76+
's/campaigns/events/new',
77+
[
78+
'campaignId' => 'mautic_041b2a401f680fb0b644654af5ba0892f31f0697',
79+
'type' => "custom_item.{$customObject->getId()}.fieldvalue",
80+
'eventType' => 'condition',
81+
'anchor' => 'leadsource',
82+
'anchorEventType' => 'source',
83+
],
84+
[],
85+
$this->createAjaxHeaders()
86+
);
87+
88+
Assert::assertTrue($this->client->getResponse()->isOk(), $this->client->getResponse()->getContent());
89+
90+
$html = json_decode($this->client->getResponse()->getContent(), true)['newContent'];
91+
92+
$crawler->addHtmlContent($html);
93+
94+
$options = $crawler->filter('#campaignevent_properties_field')->filter('option'); // ->attr('data-operators');
95+
96+
/** @var \DOMElement $option */
97+
foreach ($options as $option) {
98+
Assert::assertNotEmpty($option->getAttribute('data-operators'));
99+
}
100+
}
70101
}

Tests/Unit/Form/Type/CampaignConditionFieldValueTypeTest.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ public function testBuildForm(): void
102102
'class' => 'form-control',
103103
],
104104
'choice_attr' => [
105-
42 => [
105+
'Cheese' => [
106106
'data-operators' => '{"=":"a","!=":"b"}',
107107
'data-options' => '[]',
108108
'data-field-type' => 'int',

0 commit comments

Comments
 (0)