‪TYPO3CMS  11.5
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, ['dummy'], [], '', false);
45 
46  $runtimeCache = $this->getMockBuilder(VariableFrontend::class)
47  ->onlyMethods(['get', 'set'])
48  ->disableOriginalConstructor()
49  ->getMock();
50 
51  $runtimeCache
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 
65  {
66  $this->expectException(PersistenceManagerException::class);
67  $this->expectExceptionCode(1484071985);
68 
69  $mockFormPersistenceManager = $this->getAccessibleMock(FormPersistenceManager::class, ['dummy'], [], '', false);
70 
71  $runtimeCache = $this->getMockBuilder(VariableFrontend::class)
72  ->onlyMethods(['get', 'set'])
73  ->disableOriginalConstructor()
74  ->getMock();
75 
76  $runtimeCache
77  ->method('get')
78  ->willReturn(false);
79 
80  $mockFormPersistenceManager->_set('runtimeCache', $runtimeCache);
81 
82  $mockFormPersistenceManager->_set('formSettings', [
83  'persistenceManager' => [
84  'allowedExtensionPaths' => [],
85  ],
86  ]);
87 
88  $input = 'EXT:form/Resources/Forms/_example.form.yaml';
89  $mockFormPersistenceManager->_call('load', $input);
90  }
91 
96  {
97  $this->expectException(PersistenceManagerException::class);
98  $this->expectExceptionCode(1477679820);
99 
100  $mockFormPersistenceManager = $this->getAccessibleMock(FormPersistenceManager::class, ['dummy'], [], '', false);
101 
102  $input = '-1:/user_uploads/_example.php';
103  $mockFormPersistenceManager->_call('save', $input, []);
104  }
105 
110  {
111  $this->expectException(PersistenceManagerException::class);
112  $this->expectExceptionCode(1477680881);
113 
114  $mockFormPersistenceManager = $this->getAccessibleMock(FormPersistenceManager::class, ['dummy'], [], '', false);
115 
116  $mockFormPersistenceManager->_set('formSettings', [
117  'persistenceManager' => [
118  'allowSaveToExtensionPaths' => false,
119  ],
120  ]);
121 
122  $input = 'EXT:form/Resources/Forms/_example.form.yaml';
123  $mockFormPersistenceManager->_call('save', $input, []);
124  }
125 
130  {
131  $this->expectException(PersistenceManagerException::class);
132  $this->expectExceptionCode(1484073571);
133 
134  $mockFormPersistenceManager = $this->getAccessibleMock(FormPersistenceManager::class, ['dummy'], [], '', false);
135 
136  $runtimeCache = $this->getMockBuilder(VariableFrontend::class)
137  ->onlyMethods(['get', 'set'])
138  ->disableOriginalConstructor()
139  ->getMock();
140 
141  $runtimeCache
142  ->method('get')
143  ->willReturn(false);
144 
145  $mockFormPersistenceManager->_set('runtimeCache', $runtimeCache);
146 
147  $mockFormPersistenceManager->_set('formSettings', [
148  'persistenceManager' => [
149  'allowSaveToExtensionPaths' => true,
150  'allowedExtensionPaths' => [],
151  ],
152  ]);
153 
154  $input = 'EXT:form/Resources/Forms/_example.form.yaml';
155  $mockFormPersistenceManager->_call('save', $input, []);
156  }
157 
162  {
163  $this->expectException(PersistenceManagerException::class);
164  $this->expectExceptionCode(1472239534);
165 
166  $mockFormPersistenceManager = $this->getAccessibleMock(FormPersistenceManager::class, ['dummy'], [], '', false);
167 
168  $input = '-1:/user_uploads/_example.php';
169  $mockFormPersistenceManager->_call('delete', $input);
170  }
171 
176  {
177  $this->expectException(PersistenceManagerException::class);
178  $this->expectExceptionCode(1472239535);
179 
180  $mockFormPersistenceManager = $this->getAccessibleMock(FormPersistenceManager::class, ['exists'], [], '', false);
181 
182  $mockFormPersistenceManager
183  ->method('exists')
184  ->willReturn(false);
185 
186  $input = '-1:/user_uploads/_example.form.yaml';
187  $mockFormPersistenceManager->_call('delete', $input);
188  }
189 
194  {
195  $this->expectException(PersistenceManagerException::class);
196  $this->expectExceptionCode(1472239536);
197 
198  $mockFormPersistenceManager = $this->getAccessibleMock(FormPersistenceManager::class, ['exists'], [], '', false);
199 
200  $mockFormPersistenceManager
201  ->method('exists')
202  ->willReturn(true);
203 
204  $mockFormPersistenceManager->_set('formSettings', [
205  'persistenceManager' => [
206  'allowDeleteFromExtensionPaths' => false,
207  ],
208  ]);
209 
210  $input = 'EXT:form/Resources/Forms/_example.form.yaml';
211  $mockFormPersistenceManager->_call('delete', $input);
212  }
213 
218  {
219  $this->expectException(PersistenceManagerException::class);
220  $this->expectExceptionCode(1484073878);
221 
222  $mockFormPersistenceManager = $this->getAccessibleMock(FormPersistenceManager::class, ['exists'], [], '', false);
223 
224  $runtimeCache = $this->getMockBuilder(VariableFrontend::class)
225  ->onlyMethods(['get', 'set'])
226  ->disableOriginalConstructor()
227  ->getMock();
228 
229  $runtimeCache
230  ->method('get')
231  ->willReturn(false);
232 
233  $mockFormPersistenceManager->_set('runtimeCache', $runtimeCache);
234 
235  $mockFormPersistenceManager
236  ->method('exists')
237  ->willReturn(true);
238 
239  $mockFormPersistenceManager->_set('formSettings', [
240  'persistenceManager' => [
241  'allowDeleteFromExtensionPaths' => true,
242  'allowedExtensionPaths' => [],
243  ],
244  ]);
245 
246  $input = 'EXT:form/Resources/Forms/_example.form.yaml';
247  $mockFormPersistenceManager->_call('delete', $input);
248  }
249 
254  {
255  $this->expectException(PersistenceManagerException::class);
256  $this->expectExceptionCode(1472239516);
257 
258  $mockFormPersistenceManager = $this->getAccessibleMock(FormPersistenceManager::class, ['getStorageByUid', 'exists'], [], '', false);
259 
260  $mockStorage = $this->getMockBuilder(ResourceStorage::class)
261  ->disableOriginalConstructor()
262  ->getMock();
263 
264  $mockStorage
265  ->method('checkFileActionPermission')
266  ->willReturn(false);
267 
268  $file = new ‪File(['name' => 'foo', 'identifier' => '', 'mime_type' => ''], $mockStorage);
269  $mockStorage
270  ->method('getFile')
271  ->willReturn($file);
272 
273  $mockFormPersistenceManager
274  ->method('getStorageByUid')
275  ->willReturn($mockStorage);
276 
277  $mockFormPersistenceManager
278  ->method('exists')
279  ->willReturn(true);
280 
281  $input = '-1:/user_uploads/_example.form.yaml';
282  $mockFormPersistenceManager->_call('delete', $input);
283  }
284 
289  {
290  $mockFormPersistenceManager = $this->getAccessibleMock(FormPersistenceManager::class, ['dummy'], [], '', false);
291 
292  $runtimeCache = $this->getMockBuilder(VariableFrontend::class)
293  ->onlyMethods(['get', 'set'])
294  ->disableOriginalConstructor()
295  ->getMock();
296 
297  $runtimeCache
298  ->method('get')
299  ->willReturn(false);
300 
301  $mockFormPersistenceManager->_set('runtimeCache', $runtimeCache);
302 
303  $mockFormPersistenceManager->_set('formSettings', [
304  'persistenceManager' => [
305  'allowedExtensionPaths' => [
306  'EXT:form/Tests/Unit/Mvc/Persistence/Fixtures/',
307  ],
308  ],
309  ]);
310 
311  $input = 'EXT:form/Tests/Unit/Mvc/Persistence/Fixtures/BlankForm.form.yaml';
312  self::assertTrue($mockFormPersistenceManager->_call('exists', $input));
313  }
314 
319  {
320  $mockFormPersistenceManager = $this->getAccessibleMock(FormPersistenceManager::class, ['dummy'], [], '', false);
321  $input = 'EXT:form/Tests/Unit/Mvc/Persistence/Fixtures/BlankForm.txt';
322  self::assertFalse($mockFormPersistenceManager->_call('exists', $input));
323  }
324 
329  {
330  $mockFormPersistenceManager = $this->getAccessibleMock(FormPersistenceManager::class, ['dummy'], [], '', false);
331 
332  $mockFormPersistenceManager->_set('formSettings', [
333  'persistenceManager' => [
334  'allowedExtensionPaths' => [],
335  ],
336  ]);
337 
338  $input = 'EXT:form/Tests/Unit/Mvc/Persistence/Fixtures/BlankForm.yaml';
339  self::assertFalse($mockFormPersistenceManager->_call('exists', $input));
340  }
341 
346  {
347  $mockFormPersistenceManager = $this->getAccessibleMock(FormPersistenceManager::class, ['dummy'], [], '', false);
348  $input = 'EXT:form/Tests/Unit/Mvc/Persistence/Fixtures/_BlankForm.yaml';
349  self::assertFalse($mockFormPersistenceManager->_call('exists', $input));
350  }
351 
356  {
357  $mockFormPersistenceManager = $this->getAccessibleMock(FormPersistenceManager::class, ['getStorageByUid'], [], '', false);
358 
359  $mockStorage = $this->getMockBuilder(ResourceStorage::class)
360  ->disableOriginalConstructor()
361  ->getMock();
362  $mockStorage
363  ->method('hasFile')
364  ->willReturn(true);
365 
366  $mockFormPersistenceManager
367  ->method('getStorageByUid')
368  ->willReturn($mockStorage);
369 
370  $input = '-1:/user_uploads/_example.form.yaml';
371  self::assertTrue($mockFormPersistenceManager->_call('exists', $input));
372  }
373 
378  {
379  $mockFormPersistenceManager = $this->getAccessibleMock(FormPersistenceManager::class, ['getStorageByUid'], [], '', false);
380 
381  $mockStorage = $this->getMockBuilder(ResourceStorage::class)
382  ->disableOriginalConstructor()
383  ->getMock();
384  $mockStorage
385  ->method('hasFile')
386  ->willReturn(true);
387 
388  $mockFormPersistenceManager
389  ->method('getStorageByUid')
390  ->willReturn($mockStorage);
391 
392  $input = '-1:/user_uploads/_example.php';
393  self::assertFalse($mockFormPersistenceManager->_call('exists', $input));
394  }
395 
400  {
401  $mockFormPersistenceManager = $this->getAccessibleMock(FormPersistenceManager::class, ['getStorageByUid'], [], '', false);
402 
403  $mockStorage = $this->getMockBuilder(ResourceStorage::class)
404  ->disableOriginalConstructor()
405  ->getMock();
406  $mockStorage
407  ->method('hasFile')
408  ->willReturn(false);
409 
410  $mockFormPersistenceManager
411  ->method('getStorageByUid')
412  ->willReturn($mockStorage);
413 
414  $input = '-1:/user_uploads/_example.yaml';
415  self::assertFalse($mockFormPersistenceManager->_call('exists', $input));
416  }
417 
422  {
423  $mockFormPersistenceManager = $this->getAccessibleMock(FormPersistenceManager::class, ['exists'], [], '', false);
424 
425  $mockFormPersistenceManager
426  ->expects(self::exactly(3))
427  ->method('exists')
428  ->will(self::onConsecutiveCalls(
429  self::returnValue(true),
430  self::returnValue(true),
431  self::returnValue(false)
432  ));
433 
434  $input = 'example';
435  $expected = '-1:/user_uploads/example_2.form.yaml';
436  $result = $mockFormPersistenceManager->_call('getUniquePersistenceIdentifier', $input, '-1:/user_uploads/');
437  self::assertSame($expected, $result);
438  }
439 
444  {
445  $mockFormPersistenceManager = $this->getAccessibleMock(FormPersistenceManager::class, ['exists'], [], '', false);
446 
447  $mockFormPersistenceManager
448  ->expects(self::exactly(101))
449  ->method('exists')
450  ->will(self::onConsecutiveCalls(
451  ...$this->‪returnTrue100Times()
452  ));
453 
454  $input = 'example';
455  $expected = '#^-1:/user_uploads/example_([0-9]{10}).form.yaml$#';
456 
457  $returnValue = $mockFormPersistenceManager->_call('getUniquePersistenceIdentifier', $input, '-1:/user_uploads/');
458  self::assertMatchesRegularExpression($expected, $returnValue);
459  }
460 
465  private function ‪returnTrue100Times(): array
466  {
467  $returnValues = [];
468  $returnValues = array_pad($returnValues, 100, self::returnValue(true));
469  $returnValues[] = self::returnValue(false);
470  return $returnValues;
471  }
472 
477  {
478  $this->expectException(NoUniqueIdentifierException::class);
479  $this->expectExceptionCode(1477688567);
480 
481  $mockFormPersistenceManager = $this->getAccessibleMock(FormPersistenceManager::class, ['checkForDuplicateIdentifier'], [], '', false);
482 
483  $mockFormPersistenceManager
484  ->method('checkForDuplicateIdentifier')
485  ->willReturn(true);
486 
487  $input = 'example';
488  $mockFormPersistenceManager->_call('getUniqueIdentifier', $input);
489  }
490 
495  {
496  $mockFormPersistenceManager = $this->getAccessibleMock(FormPersistenceManager::class, ['checkForDuplicateIdentifier'], [], '', false);
497 
498  $mockFormPersistenceManager
499  ->expects(self::exactly(101))
500  ->method('checkForDuplicateIdentifier')
501  ->will(self::onConsecutiveCalls(
502  ...$this->‪returnTrue100Times()
503  ));
504 
505  $input = 'example';
506  $expected = '#^example_([0-9]{10})$#';
507 
508  $returnValue = $mockFormPersistenceManager->_call('getUniqueIdentifier', $input);
509  self::assertMatchesRegularExpression($expected, $returnValue);
510  }
511 
516  {
517  $mockFormPersistenceManager = $this->getAccessibleMock(FormPersistenceManager::class, ['listForms'], [], '', false);
518 
519  $mockFormPersistenceManager
520  ->expects(self::once())
521  ->method('listForms')
522  ->willReturn([
523  0 => [
524  'identifier' => 'example',
525  ],
526  ]);
527 
528  $input = 'example';
529  self::assertTrue($mockFormPersistenceManager->_call('checkForDuplicateIdentifier', $input));
530  }
531 
536  {
537  $mockFormPersistenceManager = $this->getAccessibleMock(FormPersistenceManager::class, ['listForms'], [], '', false);
538 
539  $mockFormPersistenceManager
540  ->expects(self::once())
541  ->method('listForms')
542  ->willReturn([
543  0 => [
544  'identifier' => 'example',
545  ],
546  ]);
547 
548  $input = 'other-example';
549  self::assertFalse($mockFormPersistenceManager->_call('checkForDuplicateIdentifier', $input));
550  }
551 
552  public function ‪metaDataIsExtractedDataProvider(): \Generator
553  {
554  yield 'enclosed with single quotation marks and escaped single quotation marks within the label' => [
555  'maybeRawFormDefinition' => "label: 'Ouverture d''un compte'",
556  'expectedMetaData' => ['label' => "Ouverture d'un compte"],
557  ];
558 
559  yield 'enclosed with double quotation marks and single quotation marks within the label' => [
560  'maybeRawFormDefinition' => 'label: "Demo: Just a \'label\'"',
561  'expectedMetaData' => ['label' => "Demo: Just a 'label'"],
562  ];
563 
564  yield 'label enclosed with single quotation marks' => [
565  'maybeRawFormDefinition' => "label: 'Demo'",
566  'expectedMetaData' => ['label' => 'Demo'],
567  ];
568 
569  yield 'label enclosed with double quotation marks' => [
570  'maybeRawFormDefinition' => 'label: "Demo"',
571  'expectedMetaData' => ['label' => 'Demo'],
572  ];
573 
574  yield 'single quotation mark only at the start of the label' => [
575  'maybeRawFormDefinition' => "label: \\'Demo",
576  'expectedMetaData' => ['label' => "\\'Demo"],
577  ];
578 
579  yield 'double quotation mark only at the start of the label' => [
580  'maybeRawFormDefinition' => 'label: \"Demo',
581  'expectedMetaData' => ['label' => '\"Demo'],
582  ];
583 
584  yield 'multiple properties are extracted' => [
585  'maybeRawFormDefinition' => implode("\n", [
586  'type: "type:type"',
587  "identifier: 'identifier:identifier'",
588  'prototypeName: prototypeName:prototypeName',
589  'label: "Demo: Label"',
590  'other: "any-other-property"',
591  ]),
592  'expectedMetaData' => [
593  'type' => 'type:type',
594  'identifier' => 'identifier:identifier',
595  'prototypeName' => 'prototypeName:prototypeName',
596  'label' => 'Demo: Label',
597  ],
598  ];
599  }
600 
605  public function ‪metaDataIsExtracted(string $maybeRawFormDefinition, array $expectedMetaData): void
606  {
607  $formPersistenceManagerMock = $this->getAccessibleMock(FormPersistenceManager::class, ['dummy'], [], '', false);
608  self::assertSame($expectedMetaData, $formPersistenceManagerMock->_call('extractMetaDataFromCouldBeFormDefinition', $maybeRawFormDefinition));
609  }
610 
615  {
616  $this->expectException(PersistenceManagerException::class);
617  $this->expectExceptionCode(1471630578);
618 
619  $mockFormPersistenceManager = $this->getAccessibleMock(FormPersistenceManager::class, [
620  'dummy',
621  ], [], '', false);
622 
623  $storage = $this->getMockBuilder(ResourceStorage::class)
624  ->disableOriginalConstructor()
625  ->getMock();
626 
627  $storage
628  ->method('checkFileActionPermission')
629  ->willReturn(false);
630 
631  $file = new ‪File(['name' => 'foo', 'identifier' => '', 'mime_type' => ''], $storage);
632 
633  $resourceFactory = $this->getMockBuilder(ResourceFactory::class)
634  ->disableOriginalConstructor()
635  ->getMock();
636 
637  $resourceFactory
638  ->method('retrieveFileOrFolderObject')
639  ->willReturn($file);
640 
641  $mockFormPersistenceManager->_set('resourceFactory', $resourceFactory);
642 
643  $input = '-1:/user_uploads/example.yaml';
644  $mockFormPersistenceManager->_call('retrieveFileByPersistenceIdentifier', $input);
645  }
646 
651  {
652  $this->expectException(PersistenceManagerException::class);
653  $this->expectExceptionCode(1471630579);
654 
655  $mockFormPersistenceManager = $this->getAccessibleMock(FormPersistenceManager::class, [
656  'getStorageByUid',
657  ], [], '', false);
658 
659  $mockStorage = $this->getMockBuilder(ResourceStorage::class)
660  ->disableOriginalConstructor()
661  ->getMock();
662 
663  $mockStorage
664  ->method('hasFolder')
665  ->willReturn(false);
666 
667  $mockFormPersistenceManager
668  ->method('getStorageByUid')
669  ->willReturn($mockStorage);
670 
671  $input = '-1:/user_uploads/example.yaml';
672  $mockFormPersistenceManager->_call('getOrCreateFile', $input);
673  }
674 
679  {
680  $this->expectException(PersistenceManagerException::class);
681  $this->expectExceptionCode(1471630580);
682 
683  $mockFormPersistenceManager = $this->getAccessibleMock(FormPersistenceManager::class, [
684  'getStorageByUid',
685  ], [], '', false);
686 
687  $mockStorage = $this->getMockBuilder(ResourceStorage::class)
688  ->disableOriginalConstructor()
689  ->getMock();
690 
691  $mockStorage
692  ->method('hasFolder')
693  ->willReturn(true);
694 
695  $mockStorage
696  ->method('checkFileActionPermission')
697  ->willReturn(false);
698 
699  $file = new ‪File(['name' => 'foo', 'identifier' => '', 'mime_type' => ''], $mockStorage);
700  $mockStorage
701  ->method('getFile')
702  ->willReturn($file);
703 
704  $mockFormPersistenceManager
705  ->method('getStorageByUid')
706  ->willReturn($mockStorage);
707 
708  $input = '-1:/user_uploads/example.yaml';
709  $mockFormPersistenceManager->_call('getOrCreateFile', $input);
710  }
711 
716  {
717  $this->expectException(PersistenceManagerException::class);
718  $this->expectExceptionCode(1471630581);
719 
720  $mockFormPersistenceManager = $this->getAccessibleMock(FormPersistenceManager::class, [
721  'dummy',
722  ], [], '', false);
723 
724  $mockStorageRepository = $this->getMockBuilder(StorageRepository::class)
725  ->disableOriginalConstructor()
726  ->getMock();
727 
728  $mockStorageRepository
729  ->method('findByUid')
730  ->willReturn(null);
731 
732  $mockFormPersistenceManager->_set('storageRepository', $mockStorageRepository);
733  $mockFormPersistenceManager->_call('getStorageByUid', -1);
734  }
735 
740  {
741  $this->expectException(PersistenceManagerException::class);
742  $this->expectExceptionCode(1471630581);
743 
744  $mockFormPersistenceManager = $this->getAccessibleMock(FormPersistenceManager::class, [
745  'dummy',
746  ], [], '', false);
747 
748  $mockStorageRepository = $this->getMockBuilder(StorageRepository::class)
749  ->disableOriginalConstructor()
750  ->getMock();
751 
752  $mockStorage = $this->getMockBuilder(ResourceStorage::class)
753  ->disableOriginalConstructor()
754  ->getMock();
755 
756  $mockStorage
757  ->method('isBrowsable')
758  ->willReturn(false);
759 
760  $mockStorageRepository
761  ->method('findByUid')
762  ->willReturn($mockStorage);
763 
764  $mockFormPersistenceManager->_set('storageRepository', $mockStorageRepository);
765  $mockFormPersistenceManager->_call('getStorageByUid', -1);
766  }
767 
769  {
770  return [
771  [
772  'persistencePath' => '',
773  'allowedExtensionPaths' => [],
774  'allowedFileMounts' => [],
775  'expected' => false,
776  ],
777  [
778  'persistencePath' => '-1:/user_uploads',
779  'allowedExtensionPaths' => [],
780  'allowedFileMounts' => [],
781  'expected' => false,
782  ],
783  [
784  'persistencePath' => 'EXT:form/Tests/Unit/Mvc/Persistence/Fixtures',
785  'allowedExtensionPaths' => [],
786  'allowedFileMounts' => [],
787  'expected' => false,
788  ],
789  [
790  'persistencePath' => '-1:/user_uploads/',
791  'allowedExtensionPaths' => [],
792  'allowedFileMounts' => [],
793  'expected' => false,
794  ],
795  [
796  'persistencePath' => 'EXT:form/Tests/Unit/Mvc/Persistence/Fixtures/',
797  'allowedExtensionPaths' => [],
798  'allowedFileMounts' => [],
799  'expected' => false,
800  ],
801  [
802  'persistencePath' => '-1:/user_uploads/example.form.yaml',
803  'allowedExtensionPaths' => [],
804  'allowedFileMounts' => [],
805  'expected' => false,
806  ],
807  [
808  'persistencePath' => 'EXT:form/Tests/Unit/Mvc/Persistence/Fixtures/BlankForm.form.yaml',
809  'allowedExtensionPaths' => [],
810  'allowedFileMounts' => [],
811  'expected' => false,
812  ],
813 
814  [
815  'persistencePath' => '-1:/user_uploads/',
816  'allowedExtensionPaths' => [],
817  'allowedFileMounts' => ['-1:/some_path/'],
818  'expected' => false,
819  ],
820  [
821  'persistencePath' => '-1:/user_uploads/',
822  'allowedExtensionPaths' => [],
823  'allowedFileMounts' => ['-1:/user_uploads/'],
824  'expected' => true,
825  ],
826  [
827  'persistencePath' => '-1:/user_uploads',
828  'allowedExtensionPaths' => [],
829  'allowedFileMounts' => ['-1:/user_uploads/'],
830  'expected' => true,
831  ],
832  [
833  'persistencePath' => '-1:/user_uploads/',
834  'allowedExtensionPaths' => [],
835  'allowedFileMounts' => ['-1:/user_uploads'],
836  'expected' => true,
837  ],
838 
839  [
840  'persistencePath' => 'EXT:form/Tests/Unit/Mvc/Persistence/Fixtures/',
841  'allowedExtensionPaths' => ['EXT:some_extension/Tests/Unit/Mvc/Persistence/Fixtures/'],
842  'allowedFileMounts' => [],
843  'expected' => false,
844  ],
845  [
846  'persistencePath' => 'EXT:form/Tests/Unit/Mvc/Persistence/Fixtures/',
847  'allowedExtensionPaths' => ['EXT:form/Tests/Unit/Mvc/Persistence/Fixtures/'],
848  'allowedFileMounts' => [],
849  'expected' => true,
850  ],
851  [
852  'persistencePath' => 'EXT:form/Tests/Unit/Mvc/Persistence/Fixtures',
853  'allowedExtensionPaths' => ['EXT:form/Tests/Unit/Mvc/Persistence/Fixtures/'],
854  'allowedFileMounts' => [],
855  'expected' => true,
856  ],
857  [
858  'persistencePath' => 'EXT:form/Tests/Unit/Mvc/Persistence/Fixtures/',
859  'allowedExtensionPaths' => ['EXT:form/Tests/Unit/Mvc/Persistence/Fixtures'],
860  'allowedFileMounts' => [],
861  'expected' => true,
862  ],
863 
864  [
865  'persistencePath' => '-1:/user_uploads/example.yaml',
866  'allowedExtensionPaths' => [],
867  'allowedFileMounts' => ['-1:/some_path/'],
868  'expected' => false,
869  ],
870  [
871  'persistencePath' => '-1:/user_uploads/example.form.yaml',
872  'allowedExtensionPaths' => [],
873  'allowedFileMounts' => ['-1:/some_path/'],
874  'expected' => false,
875  ],
876  [
877  'persistencePath' => '-1:/user_uploads/example.yaml',
878  'allowedExtensionPaths' => [],
879  'allowedFileMounts' => ['-1:/user_uploads/'],
880  'expected' => false,
881  ],
882  [
883  'persistencePath' => '-1:/user_uploads/example.yaml',
884  'allowedExtensionPaths' => [],
885  'allowedFileMounts' => ['-1:/user_uploads'],
886  'expected' => false,
887  ],
888  [
889  'persistencePath' => '-1:/user_uploads/example.form.yaml',
890  'allowedExtensionPaths' => [],
891  'allowedFileMounts' => ['-1:/user_uploads/'],
892  'expected' => true,
893  ],
894  [
895  'persistencePath' => '-1:/user_uploads/example.form.yaml',
896  'allowedExtensionPaths' => [],
897  'allowedFileMounts' => ['-1:/user_uploads'],
898  'expected' => true,
899  ],
900 
901  [
902  'persistencePath' => 'EXT:form/Tests/Unit/Mvc/Persistence/Fixtures/BlankForm.txt',
903  'allowedExtensionPaths' => ['EXT:some_extension/Tests/Unit/Mvc/Persistence/Fixtures/'],
904  'allowedFileMounts' => [],
905  'expected' => false,
906  ],
907  [
908  'persistencePath' => 'EXT:form/Tests/Unit/Mvc/Persistence/Fixtures/BlankForm.form.yaml',
909  'allowedExtensionPaths' => ['EXT:some_extension/Tests/Unit/Mvc/Persistence/Fixtures/'],
910  'allowedFileMounts' => [],
911  'expected' => false,
912  ],
913  [
914  'persistencePath' => 'EXT:form/Tests/Unit/Mvc/Persistence/Fixtures/BlankForm.txt',
915  'allowedExtensionPaths' => ['EXT:form/Tests/Unit/Mvc/Persistence/Fixtures/'],
916  'allowedFileMounts' => [],
917  'expected' => false,
918  ],
919  [
920  'persistencePath' => 'EXT:form/Tests/Unit/Mvc/Persistence/Fixtures/BlankForm.txt',
921  'allowedExtensionPaths' => ['EXT:form/Tests/Unit/Mvc/Persistence/Fixtures'],
922  'allowedFileMounts' => [],
923  'expected' => false,
924  ],
925  [
926  'persistencePath' => 'EXT:form/Tests/Unit/Mvc/Persistence/Fixtures/BlankForm.form.yaml',
927  'allowedExtensionPaths' => ['EXT:form/Tests/Unit/Mvc/Persistence/Fixtures/'],
928  'allowedFileMounts' => [],
929  'expected' => true,
930  ],
931  [
932  'persistencePath' => 'EXT:form/Tests/Unit/Mvc/Persistence/Fixtures/BlankForm.form.yaml',
933  'allowedExtensionPaths' => ['EXT:form/Tests/Unit/Mvc/Persistence/Fixtures'],
934  'allowedFileMounts' => [],
935  'expected' => true,
936  ],
937  ];
938  }
939 
944  public function ‪isAllowedPersistencePathReturnsPropperValues(string $persistencePath, array $allowedExtensionPaths, array $allowedFileMounts, $expected): void
945  {
946  $formPersistenceManagerMock = $this->getAccessibleMock(FormPersistenceManager::class, ['getStorageByUid'], [], '', false);
947 
948  $runtimeCacheMock = $this->getMockBuilder(VariableFrontend::class)
949  ->onlyMethods(['get', 'set'])
950  ->disableOriginalConstructor()
951  ->getMock();
952 
953  $runtimeCacheMock
954  ->method('get')
955  ->willReturn(false);
956 
957  $storageMock = $this->getMockBuilder(ResourceStorage::class)
958  ->disableOriginalConstructor()
959  ->getMock();
960 
961  $storageMock
962  ->method('getRootLevelFolder')
963  ->willReturn(new ‪Folder($storageMock, '', ''));
964 
965  $storageMock
966  ->method('getFileMounts')
967  ->willReturn([]);
968 
969  $storageMock
970  ->method('getFolder')
971  ->willReturn(new ‪Folder($storageMock, '', ''));
972 
973  $formPersistenceManagerMock
974  ->method('getStorageByUid')
975  ->willReturn($storageMock);
976 
977  $formPersistenceManagerMock->_set('runtimeCache', $runtimeCacheMock);
978  $formPersistenceManagerMock->_set('formSettings', [
979  'persistenceManager' => [
980  'allowedExtensionPaths' => $allowedExtensionPaths,
981  'allowedFileMounts' => $allowedFileMounts,
982  ],
983  ]);
984 
985  self::assertEquals($expected, $formPersistenceManagerMock->_call('isAllowedPersistencePath', $persistencePath));
986  }
987 }
‪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:715
‪TYPO3\CMS\Form\Tests\Unit\Mvc\Persistence\FormPersistenceManagerTest\metaDataIsExtracted
‪metaDataIsExtracted(string $maybeRawFormDefinition, array $expectedMetaData)
Definition: FormPersistenceManagerTest.php:605
‪TYPO3\CMS\Form\Tests\Unit\Mvc\Persistence\FormPersistenceManagerTest\checkForDuplicateIdentifierReturnsFalseIfIdentifierIsUsed
‪checkForDuplicateIdentifierReturnsFalseIfIdentifierIsUsed()
Definition: FormPersistenceManagerTest.php:535
‪TYPO3\CMS\Form\Tests\Unit\Mvc\Persistence\FormPersistenceManagerTest\getOrCreateFileThrowsExceptionIfWriteToStorageIsNotAllowed
‪getOrCreateFileThrowsExceptionIfWriteToStorageIsNotAllowed()
Definition: FormPersistenceManagerTest.php:678
‪TYPO3\CMS\Form\Tests\Unit\Mvc\Persistence\FormPersistenceManagerTest\deleteThrowsExceptionIfPersistenceIdentifierIsStorageLocationAndDeleteFromStorageIsNotAllowed
‪deleteThrowsExceptionIfPersistenceIdentifierIsStorageLocationAndDeleteFromStorageIsNotAllowed()
Definition: FormPersistenceManagerTest.php:253
‪TYPO3\CMS\Form\Tests\Unit\Mvc\Persistence\FormPersistenceManagerTest\getUniquePersistenceIdentifierAppendNumberIfPersistenceIdentifierExists
‪getUniquePersistenceIdentifierAppendNumberIfPersistenceIdentifierExists()
Definition: FormPersistenceManagerTest.php:421
‪TYPO3\CMS\Form\Mvc\Persistence\Exception\PersistenceManagerException
Definition: PersistenceManagerException.php:27
‪TYPO3\CMS\Form\Tests\Unit\Mvc\Persistence\FormPersistenceManagerTest\checkForDuplicateIdentifierReturnsTrueIfIdentifierIsUsed
‪checkForDuplicateIdentifierReturnsTrueIfIdentifierIsUsed()
Definition: FormPersistenceManagerTest.php:515
‪TYPO3\CMS\Form\Tests\Unit\Mvc\Persistence\FormPersistenceManagerTest\getStorageByUidThrowsExceptionIfStorageIsNotBrowsable
‪getStorageByUidThrowsExceptionIfStorageIsNotBrowsable()
Definition: FormPersistenceManagerTest.php:739
‪TYPO3\CMS\Form\Tests\Unit\Mvc\Persistence\FormPersistenceManagerTest\deleteThrowsExceptionIfPersistenceIdentifierFileDoesNotExists
‪deleteThrowsExceptionIfPersistenceIdentifierFileDoesNotExists()
Definition: FormPersistenceManagerTest.php:175
‪TYPO3\CMS\Form\Tests\Unit\Mvc\Persistence\FormPersistenceManagerTest\existsReturnsFalseIfPersistenceIdentifierIsExtensionLocationAndFileNotExistsAndFileHasYamlExtension
‪existsReturnsFalseIfPersistenceIdentifierIsExtensionLocationAndFileNotExistsAndFileHasYamlExtension()
Definition: FormPersistenceManagerTest.php:345
‪TYPO3\CMS\Form\Tests\Unit\Mvc\Persistence\FormPersistenceManagerTest\existsReturnsTrueIfPersistenceIdentifierIsExtensionLocationAndFileExistsAndFileHasYamlExtension
‪existsReturnsTrueIfPersistenceIdentifierIsExtensionLocationAndFileExistsAndFileHasYamlExtension()
Definition: FormPersistenceManagerTest.php:288
‪TYPO3\CMS\Form\Tests\Unit\Mvc\Persistence\FormPersistenceManagerTest\isAllowedPersistencePathReturnsPropperValues
‪isAllowedPersistencePathReturnsPropperValues(string $persistencePath, array $allowedExtensionPaths, array $allowedFileMounts, $expected)
Definition: FormPersistenceManagerTest.php:944
‪TYPO3\CMS\Form\Mvc\Persistence\Exception\NoUniqueIdentifierException
Definition: NoUniqueIdentifierException.php:25
‪TYPO3\CMS\Form\Tests\Unit\Mvc\Persistence\FormPersistenceManagerTest\loadThrowsExceptionIfPersistenceIdentifierIsAExtensionLocationWhichIsNotAllowed
‪loadThrowsExceptionIfPersistenceIdentifierIsAExtensionLocationWhichIsNotAllowed()
Definition: FormPersistenceManagerTest.php:64
‪TYPO3\CMS\Form\Tests\Unit\Mvc\Persistence\FormPersistenceManagerTest\metaDataIsExtractedDataProvider
‪metaDataIsExtractedDataProvider()
Definition: FormPersistenceManagerTest.php:552
‪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:465
‪TYPO3\CMS\Form\Mvc\Persistence\FormPersistenceManager
Definition: FormPersistenceManager.php:54
‪TYPO3\CMS\Form\Tests\Unit\Mvc\Persistence\FormPersistenceManagerTest\deleteThrowsExceptionIfPersistenceIdentifierHasNoYamlExtension
‪deleteThrowsExceptionIfPersistenceIdentifierHasNoYamlExtension()
Definition: FormPersistenceManagerTest.php:161
‪TYPO3\CMS\Form\Tests\Unit\Mvc\Persistence\FormPersistenceManagerTest\getOrCreateFileThrowsExceptionIfFolderNotExistsInStorage
‪getOrCreateFileThrowsExceptionIfFolderNotExistsInStorage()
Definition: FormPersistenceManagerTest.php:650
‪TYPO3\CMS\Form\Tests\Unit\Mvc\Persistence\FormPersistenceManagerTest\existsReturnsFalseIfPersistenceIdentifierIsStorageLocationAndFileExistsAndFileNoYamlExtension
‪existsReturnsFalseIfPersistenceIdentifierIsStorageLocationAndFileExistsAndFileNoYamlExtension()
Definition: FormPersistenceManagerTest.php:377
‪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:38
‪TYPO3\CMS\Core\Resource\File
Definition: File.php:24
‪TYPO3\CMS\Form\Tests\Unit\Mvc\Persistence\FormPersistenceManagerTest\deleteThrowsExceptionIfPersistenceIdentifierIsExtensionLocationWhichIsNotAllowed
‪deleteThrowsExceptionIfPersistenceIdentifierIsExtensionLocationWhichIsNotAllowed()
Definition: FormPersistenceManagerTest.php:217
‪TYPO3\CMS\Form\Tests\Unit\Mvc\Persistence\FormPersistenceManagerTest\existsReturnsFalseIfPersistenceIdentifierIsExtensionLocationAndFileExistsAndFileHasNoYamlExtension
‪existsReturnsFalseIfPersistenceIdentifierIsExtensionLocationAndFileExistsAndFileHasNoYamlExtension()
Definition: FormPersistenceManagerTest.php:318
‪TYPO3\CMS\Form\Tests\Unit\Mvc\Persistence\FormPersistenceManagerTest\existsReturnsFalseIfPersistenceIdentifierIsStorageLocationAndFileNotExistsAndFileHasYamlExtension
‪existsReturnsFalseIfPersistenceIdentifierIsStorageLocationAndFileNotExistsAndFileHasYamlExtension()
Definition: FormPersistenceManagerTest.php:399
‪TYPO3\CMS\Form\Tests\Unit\Mvc\Persistence\FormPersistenceManagerTest\saveThrowsExceptionIfPersistenceIdentifierIsAExtensionLocationWhichIsNotAllowed
‪saveThrowsExceptionIfPersistenceIdentifierIsAExtensionLocationWhichIsNotAllowed()
Definition: FormPersistenceManagerTest.php:129
‪TYPO3\CMS\Core\Resource\ResourceStorage
Definition: ResourceStorage.php:125
‪TYPO3\CMS\Form\Tests\Unit\Mvc\Persistence\FormPersistenceManagerTest\deleteThrowsExceptionIfPersistenceIdentifierIsExtensionLocationAndDeleteFromExtensionLocationsIsNotAllowed
‪deleteThrowsExceptionIfPersistenceIdentifierIsExtensionLocationAndDeleteFromExtensionLocationsIsNotAllowed()
Definition: FormPersistenceManagerTest.php:193
‪TYPO3\CMS\Form\Tests\Unit\Mvc\Persistence\FormPersistenceManagerTest\retrieveFileByPersistenceIdentifierThrowsExceptionIfReadFromStorageIsNotAllowed
‪retrieveFileByPersistenceIdentifierThrowsExceptionIfReadFromStorageIsNotAllowed()
Definition: FormPersistenceManagerTest.php:614
‪TYPO3\CMS\Form\Tests\Unit\Mvc\Persistence\FormPersistenceManagerTest\existsReturnsTrueIfPersistenceIdentifierIsStorageLocationAndFileExistsAndFileHasYamlExtension
‪existsReturnsTrueIfPersistenceIdentifierIsStorageLocationAndFileExistsAndFileHasYamlExtension()
Definition: FormPersistenceManagerTest.php:355
‪TYPO3\CMS\Form\Tests\Unit\Mvc\Persistence\FormPersistenceManagerTest\saveThrowsExceptionIfPersistenceIdentifierHasNoYamlExtension
‪saveThrowsExceptionIfPersistenceIdentifierHasNoYamlExtension()
Definition: FormPersistenceManagerTest.php:95
‪TYPO3\CMS\Form\Tests\Unit\Mvc\Persistence\FormPersistenceManagerTest\existsReturnsFalseIfPersistenceIdentifierIsExtensionLocationAndFileExistsAndExtensionLocationIsNotAllowed
‪existsReturnsFalseIfPersistenceIdentifierIsExtensionLocationAndFileExistsAndExtensionLocationIsNotAllowed()
Definition: FormPersistenceManagerTest.php:328
‪TYPO3\CMS\Form\Tests\Unit\Mvc\Persistence\FormPersistenceManagerTest\saveThrowsExceptionIfPersistenceIdentifierIsAExtensionLocationAndSaveToExtensionLocationIsNotAllowed
‪saveThrowsExceptionIfPersistenceIdentifierIsAExtensionLocationAndSaveToExtensionLocationIsNotAllowed()
Definition: FormPersistenceManagerTest.php:109
‪TYPO3\CMS\Form\Tests\Unit\Mvc\Persistence\FormPersistenceManagerTest\getUniqueIdentifierThrowsExceptionIfIdentifierExists
‪getUniqueIdentifierThrowsExceptionIfIdentifierExists()
Definition: FormPersistenceManagerTest.php:476
‪TYPO3\CMS\Form\Tests\Unit\Mvc\Persistence\FormPersistenceManagerTest\getUniquePersistenceIdentifierAppendTimestampIfPersistenceIdentifierExists
‪getUniquePersistenceIdentifierAppendTimestampIfPersistenceIdentifierExists()
Definition: FormPersistenceManagerTest.php:443
‪TYPO3\CMS\Form\Tests\Unit\Mvc\Persistence\FormPersistenceManagerTest\isAllowedPersistencePathReturnsPropperValuesDataProvider
‪isAllowedPersistencePathReturnsPropperValuesDataProvider()
Definition: FormPersistenceManagerTest.php:768
‪TYPO3\CMS\Form\Tests\Unit\Mvc\Persistence\FormPersistenceManagerTest\getUniqueIdentifierAppendTimestampIfIdentifierExists
‪getUniqueIdentifierAppendTimestampIfIdentifierExists()
Definition: FormPersistenceManagerTest.php:494
‪TYPO3\CMS\Form\Tests\Unit\Mvc\Persistence\FormPersistenceManagerTest
Definition: FormPersistenceManagerTest.php:35