‪TYPO3CMS  10.4
DocumentationFileTest.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 
20 use org\bovigo\vfs\vfsStream;
21 use org\bovigo\vfs\vfsStreamDirectory;
22 use Prophecy\Argument;
26 use TYPO3\TestingFramework\Core\Unit\UnitTestCase;
27 
28 class ‪DocumentationFileTest extends UnitTestCase
29 {
34 
38  protected ‪$docRoot;
39 
43  protected ‪$registry;
44 
48  public function ‪setUp(): void
49  {
50  parent::setUp();
51  $content_12345 = [
52  '====',
53  'Breaking: #12345 - Issue',
54  '====',
55  '',
56  'some text content',
57  ];
58  $content_45678 = [
59  '====',
60  'Important: #45678 - Issue',
61  '====',
62  '',
63  'Some more text content',
64  ];
65 
66  $content_98574 = [
67  '====',
68  'Important: #98574 - Issue',
69  '====',
70  '',
71  'Something else',
72  '',
73  '.. index:: unittest'
74  ];
75  $content_13579 = [
76  '====',
77  'Breaking: #13579 - Issue',
78  '====',
79  '',
80  'Some more content'
81  ];
82 
83  $currentVersion = (int)explode('.', ‪VersionNumberUtility::getNumericTypo3Version())[0];
84  $structure = [
85  'Changelog' => [
86  '1.2' => [
87  'Breaking-12345-Issue.rst' => implode("\n", $content_12345),
88  'Important-45678-Issue.rst' => implode("\n", $content_45678),
89 
90  ],
91  '2.0' => [
92  'Important-98574-Issue.rst' => implode("\n", $content_98574),
93  ],
94  $currentVersion-3 . '.0' => [
95  'Important-98574-Issue.rst' => implode("\n", $content_98574),
96  ],
97  $currentVersion-2 . '.0' => [
98  'Important-98574-Issue.rst' => implode("\n", $content_98574),
99  ],
100  $currentVersion-1 . '.0' => [
101  'Important-98574-Issue.rst' => implode("\n", $content_98574),
102  ],
103  $currentVersion . '.0' => [
104  'Important-98574-Issue.rst' => implode("\n", $content_98574),
105  ],
106  'master' => [
107  'Breaking-13579-Issue.rst' => implode("\n", $content_13579),
108  'Important-13579-Issue.rst' => implode("\n", $content_13579),
109  'Index.rst' => '',
110  ],
111  ],
112  ];
113 
114  $this->docRoot = vfsStream::setup('root', null, $structure);
115 
116  $this->registry = $this->prophesize(Registry::class);
117  $this->documentationFileService = new ‪DocumentationFile(
118  $this->registry->reveal(),
119  vfsStream::url('root/Changelog')
120  );
121  }
122 
127  public function ‪invalidDirProvider()
128  {
129  return [
130  [
131  'root' => '/'
132  ],
133  [
134  'etc' => '/etc'
135  ],
136  [
137  'etc/passwd' => '/etc/passwd'
138  ],
139  ];
140  }
141 
147  {
148  $this->expectException(\InvalidArgumentException::class);
149  $this->expectExceptionCode(1485425530);
150  ‪$documentationFileService = new ‪DocumentationFile($this->registry->reveal());
152  }
153 
158  {
159  $currentVersion = (int)explode('.', ‪VersionNumberUtility::getNumericTypo3Version())[0];
160  $expected = [
161  $currentVersion-2 . '.0' => [],
162  $currentVersion-1 . '.0' => [],
163  $currentVersion . '.0' => [],
164  'master' => [],
165  ];
166 
167  $result = $this->documentationFileService->findDocumentationDirectories(vfsStream::url('root/Changelog'));
168  self::assertEquals(array_keys($expected), $result);
169  }
170 
175  {
176  $result = $this->documentationFileService->findDocumentationFiles(vfsStream::url('root/Changelog/master'));
177  self::assertCount(2, $result);
178  }
179 
184  {
185  $expected = [
186  'unittest',
187  'Important',
188  ];
189  $result = $this->documentationFileService->findDocumentationFiles(vfsStream::url('root/Changelog/2.0'));
190  $firstResult = current($result);
191  self::assertEquals($expected, $firstResult['tags']);
192  }
193 
197  public function ‪filesAreFilteredByUsersChoice()
198  {
199  $ignoredFiles = ['vfs://root/Changelog/1.2/Breaking-12345-Issue.rst'];
200  $this->registry->get(
201  'upgradeAnalysisIgnoreFilter',
202  'ignoredDocumentationFiles',
203  Argument::any()
204  )->willReturn($ignoredFiles);
205 
206  $result = $this->documentationFileService->findDocumentationFiles(vfsStream::url('root/Changelog/1.2'));
207  self::assertArrayNotHasKey(12345, $result);
208  }
209 
213  public function ‪invalidFilesProvider(): array
214  {
215  return [
216  ['/etc/passwd' => '/etc/passwd'],
217  ['root' => '/'],
218  ];
219  }
220 
227  {
228  $this->expectException(\InvalidArgumentException::class);
229  $this->expectExceptionCode(1485425531);
230  $this->documentationFileService->getListEntry($path);
231  }
232 }
‪TYPO3\CMS\Core\Utility\VersionNumberUtility
Definition: VersionNumberUtility.php:25
‪TYPO3\CMS\Install\Tests\Unit\UpgradeAnalysis\DocumentationFileTest\$registry
‪Registry $registry
Definition: DocumentationFileTest.php:40
‪TYPO3\CMS\Install\Tests\Unit\UpgradeAnalysis\DocumentationFileTest\findDocumentationFilesThrowsExceptionIfPathIsNotInGivenChangelogDir
‪findDocumentationFilesThrowsExceptionIfPathIsNotInGivenChangelogDir(string $path)
Definition: DocumentationFileTest.php:143
‪TYPO3\CMS\Core\Utility\VersionNumberUtility\getNumericTypo3Version
‪static string getNumericTypo3Version()
Definition: VersionNumberUtility.php:107
‪TYPO3\CMS\Install\UpgradeAnalysis\DocumentationFile
Definition: DocumentationFile.php:33
‪TYPO3\CMS\Install\Tests\Unit\UpgradeAnalysis\DocumentationFileTest\setUp
‪setUp()
Definition: DocumentationFileTest.php:45
‪TYPO3\CMS\Core\Registry
Definition: Registry.php:33
‪TYPO3\CMS\Install\Tests\Unit\UpgradeAnalysis\DocumentationFileTest\findDocumentsRespectsFilesWithSameIssueNumber
‪findDocumentsRespectsFilesWithSameIssueNumber()
Definition: DocumentationFileTest.php:171
‪TYPO3\CMS\Install\Tests\Unit\UpgradeAnalysis\DocumentationFileTest\$docRoot
‪vfsStreamDirectory $docRoot
Definition: DocumentationFileTest.php:36
‪TYPO3\CMS\Install\Tests\Unit\UpgradeAnalysis\DocumentationFileTest\$documentationFileService
‪DocumentationFile $documentationFileService
Definition: DocumentationFileTest.php:32
‪TYPO3\CMS\Install\UpgradeAnalysis\DocumentationFile\findDocumentationFiles
‪array findDocumentationFiles(string $path)
Definition: DocumentationFile.php:103
‪TYPO3\CMS\Install\Tests\Unit\UpgradeAnalysis\DocumentationFileTest
Definition: DocumentationFileTest.php:29
‪TYPO3\CMS\Install\Tests\Unit\UpgradeAnalysis\DocumentationFileTest\getListEntryThrowsExceptionForFilesNotBelongToChangelogDir
‪getListEntryThrowsExceptionForFilesNotBelongToChangelogDir(string $path)
Definition: DocumentationFileTest.php:223
‪TYPO3\CMS\Install\Tests\Unit\UpgradeAnalysis\DocumentationFileTest\filesAreFilteredByUsersChoice
‪filesAreFilteredByUsersChoice()
Definition: DocumentationFileTest.php:194
‪TYPO3\CMS\Install\Tests\Unit\UpgradeAnalysis\DocumentationFileTest\findDocumentationFilesReturnsArrayOfFilesForTheLastThreeMajorVersions
‪findDocumentationFilesReturnsArrayOfFilesForTheLastThreeMajorVersions()
Definition: DocumentationFileTest.php:154
‪TYPO3\CMS\Install\Tests\Unit\UpgradeAnalysis\DocumentationFileTest\invalidDirProvider
‪array invalidDirProvider()
Definition: DocumentationFileTest.php:124
‪TYPO3\CMS\Install\Tests\Unit\UpgradeAnalysis\DocumentationFileTest\extractingTagsProvidesTagsAsDesired
‪extractingTagsProvidesTagsAsDesired()
Definition: DocumentationFileTest.php:180
‪TYPO3\CMS\Install\Tests\Unit\UpgradeAnalysis
Definition: DocumentationFileTest.php:18
‪TYPO3\CMS\Install\Tests\Unit\UpgradeAnalysis\DocumentationFileTest\invalidFilesProvider
‪array invalidFilesProvider()
Definition: DocumentationFileTest.php:210