[BUGFIX] Hide internal prefix "cat:" in tags of upgrade docs
[Packages/TYPO3.CMS.git] / typo3 / sysext / install / Tests / Unit / UpgradeAnalysis / DocumentationFileTest.php
1 <?php
2 declare(strict_types = 1);
3
4 namespace TYPO3\CMS\Install\Tests\Unit\UpgradeAnalysis;
5
6 /*
7 * This file is part of the TYPO3 CMS project.
8 *
9 * It is free software; you can redistribute it and/or modify it under
10 * the terms of the GNU General Public License, either version 2
11 * of the License, or any later version.
12 *
13 * For the full copyright and license information, please read the
14 * LICENSE.txt file that was distributed with this source code.
15 *
16 * The TYPO3 project - inspiring people to share!
17 */
18
19 use org\bovigo\vfs\vfsStream;
20 use org\bovigo\vfs\vfsStreamDirectory;
21 use Prophecy\Argument;
22 use TYPO3\CMS\Core\Registry;
23 use TYPO3\CMS\Install\UpgradeAnalysis\DocumentationFile;
24
25 class DocumentationFileTest extends \TYPO3\TestingFramework\Core\Unit\UnitTestCase
26 {
27 /**
28 * @var DocumentationFile
29 */
30 protected $documentationFileService;
31
32 /**
33 * @var vfsStreamDirectory
34 */
35 protected $docRoot;
36
37 /**
38 * @var Registry
39 */
40 protected $registry;
41
42 /**
43 * set up test environment
44 */
45 public function setUp()
46 {
47 $content_12345 = [
48 '====',
49 'Breaking: #12345 - Issue',
50 '====',
51 '',
52 'some text content',
53 ];
54 $content_45678 = [
55 '====',
56 'Important: #45678 - Issue',
57 '====',
58 '',
59 'Some more text content',
60 ];
61
62 $content_98574 = [
63 '====',
64 'Important: #98574 - Issue',
65 '====',
66 '',
67 'Something else',
68 '',
69 '.. index:: unittest'
70 ];
71 $content_13579 = [
72 '====',
73 'Breaking: #13579 - Issue',
74 '====',
75 '',
76 'Some more content'
77 ];
78
79 $structure = [
80 'Changelog' => [
81 '1.2' => [
82 'Breaking-12345-Issue.rst' => implode("\n", $content_12345),
83 'Important-45678-Issue.rst' => implode("\n", $content_45678),
84
85 ],
86 '2.0' => [
87 'Important-98574-Issue.rst' => implode("\n", $content_98574),
88 ],
89 'master' => [
90 'Breaking-13579-Issue.rst' => implode("\n", $content_13579),
91 'Important-13579-Issue.rst' => implode("\n", $content_13579),
92 'Index.rst' => '',
93 ],
94 ],
95 ];
96
97 $this->docRoot = vfsStream::setup('root', null, $structure);
98
99 $this->registry = $this->prophesize(Registry::class);
100 $this->documentationFileService = new DocumentationFile(
101 $this->registry->reveal(),
102 vfsStream::url('root/Changelog')
103 );
104 }
105
106 /**
107 * dataprovider with invalid dir path. They should raise an exception and don't process.
108 * @return array
109 */
110 public function invalidDirProvider()
111 {
112 return [
113 [
114 'root' => '/'
115 ],
116 [
117 'etc' => '/etc'
118 ],
119 [
120 'etc/passwd' => '/etc/passwd'
121 ],
122 ];
123 }
124
125 /**
126 * @dataProvider invalidDirProvider
127 * @test
128 */
129 public function findDocumentationFilesThrowsExceptionIfPathIsNotInGivenChangelogDir(string $path)
130 {
131 $this->expectException(\InvalidArgumentException::class);
132 $this->expectExceptionCode(1485425530);
133 $documentationFileService = new DocumentationFile($this->registry->reveal());
134 $documentationFileService->findDocumentationFiles($path);
135 }
136
137 /**
138 * @test
139 */
140 public function findDocumentationFilesReturnsArrayOfFiles()
141 {
142 $expected = [
143 '1.2' => [],
144 '2.0' => [],
145 'master' => [],
146 ];
147
148 $result = $this->documentationFileService->findDocumentationFiles(vfsStream::url('root/Changelog'));
149 self::assertEquals(array_keys($expected), array_keys($result));
150 }
151
152 /**
153 * @test
154 */
155 public function findDocumentsRespectsFilesWithSameIssueNumber()
156 {
157 $result = $this->documentationFileService->findDocumentationFiles(vfsStream::url('root/Changelog'));
158 $this->assertCount(2, $result['master']);
159 }
160
161 /**
162 * @test
163 */
164 public function extractingTagsProvidesTagsAsDesired()
165 {
166 $expected = [
167 'unittest',
168 'Important',
169 ];
170 $result = $this->documentationFileService->findDocumentationFiles(vfsStream::url('root/Changelog'));
171 $key = md5('vfs://root/Changelog/2.0/Important-98574-Issue.rst');
172 self::assertEquals($expected, $result['2.0'][$key]['tags']);
173 }
174
175 /**
176 * @test
177 */
178 public function filesAreFilteredByUsersChoice()
179 {
180 $ignoredFiles = ['vfs://root/Changelog/1.2/Breaking-12345-Issue.rst'];
181 $this->registry->get(
182 'upgradeAnalysisIgnoreFilter',
183 'ignoredDocumentationFiles',
184 Argument::any()
185 )->willReturn($ignoredFiles);
186
187 $result = $this->documentationFileService->findDocumentationFiles(vfsStream::url('root/Changelog'));
188 self::assertArrayNotHasKey(12345, $result['1.2']);
189 }
190
191 /**
192 * @return array
193 */
194 public function invalidFilesProvider(): array
195 {
196 return [
197 ['/etc/passwd' => '/etc/passwd'],
198 ['root' => '/'],
199 ];
200 }
201
202 /**
203 * @dataProvider invalidFilesProvider
204 * @param string $path
205 * @test
206 */
207 public function getListEntryThrowsExceptionForFilesNotBelongToChangelogDir(string $path)
208 {
209 $this->expectException(\InvalidArgumentException::class);
210 $this->expectExceptionCode(1485425531);
211 $this->documentationFileService->getListEntry($path);
212 }
213 }