‪TYPO3CMS  9.5
DocumentationFileTest.php
Go to the documentation of this file.
1 <?php
2 declare(strict_types = 1);
3 
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;
24 use TYPO3\TestingFramework\Core\Unit\UnitTestCase;
25 
26 class ‪DocumentationFileTest extends UnitTestCase
27 {
32 
36  protected ‪$docRoot;
37 
41  protected ‪$registry;
42 
46  public function ‪setUp()
47  {
48  $content_12345 = [
49  '====',
50  'Breaking: #12345 - Issue',
51  '====',
52  '',
53  'some text content',
54  ];
55  $content_45678 = [
56  '====',
57  'Important: #45678 - Issue',
58  '====',
59  '',
60  'Some more text content',
61  ];
62 
63  $content_98574 = [
64  '====',
65  'Important: #98574 - Issue',
66  '====',
67  '',
68  'Something else',
69  '',
70  '.. index:: unittest'
71  ];
72  $content_13579 = [
73  '====',
74  'Breaking: #13579 - Issue',
75  '====',
76  '',
77  'Some more content'
78  ];
79 
80  $structure = [
81  'Changelog' => [
82  '1.2' => [
83  'Breaking-12345-Issue.rst' => implode("\n", $content_12345),
84  'Important-45678-Issue.rst' => implode("\n", $content_45678),
85 
86  ],
87  '2.0' => [
88  'Important-98574-Issue.rst' => implode("\n", $content_98574),
89  ],
90  'master' => [
91  'Breaking-13579-Issue.rst' => implode("\n", $content_13579),
92  'Important-13579-Issue.rst' => implode("\n", $content_13579),
93  'Index.rst' => '',
94  ],
95  ],
96  ];
97 
98  $this->docRoot = vfsStream::setup('root', null, $structure);
99 
100  $this->registry = $this->prophesize(Registry::class);
101  $this->documentationFileService = new ‪DocumentationFile(
102  $this->registry->reveal(),
103  vfsStream::url('root/Changelog')
104  );
105  }
106 
111  public function ‪invalidDirProvider()
112  {
113  return [
114  [
115  'root' => '/'
116  ],
117  [
118  'etc' => '/etc'
119  ],
120  [
121  'etc/passwd' => '/etc/passwd'
122  ],
123  ];
124  }
125 
131  {
132  $this->expectException(\InvalidArgumentException::class);
133  $this->expectExceptionCode(1485425530);
134  ‪$documentationFileService = new ‪DocumentationFile($this->registry->reveal());
136  }
137 
142  {
143  $expected = [
144  '1.2' => [],
145  '2.0' => [],
146  'master' => [],
147  ];
148 
149  $result = $this->documentationFileService->findDocumentationDirectories(vfsStream::url('root/Changelog'));
150  self::assertEquals(array_keys($expected), $result);
151  }
152 
157  {
158  $result = $this->documentationFileService->findDocumentationFiles(vfsStream::url('root/Changelog/master'));
159  $this->assertCount(2, $result);
160  }
161 
166  {
167  $expected = [
168  'unittest',
169  'Important',
170  ];
171  $result = $this->documentationFileService->findDocumentationFiles(vfsStream::url('root/Changelog/2.0'));
172  $key = md5('vfs://root/Changelog/2.0/Important-98574-Issue.rst');
173  self::assertEquals($expected, $result[$key]['tags']);
174  }
175 
179  public function ‪filesAreFilteredByUsersChoice()
180  {
181  $ignoredFiles = ['vfs://root/Changelog/1.2/Breaking-12345-Issue.rst'];
182  $this->registry->get(
183  'upgradeAnalysisIgnoreFilter',
184  'ignoredDocumentationFiles',
185  Argument::any()
186  )->willReturn($ignoredFiles);
187 
188  $result = $this->documentationFileService->findDocumentationFiles(vfsStream::url('root/Changelog/1.2'));
189  self::assertArrayNotHasKey(12345, $result);
190  }
191 
195  public function ‪invalidFilesProvider(): array
196  {
197  return [
198  ['/etc/passwd' => '/etc/passwd'],
199  ['root' => '/'],
200  ];
201  }
202 
209  {
210  $this->expectException(\InvalidArgumentException::class);
211  $this->expectExceptionCode(1485425531);
212  $this->documentationFileService->getListEntry($path);
213  }
214 }
‪TYPO3\CMS\Install\Tests\Unit\UpgradeAnalysis\DocumentationFileTest\$registry
‪Registry $registry
Definition: DocumentationFileTest.php:38
‪TYPO3\CMS\Install\Tests\Unit\UpgradeAnalysis\DocumentationFileTest\findDocumentationFilesThrowsExceptionIfPathIsNotInGivenChangelogDir
‪findDocumentationFilesThrowsExceptionIfPathIsNotInGivenChangelogDir(string $path)
Definition: DocumentationFileTest.php:127
‪TYPO3\CMS\Install\UpgradeAnalysis\DocumentationFile
Definition: DocumentationFile.php:31
‪TYPO3\CMS\Install\Tests\Unit\UpgradeAnalysis\DocumentationFileTest\setUp
‪setUp()
Definition: DocumentationFileTest.php:43
‪TYPO3\CMS\Core\Registry
Definition: Registry.php:32
‪TYPO3\CMS\Install\Tests\Unit\UpgradeAnalysis\DocumentationFileTest\findDocumentsRespectsFilesWithSameIssueNumber
‪findDocumentsRespectsFilesWithSameIssueNumber()
Definition: DocumentationFileTest.php:153
‪TYPO3\CMS\Install\Tests\Unit\UpgradeAnalysis\DocumentationFileTest\$docRoot
‪vfsStreamDirectory $docRoot
Definition: DocumentationFileTest.php:34
‪TYPO3\CMS\Install\Tests\Unit\UpgradeAnalysis\DocumentationFileTest\$documentationFileService
‪DocumentationFile $documentationFileService
Definition: DocumentationFileTest.php:30
‪TYPO3\CMS\Install\UpgradeAnalysis\DocumentationFile\findDocumentationFiles
‪array findDocumentationFiles(string $path)
Definition: DocumentationFile.php:97
‪TYPO3\CMS\Install\Tests\Unit\UpgradeAnalysis\DocumentationFileTest
Definition: DocumentationFileTest.php:27
‪TYPO3\CMS\Install\Tests\Unit\UpgradeAnalysis\DocumentationFileTest\getListEntryThrowsExceptionForFilesNotBelongToChangelogDir
‪getListEntryThrowsExceptionForFilesNotBelongToChangelogDir(string $path)
Definition: DocumentationFileTest.php:205
‪TYPO3\CMS\Install\Tests\Unit\UpgradeAnalysis\DocumentationFileTest\filesAreFilteredByUsersChoice
‪filesAreFilteredByUsersChoice()
Definition: DocumentationFileTest.php:176
‪TYPO3\CMS\Install\Tests\Unit\UpgradeAnalysis\DocumentationFileTest\invalidDirProvider
‪array invalidDirProvider()
Definition: DocumentationFileTest.php:108
‪TYPO3\CMS\Install\Tests\Unit\UpgradeAnalysis\DocumentationFileTest\extractingTagsProvidesTagsAsDesired
‪extractingTagsProvidesTagsAsDesired()
Definition: DocumentationFileTest.php:162
‪TYPO3\CMS\Install\Tests\Unit\UpgradeAnalysis
Definition: DocumentationFileTest.php:4
‪TYPO3\CMS\Install\Tests\Unit\UpgradeAnalysis\DocumentationFileTest\invalidFilesProvider
‪array invalidFilesProvider()
Definition: DocumentationFileTest.php:192
‪TYPO3\CMS\Install\Tests\Unit\UpgradeAnalysis\DocumentationFileTest\findDocumentationFilesReturnsArrayOfFiles
‪findDocumentationFilesReturnsArrayOfFiles()
Definition: DocumentationFileTest.php:138