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