‪TYPO3CMS  10.4
FormPersistenceManagerTest.php
Go to the documentation of this file.
1 <?php
2 
3 declare(strict_types=1);
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 
19 
29 use TYPO3\TestingFramework\Core\Unit\UnitTestCase;
30 
34 class ‪FormPersistenceManagerTest extends UnitTestCase
35 {
40  {
41  $this->expectException(PersistenceManagerException::class);
42  $this->expectExceptionCode(1477679819);
43 
44  $mockFormPersistenceManager = $this->getAccessibleMock(FormPersistenceManager::class, [
45  'dummy'
46  ]);
47 
48  $runtimeCache= $this->getMockBuilder(VariableFrontend::class)
49  ->setMethods(['get', 'set'])
50  ->disableOriginalConstructor()
51  ->getMock();
52 
53  $runtimeCache
54  ->expects(self::any())
55  ->method('get')
56  ->willReturn(false);
57 
58  $mockFormPersistenceManager->_set('runtimeCache', $runtimeCache);
59 
60  $input = '-1:/user_uploads/_example.php';
61  $mockFormPersistenceManager->_call('load', $input);
62  }
63 
68  {
69  $this->expectException(PersistenceManagerException::class);
70  $this->expectExceptionCode(1484071985);
71 
72  $mockFormPersistenceManager = $this->getAccessibleMock(FormPersistenceManager::class, [
73  'dummy'
74  ]);
75 
76  $runtimeCache= $this->getMockBuilder(VariableFrontend::class)
77  ->setMethods(['get', 'set'])
78  ->disableOriginalConstructor()
79  ->getMock();
80 
81  $runtimeCache
82  ->expects(self::any())
83  ->method('get')
84  ->willReturn(false);
85 
86  $mockFormPersistenceManager->_set('runtimeCache', $runtimeCache);
87 
88  $mockFormPersistenceManager->_set('formSettings', [
89  'persistenceManager' => [
90  'allowedExtensionPaths' => [],
91  ],
92  ]);
93 
94  $input = 'EXT:form/Resources/Forms/_example.form.yaml';
95  $mockFormPersistenceManager->_call('load', $input);
96  }
97 
102  {
103  $this->expectException(PersistenceManagerException::class);
104  $this->expectExceptionCode(1477679820);
105 
106  $mockFormPersistenceManager = $this->getAccessibleMock(FormPersistenceManager::class, [
107  'dummy'
108  ]);
109 
110  $input = '-1:/user_uploads/_example.php';
111  $mockFormPersistenceManager->_call('save', $input, []);
112  }
113 
118  {
119  $this->expectException(PersistenceManagerException::class);
120  $this->expectExceptionCode(1477680881);
121 
122  $mockFormPersistenceManager = $this->getAccessibleMock(FormPersistenceManager::class, [
123  'dummy'
124  ]);
125 
126  $mockFormPersistenceManager->_set('formSettings', [
127  'persistenceManager' => [
128  'allowSaveToExtensionPaths' => false,
129  ],
130  ]);
131 
132  $input = 'EXT:form/Resources/Forms/_example.form.yaml';
133  $mockFormPersistenceManager->_call('save', $input, []);
134  }
135 
140  {
141  $this->expectException(PersistenceManagerException::class);
142  $this->expectExceptionCode(1484073571);
143 
144  $mockFormPersistenceManager = $this->getAccessibleMock(FormPersistenceManager::class, [
145  'dummy'
146  ]);
147 
148  $runtimeCache= $this->getMockBuilder(VariableFrontend::class)
149  ->setMethods(['get', 'set'])
150  ->disableOriginalConstructor()
151  ->getMock();
152 
153  $runtimeCache
154  ->expects(self::any())
155  ->method('get')
156  ->willReturn(false);
157 
158  $mockFormPersistenceManager->_set('runtimeCache', $runtimeCache);
159 
160  $mockFormPersistenceManager->_set('formSettings', [
161  'persistenceManager' => [
162  'allowSaveToExtensionPaths' => true,
163  'allowedExtensionPaths' => [],
164  ],
165  ]);
166 
167  $input = 'EXT:form/Resources/Forms/_example.form.yaml';
168  $mockFormPersistenceManager->_call('save', $input, []);
169  }
170 
175  {
176  $this->expectException(PersistenceManagerException::class);
177  $this->expectExceptionCode(1472239534);
178 
179  $mockFormPersistenceManager = $this->getAccessibleMock(FormPersistenceManager::class, [
180  'dummy'
181  ]);
182 
183  $input = '-1:/user_uploads/_example.php';
184  $mockFormPersistenceManager->_call('delete', $input);
185  }
186 
191  {
192  $this->expectException(PersistenceManagerException::class);
193  $this->expectExceptionCode(1472239535);
194 
195  $mockFormPersistenceManager = $this->getAccessibleMock(FormPersistenceManager::class, [
196  'exists'
197  ]);
198 
199  $mockFormPersistenceManager
200  ->expects(self::any())
201  ->method('exists')
202  ->willReturn(false);
203 
204  $input = '-1:/user_uploads/_example.form.yaml';
205  $mockFormPersistenceManager->_call('delete', $input);
206  }
207 
212  {
213  $this->expectException(PersistenceManagerException::class);
214  $this->expectExceptionCode(1472239536);
215 
216  $mockFormPersistenceManager = $this->getAccessibleMock(FormPersistenceManager::class, [
217  'exists'
218  ]);
219 
220  $mockFormPersistenceManager
221  ->expects(self::any())
222  ->method('exists')
223  ->willReturn(true);
224 
225  $mockFormPersistenceManager->_set('formSettings', [
226  'persistenceManager' => [
227  'allowDeleteFromExtensionPaths' => false,
228  ],
229  ]);
230 
231  $input = 'EXT:form/Resources/Forms/_example.form.yaml';
232  $mockFormPersistenceManager->_call('delete', $input);
233  }
234 
239  {
240  $this->expectException(PersistenceManagerException::class);
241  $this->expectExceptionCode(1484073878);
242 
243  $mockFormPersistenceManager = $this->getAccessibleMock(FormPersistenceManager::class, [
244  'exists'
245  ]);
246 
247  $runtimeCache= $this->getMockBuilder(VariableFrontend::class)
248  ->setMethods(['get', 'set'])
249  ->disableOriginalConstructor()
250  ->getMock();
251 
252  $runtimeCache
253  ->expects(self::any())
254  ->method('get')
255  ->willReturn(false);
256 
257  $mockFormPersistenceManager->_set('runtimeCache', $runtimeCache);
258 
259  $mockFormPersistenceManager
260  ->expects(self::any())
261  ->method('exists')
262  ->willReturn(true);
263 
264  $mockFormPersistenceManager->_set('formSettings', [
265  'persistenceManager' => [
266  'allowDeleteFromExtensionPaths' => true,
267  'allowedExtensionPaths' => [],
268  ],
269  ]);
270 
271  $input = 'EXT:form/Resources/Forms/_example.form.yaml';
272  $mockFormPersistenceManager->_call('delete', $input);
273  }
274 
279  {
280  $this->expectException(PersistenceManagerException::class);
281  $this->expectExceptionCode(1472239516);
282 
283  $mockFormPersistenceManager = $this->getAccessibleMock(FormPersistenceManager::class, [
284  'getStorageByUid',
285  'exists'
286  ]);
287 
288  $mockStorage = $this->getMockBuilder(ResourceStorage::class)
289  ->disableOriginalConstructor()
290  ->getMock();
291 
292  $mockStorage
293  ->expects(self::any())
294  ->method('checkFileActionPermission')
295  ->willReturn(false);
296 
297  $file = new ‪File(['name' => 'foo', 'identifier' => '', 'mime_type' => ''], $mockStorage);
298  $mockStorage
299  ->expects(self::any())
300  ->method('getFile')
301  ->willReturn($file);
302 
303  $mockFormPersistenceManager
304  ->expects(self::any())
305  ->method('getStorageByUid')
306  ->willReturn($mockStorage);
307 
308  $mockFormPersistenceManager
309  ->expects(self::any())
310  ->method('exists')
311  ->willReturn(true);
312 
313  $input = '-1:/user_uploads/_example.form.yaml';
314  $mockFormPersistenceManager->_call('delete', $input);
315  }
316 
321  {
322  $mockFormPersistenceManager = $this->getAccessibleMock(FormPersistenceManager::class, [
323  'dummy'
324  ]);
325 
326  $runtimeCache= $this->getMockBuilder(VariableFrontend::class)
327  ->setMethods(['get', 'set'])
328  ->disableOriginalConstructor()
329  ->getMock();
330 
331  $runtimeCache
332  ->expects(self::any())
333  ->method('get')
334  ->willReturn(false);
335 
336  $mockFormPersistenceManager->_set('runtimeCache', $runtimeCache);
337 
338  $mockFormPersistenceManager->_set('formSettings', [
339  'persistenceManager' => [
340  'allowedExtensionPaths' => [
341  'EXT:form/Tests/Unit/Mvc/Persistence/Fixtures/'
342  ],
343  ],
344  ]);
345 
346  $input = 'EXT:form/Tests/Unit/Mvc/Persistence/Fixtures/BlankForm.form.yaml';
347  self::assertTrue($mockFormPersistenceManager->_call('exists', $input));
348  }
349 
354  {
355  $mockFormPersistenceManager = $this->getAccessibleMock(FormPersistenceManager::class, [
356  'dummy'
357  ]);
358 
359  $input = 'EXT:form/Tests/Unit/Mvc/Persistence/Fixtures/BlankForm.txt';
360  self::assertFalse($mockFormPersistenceManager->_call('exists', $input));
361  }
362 
367  {
368  $mockFormPersistenceManager = $this->getAccessibleMock(FormPersistenceManager::class, [
369  'dummy'
370  ]);
371 
372  $mockFormPersistenceManager->_set('formSettings', [
373  'persistenceManager' => [
374  'allowedExtensionPaths' => [],
375  ],
376  ]);
377 
378  $input = 'EXT:form/Tests/Unit/Mvc/Persistence/Fixtures/BlankForm.yaml';
379  self::assertFalse($mockFormPersistenceManager->_call('exists', $input));
380  }
381 
386  {
387  $mockFormPersistenceManager = $this->getAccessibleMock(FormPersistenceManager::class, [
388  'dummy'
389  ]);
390 
391  $input = 'EXT:form/Tests/Unit/Mvc/Persistence/Fixtures/_BlankForm.yaml';
392  self::assertFalse($mockFormPersistenceManager->_call('exists', $input));
393  }
394 
399  {
400  $mockFormPersistenceManager = $this->getAccessibleMock(FormPersistenceManager::class, [
401  'getStorageByUid'
402  ]);
403 
404  $mockStorage = $this->getMockBuilder(ResourceStorage::class)
405  ->disableOriginalConstructor()
406  ->getMock();
407  $mockStorage
408  ->expects(self::any())
409  ->method('hasFile')
410  ->willReturn(true);
411 
412  $mockFormPersistenceManager
413  ->expects(self::any())
414  ->method('getStorageByUid')
415  ->willReturn($mockStorage);
416 
417  $input = '-1:/user_uploads/_example.form.yaml';
418  self::assertTrue($mockFormPersistenceManager->_call('exists', $input));
419  }
420 
425  {
426  $mockFormPersistenceManager = $this->getAccessibleMock(FormPersistenceManager::class, [
427  'getStorageByUid'
428  ]);
429 
430  $mockStorage = $this->getMockBuilder(ResourceStorage::class)
431  ->disableOriginalConstructor()
432  ->getMock();
433  $mockStorage
434  ->expects(self::any())
435  ->method('hasFile')
436  ->willReturn(true);
437 
438  $mockFormPersistenceManager
439  ->expects(self::any())
440  ->method('getStorageByUid')
441  ->willReturn($mockStorage);
442 
443  $input = '-1:/user_uploads/_example.php';
444  self::assertFalse($mockFormPersistenceManager->_call('exists', $input));
445  }
446 
451  {
452  $mockFormPersistenceManager = $this->getAccessibleMock(FormPersistenceManager::class, [
453  'getStorageByUid'
454  ]);
455 
456  $mockStorage = $this->getMockBuilder(ResourceStorage::class)
457  ->disableOriginalConstructor()
458  ->getMock();
459  $mockStorage
460  ->expects(self::any())
461  ->method('hasFile')
462  ->willReturn(false);
463 
464  $mockFormPersistenceManager
465  ->expects(self::any())
466  ->method('getStorageByUid')
467  ->willReturn($mockStorage);
468 
469  $input = '-1:/user_uploads/_example.yaml';
470  self::assertFalse($mockFormPersistenceManager->_call('exists', $input));
471  }
472 
477  {
478  $mockFormPersistenceManager = $this->getAccessibleMock(FormPersistenceManager::class, [
479  'exists'
480  ]);
481 
482  $mockFormPersistenceManager
483  ->expects(self::exactly(3))
484  ->method('exists')
485  ->will(self::onConsecutiveCalls(
486  self::returnValue(true),
487  self::returnValue(true),
488  self::returnValue(false)
489  ));
490 
491  $input = 'example';
492  $expected = '-1:/user_uploads/example_2.form.yaml';
493  $result = $mockFormPersistenceManager->_call('getUniquePersistenceIdentifier', $input, '-1:/user_uploads/');
494  self::assertSame($expected, $result);
495  }
496 
501  {
502  $mockFormPersistenceManager = $this->getAccessibleMock(FormPersistenceManager::class, [
503  'exists'
504  ]);
505 
506  $mockFormPersistenceManager
507  ->expects(self::exactly(101))
508  ->method('exists')
509  ->will(self::onConsecutiveCalls(
510  ...$this->‪returnTrue100Times()
511  ));
512 
513  $input = 'example';
514  $expected = '#^-1:/user_uploads/example_([0-9]{10}).form.yaml$#';
515 
516  $returnValue = $mockFormPersistenceManager->_call('getUniquePersistenceIdentifier', $input, '-1:/user_uploads/');
517  self::assertEquals(1, preg_match($expected, $returnValue));
518  }
519 
524  private function ‪returnTrue100Times(): array
525  {
526  $returnValues = [];
527  $returnValues = array_pad($returnValues, 100, self::returnValue(true));
528  $returnValues[] = self::returnValue(false);
529  return $returnValues;
530  }
531 
536  {
537  $this->expectException(NoUniqueIdentifierException::class);
538  $this->expectExceptionCode(1477688567);
539 
540  $mockFormPersistenceManager = $this->getAccessibleMock(FormPersistenceManager::class, [
541  'checkForDuplicateIdentifier'
542  ]);
543 
544  $mockFormPersistenceManager
545  ->expects(self::any())
546  ->method('checkForDuplicateIdentifier')
547  ->willReturn(true);
548 
549  $input = 'example';
550  $mockFormPersistenceManager->_call('getUniqueIdentifier', $input);
551  }
552 
557  {
558  $mockFormPersistenceManager = $this->getAccessibleMock(FormPersistenceManager::class, [
559  'checkForDuplicateIdentifier'
560  ]);
561 
562  $mockFormPersistenceManager
563  ->expects(self::exactly(101))
564  ->method('checkForDuplicateIdentifier')
565  ->will(self::onConsecutiveCalls(
566  ...$this->‪returnTrue100Times()
567  ));
568 
569  $input = 'example';
570  $expected = '#^example_([0-9]{10})$#';
571 
572  $returnValue = $mockFormPersistenceManager->_call('getUniqueIdentifier', $input);
573  self::assertEquals(1, preg_match($expected, $returnValue));
574  }
575 
580  {
581  $mockFormPersistenceManager = $this->getAccessibleMock(FormPersistenceManager::class, [
582  'listForms'
583  ]);
584 
585  $mockFormPersistenceManager
586  ->expects(self::once())
587  ->method('listForms')
588  ->willReturn([
589  0 => [
590  'identifier' => 'example',
591  ],
592  ]);
593 
594  $input = 'example';
595  self::assertTrue($mockFormPersistenceManager->_call('checkForDuplicateIdentifier', $input));
596  }
597 
602  {
603  $mockFormPersistenceManager = $this->getAccessibleMock(FormPersistenceManager::class, [
604  'listForms'
605  ]);
606 
607  $mockFormPersistenceManager
608  ->expects(self::once())
609  ->method('listForms')
610  ->willReturn([
611  0 => [
612  'identifier' => 'example',
613  ],
614  ]);
615 
616  $input = 'other-example';
617  self::assertFalse($mockFormPersistenceManager->_call('checkForDuplicateIdentifier', $input));
618  }
619 
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(self::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(self::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 
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(self::any())
676  ->method('hasFolder')
677  ->willReturn(false);
678 
679  $mockFormPersistenceManager
680  ->expects(self::any())
681  ->method('getStorageByUid')
682  ->willReturn($mockStorage);
683 
684  $input = '-1:/user_uploads/example.yaml';
685  $mockFormPersistenceManager->_call('getOrCreateFile', $input);
686  }
687 
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(self::any())
706  ->method('hasFolder')
707  ->willReturn(true);
708 
709  $mockStorage
710  ->expects(self::any())
711  ->method('checkFileActionPermission')
712  ->willReturn(false);
713 
714  $file = new ‪File(['name' => 'foo', 'identifier' => '', 'mime_type' => ''], $mockStorage);
715  $mockStorage
716  ->expects(self::any())
717  ->method('getFile')
718  ->willReturn($file);
719 
720  $mockFormPersistenceManager
721  ->expects(self::any())
722  ->method('getStorageByUid')
723  ->willReturn($mockStorage);
724 
725  $input = '-1:/user_uploads/example.yaml';
726  $mockFormPersistenceManager->_call('getOrCreateFile', $input);
727  }
728 
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(self::any())
747  ->method('findByUid')
748  ->willReturn(null);
749 
750  $mockFormPersistenceManager->_set('storageRepository', $mockStorageRepository);
751  $mockFormPersistenceManager->_call('getStorageByUid', -1);
752  }
753 
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(self::any())
776  ->method('isBrowsable')
777  ->willReturn(false);
778 
779  $mockStorageRepository
780  ->expects(self::any())
781  ->method('findByUid')
782  ->willReturn($mockStorage);
783 
784  $mockFormPersistenceManager->_set('storageRepository', $mockStorageRepository);
785  $mockFormPersistenceManager->_call('getStorageByUid', -1);
786  }
787 
789  {
790  return [
791  [
792  'persistencePath' => '',
793  'allowedExtensionPaths' => [],
794  'allowedFileMounts' => [],
795  'expected' => false,
796  ],
797  [
798  'persistencePath' => '-1:/user_uploads',
799  'allowedExtensionPaths' => [],
800  'allowedFileMounts' => [],
801  'expected' => false,
802  ],
803  [
804  'persistencePath' => 'EXT:form/Tests/Unit/Mvc/Persistence/Fixtures',
805  'allowedExtensionPaths' => [],
806  'allowedFileMounts' => [],
807  'expected' => false,
808  ],
809  [
810  'persistencePath' => '-1:/user_uploads/',
811  'allowedExtensionPaths' => [],
812  'allowedFileMounts' => [],
813  'expected' => false,
814  ],
815  [
816  'persistencePath' => 'EXT:form/Tests/Unit/Mvc/Persistence/Fixtures/',
817  'allowedExtensionPaths' => [],
818  'allowedFileMounts' => [],
819  'expected' => false,
820  ],
821  [
822  'persistencePath' => '-1:/user_uploads/example.form.yaml',
823  'allowedExtensionPaths' => [],
824  'allowedFileMounts' => [],
825  'expected' => false,
826  ],
827  [
828  'persistencePath' => 'EXT:form/Tests/Unit/Mvc/Persistence/Fixtures/BlankForm.form.yaml',
829  'allowedExtensionPaths' => [],
830  'allowedFileMounts' => [],
831  'expected' => false,
832  ],
833 
834  [
835  'persistencePath' => '-1:/user_uploads/',
836  'allowedExtensionPaths' => [],
837  'allowedFileMounts' => ['-1:/some_path/'],
838  'expected' => false,
839  ],
840  [
841  'persistencePath' => '-1:/user_uploads/',
842  'allowedExtensionPaths' => [],
843  'allowedFileMounts' => ['-1:/user_uploads/'],
844  'expected' => true,
845  ],
846  [
847  'persistencePath' => '-1:/user_uploads',
848  'allowedExtensionPaths' => [],
849  'allowedFileMounts' => ['-1:/user_uploads/'],
850  'expected' => true,
851  ],
852  [
853  'persistencePath' => '-1:/user_uploads/',
854  'allowedExtensionPaths' => [],
855  'allowedFileMounts' => ['-1:/user_uploads'],
856  'expected' => true,
857  ],
858 
859  [
860  'persistencePath' => 'EXT:form/Tests/Unit/Mvc/Persistence/Fixtures/',
861  'allowedExtensionPaths' => ['EXT:some_extension/Tests/Unit/Mvc/Persistence/Fixtures/'],
862  'allowedFileMounts' => [],
863  'expected' => false,
864  ],
865  [
866  'persistencePath' => 'EXT:form/Tests/Unit/Mvc/Persistence/Fixtures/',
867  'allowedExtensionPaths' => ['EXT:form/Tests/Unit/Mvc/Persistence/Fixtures/'],
868  'allowedFileMounts' => [],
869  'expected' => true,
870  ],
871  [
872  'persistencePath' => 'EXT:form/Tests/Unit/Mvc/Persistence/Fixtures',
873  'allowedExtensionPaths' => ['EXT:form/Tests/Unit/Mvc/Persistence/Fixtures/'],
874  'allowedFileMounts' => [],
875  'expected' => true,
876  ],
877  [
878  'persistencePath' => 'EXT:form/Tests/Unit/Mvc/Persistence/Fixtures/',
879  'allowedExtensionPaths' => ['EXT:form/Tests/Unit/Mvc/Persistence/Fixtures'],
880  'allowedFileMounts' => [],
881  'expected' => true,
882  ],
883 
884  [
885  'persistencePath' => '-1:/user_uploads/example.yaml',
886  'allowedExtensionPaths' => [],
887  'allowedFileMounts' => ['-1:/some_path/'],
888  'expected' => false,
889  ],
890  [
891  'persistencePath' => '-1:/user_uploads/example.form.yaml',
892  'allowedExtensionPaths' => [],
893  'allowedFileMounts' => ['-1:/some_path/'],
894  'expected' => false,
895  ],
896  [
897  'persistencePath' => '-1:/user_uploads/example.yaml',
898  'allowedExtensionPaths' => [],
899  'allowedFileMounts' => ['-1:/user_uploads/'],
900  'expected' => false,
901  ],
902  [
903  'persistencePath' => '-1:/user_uploads/example.yaml',
904  'allowedExtensionPaths' => [],
905  'allowedFileMounts' => ['-1:/user_uploads'],
906  'expected' => false,
907  ],
908  [
909  'persistencePath' => '-1:/user_uploads/example.form.yaml',
910  'allowedExtensionPaths' => [],
911  'allowedFileMounts' => ['-1:/user_uploads/'],
912  'expected' => true,
913  ],
914  [
915  'persistencePath' => '-1:/user_uploads/example.form.yaml',
916  'allowedExtensionPaths' => [],
917  'allowedFileMounts' => ['-1:/user_uploads'],
918  'expected' => true,
919  ],
920 
921  [
922  'persistencePath' => 'EXT:form/Tests/Unit/Mvc/Persistence/Fixtures/BlankForm.txt',
923  'allowedExtensionPaths' => ['EXT:some_extension/Tests/Unit/Mvc/Persistence/Fixtures/'],
924  'allowedFileMounts' => [],
925  'expected' => false,
926  ],
927  [
928  'persistencePath' => 'EXT:form/Tests/Unit/Mvc/Persistence/Fixtures/BlankForm.form.yaml',
929  'allowedExtensionPaths' => ['EXT:some_extension/Tests/Unit/Mvc/Persistence/Fixtures/'],
930  'allowedFileMounts' => [],
931  'expected' => false,
932  ],
933  [
934  'persistencePath' => 'EXT:form/Tests/Unit/Mvc/Persistence/Fixtures/BlankForm.txt',
935  'allowedExtensionPaths' => ['EXT:form/Tests/Unit/Mvc/Persistence/Fixtures/'],
936  'allowedFileMounts' => [],
937  'expected' => false,
938  ],
939  [
940  'persistencePath' => 'EXT:form/Tests/Unit/Mvc/Persistence/Fixtures/BlankForm.txt',
941  'allowedExtensionPaths' => ['EXT:form/Tests/Unit/Mvc/Persistence/Fixtures'],
942  'allowedFileMounts' => [],
943  'expected' => false,
944  ],
945  [
946  'persistencePath' => 'EXT:form/Tests/Unit/Mvc/Persistence/Fixtures/BlankForm.form.yaml',
947  'allowedExtensionPaths' => ['EXT:form/Tests/Unit/Mvc/Persistence/Fixtures/'],
948  'allowedFileMounts' => [],
949  'expected' => true,
950  ],
951  [
952  'persistencePath' => 'EXT:form/Tests/Unit/Mvc/Persistence/Fixtures/BlankForm.form.yaml',
953  'allowedExtensionPaths' => ['EXT:form/Tests/Unit/Mvc/Persistence/Fixtures'],
954  'allowedFileMounts' => [],
955  'expected' => true,
956  ],
957  ];
958  }
959 
964  public function ‪isAllowedPersistencePathReturnsPropperValues(string $persistencePath, array $allowedExtensionPaths, array $allowedFileMounts, $expected): void
965  {
966  $formPersistenceManagerMock = $this->getAccessibleMock(FormPersistenceManager::class, [
967  'getStorageByUid',
968  ]);
969 
970  $runtimeCacheMock = $this->getMockBuilder(VariableFrontend::class)
971  ->setMethods(['get', 'set'])
972  ->disableOriginalConstructor()
973  ->getMock();
974 
975  $runtimeCacheMock
976  ->expects(self::any())
977  ->method('get')
978  ->willReturn(false);
979 
980  $storageMock = $this->getMockBuilder(ResourceStorage::class)
981  ->disableOriginalConstructor()
982  ->getMock();
983 
984  $storageMock
985  ->expects(self::any())
986  ->method('getRootLevelFolder')
987  ->willReturn(new ‪Folder($storageMock, '', ''));
988 
989  $storageMock
990  ->expects(self::any())
991  ->method('getFileMounts')
992  ->willReturn([]);
993 
994  $storageMock
995  ->expects(self::any())
996  ->method('getFolder')
997  ->willReturn(new ‪Folder($storageMock, '', ''));
998 
999  $formPersistenceManagerMock
1000  ->expects(self::any())
1001  ->method('getStorageByUid')
1002  ->willReturn($storageMock);
1003 
1004  $formPersistenceManagerMock->_set('runtimeCache', $runtimeCacheMock);
1005  $formPersistenceManagerMock->_set('formSettings', [
1006  'persistenceManager' => [
1007  'allowedExtensionPaths' => $allowedExtensionPaths,
1008  'allowedFileMounts' => $allowedFileMounts,
1009  ],
1010  ]);
1011 
1012  self::assertEquals($expected, $formPersistenceManagerMock->_call('isAllowedPersistencePath', $persistencePath));
1013  }
1014 }
‪TYPO3\CMS\Form\Tests\Unit\Mvc\Persistence\FormPersistenceManagerTest\loadThrowsExceptionIfPersistenceIdentifierHasNoYamlExtension
‪loadThrowsExceptionIfPersistenceIdentifierHasNoYamlExtension()
Definition: FormPersistenceManagerTest.php:39
‪TYPO3\CMS\Form\Tests\Unit\Mvc\Persistence\FormPersistenceManagerTest\getStorageByUidThrowsExceptionIfStorageNotExists
‪getStorageByUidThrowsExceptionIfStorageNotExists()
Definition: FormPersistenceManagerTest.php:732
‪TYPO3\CMS\Form\Tests\Unit\Mvc\Persistence\FormPersistenceManagerTest\checkForDuplicateIdentifierReturnsFalseIfIdentifierIsUsed
‪checkForDuplicateIdentifierReturnsFalseIfIdentifierIsUsed()
Definition: FormPersistenceManagerTest.php:601
‪TYPO3\CMS\Form\Tests\Unit\Mvc\Persistence\FormPersistenceManagerTest\getOrCreateFileThrowsExceptionIfWriteToStorageIsNotAllowed
‪getOrCreateFileThrowsExceptionIfWriteToStorageIsNotAllowed()
Definition: FormPersistenceManagerTest.php:691
‪TYPO3\CMS\Form\Tests\Unit\Mvc\Persistence\FormPersistenceManagerTest\deleteThrowsExceptionIfPersistenceIdentifierIsStorageLocationAndDeleteFromStorageIsNotAllowed
‪deleteThrowsExceptionIfPersistenceIdentifierIsStorageLocationAndDeleteFromStorageIsNotAllowed()
Definition: FormPersistenceManagerTest.php:278
‪TYPO3\CMS\Form\Tests\Unit\Mvc\Persistence\FormPersistenceManagerTest\getUniquePersistenceIdentifierAppendNumberIfPersistenceIdentifierExists
‪getUniquePersistenceIdentifierAppendNumberIfPersistenceIdentifierExists()
Definition: FormPersistenceManagerTest.php:476
‪TYPO3\CMS\Form\Mvc\Persistence\Exception\PersistenceManagerException
Definition: PersistenceManagerException.php:28
‪TYPO3\CMS\Form\Tests\Unit\Mvc\Persistence\FormPersistenceManagerTest\checkForDuplicateIdentifierReturnsTrueIfIdentifierIsUsed
‪checkForDuplicateIdentifierReturnsTrueIfIdentifierIsUsed()
Definition: FormPersistenceManagerTest.php:579
‪TYPO3\CMS\Form\Tests\Unit\Mvc\Persistence\FormPersistenceManagerTest\getStorageByUidThrowsExceptionIfStorageIsNotBrowsable
‪getStorageByUidThrowsExceptionIfStorageIsNotBrowsable()
Definition: FormPersistenceManagerTest.php:757
‪TYPO3\CMS\Form\Tests\Unit\Mvc\Persistence\FormPersistenceManagerTest\deleteThrowsExceptionIfPersistenceIdentifierFileDoesNotExists
‪deleteThrowsExceptionIfPersistenceIdentifierFileDoesNotExists()
Definition: FormPersistenceManagerTest.php:190
‪TYPO3\CMS\Form\Tests\Unit\Mvc\Persistence\FormPersistenceManagerTest\existsReturnsFalseIfPersistenceIdentifierIsExtensionLocationAndFileNotExistsAndFileHasYamlExtension
‪existsReturnsFalseIfPersistenceIdentifierIsExtensionLocationAndFileNotExistsAndFileHasYamlExtension()
Definition: FormPersistenceManagerTest.php:385
‪TYPO3\CMS\Form\Tests\Unit\Mvc\Persistence\FormPersistenceManagerTest\existsReturnsTrueIfPersistenceIdentifierIsExtensionLocationAndFileExistsAndFileHasYamlExtension
‪existsReturnsTrueIfPersistenceIdentifierIsExtensionLocationAndFileExistsAndFileHasYamlExtension()
Definition: FormPersistenceManagerTest.php:320
‪TYPO3\CMS\Form\Tests\Unit\Mvc\Persistence\FormPersistenceManagerTest\isAllowedPersistencePathReturnsPropperValues
‪isAllowedPersistencePathReturnsPropperValues(string $persistencePath, array $allowedExtensionPaths, array $allowedFileMounts, $expected)
Definition: FormPersistenceManagerTest.php:964
‪TYPO3\CMS\Form\Mvc\Persistence\Exception\NoUniqueIdentifierException
Definition: NoUniqueIdentifierException.php:26
‪TYPO3\CMS\Form\Tests\Unit\Mvc\Persistence\FormPersistenceManagerTest\loadThrowsExceptionIfPersistenceIdentifierIsAExtensionLocationWhichIsNotAllowed
‪loadThrowsExceptionIfPersistenceIdentifierIsAExtensionLocationWhichIsNotAllowed()
Definition: FormPersistenceManagerTest.php:67
‪TYPO3\CMS\Form\Tests\Unit\Mvc\Persistence
Definition: FormPersistenceManagerTest.php:18
‪TYPO3\CMS\Form\Tests\Unit\Mvc\Persistence\FormPersistenceManagerTest\returnTrue100Times
‪array returnTrue100Times()
Definition: FormPersistenceManagerTest.php:524
‪TYPO3\CMS\Form\Mvc\Persistence\FormPersistenceManager
Definition: FormPersistenceManager.php:54
‪TYPO3\CMS\Form\Tests\Unit\Mvc\Persistence\FormPersistenceManagerTest\deleteThrowsExceptionIfPersistenceIdentifierHasNoYamlExtension
‪deleteThrowsExceptionIfPersistenceIdentifierHasNoYamlExtension()
Definition: FormPersistenceManagerTest.php:174
‪TYPO3\CMS\Form\Tests\Unit\Mvc\Persistence\FormPersistenceManagerTest\getOrCreateFileThrowsExceptionIfFolderNotExistsInStorage
‪getOrCreateFileThrowsExceptionIfFolderNotExistsInStorage()
Definition: FormPersistenceManagerTest.php:661
‪TYPO3\CMS\Form\Tests\Unit\Mvc\Persistence\FormPersistenceManagerTest\existsReturnsFalseIfPersistenceIdentifierIsStorageLocationAndFileExistsAndFileNoYamlExtension
‪existsReturnsFalseIfPersistenceIdentifierIsStorageLocationAndFileExistsAndFileNoYamlExtension()
Definition: FormPersistenceManagerTest.php:424
‪TYPO3\CMS\Core\Cache\Frontend\VariableFrontend
Definition: VariableFrontend.php:25
‪TYPO3\CMS\Core\Resource\Folder
Definition: Folder.php:37
‪TYPO3\CMS\Core\Resource\ResourceFactory
Definition: ResourceFactory.php:41
‪TYPO3\CMS\Core\Resource\StorageRepository
Definition: StorageRepository.php:31
‪TYPO3\CMS\Core\Resource\File
Definition: File.php:24
‪TYPO3\CMS\Form\Tests\Unit\Mvc\Persistence\FormPersistenceManagerTest\deleteThrowsExceptionIfPersistenceIdentifierIsExtensionLocationWhichIsNotAllowed
‪deleteThrowsExceptionIfPersistenceIdentifierIsExtensionLocationWhichIsNotAllowed()
Definition: FormPersistenceManagerTest.php:238
‪TYPO3\CMS\Form\Tests\Unit\Mvc\Persistence\FormPersistenceManagerTest\existsReturnsFalseIfPersistenceIdentifierIsExtensionLocationAndFileExistsAndFileHasNoYamlExtension
‪existsReturnsFalseIfPersistenceIdentifierIsExtensionLocationAndFileExistsAndFileHasNoYamlExtension()
Definition: FormPersistenceManagerTest.php:353
‪TYPO3\CMS\Form\Tests\Unit\Mvc\Persistence\FormPersistenceManagerTest\existsReturnsFalseIfPersistenceIdentifierIsStorageLocationAndFileNotExistsAndFileHasYamlExtension
‪existsReturnsFalseIfPersistenceIdentifierIsStorageLocationAndFileNotExistsAndFileHasYamlExtension()
Definition: FormPersistenceManagerTest.php:450
‪TYPO3\CMS\Form\Tests\Unit\Mvc\Persistence\FormPersistenceManagerTest\saveThrowsExceptionIfPersistenceIdentifierIsAExtensionLocationWhichIsNotAllowed
‪saveThrowsExceptionIfPersistenceIdentifierIsAExtensionLocationWhichIsNotAllowed()
Definition: FormPersistenceManagerTest.php:139
‪TYPO3\CMS\Core\Resource\ResourceStorage
Definition: ResourceStorage.php:122
‪TYPO3\CMS\Form\Tests\Unit\Mvc\Persistence\FormPersistenceManagerTest\deleteThrowsExceptionIfPersistenceIdentifierIsExtensionLocationAndDeleteFromExtensionLocationsIsNotAllowed
‪deleteThrowsExceptionIfPersistenceIdentifierIsExtensionLocationAndDeleteFromExtensionLocationsIsNotAllowed()
Definition: FormPersistenceManagerTest.php:211
‪TYPO3\CMS\Form\Tests\Unit\Mvc\Persistence\FormPersistenceManagerTest\retrieveFileByPersistenceIdentifierThrowsExceptionIfReadFromStorageIsNotAllowed
‪retrieveFileByPersistenceIdentifierThrowsExceptionIfReadFromStorageIsNotAllowed()
Definition: FormPersistenceManagerTest.php:623
‪TYPO3\CMS\Form\Tests\Unit\Mvc\Persistence\FormPersistenceManagerTest\existsReturnsTrueIfPersistenceIdentifierIsStorageLocationAndFileExistsAndFileHasYamlExtension
‪existsReturnsTrueIfPersistenceIdentifierIsStorageLocationAndFileExistsAndFileHasYamlExtension()
Definition: FormPersistenceManagerTest.php:398
‪TYPO3\CMS\Form\Tests\Unit\Mvc\Persistence\FormPersistenceManagerTest\saveThrowsExceptionIfPersistenceIdentifierHasNoYamlExtension
‪saveThrowsExceptionIfPersistenceIdentifierHasNoYamlExtension()
Definition: FormPersistenceManagerTest.php:101
‪TYPO3\CMS\Form\Tests\Unit\Mvc\Persistence\FormPersistenceManagerTest\existsReturnsFalseIfPersistenceIdentifierIsExtensionLocationAndFileExistsAndExtensionLocationIsNotAllowed
‪existsReturnsFalseIfPersistenceIdentifierIsExtensionLocationAndFileExistsAndExtensionLocationIsNotAllowed()
Definition: FormPersistenceManagerTest.php:366
‪TYPO3\CMS\Form\Tests\Unit\Mvc\Persistence\FormPersistenceManagerTest\saveThrowsExceptionIfPersistenceIdentifierIsAExtensionLocationAndSaveToExtensionLocationIsNotAllowed
‪saveThrowsExceptionIfPersistenceIdentifierIsAExtensionLocationAndSaveToExtensionLocationIsNotAllowed()
Definition: FormPersistenceManagerTest.php:117
‪TYPO3\CMS\Form\Tests\Unit\Mvc\Persistence\FormPersistenceManagerTest\getUniqueIdentifierThrowsExceptionIfIdentifierExists
‪getUniqueIdentifierThrowsExceptionIfIdentifierExists()
Definition: FormPersistenceManagerTest.php:535
‪TYPO3\CMS\Form\Tests\Unit\Mvc\Persistence\FormPersistenceManagerTest\getUniquePersistenceIdentifierAppendTimestampIfPersistenceIdentifierExists
‪getUniquePersistenceIdentifierAppendTimestampIfPersistenceIdentifierExists()
Definition: FormPersistenceManagerTest.php:500
‪TYPO3\CMS\Form\Tests\Unit\Mvc\Persistence\FormPersistenceManagerTest\isAllowedPersistencePathReturnsPropperValuesDataProvider
‪isAllowedPersistencePathReturnsPropperValuesDataProvider()
Definition: FormPersistenceManagerTest.php:788
‪TYPO3\CMS\Form\Tests\Unit\Mvc\Persistence\FormPersistenceManagerTest\getUniqueIdentifierAppendTimestampIfIdentifierExists
‪getUniqueIdentifierAppendTimestampIfIdentifierExists()
Definition: FormPersistenceManagerTest.php:556
‪TYPO3\CMS\Form\Tests\Unit\Mvc\Persistence\FormPersistenceManagerTest
Definition: FormPersistenceManagerTest.php:35