‪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 
20 use PHPUnit\Framework\Attributes\DataProvider;
21 use PHPUnit\Framework\Attributes\Test;
26 use TYPO3\TestingFramework\Core\Functional\FunctionalTestCase;
27 
28 final class ‪DocumentationFileTest extends FunctionalTestCase
29 {
30  protected bool ‪$initializeDatabase = false;
31 
32  public function ‪setUp(): void
33  {
34  parent::setUp();
35 
36  $content_12345 = [
37  '====',
38  'Breaking: #12345 - Issue',
39  '====',
40  '',
41  'some text content',
42  ];
43  $content_98574 = [
44  '====',
45  'Important: #98574 - Issue',
46  '====',
47  '',
48  'Something else',
49  '',
50  '.. index:: unittest',
51  ];
52  $content_13579 = [
53  '====',
54  'Breaking: #13579 - Issue',
55  '====',
56  '',
57  'Some more content',
58  ];
59  $currentVersion = (int)explode('.', ‪VersionNumberUtility::getNumericTypo3Version())[0];
60  $publicPath = ‪Environment::getPublicPath();
61  mkdir($publicPath . '/Changelog');
62  mkdir($publicPath . '/Changelog/1.2');
63  file_put_contents($publicPath . '/Changelog/1.2/Breaking-12345-Issue.rst', implode("\n", $content_12345));
64  mkdir($publicPath . '/Changelog/2.0');
65  file_put_contents($publicPath . '/Changelog/2.0/Important-98574-Issue.rst', implode("\n", $content_98574));
66  mkdir($publicPath . '/Changelog/' . ($currentVersion - 3) . '.0');
67  file_put_contents($publicPath . '/Changelog/' . ($currentVersion - 3) . '.0/Important-98574-Issue.rst', implode("\n", $content_98574));
68  mkdir($publicPath . '/Changelog/' . ($currentVersion - 2) . '.0');
69  file_put_contents($publicPath . '/Changelog/' . ($currentVersion - 2) . '.0/Important-98574-Issue.rst', implode("\n", $content_98574));
70  mkdir($publicPath . '/Changelog/' . ($currentVersion - 1) . '.0');
71  file_put_contents($publicPath . '/Changelog/' . ($currentVersion - 1) . '.0/Important-98574-Issue.rst', implode("\n", $content_98574));
72  mkdir($publicPath . '/Changelog/' . $currentVersion . '.0');
73  file_put_contents($publicPath . '/Changelog/' . $currentVersion . '.0/Breaking-13579-Issue.rst', implode("\n", $content_13579));
74  file_put_contents($publicPath . '/Changelog/' . $currentVersion . '.0/Important-13579-Issue.rst', implode("\n", $content_13579));
75  file_put_contents($publicPath . '/Changelog/' . $currentVersion . '.0/Index.rst', '');
76  }
77 
78  public function ‪tearDown(): void
79  {
81  parent::tearDown();
82  }
83 
87  public static function ‪invalidDirProvider(): array
88  {
89  return [
90  'root' => ['/'],
91  'etc' => ['/etc'],
92  'etc/passwd' => ['/etc/passwd'],
93  ];
94  }
95 
96  #[DataProvider('invalidDirProvider')]
97  #[Test]
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 
117  #[DataProvider('invalidFilesProvider')]
118  #[Test]
120  {
121  $this->expectException(\InvalidArgumentException::class);
122  $this->expectExceptionCode(1485425531);
123  $subject = new ‪DocumentationFile();
124  $subject->getListEntry($path);
125  }
126 
127  #[Test]
129  {
130  $currentVersion = (int)explode('.', ‪VersionNumberUtility::getNumericTypo3Version())[0];
131  $expected = [
132  0 => $currentVersion - 2 . '.0',
133  1 => $currentVersion - 1 . '.0',
134  2 => $currentVersion . '.0',
135  ];
136  $subject = new ‪DocumentationFile(‪Environment::getPublicPath() . '/Changelog');
137  self::assertEquals($expected, $subject->findDocumentationDirectories(‪Environment::getPublicPath() . '/Changelog'));
138  }
139 
140  #[Test]
142  {
143  $currentVersion = (int)explode('.', ‪VersionNumberUtility::getNumericTypo3Version())[0];
144  $subject = new ‪DocumentationFile(‪Environment::getPublicPath() . '/Changelog');
145  self::assertCount(2, $subject->findDocumentationFiles(‪Environment::getPublicPath() . '/Changelog/' . $currentVersion . '.0'));
146  }
147 
148  #[Test]
150  {
151  $expected = [
152  'unittest',
153  'Important',
154  ];
155  $subject = new ‪DocumentationFile(‪Environment::getPublicPath() . '/Changelog');
156  $result = $subject->findDocumentationFiles(‪Environment::getPublicPath() . '/Changelog/2.0');
157  $firstResult = current($result);
158  self::assertEquals($expected, $firstResult['tags']);
159  }
160 }
‪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:141
‪TYPO3\CMS\Core\Core\Environment\getPublicPath
‪static getPublicPath()
Definition: Environment.php:187
‪TYPO3\CMS\Install\Tests\Functional\UpgradeAnalysis\DocumentationFileTest\tearDown
‪tearDown()
Definition: DocumentationFileTest.php:78
‪TYPO3\CMS\Install\Tests\Functional\UpgradeAnalysis\DocumentationFileTest\getListEntryThrowsExceptionForFilesNotBelongToChangelogDir
‪getListEntryThrowsExceptionForFilesNotBelongToChangelogDir(string $path)
Definition: DocumentationFileTest.php:119
‪TYPO3\CMS\Core\Utility\VersionNumberUtility\getNumericTypo3Version
‪static getNumericTypo3Version()
Definition: VersionNumberUtility.php:51
‪TYPO3\CMS\Install\Tests\Functional\UpgradeAnalysis\DocumentationFileTest\extractingTagsProvidesTagsAsDesired
‪extractingTagsProvidesTagsAsDesired()
Definition: DocumentationFileTest.php:149
‪TYPO3\CMS\Install\Tests\Functional\UpgradeAnalysis
Definition: DocumentationFileTest.php:18
‪TYPO3\CMS\Install\Tests\Functional\UpgradeAnalysis\DocumentationFileTest\invalidDirProvider
‪static invalidDirProvider()
Definition: DocumentationFileTest.php:87
‪TYPO3\CMS\Core\Utility\GeneralUtility\rmdir
‪static bool rmdir(string $path, bool $removeNonEmpty=false)
Definition: GeneralUtility.php:1702
‪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:128
‪TYPO3\CMS\Core\Core\Environment
Definition: Environment.php:41
‪TYPO3\CMS\Install\Tests\Functional\UpgradeAnalysis\DocumentationFileTest
Definition: DocumentationFileTest.php:29
‪TYPO3\CMS\Install\Tests\Functional\UpgradeAnalysis\DocumentationFileTest\$initializeDatabase
‪bool $initializeDatabase
Definition: DocumentationFileTest.php:30
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:52
‪TYPO3\CMS\Install\Tests\Functional\UpgradeAnalysis\DocumentationFileTest\setUp
‪setUp()
Definition: DocumentationFileTest.php:32