4562ce6a800a133aef62bde9ffbe26d9ae482131
[Packages/TYPO3.CMS.git] / typo3 / sysext / install / Tests / Unit / UpgradeAnalysis / DocumentationFileTest.php
1 <?php
2 declare(strict_types=1);
3 namespace TYPO3\CMS\Install\Tests\Unit\UpgradeAnalysis;
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
18 use org\bovigo\vfs\vfsStream;
19 use org\bovigo\vfs\vfsStreamDirectory;
20 use TYPO3\CMS\Install\UpgradeAnalysis\DocumentationFile;
21
22 class DocumentationFileTest extends \TYPO3\Components\TestingFramework\Core\Unit\UnitTestCase
23 {
24
25 /**
26 * @var DocumentationFile
27 */
28 protected $documentationFileService;
29
30 /**
31 * @var vfsStreamDirectory
32 */
33 protected $docRoot;
34
35 /**
36 * set up test environment
37 */
38 public function setUp()
39 {
40 $content_12345 = [
41 '====',
42 'Breaking: #12345 - Issue',
43 '====',
44 '',
45 'some text content',
46 ];
47 $content_45678 = [
48 '====',
49 'Important: #45678 - Issue',
50 '====',
51 '',
52 'Some more text content',
53 ];
54
55 $content_98574 = [
56 '====',
57 'Important: #98574 - Issue',
58 '====',
59 '',
60 'Something else',
61 '',
62 '.. index:: unittest'
63 ];
64 $content_13579 = [
65 '====',
66 'Breaking: #13579 - Issue',
67 '====',
68 '',
69 'Some more content'
70 ];
71
72 $structure = [
73 'Changelog' => [
74 '1.2' => [
75 'Breaking-12345-Issue.rst' => implode("\n", $content_12345),
76 'Important-45678-Issue.rst' => implode("\n", $content_45678),
77
78 ],
79 '2.0' => [
80 'Important-98574-Issue.rst' => implode("\n", $content_98574),
81 ],
82 'master' => [
83 'Breaking-13579-Issue.rst' => implode("\n", $content_13579),
84 'Index.rst' => '',
85 ],
86 ],
87 ];
88
89 $this->docRoot = vfsStream::setup('root', null, $structure);
90 $this->documentationFileService = new DocumentationFile();
91 }
92
93 /**
94 * @test
95 */
96 public function findDocumentationFilesReturnsArrayOfFiles()
97 {
98 $expected = [
99 '1.2' => [],
100 '2.0' => [],
101 'master' => [],
102 ];
103
104 $result = $this->documentationFileService->findDocumentationFiles(vfsStream::url('root/Changelog'));
105 self::assertEquals(array_keys($expected), array_keys($result));
106 }
107
108 /**
109 * @test
110 */
111 public function extractingTagsProvidesTagsAsDesired()
112 {
113 $expected = [
114 'unittest',
115 'cat:Important',
116 ];
117 $result = $this->documentationFileService->findDocumentationFiles(vfsStream::url('root/Changelog'));
118 self::assertEquals($expected, $result['2.0'][98574]['tags']);
119 }
120 }