@@ -39,4 +39,77 @@ public function testIsPrerequisites() {
3939 $ output = $ instance ->isPrerequisites ();
4040 $ this ->boolean ($ output )->isEqualTo (true );
4141 }
42+
43+ public function providerParseAnswerValue () {
44+ return [
45+ [
46+ 'input ' => 42 ,
47+ 'expected ' => false ,
48+ ],
49+ [
50+ 'input ' => '' ,
51+ 'expected ' => true ,
52+ ],
53+ [
54+ 55+ 'expected ' => true ,
56+ ],
57+ [
58+ 'input ' => 'not an email ' ,
59+ 'expected ' => false ,
60+ ],
61+ ];
62+ }
63+
64+ /**
65+ * @dataProvider providerParseAnswerValue
66+ */
67+ public function testParseAnswerValue ($ input , $ expected ) {
68+ $ instance = $ this ->newTestedInstance ([
69+ 'id ' => 1
70+ ]);
71+ $ output = $ instance ->parseAnswerValues ([
72+ 'formcreator_field_1 ' => $ input
73+ ]);
74+ $ this ->boolean ($ output )->isEqualTo ($ expected );
75+ }
76+
77+ public function providerSerializeValue () {
78+ return $ this ->providerParseAnswerValue ();
79+ }
80+
81+ /**
82+ * @dataProvider providerSerializeValue
83+ */
84+ public function testSerializeValue ($ value , $ expected ) {
85+ $ instance = new \PluginFormcreatorEmailField (['id ' => 1 ]);
86+ $ instance ->parseAnswerValues (['formcreator_field_1 ' => $ value ]);
87+ $ output = $ instance ->serializeValue ();
88+
89+ $ this ->string ($ output )->isEqualTo ($ expected ? $ value : '' );
90+ }
91+
92+ public function testIsAnonymousFormCompatible () {
93+ $ instance = new \PluginFormcreatorEmailField (['id ' => 1 ]);
94+ $ output = $ instance ->isAnonymousFormCompatible ();
95+ $ this ->boolean ($ output )->isEqualTo (true );
96+ }
97+
98+ public function testGreaterThan () {
99+ $ this ->exception (
100+ function () {
101+ $ instance = new \PluginFormcreatorEmailField ([]);
102+ $ instance ->greaterThan ('' );
103+ }
104+ )->isInstanceOf (\PluginFormcreatorComparisonException::class);
105+ }
106+
107+ public function testLessThan () {
108+ $ this ->exception (
109+ function () {
110+ $ instance = new \PluginFormcreatorEmailField ([]);
111+ $ instance ->lessThan ('' );
112+ }
113+ )->isInstanceOf (\PluginFormcreatorComparisonException::class);
114+ }
42115}
0 commit comments