1 | <?php |
||
2 | |||
3 | /* |
||
4 | * @copyright 2019 Mautic Contributors. All rights reserved |
||
5 | * @author Mautic, Inc. |
||
6 | * |
||
7 | * @link https://mautic.org |
||
8 | * |
||
9 | * @license GNU/GPLv3 http://www.gnu.org/licenses/gpl-3.0.html |
||
10 | */ |
||
11 | |||
12 | namespace Mautic\LeadBundle\Tests\Helper; |
||
13 | |||
14 | use Mautic\LeadBundle\Helper\CustomFieldValueHelper; |
||
15 | |||
16 | class CustomFieldValueHelperTest extends \PHPUnit\Framework\TestCase |
||
17 | { |
||
18 | public function testNormalizeValueBooleans() |
||
19 | { |
||
20 | $fieldParams = [ |
||
21 | 'type' => CustomFieldValueHelper::TYPE_BOOLEAN, |
||
22 | 'value' => 1, |
||
23 | 'properties'=> 'a:2:{s:2:"no";s:2:"No";s:3:"yes";s:3:"Yes";}', |
||
24 | ]; |
||
25 | |||
26 | $fields['core']['test'] = $fieldParams; |
||
0 ignored issues
–
show
Comprehensibility
Best Practice
introduced
by
Loading history...
|
|||
27 | |||
28 | $fieldParams['value'] = 0; |
||
29 | $fields['core']['test2'] = $fieldParams; |
||
30 | |||
31 | $fieldParams['value'] = null; |
||
32 | $fields['core']['test3'] = $fieldParams; |
||
33 | |||
34 | $normalizedFields = CustomFieldValueHelper::normalizeValues($fields); |
||
35 | |||
36 | $this->assertEquals('Yes', $normalizedFields['core']['test']['normalizedValue']); |
||
37 | $this->assertEquals('No', $normalizedFields['core']['test2']['normalizedValue']); |
||
38 | $this->assertEquals('', $normalizedFields['core']['test3']['normalizedValue']); |
||
39 | } |
||
40 | |||
41 | public function testNormalizeValueSelect() |
||
42 | { |
||
43 | $fields['core']['test'] = [ |
||
0 ignored issues
–
show
Comprehensibility
Best Practice
introduced
by
|
|||
44 | 'type' => CustomFieldValueHelper::TYPE_SELECT, |
||
45 | 'value' => 'second', |
||
46 | 'properties'=> 'a:1:{s:4:"list";a:2:{i:0;a:2:{s:5:"label";s:12:"First option";s:5:"value";s:5:"first";}i:1;a:2:{s:5:"label";s:13:"Second option";s:5:"value";s:6:"second";}}}', |
||
47 | ]; |
||
48 | $normalizedFields = CustomFieldValueHelper::normalizeValues($fields); |
||
49 | $this->assertEquals('Second option', $normalizedFields['core']['test']['normalizedValue']); |
||
50 | } |
||
51 | |||
52 | public function testNormalizeValueSelectWithoutProperties() |
||
53 | { |
||
54 | $fields['core']['test'] = [ |
||
0 ignored issues
–
show
Comprehensibility
Best Practice
introduced
by
|
|||
55 | 'type' => CustomFieldValueHelper::TYPE_SELECT, |
||
56 | 'value' => 'second', |
||
57 | ]; |
||
58 | $normalizedFields = CustomFieldValueHelper::normalizeValues($fields); |
||
59 | $this->assertEquals('second', $normalizedFields['core']['test']['normalizedValue']); |
||
60 | } |
||
61 | |||
62 | public function testNormalizeValueMultiSelect() |
||
63 | { |
||
64 | $fieldParams = [ |
||
65 | 'type' => CustomFieldValueHelper::TYPE_MULTISELECT, |
||
66 | 'value' => 'option 1', |
||
67 | 'properties'=> 'a:1:{s:4:"list";a:3:{i:0;a:2:{s:5:"label";s:12:"Option 1 yes";s:5:"value";s:8:"option 1";}i:1;a:2:{s:5:"label";s:12:"Option 2 yes";s:5:"value";s:8:"option 2";}i:2;a:2:{s:5:"label";s:12:"Option 3 yes";s:5:"value";s:8:"option 3";}}}', |
||
68 | ]; |
||
69 | |||
70 | $fields['core']['test'] = $fieldParams; |
||
0 ignored issues
–
show
Comprehensibility
Best Practice
introduced
by
|
|||
71 | |||
72 | $fieldParams['value'] = 'option 4'; |
||
73 | $fields['core']['test2'] = $fieldParams; |
||
74 | |||
75 | $normalizedFields = CustomFieldValueHelper::normalizeValues($fields); |
||
76 | |||
77 | $this->assertEquals('Option 1 yes', $normalizedFields['core']['test']['normalizedValue']); |
||
78 | $this->assertEquals('option 4', $normalizedFields['core']['test2']['normalizedValue']); |
||
79 | } |
||
80 | } |
||
81 |