‪TYPO3CMS  ‪main
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 
24 use TYPO3\TestingFramework\Core\Functional\FunctionalTestCase;
25 
26 final class ‪DocumentationFileTest extends FunctionalTestCase
27 {
28  protected bool ‪$initializeDatabase = false;
29 
30  public function ‪setUp(): void
31  {
32  parent::setUp();
33 
34  $content_12345 = [
35  '====',
36  'Breaking: #12345 - Issue',
37  '====',
38  '',
39  'some text content',
40  ];
41  $content_98574 = [
42  '====',
43  'Important: #98574 - Issue',
44  '====',
45  '',
46  'Something else',
47  '',
48  '.. index:: unittest',
49  ];
50  $content_13579 = [
51  '====',
52  'Breaking: #13579 - Issue',
53  '====',
54  '',
55  'Some more content',
56  ];
57  $currentVersion = (int)explode('.', ‪VersionNumberUtility::getNumericTypo3Version())[0];
58  $publicPath = ‪Environment::getPublicPath();
59  mkdir($publicPath . '/Changelog');
60  mkdir($publicPath . '/Changelog/1.2');
61  file_put_contents($publicPath . '/Changelog/1.2/Breaking-12345-Issue.rst', implode("\n", $content_12345));
62  mkdir($publicPath . '/Changelog/2.0');
63  file_put_contents($publicPath . '/Changelog/2.0/Important-98574-Issue.rst', implode("\n", $content_98574));
64  mkdir($publicPath . '/Changelog/' . ($currentVersion - 3) . '.0');
65  file_put_contents($publicPath . '/Changelog/' . ($currentVersion - 3) . '.0/Important-98574-Issue.rst', implode("\n", $content_98574));
66  mkdir($publicPath . '/Changelog/' . ($currentVersion - 2) . '.0');
67  file_put_contents($publicPath . '/Changelog/' . ($currentVersion - 2) . '.0/Important-98574-Issue.rst', implode("\n", $content_98574));
68  mkdir($publicPath . '/Changelog/' . ($currentVersion - 1) . '.0');
69  file_put_contents($publicPath . '/Changelog/' . ($currentVersion - 1) . '.0/Important-98574-Issue.rst', implode("\n", $content_98574));
70  mkdir($publicPath . '/Changelog/' . $currentVersion . '.0');
71  file_put_contents($publicPath . '/Changelog/' . $currentVersion . '.0/Breaking-13579-Issue.rst', implode("\n", $content_13579));
72  file_put_contents($publicPath . '/Changelog/' . $currentVersion . '.0/Important-13579-Issue.rst', implode("\n", $content_13579));
73  file_put_contents($publicPath . '/Changelog/' . $currentVersion . '.0/Index.rst', '');
74  }
75 
76  public function ‪tearDown(): void
77  {
79  parent::tearDown();
80  }
81 
85  public static function ‪invalidDirProvider(): array
86  {
87  return [
88  ['root' => '/'],
89  ['etc' => '/etc'],
90  ['etc/passwd' => '/etc/passwd'],
91  ];
92  }
93 
99  {
100  $this->expectException(\InvalidArgumentException::class);
101  $this->expectExceptionCode(1485425530);
102  $subject = new ‪DocumentationFile();
103  $subject->findDocumentationFiles($path);
104  }
105 
109  public static function ‪invalidFilesProvider(): array
110  {
111  return [
112  ['/etc/passwd' => '/etc/passwd'],
113  ['root' => '/'],
114  ];
115  }
116 
122  {
123  $this->expectException(\InvalidArgumentException::class);
124  $this->expectExceptionCode(1485425531);
125  $subject = new ‪DocumentationFile();
126  $subject->getListEntry($path);
127  }
128 
133  {
134  $currentVersion = (int)explode('.', ‪VersionNumberUtility::getNumericTypo3Version())[0];
135  $expected = [
136  0 => $currentVersion - 2 . '.0',
137  1 => $currentVersion - 1 . '.0',
138  2 => $currentVersion . '.0',
139  ];
140  $subject = new ‪DocumentationFile(‪Environment::getPublicPath() . '/Changelog');
141  self::assertEquals($expected, $subject->findDocumentationDirectories(‪Environment::getPublicPath() . '/Changelog'));
142  }
143 
148  {
149  $currentVersion = (int)explode('.', ‪VersionNumberUtility::getNumericTypo3Version())[0];
150  $subject = new ‪DocumentationFile(‪Environment::getPublicPath() . '/Changelog');
151  self::assertCount(2, $subject->findDocumentationFiles(‪Environment::getPublicPath() . '/Changelog/' . $currentVersion . '.0'));
152  }
153 
158  {
159  $expected = [
160  'unittest',
161  'Important',
162  ];
163  $subject = new ‪DocumentationFile(‪Environment::getPublicPath() . '/Changelog');
164  $result = $subject->findDocumentationFiles(‪Environment::getPublicPath() . '/Changelog/2.0');
165  $firstResult = current($result);
166  self::assertEquals($expected, $firstResult['tags']);
167  }
168 }
‪TYPO3\CMS\Core\Utility\VersionNumberUtility
Definition: VersionNumberUtility.php:26
‪TYPO3\CMS\Install\UpgradeAnalysis\DocumentationFile
Definition: DocumentationFile.php:33
‪TYPO3\CMS\Install\Tests\Functional\UpgradeAnalysis\DocumentationFileTest\invalidFilesProvider
‪static invalidFilesProvider()
Definition: DocumentationFileTest.php:109
‪TYPO3\CMS\Install\Tests\Functional\UpgradeAnalysis\DocumentationFileTest\findDocumentsRespectsFilesWithSameIssueNumber
‪findDocumentsRespectsFilesWithSameIssueNumber()
Definition: DocumentationFileTest.php:147
‪TYPO3\CMS\Core\Core\Environment\getPublicPath
‪static getPublicPath()
Definition: Environment.php:187
‪TYPO3\CMS\Install\Tests\Functional\UpgradeAnalysis\DocumentationFileTest\tearDown
‪tearDown()
Definition: DocumentationFileTest.php:76
‪TYPO3\CMS\Install\Tests\Functional\UpgradeAnalysis\DocumentationFileTest\getListEntryThrowsExceptionForFilesNotBelongToChangelogDir
‪getListEntryThrowsExceptionForFilesNotBelongToChangelogDir(string $path)
Definition: DocumentationFileTest.php:121
‪TYPO3\CMS\Core\Utility\VersionNumberUtility\getNumericTypo3Version
‪static getNumericTypo3Version()
Definition: VersionNumberUtility.php:51
‪TYPO3\CMS\Install\Tests\Functional\UpgradeAnalysis\DocumentationFileTest\extractingTagsProvidesTagsAsDesired
‪extractingTagsProvidesTagsAsDesired()
Definition: DocumentationFileTest.php:157
‪TYPO3\CMS\Install\Tests\Functional\UpgradeAnalysis
Definition: DocumentationFileTest.php:18
‪TYPO3\CMS\Install\Tests\Functional\UpgradeAnalysis\DocumentationFileTest\invalidDirProvider
‪static invalidDirProvider()
Definition: DocumentationFileTest.php:85
‪TYPO3\CMS\Install\Tests\Functional\UpgradeAnalysis\DocumentationFileTest\findDocumentationFilesThrowsExceptionIfPathIsNotInGivenChangelogDir
‪findDocumentationFilesThrowsExceptionIfPathIsNotInGivenChangelogDir(string $path)
Definition: DocumentationFileTest.php:98
‪TYPO3\CMS\Install\Tests\Functional\UpgradeAnalysis\DocumentationFileTest\findDocumentationFilesReturnsArrayOfFilesForTheLastThreeMajorVersions
‪findDocumentationFilesReturnsArrayOfFilesForTheLastThreeMajorVersions()
Definition: DocumentationFileTest.php:132
‪TYPO3\CMS\Core\Core\Environment
Definition: Environment.php:41
‪TYPO3\CMS\Install\Tests\Functional\UpgradeAnalysis\DocumentationFileTest
Definition: DocumentationFileTest.php:27
‪TYPO3\CMS\Core\Utility\GeneralUtility\rmdir
‪static bool rmdir($path, $removeNonEmpty=false)
Definition: GeneralUtility.php:1691
‪TYPO3\CMS\Install\Tests\Functional\UpgradeAnalysis\DocumentationFileTest\$initializeDatabase
‪bool $initializeDatabase
Definition: DocumentationFileTest.php:28
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:51
‪TYPO3\CMS\Install\Tests\Functional\UpgradeAnalysis\DocumentationFileTest\setUp
‪setUp()
Definition: DocumentationFileTest.php:30