|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Jaxon\Attributes\Tests\TestAttributes; |
|
4
|
|
|
|
|
5
|
|
|
use Jaxon\Attributes\Tests\AttributeTrait; |
|
6
|
|
|
use Jaxon\Attributes\Tests\Attr\Ajax\AttributeNoName; |
|
7
|
|
|
use Jaxon\Attributes\Tests\Attr\Ajax\ClassAttributeNoName; |
|
8
|
|
|
use Jaxon\Attributes\Tests\Attr\Ajax\ClassExcludedNoName; |
|
9
|
|
|
use Jaxon\Exception\SetupException; |
|
10
|
|
|
use PHPUnit\Framework\TestCase; |
|
11
|
|
|
|
|
12
|
|
|
use function Jaxon\Attributes\_register; |
|
13
|
|
|
use function Jaxon\jaxon; |
|
14
|
|
|
use function mkdir; |
|
15
|
|
|
use function rmdir; |
|
16
|
|
|
|
|
17
|
|
|
class NoNameAttributeTest extends TestCase |
|
18
|
|
|
{ |
|
19
|
|
|
use AttributeTrait; |
|
20
|
|
|
|
|
21
|
|
|
/** |
|
22
|
|
|
* @var string |
|
23
|
|
|
*/ |
|
24
|
|
|
private $sCacheDir; |
|
25
|
|
|
|
|
26
|
|
|
/** |
|
27
|
|
|
* @throws SetupException |
|
28
|
|
|
*/ |
|
29
|
|
|
public function setUp(): void |
|
30
|
|
|
{ |
|
31
|
|
|
$this->sCacheDir = __DIR__ . '/../cache'; |
|
32
|
|
|
@mkdir($this->sCacheDir); |
|
|
|
|
|
|
33
|
|
|
|
|
34
|
|
|
jaxon()->di()->getPluginManager()->registerPlugins(); |
|
35
|
|
|
_register(); |
|
36
|
|
|
|
|
37
|
|
|
jaxon()->di()->val('jaxon_attributes_cache_dir', $this->sCacheDir); |
|
38
|
|
|
} |
|
39
|
|
|
|
|
40
|
|
|
/** |
|
41
|
|
|
* @throws SetupException |
|
42
|
|
|
*/ |
|
43
|
|
|
public function tearDown(): void |
|
44
|
|
|
{ |
|
45
|
|
|
jaxon()->reset(); |
|
46
|
|
|
parent::tearDown(); |
|
47
|
|
|
} |
|
48
|
|
|
|
|
49
|
|
|
/** |
|
50
|
|
|
* @throws SetupException |
|
51
|
|
|
*/ |
|
52
|
|
|
public function testUploadAndExcludeAttribute() |
|
53
|
|
|
{ |
|
54
|
|
|
$xMetadata = $this->getAttributes(AttributeNoName::class, ['saveFiles', 'doNot']); |
|
55
|
|
|
$bExcluded = $xMetadata->isExcluded(); |
|
56
|
|
|
$aProperties = $xMetadata->getProperties(); |
|
57
|
|
|
$aProtected = $xMetadata->getProtectedMethods(); |
|
58
|
|
|
|
|
59
|
|
|
$this->assertFalse($bExcluded); |
|
60
|
|
|
|
|
61
|
|
|
$this->assertCount(1, $aProperties); |
|
62
|
|
|
$this->assertArrayHasKey('saveFiles', $aProperties); |
|
63
|
|
|
$this->assertCount(1, $aProperties['saveFiles']); |
|
64
|
|
|
$this->assertEquals("'user-files'", $aProperties['saveFiles']['upload']); |
|
65
|
|
|
|
|
66
|
|
|
$this->assertCount(1, $aProtected); |
|
67
|
|
|
$this->assertEquals('doNot', $aProtected[0]); |
|
68
|
|
|
} |
|
69
|
|
|
|
|
70
|
|
|
/** |
|
71
|
|
|
* @throws SetupException |
|
72
|
|
|
*/ |
|
73
|
|
|
public function testDatabagAttribute() |
|
74
|
|
|
{ |
|
75
|
|
|
$xMetadata = $this->getAttributes(AttributeNoName::class, ['withBags']); |
|
76
|
|
|
$bExcluded = $xMetadata->isExcluded(); |
|
77
|
|
|
$aProperties = $xMetadata->getProperties(); |
|
78
|
|
|
$aProtected = $xMetadata->getProtectedMethods(); |
|
|
|
|
|
|
79
|
|
|
|
|
80
|
|
|
$this->assertFalse($bExcluded); |
|
81
|
|
|
|
|
82
|
|
|
$this->assertCount(1, $aProperties); |
|
83
|
|
|
$this->assertArrayHasKey('withBags', $aProperties); |
|
84
|
|
|
$this->assertCount(1, $aProperties['withBags']); |
|
85
|
|
|
$this->assertCount(2, $aProperties['withBags']['bags']); |
|
86
|
|
|
$this->assertEquals('user.name', $aProperties['withBags']['bags'][0]); |
|
87
|
|
|
$this->assertEquals('page.number', $aProperties['withBags']['bags'][1]); |
|
88
|
|
|
} |
|
89
|
|
|
|
|
90
|
|
|
/** |
|
91
|
|
|
* @throws SetupException |
|
92
|
|
|
*/ |
|
93
|
|
|
public function testCallbacksAttribute() |
|
94
|
|
|
{ |
|
95
|
|
|
$xMetadata = $this->getAttributes(AttributeNoName::class, |
|
96
|
|
|
['cbSingle', 'cbMultiple', 'cbParams']); |
|
97
|
|
|
$bExcluded = $xMetadata->isExcluded(); |
|
98
|
|
|
$aProperties = $xMetadata->getProperties(); |
|
99
|
|
|
$aProtected = $xMetadata->getProtectedMethods(); |
|
|
|
|
|
|
100
|
|
|
|
|
101
|
|
|
$this->assertFalse($bExcluded); |
|
102
|
|
|
|
|
103
|
|
|
$this->assertCount(3, $aProperties); |
|
104
|
|
|
$this->assertArrayHasKey('cbSingle', $aProperties); |
|
105
|
|
|
$this->assertArrayHasKey('cbMultiple', $aProperties); |
|
106
|
|
|
$this->assertArrayHasKey('cbParams', $aProperties); |
|
107
|
|
|
|
|
108
|
|
|
$this->assertCount(1, $aProperties['cbSingle']['__before']); |
|
109
|
|
|
$this->assertCount(2, $aProperties['cbMultiple']['__before']); |
|
110
|
|
|
$this->assertCount(2, $aProperties['cbParams']['__before']); |
|
111
|
|
|
$this->assertArrayHasKey('funcBefore', $aProperties['cbSingle']['__before']); |
|
112
|
|
|
$this->assertArrayHasKey('funcBefore1', $aProperties['cbMultiple']['__before']); |
|
113
|
|
|
$this->assertArrayHasKey('funcBefore2', $aProperties['cbMultiple']['__before']); |
|
114
|
|
|
$this->assertArrayHasKey('funcBefore1', $aProperties['cbParams']['__before']); |
|
115
|
|
|
$this->assertArrayHasKey('funcBefore2', $aProperties['cbParams']['__before']); |
|
116
|
|
|
$this->assertIsArray($aProperties['cbSingle']['__before']['funcBefore']); |
|
117
|
|
|
$this->assertIsArray($aProperties['cbMultiple']['__before']['funcBefore1']); |
|
118
|
|
|
$this->assertIsArray($aProperties['cbMultiple']['__before']['funcBefore2']); |
|
119
|
|
|
$this->assertIsArray($aProperties['cbParams']['__before']['funcBefore1']); |
|
120
|
|
|
$this->assertIsArray($aProperties['cbParams']['__before']['funcBefore2']); |
|
121
|
|
|
|
|
122
|
|
|
$this->assertCount(1, $aProperties['cbSingle']['__after']); |
|
123
|
|
|
$this->assertCount(3, $aProperties['cbMultiple']['__after']); |
|
124
|
|
|
$this->assertCount(1, $aProperties['cbParams']['__after']); |
|
125
|
|
|
$this->assertArrayHasKey('funcAfter', $aProperties['cbSingle']['__after']); |
|
126
|
|
|
$this->assertArrayHasKey('funcAfter1', $aProperties['cbMultiple']['__after']); |
|
127
|
|
|
$this->assertArrayHasKey('funcAfter2', $aProperties['cbMultiple']['__after']); |
|
128
|
|
|
$this->assertArrayHasKey('funcAfter3', $aProperties['cbMultiple']['__after']); |
|
129
|
|
|
$this->assertArrayHasKey('funcAfter1', $aProperties['cbParams']['__after']); |
|
130
|
|
|
$this->assertIsArray($aProperties['cbSingle']['__after']['funcAfter']); |
|
131
|
|
|
$this->assertIsArray($aProperties['cbMultiple']['__after']['funcAfter1']); |
|
132
|
|
|
$this->assertIsArray($aProperties['cbMultiple']['__after']['funcAfter2']); |
|
133
|
|
|
$this->assertIsArray($aProperties['cbMultiple']['__after']['funcAfter3']); |
|
134
|
|
|
$this->assertIsArray($aProperties['cbParams']['__after']['funcAfter1']); |
|
135
|
|
|
} |
|
136
|
|
|
|
|
137
|
|
|
/** |
|
138
|
|
|
* @throws SetupException |
|
139
|
|
|
*/ |
|
140
|
|
|
public function testContainerAttribute() |
|
141
|
|
|
{ |
|
142
|
|
|
$xMetadata = $this->getAttributes(AttributeNoName::class, ['di1', 'di2']); |
|
143
|
|
|
$bExcluded = $xMetadata->isExcluded(); |
|
144
|
|
|
$aProperties = $xMetadata->getProperties(); |
|
145
|
|
|
$aProtected = $xMetadata->getProtectedMethods(); |
|
|
|
|
|
|
146
|
|
|
|
|
147
|
|
|
$this->assertFalse($bExcluded); |
|
148
|
|
|
|
|
149
|
|
|
$this->assertCount(2, $aProperties); |
|
150
|
|
|
$this->assertArrayHasKey('di1', $aProperties); |
|
151
|
|
|
$this->assertArrayHasKey('di2', $aProperties); |
|
152
|
|
|
$this->assertCount(2, $aProperties['di1']['__di']); |
|
153
|
|
|
$this->assertCount(2, $aProperties['di2']['__di']); |
|
154
|
|
|
$this->assertEquals('Jaxon\Attributes\Tests\Service\ColorService', $aProperties['di1']['__di']['colorService']); |
|
155
|
|
|
$this->assertEquals('Jaxon\Attributes\Tests\Attr\Ajax\FontService', $aProperties['di1']['__di']['fontService']); |
|
156
|
|
|
$this->assertEquals('Jaxon\Attributes\Tests\Service\ColorService', $aProperties['di2']['__di']['colorService']); |
|
157
|
|
|
$this->assertEquals('Jaxon\Attributes\Tests\Service\TextService', $aProperties['di2']['__di']['textService']); |
|
158
|
|
|
} |
|
159
|
|
|
|
|
160
|
|
|
/** |
|
161
|
|
|
* @throws SetupException |
|
162
|
|
|
*/ |
|
163
|
|
|
public function testClassAttribute() |
|
164
|
|
|
{ |
|
165
|
|
|
$xMetadata = $this->getAttributes(ClassAttributeNoName::class, []); |
|
166
|
|
|
$bExcluded = $xMetadata->isExcluded(); |
|
167
|
|
|
$aProperties = $xMetadata->getProperties(); |
|
168
|
|
|
$aProtected = $xMetadata->getProtectedMethods(); |
|
|
|
|
|
|
169
|
|
|
// $this->assertEquals('', json_encode($aProperties)); |
|
170
|
|
|
|
|
171
|
|
|
$this->assertFalse($bExcluded); |
|
172
|
|
|
|
|
173
|
|
|
$this->assertCount(1, $aProperties); |
|
174
|
|
|
$this->assertArrayHasKey('*', $aProperties); |
|
175
|
|
|
$this->assertCount(4, $aProperties['*']); |
|
176
|
|
|
$this->assertArrayHasKey('bags', $aProperties['*']); |
|
177
|
|
|
$this->assertArrayHasKey('__before', $aProperties['*']); |
|
178
|
|
|
$this->assertArrayHasKey('__after', $aProperties['*']); |
|
179
|
|
|
|
|
180
|
|
|
$this->assertCount(2, $aProperties['*']['bags']); |
|
181
|
|
|
$this->assertEquals('user.name', $aProperties['*']['bags'][0]); |
|
182
|
|
|
$this->assertEquals('page.number', $aProperties['*']['bags'][1]); |
|
183
|
|
|
|
|
184
|
|
|
$this->assertCount(2, $aProperties['*']['__before']); |
|
185
|
|
|
$this->assertArrayHasKey('funcBefore1', $aProperties['*']['__before']); |
|
186
|
|
|
$this->assertArrayHasKey('funcBefore2', $aProperties['*']['__before']); |
|
187
|
|
|
$this->assertIsArray($aProperties['*']['__before']['funcBefore1']); |
|
188
|
|
|
$this->assertIsArray($aProperties['*']['__before']['funcBefore2']); |
|
189
|
|
|
|
|
190
|
|
|
$this->assertCount(3, $aProperties['*']['__after']); |
|
191
|
|
|
$this->assertArrayHasKey('funcAfter1', $aProperties['*']['__after']); |
|
192
|
|
|
$this->assertArrayHasKey('funcAfter2', $aProperties['*']['__after']); |
|
193
|
|
|
$this->assertArrayHasKey('funcAfter3', $aProperties['*']['__after']); |
|
194
|
|
|
$this->assertIsArray($aProperties['*']['__after']['funcAfter1']); |
|
195
|
|
|
$this->assertIsArray($aProperties['*']['__after']['funcAfter2']); |
|
196
|
|
|
$this->assertIsArray($aProperties['*']['__after']['funcAfter3']); |
|
197
|
|
|
|
|
198
|
|
|
$this->assertCount(3, $aProperties['*']['__di']); |
|
199
|
|
|
$this->assertArrayHasKey('colorService', $aProperties['*']['__di']); |
|
200
|
|
|
$this->assertArrayHasKey('textService', $aProperties['*']['__di']); |
|
201
|
|
|
$this->assertArrayHasKey('fontService', $aProperties['*']['__di']); |
|
202
|
|
|
$this->assertEquals('Jaxon\Attributes\Tests\Service\ColorService', $aProperties['*']['__di']['colorService']); |
|
203
|
|
|
$this->assertEquals('Jaxon\Attributes\Tests\Service\TextService', $aProperties['*']['__di']['textService']); |
|
204
|
|
|
$this->assertEquals('Jaxon\Attributes\Tests\Attr\Ajax\FontService', $aProperties['*']['__di']['fontService']); |
|
205
|
|
|
} |
|
206
|
|
|
|
|
207
|
|
|
/** |
|
208
|
|
|
* @throws SetupException |
|
209
|
|
|
*/ |
|
210
|
|
|
public function testClassExcludeAttribute() |
|
211
|
|
|
{ |
|
212
|
|
|
$xMetadata = $this->getAttributes(ClassExcludedNoName::class, |
|
213
|
|
|
['doNot', 'withBags', 'cbSingle']); |
|
214
|
|
|
$bExcluded = $xMetadata->isExcluded(); |
|
215
|
|
|
$aProperties = $xMetadata->getProperties(); |
|
216
|
|
|
$aProtected = $xMetadata->getProtectedMethods(); |
|
217
|
|
|
|
|
218
|
|
|
$this->assertTrue($bExcluded); |
|
219
|
|
|
$this->assertEmpty($aProperties); |
|
220
|
|
|
$this->assertEmpty($aProtected); |
|
221
|
|
|
} |
|
222
|
|
|
|
|
223
|
|
|
public function testUploadAttributeErrorFieldName() |
|
224
|
|
|
{ |
|
225
|
|
|
$this->expectException(SetupException::class); |
|
226
|
|
|
$this->getAttributes(AttributeNoName::class, ['saveFileErrorFieldName']); |
|
227
|
|
|
} |
|
228
|
|
|
|
|
229
|
|
|
public function testUploadAttributeErrorFieldNumber() |
|
230
|
|
|
{ |
|
231
|
|
|
$this->expectException(SetupException::class); |
|
232
|
|
|
$this->getAttributes(AttributeNoName::class, ['saveFileErrorFieldNumber']); |
|
233
|
|
|
} |
|
234
|
|
|
|
|
235
|
|
|
public function testDatabagAttributeErrorName() |
|
236
|
|
|
{ |
|
237
|
|
|
$this->expectException(SetupException::class); |
|
238
|
|
|
$this->getAttributes(AttributeNoName::class, ['withBagsErrorName']); |
|
239
|
|
|
} |
|
240
|
|
|
|
|
241
|
|
|
public function testDatabagAttributeErrorNumber() |
|
242
|
|
|
{ |
|
243
|
|
|
$this->expectException(SetupException::class); |
|
244
|
|
|
$this->getAttributes(AttributeNoName::class, ['withBagsErrorNumber']); |
|
245
|
|
|
} |
|
246
|
|
|
|
|
247
|
|
|
public function testContainerAttributeErrorAttr() |
|
248
|
|
|
{ |
|
249
|
|
|
$this->expectException(SetupException::class); |
|
250
|
|
|
$this->getAttributes(AttributeNoName::class, ['diErrorAttr']); |
|
251
|
|
|
} |
|
252
|
|
|
|
|
253
|
|
|
public function testContainerAttributeErrorClass() |
|
254
|
|
|
{ |
|
255
|
|
|
$this->expectException(SetupException::class); |
|
256
|
|
|
$this->getAttributes(AttributeNoName::class, ['diErrorClass']); |
|
257
|
|
|
} |
|
258
|
|
|
|
|
259
|
|
|
public function testContainerAttributeErrorOneParam() |
|
260
|
|
|
{ |
|
261
|
|
|
$this->expectException(SetupException::class); |
|
262
|
|
|
$this->getAttributes(AttributeNoName::class, ['diErrorOneParam']); |
|
263
|
|
|
} |
|
264
|
|
|
|
|
265
|
|
|
public function testCbBeforeAttributeErrorName() |
|
266
|
|
|
{ |
|
267
|
|
|
$this->expectException(SetupException::class); |
|
268
|
|
|
$this->getAttributes(AttributeNoName::class, ['cbBeforeErrorName']); |
|
269
|
|
|
} |
|
270
|
|
|
|
|
271
|
|
|
public function testCbBeforeAttributeErrorParam() |
|
272
|
|
|
{ |
|
273
|
|
|
$this->expectException(SetupException::class); |
|
274
|
|
|
$this->getAttributes(AttributeNoName::class, ['cbBeforeErrorParam']); |
|
275
|
|
|
} |
|
276
|
|
|
|
|
277
|
|
|
public function testCbAfterAttributeErrorName() |
|
278
|
|
|
{ |
|
279
|
|
|
$this->expectException(SetupException::class); |
|
280
|
|
|
$this->getAttributes(AttributeNoName::class, ['cbAfterErrorName']); |
|
281
|
|
|
} |
|
282
|
|
|
|
|
283
|
|
|
public function testCbAfterAttributeErrorParam() |
|
284
|
|
|
{ |
|
285
|
|
|
$this->expectException(SetupException::class); |
|
286
|
|
|
$this->getAttributes(AttributeNoName::class, ['cbAfterErrorParam']); |
|
287
|
|
|
} |
|
288
|
|
|
} |
|
289
|
|
|
|
If you suppress an error, we recommend checking for the error condition explicitly: