TYPO3 CMS  TYPO3_8-7
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 
24 
25 class DocumentationFileTest extends \TYPO3\TestingFramework\Core\Unit\UnitTestCase
26 {
31 
35  protected $docRoot;
36 
40  protected $registry;
41 
45  public function setUp()
46  {
47  $content_12345 = [
48  '====',
49  'Breaking: #12345 - Issue',
50  '====',
51  '',
52  'some text content',
53  ];
54  $content_45678 = [
55  '====',
56  'Important: #45678 - Issue',
57  '====',
58  '',
59  'Some more text content',
60  ];
61 
62  $content_98574 = [
63  '====',
64  'Important: #98574 - Issue',
65  '====',
66  '',
67  'Something else',
68  '',
69  '.. index:: unittest'
70  ];
71  $content_13579 = [
72  '====',
73  'Breaking: #13579 - Issue',
74  '====',
75  '',
76  'Some more content'
77  ];
78 
79  $structure = [
80  'Changelog' => [
81  '1.2' => [
82  'Breaking-12345-Issue.rst' => implode("\n", $content_12345),
83  'Important-45678-Issue.rst' => implode("\n", $content_45678),
84 
85  ],
86  '2.0' => [
87  'Important-98574-Issue.rst' => implode("\n", $content_98574),
88  ],
89  'master' => [
90  'Breaking-13579-Issue.rst' => implode("\n", $content_13579),
91  'Important-13579-Issue.rst' => implode("\n", $content_13579),
92  'Index.rst' => '',
93  ],
94  ],
95  ];
96 
97  $this->docRoot = vfsStream::setup('root', null, $structure);
98 
99  $this->registry = $this->prophesize(Registry::class);
100  $this->documentationFileService = new DocumentationFile(
101  $this->registry->reveal(),
102  vfsStream::url('root/Changelog')
103  );
104  }
105 
110  public function invalidDirProvider()
111  {
112  return [
113  [
114  'root' => '/'
115  ],
116  [
117  'etc' => '/etc'
118  ],
119  [
120  'etc/passwd' => '/etc/passwd'
121  ],
122  ];
123  }
124 
130  {
131  $this->expectException(\InvalidArgumentException::class);
132  $this->expectExceptionCode(1485425530);
133  $documentationFileService = new DocumentationFile($this->registry->reveal());
134  $documentationFileService->findDocumentationFiles($path);
135  }
136 
141  {
142  $expected = [
143  '1.2' => [],
144  '2.0' => [],
145  'master' => [],
146  ];
147 
148  $result = $this->documentationFileService->findDocumentationFiles(vfsStream::url('root/Changelog'));
149  self::assertEquals(array_keys($expected), array_keys($result));
150  }
151 
156  {
157  $result = $this->documentationFileService->findDocumentationFiles(vfsStream::url('root/Changelog'));
158  $this->assertCount(2, $result['master']);
159  }
160 
165  {
166  $expected = [
167  'unittest',
168  'Important',
169  ];
170  $result = $this->documentationFileService->findDocumentationFiles(vfsStream::url('root/Changelog'));
171  $key = md5('vfs://root/Changelog/2.0/Important-98574-Issue.rst');
172  self::assertEquals($expected, $result['2.0'][$key]['tags']);
173  }
174 
179  {
180  $ignoredFiles = ['vfs://root/Changelog/1.2/Breaking-12345-Issue.rst'];
181  $this->registry->get(
182  'upgradeAnalysisIgnoreFilter',
183  'ignoredDocumentationFiles',
184  Argument::any()
185  )->willReturn($ignoredFiles);
186 
187  $result = $this->documentationFileService->findDocumentationFiles(vfsStream::url('root/Changelog'));
188  self::assertArrayNotHasKey(12345, $result['1.2']);
189  }
190 
194  public function invalidFilesProvider(): array
195  {
196  return [
197  ['/etc/passwd' => '/etc/passwd'],
198  ['root' => '/'],
199  ];
200  }
201 
208  {
209  $this->expectException(\InvalidArgumentException::class);
210  $this->expectExceptionCode(1485425531);
211  $this->documentationFileService->getListEntry($path);
212  }
213 }