[!!!][TASK] Extract testing framework for TYPO3
[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\CMS\Components\TestingFramework\Core\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 if (!extension_loaded('yaml')) {
53 $this->expectException(ParseErrorException::class);
54 $this->expectExceptionCode(1480195405);
55
56 $mockYamlSource = $this->getAccessibleMock(YamlSource::class, [
57 'dummy',
58 ], [], '', false);
59
60 $input = [
61 'EXT:form/Tests/Unit/Mvc/Configuration/Fixtures/Invalid.yaml'
62 ];
63
64 $mockYamlSource->_call('load', $input);
65 }
66 }
67
68 /**
69 * @test
70 */
71 public function loadThrowsExceptionIfFileToLoadIsNotValidYamlUsePhpExtensionParser()
72 {
73 if (extension_loaded('yaml')) {
74 $this->expectException(ParseErrorException::class);
75 $this->expectExceptionCode(1391894094);
76
77 $mockYamlSource = $this->getAccessibleMock(YamlSource::class, [
78 'dummy',
79 ], [], '', false);
80
81 $input = [
82 'EXT:form/Tests/Unit/Mvc/Configuration/Fixtures/Invalid.yaml'
83 ];
84
85 $mockYamlSource->_call('load', $input);
86 }
87 }
88
89 /**
90 * @test
91 */
92 public function getHeaderFromFileReturnsHeaderPart()
93 {
94 $mockYamlSource = $this->getAccessibleMock(YamlSource::class, [
95 'dummy',
96 ], [], '', false);
97
98 $input = GeneralUtility::getFileAbsFileName('EXT:form/Tests/Unit/Mvc/Configuration/Fixtures/Header.yaml');
99 $expected =
100 '# Header 1
101 # Header 2
102 ';
103
104 $this->assertSame($expected, $mockYamlSource->_call('getHeaderFromFile', $input));
105 }
106 }