1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace AbterPhp\Framework\Grid\Collection; |
6
|
|
|
|
7
|
|
|
use AbterPhp\Framework\Grid\Cell\Cell; |
8
|
|
|
use AbterPhp\Framework\Grid\Cell\ICell; |
9
|
|
|
use AbterPhp\Framework\Html\CollectionTest; |
10
|
|
|
use AbterPhp\Framework\Html\INode; |
11
|
|
|
use AbterPhp\Framework\Html\Node; |
12
|
|
|
use AbterPhp\Framework\TestDouble\I18n\MockTranslatorFactory; |
13
|
|
|
|
14
|
|
|
class CellsTest extends CollectionTest |
15
|
|
|
{ |
16
|
|
|
/** |
17
|
|
|
* @return array |
18
|
|
|
*/ |
19
|
|
|
public function toStringReturnsRawContentByDefaultProvider(): array |
20
|
|
|
{ |
21
|
|
|
return [ |
22
|
|
|
'ICell' => [new Cell('foo', 'A'), 'foo'], |
23
|
|
|
'ICell[]' => [[new Cell('foo', 'A')], 'foo'], |
24
|
|
|
]; |
25
|
|
|
} |
26
|
|
|
|
27
|
|
|
/** |
28
|
|
|
* @dataProvider toStringReturnsRawContentByDefaultProvider |
29
|
|
|
* |
30
|
|
|
* @param string $rawContent |
31
|
|
|
* @param string $expectedResult |
32
|
|
|
*/ |
33
|
|
|
public function testToStringReturnsRawContentByDefault($rawContent, string $expectedResult) |
34
|
|
|
{ |
35
|
|
|
$sut = $this->createNode($rawContent); |
36
|
|
|
|
37
|
|
|
$this->assertStringContainsString($expectedResult, (string)$sut); |
38
|
|
|
} |
39
|
|
|
|
40
|
|
|
/** |
41
|
|
|
* @return array |
42
|
|
|
*/ |
43
|
|
|
public function toStringCanReturnTranslatedContentProvider(): array |
44
|
|
|
{ |
45
|
|
|
$translations = ['foo' => 'bar']; |
46
|
|
|
|
47
|
|
|
return [ |
48
|
|
|
'INode' => [new Cell('foo', 'A'), $translations, 'bar'], |
49
|
|
|
'INode[]' => [[new Cell('foo', 'A')], $translations, 'bar'], |
50
|
|
|
]; |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
/** |
54
|
|
|
* @dataProvider toStringCanReturnTranslatedContentProvider |
55
|
|
|
* |
56
|
|
|
* @param string $rawContent |
57
|
|
|
* @param string $expectedResult |
58
|
|
|
*/ |
59
|
|
|
public function testToStringCanReturnTranslatedContent($rawContent, array $translations, string $expectedResult) |
60
|
|
|
{ |
61
|
|
|
$translatorMock = MockTranslatorFactory::createSimpleTranslator($this, $translations); |
62
|
|
|
|
63
|
|
|
$sut = $this->createNode($rawContent); |
64
|
|
|
|
65
|
|
|
$sut->setTranslator($translatorMock); |
66
|
|
|
|
67
|
|
|
$this->assertStringContainsString($expectedResult, (string)$sut); |
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
public function testCountWithoutOffset() |
71
|
|
|
{ |
72
|
|
|
$expectedResult = 2; |
73
|
|
|
|
74
|
|
|
$node1 = new Cell('1', 'A'); |
75
|
|
|
$node2 = new Cell('2', 'A'); |
76
|
|
|
|
77
|
|
|
$sut = $this->createNode(); |
78
|
|
|
|
79
|
|
|
$sut[] = $node1; |
80
|
|
|
$sut[] = $node2; |
81
|
|
|
|
82
|
|
|
$this->assertSame($expectedResult, count($sut)); |
83
|
|
|
} |
84
|
|
|
|
85
|
|
|
public function testCountWithExplicitOffset() |
86
|
|
|
{ |
87
|
|
|
$expectedResult = 2; |
88
|
|
|
|
89
|
|
|
$node1 = new Cell('1', 'A'); |
90
|
|
|
$node2 = new Cell('2', 'A'); |
91
|
|
|
|
92
|
|
|
$sut = $this->createNode(); |
93
|
|
|
|
94
|
|
|
$sut[0] = $node1; |
95
|
|
|
$sut[1] = $node2; |
96
|
|
|
|
97
|
|
|
$this->assertSame($expectedResult, count($sut)); |
98
|
|
|
} |
99
|
|
|
|
100
|
|
|
public function testCountWithMixedOffset() |
101
|
|
|
{ |
102
|
|
|
$node1 = new Cell('1', 'A'); |
103
|
|
|
$node2 = new Cell('2', 'A'); |
104
|
|
|
|
105
|
|
|
$expectedCount = 5; |
106
|
|
|
|
107
|
|
|
$sut = $this->createNode(); |
108
|
|
|
|
109
|
|
|
$sut[] = $node1; |
110
|
|
|
$sut[] = $node1; |
111
|
|
|
$sut[1] = $node2; |
112
|
|
|
$sut[2] = $node1; |
113
|
|
|
$sut[3] = $node1; |
114
|
|
|
$sut[] = $node1; |
115
|
|
|
|
116
|
|
|
$this->assertSame($expectedCount, count($sut)); |
117
|
|
|
} |
118
|
|
|
|
119
|
|
|
public function testArrayAccessWithoutOffset() |
120
|
|
|
{ |
121
|
|
|
$node1 = new Cell('1', 'A'); |
122
|
|
|
$node2 = new Cell('2', 'A'); |
123
|
|
|
|
124
|
|
|
$sut = $this->createNode(); |
125
|
|
|
|
126
|
|
|
$sut[] = $node1; |
127
|
|
|
$sut[] = $node2; |
128
|
|
|
|
129
|
|
|
$this->assertSame($node1, $sut[0]); |
130
|
|
|
$this->assertSame($node2, $sut[1]); |
131
|
|
|
} |
132
|
|
|
|
133
|
|
|
public function testArrayAccessWithExplicitOffset() |
134
|
|
|
{ |
135
|
|
|
$node1 = new Cell('1', 'A'); |
136
|
|
|
$node2 = new Cell('2', 'A'); |
137
|
|
|
|
138
|
|
|
$sut = $this->createNode(); |
139
|
|
|
|
140
|
|
|
$sut[0] = $node1; |
141
|
|
|
$sut[1] = $node2; |
142
|
|
|
|
143
|
|
|
$this->assertSame($node1, $sut[0]); |
144
|
|
|
$this->assertSame($node2, $sut[1]); |
145
|
|
|
} |
146
|
|
|
|
147
|
|
|
public function testArrayAccessThrowExceptionWhenMadeDirty() |
148
|
|
|
{ |
149
|
|
|
$this->expectException(\InvalidArgumentException::class); |
150
|
|
|
|
151
|
|
|
$node1 = new Cell('1', 'A'); |
152
|
|
|
|
153
|
|
|
$sut = $this->createNode(); |
154
|
|
|
|
155
|
|
|
$sut[1] = $node1; |
156
|
|
|
} |
157
|
|
|
|
158
|
|
|
public function testArrayAccessWithMixedOffset() |
159
|
|
|
{ |
160
|
|
|
$node1 = new Cell('1', 'A'); |
161
|
|
|
$node2 = new Cell('2', 'A'); |
162
|
|
|
|
163
|
|
|
$expectedNodes = [0 => $node1, 1 => $node2, 2 => $node1, 3 => $node1, 4 => $node1]; |
164
|
|
|
|
165
|
|
|
$sut = $this->createNode(); |
166
|
|
|
|
167
|
|
|
$sut[] = $node1; |
168
|
|
|
$sut[] = $node1; |
169
|
|
|
$sut[1] = $node2; |
170
|
|
|
$sut[2] = $node1; |
171
|
|
|
$sut[3] = $node1; |
172
|
|
|
$sut[] = $node1; |
173
|
|
|
|
174
|
|
|
$this->assertEquals($expectedNodes, $sut->getExtendedNodes()); |
175
|
|
|
} |
176
|
|
|
|
177
|
|
|
/** |
178
|
|
|
* @return array |
179
|
|
|
*/ |
180
|
|
|
public function contentFailureProvider(): array |
181
|
|
|
{ |
182
|
|
|
return [ |
183
|
|
|
'bool' => [true], |
184
|
|
|
'non-node object' => [new \StdClass()], |
185
|
|
|
'string wrapped' => [['']], |
186
|
|
|
'non-node object wrapped' => [[new \StdClass()]], |
187
|
|
|
'node double wrapped' => [[[new Cell('1', 'A')]]], |
188
|
|
|
'collection' => [new Cells()], |
189
|
|
|
]; |
190
|
|
|
} |
191
|
|
|
|
192
|
|
|
/** |
193
|
|
|
* @dataProvider contentFailureProvider |
194
|
|
|
*/ |
195
|
|
|
public function testConstructFailure($item) |
196
|
|
|
{ |
197
|
|
|
$this->expectException(\InvalidArgumentException::class); |
198
|
|
|
|
199
|
|
|
$this->createNode($item); |
200
|
|
|
} |
201
|
|
|
|
202
|
|
|
/** |
203
|
|
|
* @dataProvider contentFailureProvider |
204
|
|
|
*/ |
205
|
|
|
public function testSetContentFailure($item) |
206
|
|
|
{ |
207
|
|
|
$this->expectException(\InvalidArgumentException::class); |
208
|
|
|
|
209
|
|
|
$sut = $this->createNode(); |
210
|
|
|
|
211
|
|
|
$sut->setContent($item); |
212
|
|
|
} |
213
|
|
|
|
214
|
|
|
/** |
215
|
|
|
* @return array |
216
|
|
|
*/ |
217
|
|
|
public function offsetSetFailureProvider(): array |
218
|
|
|
{ |
219
|
|
|
$contentFailure = $this->contentFailureProvider(); |
220
|
|
|
|
221
|
|
|
$offsetFailure = [ |
222
|
|
|
'string' => ['foo'], |
223
|
|
|
'node wrapped' => [[new Cell('1', 'A')]], |
224
|
|
|
]; |
225
|
|
|
|
226
|
|
|
return array_merge($contentFailure, $offsetFailure); |
227
|
|
|
} |
228
|
|
|
|
229
|
|
|
/** |
230
|
|
|
* @dataProvider offsetSetFailureProvider |
231
|
|
|
*/ |
232
|
|
|
public function testArrayAccessFailureWithoutOffset($item) |
233
|
|
|
{ |
234
|
|
|
$this->expectException(\InvalidArgumentException::class); |
235
|
|
|
|
236
|
|
|
$sut = $this->createNode(); |
237
|
|
|
|
238
|
|
|
$sut[] = $item; |
239
|
|
|
} |
240
|
|
|
|
241
|
|
|
/** |
242
|
|
|
* @dataProvider offsetSetFailureProvider |
243
|
|
|
*/ |
244
|
|
|
public function testArrayAccessFailureWithExplicitOffset($item) |
245
|
|
|
{ |
246
|
|
|
$this->expectException(\InvalidArgumentException::class); |
247
|
|
|
|
248
|
|
|
$sut = $this->createNode(); |
249
|
|
|
|
250
|
|
|
$sut[] = $item; |
251
|
|
|
} |
252
|
|
|
|
253
|
|
|
public function testSetContent() |
254
|
|
|
{ |
255
|
|
|
$node1 = new Cell('1', 'A'); |
256
|
|
|
$node2 = new Cell('2', 'A'); |
257
|
|
|
|
258
|
|
|
$sut = $this->createNode(); |
259
|
|
|
$sut[] = $node1; |
260
|
|
|
$sut[] = $node1; |
261
|
|
|
$sut[1] = $node2; |
262
|
|
|
$sut[2] = $node1; |
263
|
|
|
$sut[3] = $node1; |
264
|
|
|
$sut[] = $node1; |
265
|
|
|
|
266
|
|
|
$expectedNodes = [new Cell('3', 'A')]; |
267
|
|
|
|
268
|
|
|
$sut->setContent($expectedNodes[0]); |
269
|
|
|
|
270
|
|
|
$this->assertEquals($expectedNodes, $sut->getExtendedNodes()); |
271
|
|
|
} |
272
|
|
|
|
273
|
|
|
public function testGetNodes() |
274
|
|
|
{ |
275
|
|
|
$node1 = new Cell('1', 'A'); |
276
|
|
|
$node2 = new Cell('2', 'A'); |
277
|
|
|
|
278
|
|
|
$sut = $this->createNode(); |
279
|
|
|
$sut[] = $node1; |
280
|
|
|
$sut[] = $node1; |
281
|
|
|
$sut[1] = $node2; |
282
|
|
|
$sut[2] = $node1; |
283
|
|
|
$sut[3] = $node1; |
284
|
|
|
$sut[] = $node1; |
285
|
|
|
|
286
|
|
|
$expectedNodes = [$node1, $node2, $node1, $node1, $node1]; |
287
|
|
|
|
288
|
|
|
$actualResult = $sut->getNodes(); |
289
|
|
|
|
290
|
|
|
$this->assertEquals($expectedNodes, $actualResult); |
291
|
|
|
} |
292
|
|
|
|
293
|
|
|
public function testGetExtendedNodes() |
294
|
|
|
{ |
295
|
|
|
$node1 = new Cell('1', 'A'); |
296
|
|
|
$node2 = new Cell('2', 'A'); |
297
|
|
|
|
298
|
|
|
$expectedNodes = [$node1, $node2, $node1, $node1, $node1]; |
299
|
|
|
|
300
|
|
|
$sut = $this->createNode(); |
301
|
|
|
$sut[] = $node1; |
302
|
|
|
$sut[] = $node1; |
303
|
|
|
$sut[1] = $node2; |
304
|
|
|
$sut[2] = $node1; |
305
|
|
|
$sut[3] = $node1; |
306
|
|
|
$sut[] = $node1; |
307
|
|
|
|
308
|
|
|
$actualResult = $sut->getExtendedNodes(); |
309
|
|
|
|
310
|
|
|
$this->assertEquals($expectedNodes, $actualResult); |
311
|
|
|
} |
312
|
|
|
|
313
|
|
|
public function testGetDescendantNodes() |
314
|
|
|
{ |
315
|
|
|
$nodeContent1 = new Node('1'); |
316
|
|
|
$nodeContent2 = new Node('2'); |
317
|
|
|
|
318
|
|
|
$node1 = new Cell($nodeContent1, 'A'); |
319
|
|
|
$node2 = new Cell($nodeContent2, 'A'); |
320
|
|
|
|
321
|
|
|
$sut = $this->createNode(); |
322
|
|
|
$sut[] = $node1; |
323
|
|
|
$sut[] = $node1; |
324
|
|
|
$sut[1] = $node2; |
325
|
|
|
$sut[2] = $node1; |
326
|
|
|
$sut[3] = $node1; |
327
|
|
|
$sut[] = $node1; |
328
|
|
|
|
329
|
|
|
$expectedNodes = [ |
330
|
|
|
$node1, $nodeContent1, |
331
|
|
|
$node2, $nodeContent2, |
332
|
|
|
$node1, $nodeContent1, |
333
|
|
|
$node1, $nodeContent1, |
334
|
|
|
$node1, $nodeContent1, |
335
|
|
|
]; |
336
|
|
|
|
337
|
|
|
$actualResult = $sut->getDescendantNodes(); |
338
|
|
|
|
339
|
|
|
$this->assertEquals($expectedNodes, $actualResult); |
340
|
|
|
} |
341
|
|
|
|
342
|
|
|
public function testGetExtendedDescendantNodes() |
343
|
|
|
{ |
344
|
|
|
$nodeContent1 = new Node('1'); |
345
|
|
|
$nodeContent2 = new Node('2'); |
346
|
|
|
|
347
|
|
|
$node1 = new Cell($nodeContent1, 'A'); |
348
|
|
|
$node2 = new Cell($nodeContent2, 'A'); |
349
|
|
|
|
350
|
|
|
$sut = $this->createNode(); |
351
|
|
|
$sut[] = $node1; |
352
|
|
|
$sut[] = $node1; |
353
|
|
|
$sut[1] = $node2; |
354
|
|
|
$sut[2] = $node1; |
355
|
|
|
$sut[3] = $node1; |
356
|
|
|
$sut[] = $node1; |
357
|
|
|
|
358
|
|
|
$expectedNodes = [ |
359
|
|
|
$node1, $nodeContent1, |
360
|
|
|
$node2, $nodeContent2, |
361
|
|
|
$node1, $nodeContent1, |
362
|
|
|
$node1, $nodeContent1, |
363
|
|
|
$node1, $nodeContent1, |
364
|
|
|
]; |
365
|
|
|
|
366
|
|
|
$actualResult = $sut->getExtendedDescendantNodes(); |
367
|
|
|
|
368
|
|
|
$this->assertEquals($expectedNodes, $actualResult); |
369
|
|
|
} |
370
|
|
|
|
371
|
|
|
public function testIterator() |
372
|
|
|
{ |
373
|
|
|
$node1 = new Cell('1', 'A'); |
374
|
|
|
$node2 = new Cell('2', 'A'); |
375
|
|
|
|
376
|
|
|
$expectedKeys = [0, 1, 2, 3, 4]; |
377
|
|
|
$expectedNodes = [$node1, $node2, $node1, $node1, $node1]; |
378
|
|
|
|
379
|
|
|
$sut = $this->createNode(); |
380
|
|
|
|
381
|
|
|
$sut[] = $node1; |
382
|
|
|
$sut[] = $node1; |
383
|
|
|
$sut[1] = $node2; |
384
|
|
|
$sut[2] = $node1; |
385
|
|
|
$sut[3] = $node1; |
386
|
|
|
$sut[] = $node1; |
387
|
|
|
|
388
|
|
|
$pos = 0; |
389
|
|
|
foreach ($sut as $key => $node) { |
390
|
|
|
$this->assertSame($expectedKeys[$pos], $key); |
391
|
|
|
$this->assertSame($expectedNodes[$pos], $node); |
392
|
|
|
$pos++; |
393
|
|
|
} |
394
|
|
|
} |
395
|
|
|
|
396
|
|
|
public function testGetRawContentReturnsNonTranslatedContent() |
397
|
|
|
{ |
398
|
|
|
$this->assertTrue(true, 'No need to test getRawContent'); |
399
|
|
|
} |
400
|
|
|
|
401
|
|
|
/** |
402
|
|
|
* @return array |
403
|
|
|
*/ |
404
|
|
|
public function insertBeforeProvider(): array |
405
|
|
|
{ |
406
|
|
|
$needle = new Cell('1', 'A'); |
407
|
|
|
$cell2 = new Cell('2', 'A'); |
408
|
|
|
$cell3 = new Cell('3', 'A'); |
409
|
|
|
|
410
|
|
|
return [ |
411
|
|
|
'empty-content' => [ |
412
|
|
|
[], |
413
|
|
|
$needle, |
414
|
|
|
[$cell2], |
415
|
|
|
false, |
416
|
|
|
[], |
417
|
|
|
], |
418
|
|
|
'only-non-matching-content' => [ |
419
|
|
|
[$cell2, $cell3], |
420
|
|
|
$needle, |
421
|
|
|
[$needle, $cell3], |
422
|
|
|
false, |
423
|
|
|
[$cell2, $cell3], |
424
|
|
|
], |
425
|
|
|
'only-matching-content' => [ |
426
|
|
|
[$needle], |
427
|
|
|
$needle, |
428
|
|
|
[$cell2, $cell3], |
429
|
|
|
true, |
430
|
|
|
[$cell2, $cell3, $needle], |
431
|
|
|
], |
432
|
|
|
'non-first-matching-content' => [ |
433
|
|
|
[$cell2, $needle], |
434
|
|
|
$needle, |
435
|
|
|
[$cell3, $cell3], |
436
|
|
|
true, |
437
|
|
|
[$cell2, $cell3, $cell3, $needle], |
438
|
|
|
], |
439
|
|
|
]; |
440
|
|
|
} |
441
|
|
|
|
442
|
|
|
/** |
443
|
|
|
* @return array |
444
|
|
|
*/ |
445
|
|
|
public function insertAfterProvider(): array |
446
|
|
|
{ |
447
|
|
|
$needle = new Cell('1', 'A'); |
448
|
|
|
$cell2 = new Cell('2', 'A'); |
449
|
|
|
$cell3 = new Cell('3', 'A'); |
450
|
|
|
|
451
|
|
|
return [ |
452
|
|
|
'empty-content' => [ |
453
|
|
|
[], |
454
|
|
|
$needle, |
455
|
|
|
[$cell2], |
456
|
|
|
false, |
457
|
|
|
[], |
458
|
|
|
], |
459
|
|
|
'only-non-matching-content' => [ |
460
|
|
|
[$cell2, $cell3], |
461
|
|
|
$needle, |
462
|
|
|
[$needle, $cell3], |
463
|
|
|
false, |
464
|
|
|
[$cell2, $cell3], |
465
|
|
|
], |
466
|
|
|
'only-matching-content' => [ |
467
|
|
|
[$needle], |
468
|
|
|
$needle, |
469
|
|
|
[$cell2, $cell3], |
470
|
|
|
true, |
471
|
|
|
[$needle, $cell2, $cell3], |
472
|
|
|
], |
473
|
|
|
'non-last-matching-content' => [ |
474
|
|
|
[$needle, $cell2], |
475
|
|
|
$needle, |
476
|
|
|
[$cell3, $cell3], |
477
|
|
|
true, |
478
|
|
|
[$needle, $cell3, $cell3, $cell2], |
479
|
|
|
], |
480
|
|
|
]; |
481
|
|
|
} |
482
|
|
|
|
483
|
|
|
/** |
484
|
|
|
* @return array |
485
|
|
|
*/ |
486
|
|
|
public function replaceProvider(): array |
487
|
|
|
{ |
488
|
|
|
$needle = new Cell('1', 'A'); |
489
|
|
|
$cell2 = new Cell('2', 'A'); |
490
|
|
|
$cell3 = new Cell('3', 'A'); |
491
|
|
|
|
492
|
|
|
return [ |
493
|
|
|
'empty-content' => [ |
494
|
|
|
[], |
495
|
|
|
$needle, |
496
|
|
|
[$cell2], |
497
|
|
|
false, |
498
|
|
|
[], |
499
|
|
|
], |
500
|
|
|
'only-non-matching-content' => [ |
501
|
|
|
[$cell2, $cell3], |
502
|
|
|
$needle, |
503
|
|
|
[$needle, $cell3], |
504
|
|
|
false, |
505
|
|
|
[$cell2, $cell3], |
506
|
|
|
], |
507
|
|
|
'only-matching-content' => [ |
508
|
|
|
[$needle], |
509
|
|
|
$needle, |
510
|
|
|
[$cell2, $cell3], |
511
|
|
|
true, |
512
|
|
|
[$cell2, $cell3], |
513
|
|
|
], |
514
|
|
|
'non-first-matching-content' => [ |
515
|
|
|
[$cell2, $needle], |
516
|
|
|
$needle, |
517
|
|
|
[$cell3, $cell3], |
518
|
|
|
true, |
519
|
|
|
[$cell2, $cell3, $cell3], |
520
|
|
|
], |
521
|
|
|
'non-last-matching-content' => [ |
522
|
|
|
[$needle, $cell2], |
523
|
|
|
$needle, |
524
|
|
|
[$cell3, $cell3], |
525
|
|
|
true, |
526
|
|
|
[$cell3, $cell3, $cell2], |
527
|
|
|
], |
528
|
|
|
]; |
529
|
|
|
} |
530
|
|
|
|
531
|
|
|
/** |
532
|
|
|
* @return array |
533
|
|
|
*/ |
534
|
|
|
public function removeProvider(): array |
535
|
|
|
{ |
536
|
|
|
$needle = new Cell('1', 'A'); |
537
|
|
|
$cell2 = new Cell('2', 'A'); |
538
|
|
|
$cell3 = new Cell('3', 'A'); |
539
|
|
|
|
540
|
|
|
return [ |
541
|
|
|
'empty-content' => [ |
542
|
|
|
[], |
543
|
|
|
$needle, |
544
|
|
|
false, |
545
|
|
|
[], |
546
|
|
|
], |
547
|
|
|
'only-non-matching-content' => [ |
548
|
|
|
[$cell2, $cell3], |
549
|
|
|
$needle, |
550
|
|
|
false, |
551
|
|
|
[$cell2, $cell3], |
552
|
|
|
], |
553
|
|
|
'only-matching-content' => [ |
554
|
|
|
[$needle], |
555
|
|
|
$needle, |
556
|
|
|
true, |
557
|
|
|
[], |
558
|
|
|
], |
559
|
|
|
'non-first-matching-content' => [ |
560
|
|
|
[$cell2, $needle], |
561
|
|
|
$needle, |
562
|
|
|
true, |
563
|
|
|
[$cell2], |
564
|
|
|
], |
565
|
|
|
'non-last-matching-content' => [ |
566
|
|
|
[$needle, $cell2], |
567
|
|
|
$needle, |
568
|
|
|
true, |
569
|
|
|
[$cell2], |
570
|
|
|
], |
571
|
|
|
]; |
572
|
|
|
} |
573
|
|
|
|
574
|
|
|
public function testArrayAccessUnset() |
575
|
|
|
{ |
576
|
|
|
$node1 = new Cell('1', 'A'); |
577
|
|
|
|
578
|
|
|
$sut = $this->createNode(); |
579
|
|
|
|
580
|
|
|
$sut[] = $node1; |
581
|
|
|
|
582
|
|
|
$this->assertTrue($sut->offsetExists(0)); |
583
|
|
|
|
584
|
|
|
unset($sut[0]); |
585
|
|
|
|
586
|
|
|
$this->assertfalse($sut->offsetExists(0)); |
587
|
|
|
} |
588
|
|
|
|
589
|
|
|
public function testCreateNodeThrowsLogicException() |
590
|
|
|
{ |
591
|
|
|
$this->expectException(\LogicException::class); |
592
|
|
|
|
593
|
|
|
$sut = $this->createNode(); |
594
|
|
|
|
595
|
|
|
$sut->setContent(''); |
596
|
|
|
} |
597
|
|
|
|
598
|
|
|
/** |
599
|
|
|
* @param ICell[]|ICell|string|null $content |
600
|
|
|
* |
601
|
|
|
* @return Cells |
602
|
|
|
*/ |
603
|
|
|
private function createNode($content = null): INode |
604
|
|
|
{ |
605
|
|
|
return new Cells($content); |
606
|
|
|
} |
607
|
|
|
} |
608
|
|
|
|