-
Notifications
You must be signed in to change notification settings - Fork 352
/
OroPercentTypeTest.php
160 lines (144 loc) · 4.89 KB
/
OroPercentTypeTest.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
<?php
namespace Oro\Bundle\FormBundle\Tests\Unit\Form\Type;
use Symfony\Component\Form\Test\FormIntegrationTestCase;
use Oro\Bundle\FormBundle\Form\Type\OroPercentType;
class OroPercentTypeTest extends FormIntegrationTestCase
{
/**
* @var string
*/
protected $locale;
/**
* @var OroPercentType
*/
protected $formType;
protected function setUp()
{
parent::setUp();
$this->locale = \Locale::getDefault();
\Locale::setDefault('en');
$this->formType = new OroPercentType();
}
protected function tearDown()
{
parent::tearDown();
\Locale::setDefault($this->locale);
unset($this->locale);
unset($this->formType);
}
public function testGetName()
{
$this->assertEquals(OroPercentType::NAME, $this->formType->getName());
}
public function testGetParent()
{
$this->assertEquals('percent', $this->formType->getParent());
}
/**
* @param float $data
* @param array $viewData
* @param array $options
* @dataProvider buildFormDataProvider
*/
public function testBuildForm(
$data,
array $viewData,
array $options = array()
) {
$form = $this->factory->create($this->formType, $data, $options);
$view = $form->createView();
foreach ($viewData as $key => $value) {
$this->assertArrayHasKey($key, $view->vars);
$this->assertEquals($value, $view->vars[$key]);
}
}
/**
* @return array
*/
public function buildFormDataProvider()
{
return array(
'default' => array(
'data' => 0.1122,
'viewData' => array(
'value' => '11.22'
),
),
'custom precision' => array(
'data' => 0.1122,
'viewData' => array(
'value' => '11'
),
'options' => array(
'precision' => 0
),
),
);
}
/**
* @param float $data
* @param array $expectedData
* @param array $options
* @dataProvider submitFormDataProvider
*/
public function testSubmitForm(
$data,
$expectedData,
array $options = array()
) {
$form = $this->factory->create($this->formType, null, $options);
$form->submit($data);
self::assertTrue($form->isSynchronized());
self::assertSame($expectedData, $form->getData());
}
/**
* @return array
*/
public function submitFormDataProvider()
{
return [
'unspecified precision, with numbers after decimal point' => [
'data' => (string)123.45,
'expectedData' => 1.2345
],
'unspecified precision, without numbers after decimal point' => [
'data' => (string)123,
'expectedData' => 1.23
],
'unspecified precision, without numbers after decimal point, value can be converted to integer' => [
'data' => (string)100,
'expectedData' => (float)1
],
'zero precision, with numbers after decimal point' => [
'data' => (string)123.45,
'expectedData' => 1.2345,
'options' => ['precision' => 0]
],
'zero precision, without numbers after decimal point' => [
'data' => (string)123,
'expectedData' => 1.23,
'options' => ['precision' => 0]
],
'zero precision, without numbers after decimal point, value can be converted to integer' => [
'data' => 100,
'expectedData' => (float)1,
'options' => ['precision' => 0]
],
'custom precision, with numbers after decimal point' => [
'data' => (string)123.45,
'expectedData' => 1.2345,
'options' => ['precision' => 1]
],
'custom precision, without numbers after decimal point' => [
'data' => (string)123,
'expectedData' => 1.23,
'options' => ['precision' => 1]
],
'custom precision, without numbers after decimal point, value can be converted to integer' => [
'data' => (string)100,
'expectedData' => (float)1,
'options' => ['precision' => 1]
],
];
}
}