|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Yaro\Jarboe\Tests\Fields; |
|
4
|
|
|
|
|
5
|
|
|
use Symfony\Component\Mime\Exception\RuntimeException; |
|
6
|
|
|
use Yaro\Jarboe\Table\Fields\AbstractField; |
|
7
|
|
|
use Yaro\Jarboe\Table\Filters\TextFilter; |
|
8
|
|
|
use Yaro\Jarboe\Tests\AbstractBaseTest; |
|
9
|
|
|
|
|
10
|
|
|
abstract class AbstractFieldTest extends AbstractBaseTest |
|
11
|
|
|
{ |
|
12
|
|
|
const NAME = 'name'; |
|
13
|
|
|
const TITLE_FROM_NAME = 'Name'; |
|
14
|
|
|
const TITLE = 'Title'; |
|
15
|
|
|
const ANOTHER_NAME = 'another'; |
|
16
|
|
|
const ANOTHER_TITLE = 'Another'; |
|
17
|
|
|
|
|
18
|
|
|
abstract protected function getFieldWithName(): AbstractField; |
|
19
|
|
|
abstract protected function getFieldWithNameAndTitle(): AbstractField; |
|
20
|
|
|
|
|
21
|
|
|
protected function field(): AbstractField |
|
22
|
|
|
{ |
|
23
|
|
|
return $this->getFieldWithName(); |
|
24
|
|
|
} |
|
25
|
|
|
|
|
26
|
|
|
/** |
|
27
|
|
|
* @test |
|
28
|
|
|
* @expectedException RuntimeException |
|
29
|
|
|
*/ |
|
30
|
|
|
public function check_not_supported_hidden_attribute() |
|
31
|
|
|
{ |
|
32
|
|
|
$this->field()->hidden('not_supported'); |
|
33
|
|
|
} |
|
34
|
|
|
|
|
35
|
|
|
/** |
|
36
|
|
|
* @test |
|
37
|
|
|
*/ |
|
38
|
|
|
public function check_ability_to_be_hidden() |
|
39
|
|
|
{ |
|
40
|
|
|
$field = $this->field(); |
|
41
|
|
|
|
|
42
|
|
|
$this->assertFalse($field->hidden('list')); |
|
43
|
|
|
$this->assertFalse($field->hidden('edit')); |
|
44
|
|
|
$this->assertFalse($field->hidden('create')); |
|
45
|
|
|
|
|
46
|
|
|
|
|
47
|
|
|
$field->hideList(true); |
|
48
|
|
|
$this->assertTrue($field->hidden('list')); |
|
49
|
|
|
$field->hideEdit(true); |
|
50
|
|
|
$this->assertTrue($field->hidden('edit')); |
|
51
|
|
|
$field->hideCreate(true); |
|
52
|
|
|
$this->assertTrue($field->hidden('create')); |
|
53
|
|
|
} |
|
54
|
|
|
|
|
55
|
|
|
/** |
|
56
|
|
|
* @test |
|
57
|
|
|
*/ |
|
58
|
|
|
public function filter_passed() |
|
59
|
|
|
{ |
|
60
|
|
|
$filter = TextFilter::make(); |
|
61
|
|
|
$field = $this->field()->filter($filter); |
|
62
|
|
|
|
|
63
|
|
|
$this->assertEquals($filter, $field->filter()); |
|
64
|
|
|
} |
|
65
|
|
|
|
|
66
|
|
|
/** |
|
67
|
|
|
* @test |
|
68
|
|
|
*/ |
|
69
|
|
|
public function no_filter_passed() |
|
70
|
|
|
{ |
|
71
|
|
|
$field = $this->field(); |
|
72
|
|
|
|
|
73
|
|
|
$this->assertNull($field->filter()); |
|
74
|
|
|
} |
|
75
|
|
|
|
|
76
|
|
|
/** |
|
77
|
|
|
* @test |
|
78
|
|
|
*/ |
|
79
|
|
|
public function model_is_setted() |
|
80
|
|
|
{ |
|
81
|
|
|
$field = $this->field(); |
|
82
|
|
|
$field->setModel(self::class); |
|
83
|
|
|
|
|
84
|
|
|
$this->assertEquals(self::class, $field->getModel()); |
|
85
|
|
|
} |
|
86
|
|
|
|
|
87
|
|
|
/** |
|
88
|
|
|
* @test |
|
89
|
|
|
*/ |
|
90
|
|
|
public function name_as_passed() |
|
91
|
|
|
{ |
|
92
|
|
|
$field = $this->field(); |
|
93
|
|
|
|
|
94
|
|
|
$this->assertEquals(self::NAME, $field->name()); |
|
95
|
|
|
} |
|
96
|
|
|
|
|
97
|
|
|
/** |
|
98
|
|
|
* @test |
|
99
|
|
|
*/ |
|
100
|
|
|
public function name_redefined() |
|
101
|
|
|
{ |
|
102
|
|
|
$field = $this->field()->name(self::ANOTHER_NAME); |
|
103
|
|
|
|
|
104
|
|
|
$this->assertEquals(self::ANOTHER_NAME, $field->name()); |
|
105
|
|
|
} |
|
106
|
|
|
|
|
107
|
|
|
/** |
|
108
|
|
|
* @test |
|
109
|
|
|
*/ |
|
110
|
|
|
public function title_generated_from_name() |
|
111
|
|
|
{ |
|
112
|
|
|
$field = $this->getFieldWithName(); |
|
113
|
|
|
|
|
114
|
|
|
$this->assertEquals(self::TITLE_FROM_NAME, $field->title()); |
|
115
|
|
|
} |
|
116
|
|
|
|
|
117
|
|
|
/** |
|
118
|
|
|
* @test |
|
119
|
|
|
*/ |
|
120
|
|
|
public function title_not_generated_from_name() |
|
121
|
|
|
{ |
|
122
|
|
|
$field = $this->getFieldWithNameAndTitle(); |
|
123
|
|
|
|
|
124
|
|
|
$this->assertEquals(self::TITLE, $field->title()); |
|
125
|
|
|
} |
|
126
|
|
|
|
|
127
|
|
|
/** |
|
128
|
|
|
* @test |
|
129
|
|
|
*/ |
|
130
|
|
|
public function title_redefined() |
|
131
|
|
|
{ |
|
132
|
|
|
$field = $this->getFieldWithNameAndTitle()->title(self::ANOTHER_TITLE); |
|
133
|
|
|
|
|
134
|
|
|
$this->assertEquals(self::ANOTHER_TITLE, $field->title()); |
|
135
|
|
|
} |
|
136
|
|
|
|
|
137
|
|
|
/** |
|
138
|
|
|
* @test |
|
139
|
|
|
*/ |
|
140
|
|
|
public function title_not_generated_after_name_change() |
|
141
|
|
|
{ |
|
142
|
|
|
$field = $this->getFieldWithNameAndTitle()->name(self::ANOTHER_NAME); |
|
143
|
|
|
|
|
144
|
|
|
$this->assertEquals(self::TITLE, $field->title()); |
|
145
|
|
|
} |
|
146
|
|
|
|
|
147
|
|
|
/** |
|
148
|
|
|
* @test |
|
149
|
|
|
*/ |
|
150
|
|
|
public function default_col_width() |
|
151
|
|
|
{ |
|
152
|
|
|
$field = $this->field(); |
|
153
|
|
|
|
|
154
|
|
|
$this->assertEquals(12, $field->getCol()); |
|
155
|
|
|
} |
|
156
|
|
|
|
|
157
|
|
|
/** |
|
158
|
|
|
* @test |
|
159
|
|
|
*/ |
|
160
|
|
|
public function changed_col_width() |
|
161
|
|
|
{ |
|
162
|
|
|
$field = $this->field()->col(4); |
|
163
|
|
|
|
|
164
|
|
|
$this->assertEquals(4, $field->getCol()); |
|
165
|
|
|
} |
|
166
|
|
|
|
|
167
|
|
|
/** |
|
168
|
|
|
* @test |
|
169
|
|
|
*/ |
|
170
|
|
|
public function default_width() |
|
171
|
|
|
{ |
|
172
|
|
|
$field = $this->field(); |
|
173
|
|
|
|
|
174
|
|
|
$this->assertNull($field->getWidth()); |
|
175
|
|
|
} |
|
176
|
|
|
|
|
177
|
|
|
/** |
|
178
|
|
|
* @test |
|
179
|
|
|
*/ |
|
180
|
|
|
public function changed_width() |
|
181
|
|
|
{ |
|
182
|
|
|
$field = $this->field()->width(40); |
|
183
|
|
|
|
|
184
|
|
|
$this->assertEquals(40, $field->getWidth()); |
|
185
|
|
|
} |
|
186
|
|
|
|
|
187
|
|
|
/** |
|
188
|
|
|
* @test |
|
189
|
|
|
*/ |
|
190
|
|
|
public function default_tab() |
|
191
|
|
|
{ |
|
192
|
|
|
$field = $this->field(); |
|
193
|
|
|
|
|
194
|
|
|
$this->assertEquals(AbstractField::DEFAULT_TAB_IDENT, $field->getTab()); |
|
195
|
|
|
} |
|
196
|
|
|
|
|
197
|
|
|
/** |
|
198
|
|
|
* @test |
|
199
|
|
|
*/ |
|
200
|
|
|
public function changed_tab() |
|
201
|
|
|
{ |
|
202
|
|
|
$field = $this->field()->tab('tab'); |
|
203
|
|
|
|
|
204
|
|
|
$this->assertEquals('tab', $field->getTab()); |
|
205
|
|
|
} |
|
206
|
|
|
|
|
207
|
|
|
/** |
|
208
|
|
|
* @test |
|
209
|
|
|
*/ |
|
210
|
|
|
public function default_default_value() |
|
211
|
|
|
{ |
|
212
|
|
|
$field = $this->field(); |
|
213
|
|
|
|
|
214
|
|
|
$this->assertNull($field->getDefault()); |
|
215
|
|
|
} |
|
216
|
|
|
|
|
217
|
|
|
/** |
|
218
|
|
|
* @test |
|
219
|
|
|
*/ |
|
220
|
|
|
public function changed_default_value() |
|
221
|
|
|
{ |
|
222
|
|
|
$field = $this->field()->default('default value'); |
|
223
|
|
|
|
|
224
|
|
|
$this->assertEquals('default value', $field->getDefault()); |
|
225
|
|
|
} |
|
226
|
|
|
|
|
227
|
|
|
/** |
|
228
|
|
|
* @test |
|
229
|
|
|
*/ |
|
230
|
|
|
public function default_readonly() |
|
231
|
|
|
{ |
|
232
|
|
|
$field = $this->field(); |
|
233
|
|
|
|
|
234
|
|
|
$this->assertFalse($field->isReadonly()); |
|
235
|
|
|
} |
|
236
|
|
|
|
|
237
|
|
|
/** |
|
238
|
|
|
* @test |
|
239
|
|
|
*/ |
|
240
|
|
|
public function changed_readonly() |
|
241
|
|
|
{ |
|
242
|
|
|
$field = $this->field()->readonly(); |
|
243
|
|
|
|
|
244
|
|
|
$this->assertTrue($field->isReadonly()); |
|
245
|
|
|
} |
|
246
|
|
|
|
|
247
|
|
|
/** |
|
248
|
|
|
* @test |
|
249
|
|
|
*/ |
|
250
|
|
|
public function default_inline() |
|
251
|
|
|
{ |
|
252
|
|
|
$field = $this->field(); |
|
253
|
|
|
|
|
254
|
|
|
$this->assertFalse($field->isInline()); |
|
255
|
|
|
} |
|
256
|
|
|
} |
|
257
|
|
|
|