Skip to content

Commit 80f742e

Browse files
committed
test: add tests
Signed-off-by: Thierry Bugier <[email protected]>
1 parent 8ac9631 commit 80f742e

File tree

1 file changed

+73
-0
lines changed

1 file changed

+73
-0
lines changed

tests/suite-unit/PluginFormcreatorEmailField.php

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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+
'input' => '[email protected]',
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

Comments
 (0)