[SECURITY][TASK] Remove support for native PHP yaml extension
[Packages/TYPO3.CMS.git] / typo3 / sysext / form / Tests / Unit / Mvc / Configuration / YamlSourceTest.php
1 <?php
2 namespace TYPO3\CMS\Form\Tests\Unit\Mvc\Configuration;
3
4 /*
5 * This file is part of the TYPO3 CMS project.
6 *
7 * It is free software; you can redistribute it and/or modify it under
8 * the terms of the GNU General Public License, either version 2
9 * of the License, or any later version.
10 *
11 * For the full copyright and license information, please read the
12 * LICENSE.txt file that was distributed with this source code.
13 *
14 * The TYPO3 project - inspiring people to share!
15 */
16
17 use TYPO3\CMS\Core\Utility\GeneralUtility;
18 use TYPO3\CMS\Form\Mvc\Configuration\Exception\NoSuchFileException;
19 use TYPO3\CMS\Form\Mvc\Configuration\Exception\ParseErrorException;
20 use TYPO3\CMS\Form\Mvc\Configuration\YamlSource;
21
22 /**
23 * Test case
24 */
25 class YamlSourceTest extends \TYPO3\TestingFramework\Core\Unit\UnitTestCase
26 {
27
28 /**
29 * @test
30 */
31 public function loadThrowsExceptionIfFileToLoadNotExists()
32 {
33 $this->expectException(NoSuchFileException::class);
34 $this->expectExceptionCode(1471473378);
35
36 $mockYamlSource = $this->getAccessibleMock(YamlSource::class, [
37 'dummy',
38 ], [], '', false);
39
40 $input = [
41 'EXT:form/Resources/Forms/_example.yaml'
42 ];
43
44 $mockYamlSource->_call('load', $input);
45 }
46
47 /**
48 * @test
49 */
50 public function loadThrowsExceptionIfFileToLoadIsNotValidYamlUseSymfonyParser()
51 {
52 $this->expectException(ParseErrorException::class);
53 $this->expectExceptionCode(1480195405);
54
55 $mockYamlSource = $this->getAccessibleMock(YamlSource::class, [
56 'dummy',
57 ], [], '', false);
58
59 $input = [
60 'EXT:form/Tests/Unit/Mvc/Configuration/Fixtures/Invalid.yaml'
61 ];
62
63 $mockYamlSource->_call('load', $input);
64 }
65
66 /**
67 * @test
68 */
69 public function getHeaderFromFileReturnsHeaderPart()
70 {
71 $mockYamlSource = $this->getAccessibleMock(YamlSource::class, [
72 'dummy',
73 ], [], '', false);
74
75 $input = GeneralUtility::getFileAbsFileName('EXT:form/Tests/Unit/Mvc/Configuration/Fixtures/Header.yaml');
76 $expected =
77 '# Header 1
78 # Header 2
79 ';
80
81 $this->assertSame($expected, $mockYamlSource->_call('getHeaderFromFile', $input));
82 }
83
84 /**
85 * @test
86 */
87 public function loadOverruleNonArrayValuesOverArrayValues()
88 {
89 $mockYamlSource = $this->getAccessibleMock(YamlSource::class, ['dummy'], [], '', false);
90
91 $input = [
92 'EXT:form/Tests/Unit/Mvc/Configuration/Fixtures/OverruleNonArrayValuesOverArrayValues1.yaml',
93 'EXT:form/Tests/Unit/Mvc/Configuration/Fixtures/OverruleNonArrayValuesOverArrayValues2.yaml'
94 ];
95
96 $expected = [
97 'Form' => [
98 'klaus01' => null,
99 'key03' => 'value2',
100 ],
101 ];
102
103 $this->assertSame($expected, $mockYamlSource->_call('load', $input));
104 }
105 }