-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathSectionTest.php
137 lines (117 loc) · 4.44 KB
/
SectionTest.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
<?php
/**
* This file is part of the PHPFUI\InstaDoc package
*
* (c) Bruce Wells
*
* For the full copyright and license information, please view
* the LICENSE.md file that was distributed with this source
* code
*/
class SectionTest extends \PHPFUI\HTMLUnitTester\Extensions
{
private $controller;
private $fileManager;
private array $sections = [];
/**
* Get all sections and save for later use
*/
public function setUp() : void
{
// give us easier to debug line numbers
\PHPFUI\Page::setDebug(1);
$rdi = new \RecursiveDirectoryIterator('src/PHPFUI/InstaDoc/Section');
$iterator = new \RecursiveIteratorIterator($rdi, \RecursiveIteratorIterator::CHILD_FIRST);
foreach ($iterator as $filename => $fileInfo)
{
if (! $fileInfo->isDir())
{
$path = \str_replace('/', '\\', \str_replace('.php', '', $filename));
$parts = \explode('\\', $path);
while (\count($parts) && 'src' != \array_shift($parts))
{
// leave part on floor, not needed
}
$this->sections[] = \implode('\\', $parts);
}
}
$this->fileManager = new \PHPFUI\InstaDoc\FileManager('./');
$this->fileManager->excludeNamespace('cebe');
$this->fileManager->addNamespace('PHPFUI', './src', true);
$this->fileManager->rescan();
$this->controller = new \PHPFUI\InstaDoc\Controller($this->fileManager);
$this->controller->setGitFileOffset('src');
}
public function testClassesGenerateValidHTML() : void
{
foreach ($this->sections as $section)
{
$this->controller->setParameters($this->controller->getClassParts($section));
foreach ([\PHPFUI\InstaDoc\Controller::DOC_PAGE, \PHPFUI\InstaDoc\Controller::FILE_PAGE, \PHPFUI\InstaDoc\Controller::GIT_PAGE] as $type)
{
$this->controller->setParameter(\PHPFUI\InstaDoc\Controller::PAGE, $type);
$parts = \explode('\\', $section);
$this->controller->setParameter(\PHPFUI\InstaDoc\Controller::CLASS_NAME, \array_pop($parts));
$page = $this->controller->display(\PHPFUI\InstaDoc\Controller::VALID_CLASS_PAGES, $this->controller->getPage());
$this->assertValidHtml("{$page}");
$this->assertNotWarningHtml("{$page}");
}
// should just display landing page
$this->controller->setParameter(\PHPFUI\InstaDoc\Controller::PAGE, '');
$this->controller->setParameter(\PHPFUI\InstaDoc\Controller::CLASS_NAME, '');
$page = $this->controller->display(\PHPFUI\InstaDoc\Controller::VALID_CLASS_PAGES, $this->controller->getPage());
$this->assertValidHtml("{$page}");
$this->assertNotWarningHtml("{$page}");
}
}
public function testHaveSections() : void
{
$this->assertNotEmpty($this->sections, 'No PHPFUI\InstaDoc\Section classes found');
}
public function testHomePage() : void
{
// should just display home page
$this->controller->setParameters([]);
$page = $this->controller->display(\PHPFUI\InstaDoc\Controller::VALID_CLASS_PAGES, $this->controller->getPage());
$this->assertValidHtml("{$page}");
$this->assertNotWarningHtml("{$page}");
}
public function testInvalidPage() : void
{
$this->controller->setParameters($this->controller->getClassParts('\\Fred\\Flintstone\\Bedrock'));
$page = $this->controller->display(\PHPFUI\InstaDoc\Controller::VALID_CLASS_PAGES, $this->controller->getPage());
$this->assertValidHtml("{$page}");
}
public function testMarkDown() : void
{
$parser = new \PHPFUI\InstaDoc\MarkDownParser();
$html = $parser->fileText(__DIR__ . '/../README.md');
$this->assertValidHtml("{$html}");
$this->assertNotWarningHtml("{$html}");
$this->assertStringNotContainsStringIgnoringCase('simple_html_dom__voku__html_wrapper', $html);
}
public function testSectionsGenerateValidHTML() : void
{
$page = new \PHPFUI\InstaDoc\Page($this->controller);
foreach ($this->sections as $section)
{
$sectionObject = new $section($this->controller);
$container = $sectionObject->generate($page, $section . '.php');
$this->assertValidHtml("{$container}");
}
}
public function testTestClass() : void
{
$runningPHPVersion = PHP_MAJOR_VERSION * 10 + PHP_MINOR_VERSION;
foreach ([82, 81, 80, 74, 73, 72, 71] as $phpVersion)
{
if ($runningPHPVersion >= $phpVersion)
{
$this->controller->setParameters($this->controller->getClassParts('\\PHPFUI\\InstaDoc\\Tests\\Test' . $phpVersion));
$page = $this->controller->display(\PHPFUI\InstaDoc\Controller::VALID_CLASS_PAGES, $this->controller->getPage());
$this->assertValidHtml("{$page}");
$this->assertNotWarningHtml("{$page}");
}
}
}
}