[TASK] Performance optimizations for the form manager module
[Packages/TYPO3.CMS.git] / typo3 / sysext / form / Tests / Unit / Mvc / Persistence / FormPersistenceManagerTest.php
1 <?php
2 declare(strict_types = 1);
3 namespace TYPO3\CMS\Form\Tests\Unit\Mvc\Persistence;
4
5 /*
6 * This file is part of the TYPO3 CMS project.
7 *
8 * It is free software; you can redistribute it and/or modify it under
9 * the terms of the GNU General Public License, either version 2
10 * of the License, or any later version.
11 *
12 * For the full copyright and license information, please read the
13 * LICENSE.txt file that was distributed with this source code.
14 *
15 * The TYPO3 project - inspiring people to share!
16 */
17
18 use TYPO3\CMS\Core\Cache\Frontend\VariableFrontend;
19 use TYPO3\CMS\Core\Resource\File;
20 use TYPO3\CMS\Core\Resource\ResourceFactory;
21 use TYPO3\CMS\Core\Resource\ResourceStorage;
22 use TYPO3\CMS\Core\Resource\StorageRepository;
23 use TYPO3\CMS\Form\Mvc\Persistence\Exception\NoUniqueIdentifierException;
24 use TYPO3\CMS\Form\Mvc\Persistence\Exception\PersistenceManagerException;
25 use TYPO3\CMS\Form\Mvc\Persistence\FormPersistenceManager;
26 use TYPO3\TestingFramework\Core\Unit\UnitTestCase;
27
28 /**
29 * Test case
30 */
31 class FormPersistenceManagerTest extends UnitTestCase
32 {
33 /**
34 * @test
35 */
36 public function loadThrowsExceptionIfPersistenceIdentifierHasNoYamlExtension(): void
37 {
38 $this->expectException(PersistenceManagerException::class);
39 $this->expectExceptionCode(1477679819);
40
41 $mockFormPersistenceManager = $this->getAccessibleMock(FormPersistenceManager::class, [
42 'dummy'
43 ], [], '', false);
44
45 $runtimeCache= $this->getMockBuilder(VariableFrontend::class)
46 ->setMethods(['get', 'set'])
47 ->disableOriginalConstructor()
48 ->getMock();
49
50 $runtimeCache
51 ->expects($this->any())
52 ->method('get')
53 ->willReturn(false);
54
55 $mockFormPersistenceManager->_set('runtimeCache', $runtimeCache);
56
57 $input = '-1:/user_uploads/_example.php';
58 $mockFormPersistenceManager->_call('load', $input);
59 }
60
61 /**
62 * @test
63 */
64 public function loadThrowsExceptionIfPersistenceIdentifierIsAExtensionLocationWhichIsNotAllowed(): void
65 {
66 $this->expectException(PersistenceManagerException::class);
67 $this->expectExceptionCode(1484071985);
68
69 $mockFormPersistenceManager = $this->getAccessibleMock(FormPersistenceManager::class, [
70 'dummy'
71 ], [], '', false);
72
73 $runtimeCache= $this->getMockBuilder(VariableFrontend::class)
74 ->setMethods(['get', 'set'])
75 ->disableOriginalConstructor()
76 ->getMock();
77
78 $runtimeCache
79 ->expects($this->any())
80 ->method('get')
81 ->willReturn(false);
82
83 $mockFormPersistenceManager->_set('runtimeCache', $runtimeCache);
84
85 $mockFormPersistenceManager->_set('formSettings', [
86 'persistenceManager' => [
87 'allowedExtensionPaths' => [],
88 ],
89 ]);
90
91 $input = 'EXT:form/Resources/Forms/_example.form.yaml';
92 $mockFormPersistenceManager->_call('load', $input);
93 }
94
95 /**
96 * @test
97 */
98 public function saveThrowsExceptionIfPersistenceIdentifierHasNoYamlExtension(): void
99 {
100 $this->expectException(PersistenceManagerException::class);
101 $this->expectExceptionCode(1477679820);
102
103 $mockFormPersistenceManager = $this->getAccessibleMock(FormPersistenceManager::class, [
104 'dummy'
105 ], [], '', false);
106
107 $input = '-1:/user_uploads/_example.php';
108 $mockFormPersistenceManager->_call('save', $input, []);
109 }
110
111 /**
112 * @test
113 */
114 public function saveThrowsExceptionIfPersistenceIdentifierIsAExtensionLocationAndSaveToExtensionLocationIsNotAllowed(): void
115 {
116 $this->expectException(PersistenceManagerException::class);
117 $this->expectExceptionCode(1477680881);
118
119 $mockFormPersistenceManager = $this->getAccessibleMock(FormPersistenceManager::class, [
120 'dummy'
121 ], [], '', false);
122
123 $mockFormPersistenceManager->_set('formSettings', [
124 'persistenceManager' => [
125 'allowSaveToExtensionPaths' => false,
126 ],
127 ]);
128
129 $input = 'EXT:form/Resources/Forms/_example.form.yaml';
130 $mockFormPersistenceManager->_call('save', $input, []);
131 }
132
133 /**
134 * @test
135 */
136 public function saveThrowsExceptionIfPersistenceIdentifierIsAExtensionLocationWhichIsNotAllowed(): void
137 {
138 $this->expectException(PersistenceManagerException::class);
139 $this->expectExceptionCode(1484073571);
140
141 $mockFormPersistenceManager = $this->getAccessibleMock(FormPersistenceManager::class, [
142 'dummy'
143 ], [], '', false);
144
145 $runtimeCache= $this->getMockBuilder(VariableFrontend::class)
146 ->setMethods(['get', 'set'])
147 ->disableOriginalConstructor()
148 ->getMock();
149
150 $runtimeCache
151 ->expects($this->any())
152 ->method('get')
153 ->willReturn(false);
154
155 $mockFormPersistenceManager->_set('runtimeCache', $runtimeCache);
156
157 $mockFormPersistenceManager->_set('formSettings', [
158 'persistenceManager' => [
159 'allowSaveToExtensionPaths' => true,
160 'allowedExtensionPaths' => [],
161 ],
162 ]);
163
164 $input = 'EXT:form/Resources/Forms/_example.form.yaml';
165 $mockFormPersistenceManager->_call('save', $input, []);
166 }
167
168 /**
169 * @test
170 */
171 public function deleteThrowsExceptionIfPersistenceIdentifierHasNoYamlExtension(): void
172 {
173 $this->expectException(PersistenceManagerException::class);
174 $this->expectExceptionCode(1472239534);
175
176 $mockFormPersistenceManager = $this->getAccessibleMock(FormPersistenceManager::class, [
177 'dummy'
178 ], [], '', false);
179
180 $input = '-1:/user_uploads/_example.php';
181 $mockFormPersistenceManager->_call('delete', $input);
182 }
183
184 /**
185 * @test
186 */
187 public function deleteThrowsExceptionIfPersistenceIdentifierFileDoesNotExists(): void
188 {
189 $this->expectException(PersistenceManagerException::class);
190 $this->expectExceptionCode(1472239535);
191
192 $mockFormPersistenceManager = $this->getAccessibleMock(FormPersistenceManager::class, [
193 'exists'
194 ], [], '', false);
195
196 $mockFormPersistenceManager
197 ->expects($this->any())
198 ->method('exists')
199 ->willReturn(false);
200
201 $input = '-1:/user_uploads/_example.form.yaml';
202 $mockFormPersistenceManager->_call('delete', $input);
203 }
204
205 /**
206 * @test
207 */
208 public function deleteThrowsExceptionIfPersistenceIdentifierIsExtensionLocationAndDeleteFromExtensionLocationsIsNotAllowed(): void
209 {
210 $this->expectException(PersistenceManagerException::class);
211 $this->expectExceptionCode(1472239536);
212
213 $mockFormPersistenceManager = $this->getAccessibleMock(FormPersistenceManager::class, [
214 'exists'
215 ], [], '', false);
216
217 $mockFormPersistenceManager
218 ->expects($this->any())
219 ->method('exists')
220 ->willReturn(true);
221
222 $mockFormPersistenceManager->_set('formSettings', [
223 'persistenceManager' => [
224 'allowDeleteFromExtensionPaths' => false,
225 ],
226 ]);
227
228 $input = 'EXT:form/Resources/Forms/_example.form.yaml';
229 $mockFormPersistenceManager->_call('delete', $input);
230 }
231
232 /**
233 * @test
234 */
235 public function deleteThrowsExceptionIfPersistenceIdentifierIsExtensionLocationWhichIsNotAllowed(): void
236 {
237 $this->expectException(PersistenceManagerException::class);
238 $this->expectExceptionCode(1484073878);
239
240 $mockFormPersistenceManager = $this->getAccessibleMock(FormPersistenceManager::class, [
241 'exists'
242 ], [], '', false);
243
244 $runtimeCache= $this->getMockBuilder(VariableFrontend::class)
245 ->setMethods(['get', 'set'])
246 ->disableOriginalConstructor()
247 ->getMock();
248
249 $runtimeCache
250 ->expects($this->any())
251 ->method('get')
252 ->willReturn(false);
253
254 $mockFormPersistenceManager->_set('runtimeCache', $runtimeCache);
255
256 $mockFormPersistenceManager
257 ->expects($this->any())
258 ->method('exists')
259 ->willReturn(true);
260
261 $mockFormPersistenceManager->_set('formSettings', [
262 'persistenceManager' => [
263 'allowDeleteFromExtensionPaths' => true,
264 'allowedExtensionPaths' => [],
265 ],
266 ]);
267
268 $input = 'EXT:form/Resources/Forms/_example.form.yaml';
269 $mockFormPersistenceManager->_call('delete', $input);
270 }
271
272 /**
273 * @test
274 */
275 public function deleteThrowsExceptionIfPersistenceIdentifierIsStorageLocationAndDeleteFromStorageIsNotAllowed(): void
276 {
277 $this->expectException(PersistenceManagerException::class);
278 $this->expectExceptionCode(1472239516);
279
280 $mockFormPersistenceManager = $this->getAccessibleMock(FormPersistenceManager::class, [
281 'getStorageByUid',
282 'exists'
283 ], [], '', false);
284
285 $mockStorage = $this->getMockBuilder(ResourceStorage::class)
286 ->disableOriginalConstructor()
287 ->getMock();
288
289 $mockStorage
290 ->expects($this->any())
291 ->method('checkFileActionPermission')
292 ->willReturn(false);
293
294 $file = new File(['name' => 'foo', 'identifier' => '', 'mime_type' => ''], $mockStorage);
295 $mockStorage
296 ->expects($this->any())
297 ->method('getFile')
298 ->willReturn($file);
299
300 $mockFormPersistenceManager
301 ->expects($this->any())
302 ->method('getStorageByUid')
303 ->willReturn($mockStorage);
304
305 $mockFormPersistenceManager
306 ->expects($this->any())
307 ->method('exists')
308 ->willReturn(true);
309
310 $input = '-1:/user_uploads/_example.form.yaml';
311 $mockFormPersistenceManager->_call('delete', $input);
312 }
313
314 /**
315 * @test
316 */
317 public function existsReturnsTrueIfPersistenceIdentifierIsExtensionLocationAndFileExistsAndFileHasYamlExtension(): void
318 {
319 $mockFormPersistenceManager = $this->getAccessibleMock(FormPersistenceManager::class, [
320 'dummy'
321 ], [], '', false);
322
323 $runtimeCache= $this->getMockBuilder(VariableFrontend::class)
324 ->setMethods(['get', 'set'])
325 ->disableOriginalConstructor()
326 ->getMock();
327
328 $runtimeCache
329 ->expects($this->any())
330 ->method('get')
331 ->willReturn(false);
332
333 $mockFormPersistenceManager->_set('runtimeCache', $runtimeCache);
334
335 $mockFormPersistenceManager->_set('formSettings', [
336 'persistenceManager' => [
337 'allowedExtensionPaths' => [
338 'EXT:form/Tests/Unit/Mvc/Persistence/Fixtures/'
339 ],
340 ],
341 ]);
342
343 $input = 'EXT:form/Tests/Unit/Mvc/Persistence/Fixtures/BlankForm.form.yaml';
344 $this->assertTrue($mockFormPersistenceManager->_call('exists', $input));
345 }
346
347 /**
348 * @test
349 */
350 public function existsReturnsFalseIfPersistenceIdentifierIsExtensionLocationAndFileExistsAndFileHasNoYamlExtension(): void
351 {
352 $mockFormPersistenceManager = $this->getAccessibleMock(FormPersistenceManager::class, [
353 'dummy'
354 ], [], '', false);
355
356 $input = 'EXT:form/Tests/Unit/Mvc/Persistence/Fixtures/BlankForm.txt';
357 $this->assertFalse($mockFormPersistenceManager->_call('exists', $input));
358 }
359
360 /**
361 * @test
362 */
363 public function existsReturnsFalseIfPersistenceIdentifierIsExtensionLocationAndFileExistsAndExtensionLocationIsNotAllowed(): void
364 {
365 $mockFormPersistenceManager = $this->getAccessibleMock(FormPersistenceManager::class, [
366 'dummy'
367 ], [], '', false);
368
369 $mockFormPersistenceManager->_set('formSettings', [
370 'persistenceManager' => [
371 'allowedExtensionPaths' => [],
372 ],
373 ]);
374
375 $input = 'EXT:form/Tests/Unit/Mvc/Persistence/Fixtures/BlankForm.yaml';
376 $this->assertFalse($mockFormPersistenceManager->_call('exists', $input));
377 }
378
379 /**
380 * @test
381 */
382 public function existsReturnsFalseIfPersistenceIdentifierIsExtensionLocationAndFileNotExistsAndFileHasYamlExtension(): void
383 {
384 $mockFormPersistenceManager = $this->getAccessibleMock(FormPersistenceManager::class, [
385 'dummy'
386 ], [], '', false);
387
388 $input = 'EXT:form/Tests/Unit/Mvc/Persistence/Fixtures/_BlankForm.yaml';
389 $this->assertFalse($mockFormPersistenceManager->_call('exists', $input));
390 }
391
392 /**
393 * @test
394 */
395 public function existsReturnsTrueIfPersistenceIdentifierIsStorageLocationAndFileExistsAndFileHasYamlExtension(): void
396 {
397 $mockFormPersistenceManager = $this->getAccessibleMock(FormPersistenceManager::class, [
398 'getStorageByUid'
399 ], [], '', false);
400
401 $mockStorage = $this->getMockBuilder(ResourceStorage::class)
402 ->disableOriginalConstructor()
403 ->getMock();
404 $mockStorage
405 ->expects($this->any())
406 ->method('hasFile')
407 ->willReturn(true);
408
409 $mockFormPersistenceManager
410 ->expects($this->any())
411 ->method('getStorageByUid')
412 ->willReturn($mockStorage);
413
414 $input = '-1:/user_uploads/_example.form.yaml';
415 $this->assertTrue($mockFormPersistenceManager->_call('exists', $input));
416 }
417
418 /**
419 * @test
420 */
421 public function existsReturnsFalseIfPersistenceIdentifierIsStorageLocationAndFileExistsAndFileNoYamlExtension(): void
422 {
423 $mockFormPersistenceManager = $this->getAccessibleMock(FormPersistenceManager::class, [
424 'getStorageByUid'
425 ], [], '', false);
426
427 $mockStorage = $this->getMockBuilder(ResourceStorage::class)
428 ->disableOriginalConstructor()
429 ->getMock();
430 $mockStorage
431 ->expects($this->any())
432 ->method('hasFile')
433 ->willReturn(true);
434
435 $mockFormPersistenceManager
436 ->expects($this->any())
437 ->method('getStorageByUid')
438 ->willReturn($mockStorage);
439
440 $input = '-1:/user_uploads/_example.php';
441 $this->assertFalse($mockFormPersistenceManager->_call('exists', $input));
442 }
443
444 /**
445 * @test
446 */
447 public function existsReturnsFalseIfPersistenceIdentifierIsStorageLocationAndFileNotExistsAndFileHasYamlExtension(): void
448 {
449 $mockFormPersistenceManager = $this->getAccessibleMock(FormPersistenceManager::class, [
450 'getStorageByUid'
451 ], [], '', false);
452
453 $mockStorage = $this->getMockBuilder(ResourceStorage::class)
454 ->disableOriginalConstructor()
455 ->getMock();
456 $mockStorage
457 ->expects($this->any())
458 ->method('hasFile')
459 ->willReturn(false);
460
461 $mockFormPersistenceManager
462 ->expects($this->any())
463 ->method('getStorageByUid')
464 ->willReturn($mockStorage);
465
466 $input = '-1:/user_uploads/_example.yaml';
467 $this->assertFalse($mockFormPersistenceManager->_call('exists', $input));
468 }
469
470 /**
471 * @test
472 */
473 public function getUniquePersistenceIdentifierAppendNumberIfPersistenceIdentifierExists(): void
474 {
475 $mockFormPersistenceManager = $this->getAccessibleMock(FormPersistenceManager::class, [
476 'exists'
477 ], [], '', false);
478
479 $mockFormPersistenceManager
480 ->expects($this->at(0))
481 ->method('exists')
482 ->willReturn(true);
483
484 $mockFormPersistenceManager
485 ->expects($this->at(1))
486 ->method('exists')
487 ->willReturn(true);
488
489 $mockFormPersistenceManager
490 ->expects($this->at(2))
491 ->method('exists')
492 ->willReturn(false);
493
494 $input = 'example';
495 $expected = '-1:/user_uploads/example_2.form.yaml';
496 $this->assertSame($expected, $mockFormPersistenceManager->_call('getUniquePersistenceIdentifier', $input, '-1:/user_uploads/'));
497 }
498
499 /**
500 * @test
501 */
502 public function getUniquePersistenceIdentifierAppendTimestampIfPersistenceIdentifierExists(): void
503 {
504 $mockFormPersistenceManager = $this->getAccessibleMock(FormPersistenceManager::class, [
505 'exists'
506 ], [], '', false);
507
508 for ($attempts = 0; $attempts <= 99; $attempts++) {
509 $mockFormPersistenceManager
510 ->expects($this->at($attempts))
511 ->method('exists')
512 ->willReturn(true);
513 }
514
515 $mockFormPersistenceManager
516 ->expects($this->at(100))
517 ->method('exists')
518 ->willReturn(false);
519
520 $input = 'example';
521 $expected = '#^-1:/user_uploads/example_([0-9]{10}).form.yaml$#';
522
523 $returnValue = $mockFormPersistenceManager->_call('getUniquePersistenceIdentifier', $input, '-1:/user_uploads/');
524 $this->assertEquals(1, preg_match($expected, $returnValue));
525 }
526
527 /**
528 * @test
529 */
530 public function getUniqueIdentifierThrowsExceptionIfIdentifierExists(): void
531 {
532 $this->expectException(NoUniqueIdentifierException::class);
533 $this->expectExceptionCode(1477688567);
534
535 $mockFormPersistenceManager = $this->getAccessibleMock(FormPersistenceManager::class, [
536 'checkForDuplicateIdentifier'
537 ], [], '', false);
538
539 $mockFormPersistenceManager
540 ->expects($this->any())
541 ->method('checkForDuplicateIdentifier')
542 ->willReturn(true);
543
544 $input = 'example';
545 $mockFormPersistenceManager->_call('getUniqueIdentifier', $input);
546 }
547
548 /**
549 * @test
550 */
551 public function getUniqueIdentifierAppendTimestampIfIdentifierExists(): void
552 {
553 $mockFormPersistenceManager = $this->getAccessibleMock(FormPersistenceManager::class, [
554 'checkForDuplicateIdentifier'
555 ], [], '', false);
556
557 for ($attempts = 0; $attempts <= 99; $attempts++) {
558 $mockFormPersistenceManager
559 ->expects($this->at($attempts))
560 ->method('checkForDuplicateIdentifier')
561 ->willReturn(true);
562 }
563
564 $mockFormPersistenceManager
565 ->expects($this->at(100))
566 ->method('checkForDuplicateIdentifier')
567 ->willReturn(false);
568
569 $input = 'example';
570 $expected = '#^example_([0-9]{10})$#';
571
572 $returnValue = $mockFormPersistenceManager->_call('getUniqueIdentifier', $input);
573 $this->assertEquals(1, preg_match($expected, $returnValue));
574 }
575
576 /**
577 * @test
578 */
579 public function checkForDuplicateIdentifierReturnsTrueIfIdentifierIsUsed(): void
580 {
581 $mockFormPersistenceManager = $this->getAccessibleMock(FormPersistenceManager::class, [
582 'listForms'
583 ], [], '', false);
584
585 $mockFormPersistenceManager
586 ->expects($this->at(0))
587 ->method('listForms')
588 ->willReturn([
589 0 => [
590 'identifier' => 'example',
591 ],
592 ]);
593
594 $input = 'example';
595 $this->assertTrue($mockFormPersistenceManager->_call('checkForDuplicateIdentifier', $input));
596 }
597
598 /**
599 * @test
600 */
601 public function checkForDuplicateIdentifierReturnsFalseIfIdentifierIsUsed(): void
602 {
603 $mockFormPersistenceManager = $this->getAccessibleMock(FormPersistenceManager::class, [
604 'listForms'
605 ], [], '', false);
606
607 $mockFormPersistenceManager
608 ->expects($this->at(0))
609 ->method('listForms')
610 ->willReturn([
611 0 => [
612 'identifier' => 'example',
613 ],
614 ]);
615
616 $input = 'other-example';
617 $this->assertFalse($mockFormPersistenceManager->_call('checkForDuplicateIdentifier', $input));
618 }
619
620 /**
621 * @test
622 */
623 public function retrieveFileByPersistenceIdentifierThrowsExceptionIfReadFromStorageIsNotAllowed(): void
624 {
625 $this->expectException(PersistenceManagerException::class);
626 $this->expectExceptionCode(1471630578);
627
628 $mockFormPersistenceManager = $this->getAccessibleMock(FormPersistenceManager::class, [
629 'dummy',
630 ], [], '', false);
631
632 $storage = $this->getMockBuilder(ResourceStorage::class)
633 ->disableOriginalConstructor()
634 ->getMock();
635
636 $storage
637 ->expects($this->any())
638 ->method('checkFileActionPermission')
639 ->willReturn(false);
640
641 $file = new File(['name' => 'foo', 'identifier' => '', 'mime_type' => ''], $storage);
642
643 $resourceFactory = $this->getMockBuilder(ResourceFactory::class)
644 ->disableOriginalConstructor()
645 ->getMock();
646
647 $resourceFactory
648 ->expects($this->any())
649 ->method('retrieveFileOrFolderObject')
650 ->willReturn($file);
651
652 $mockFormPersistenceManager->_set('resourceFactory', $resourceFactory);
653
654 $input = '-1:/user_uploads/example.yaml';
655 $mockFormPersistenceManager->_call('retrieveFileByPersistenceIdentifier', $input);
656 }
657
658 /**
659 * @test
660 */
661 public function getOrCreateFileThrowsExceptionIfFolderNotExistsInStorage(): void
662 {
663 $this->expectException(PersistenceManagerException::class);
664 $this->expectExceptionCode(1471630579);
665
666 $mockFormPersistenceManager = $this->getAccessibleMock(FormPersistenceManager::class, [
667 'getStorageByUid',
668 ], [], '', false);
669
670 $mockStorage = $this->getMockBuilder(ResourceStorage::class)
671 ->disableOriginalConstructor()
672 ->getMock();
673
674 $mockStorage
675 ->expects($this->any())
676 ->method('hasFolder')
677 ->willReturn(false);
678
679 $mockFormPersistenceManager
680 ->expects($this->any())
681 ->method('getStorageByUid')
682 ->willReturn($mockStorage);
683
684 $input = '-1:/user_uploads/example.yaml';
685 $mockFormPersistenceManager->_call('getOrCreateFile', $input);
686 }
687
688 /**
689 * @test
690 */
691 public function getOrCreateFileThrowsExceptionIfWriteToStorageIsNotAllowed(): void
692 {
693 $this->expectException(PersistenceManagerException::class);
694 $this->expectExceptionCode(1471630580);
695
696 $mockFormPersistenceManager = $this->getAccessibleMock(FormPersistenceManager::class, [
697 'getStorageByUid',
698 ], [], '', false);
699
700 $mockStorage = $this->getMockBuilder(ResourceStorage::class)
701 ->disableOriginalConstructor()
702 ->getMock();
703
704 $mockStorage
705 ->expects($this->any())
706 ->method('hasFolder')
707 ->willReturn(true);
708
709 $mockStorage
710 ->expects($this->any())
711 ->method('checkFileActionPermission')
712 ->willReturn(false);
713
714 $file = new File(['name' => 'foo', 'identifier' => '', 'mime_type' => ''], $mockStorage);
715 $mockStorage
716 ->expects($this->any())
717 ->method('getFile')
718 ->willReturn($file);
719
720 $mockFormPersistenceManager
721 ->expects($this->any())
722 ->method('getStorageByUid')
723 ->willReturn($mockStorage);
724
725 $input = '-1:/user_uploads/example.yaml';
726 $mockFormPersistenceManager->_call('getOrCreateFile', $input);
727 }
728
729 /**
730 * @test
731 */
732 public function getStorageByUidThrowsExceptionIfStorageNotExists(): void
733 {
734 $this->expectException(PersistenceManagerException::class);
735 $this->expectExceptionCode(1471630581);
736
737 $mockFormPersistenceManager = $this->getAccessibleMock(FormPersistenceManager::class, [
738 'dummy',
739 ], [], '', false);
740
741 $mockStorageRepository = $this->getMockBuilder(StorageRepository::class)
742 ->disableOriginalConstructor()
743 ->getMock();
744
745 $mockStorageRepository
746 ->expects($this->any())
747 ->method('findByUid')
748 ->willReturn(null);
749
750 $mockFormPersistenceManager->_set('storageRepository', $mockStorageRepository);
751 $mockFormPersistenceManager->_call('getStorageByUid', -1);
752 }
753
754 /**
755 * @test
756 */
757 public function getStorageByUidThrowsExceptionIfStorageIsNotBrowsable(): void
758 {
759 $this->expectException(PersistenceManagerException::class);
760 $this->expectExceptionCode(1471630581);
761
762 $mockFormPersistenceManager = $this->getAccessibleMock(FormPersistenceManager::class, [
763 'dummy',
764 ], [], '', false);
765
766 $mockStorageRepository = $this->getMockBuilder(StorageRepository::class)
767 ->disableOriginalConstructor()
768 ->getMock();
769
770 $mockStorage = $this->getMockBuilder(ResourceStorage::class)
771 ->disableOriginalConstructor()
772 ->getMock();
773
774 $mockStorage
775 ->expects($this->any())
776 ->method('isBrowsable')
777 ->willReturn(false);
778
779 $mockStorageRepository
780 ->expects($this->any())
781 ->method('findByUid')
782 ->willReturn($mockStorage);
783
784 $mockFormPersistenceManager->_set('storageRepository', $mockStorageRepository);
785 $mockFormPersistenceManager->_call('getStorageByUid', -1);
786 }
787 }