Skip to content

Commit 32d387a

Browse files
committed
More unit testing
1 parent ad1dd00 commit 32d387a

File tree

7 files changed

+111
-11
lines changed

7 files changed

+111
-11
lines changed

css/styles.css

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

scss/_settings.scss

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -275,7 +275,7 @@ $breadcrumbs-item-color-disabled: $medium-gray;
275275
$breadcrumbs-item-margin: 0;
276276
$breadcrumbs-item-uppercase: false;
277277
$breadcrumbs-item-separator: true;
278-
$breadcrumbs-item-separator-item: '/';
278+
$breadcrumbs-item-separator-item: '\\';
279279
$breadcrumbs-item-separator-item-rtl: '\\';
280280
$breadcrumbs-item-separator-color: black;
281281

src/PHPFUI/InstaDoc/Controller.php

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ public function generate(string $directoryPath, array $pagesToInclude = [Control
156156
$directoryPath = str_replace('//', '/', $directoryPath);
157157

158158
// add in the index file
159-
file_put_contents($directoryPath . 'index' . $extension, $this->display());
159+
file_put_contents($directoryPath . 'index' . $extension, $this->display($pagesToInclude));
160160

161161
$namespaces = [];
162162

@@ -170,7 +170,7 @@ public function generate(string $directoryPath, array $pagesToInclude = [Control
170170
{
171171
$parameters[Controller::PAGE] = $page;
172172
$this->setParameters($parameters);
173-
file_put_contents($directoryPath . $this->getUrl($parameters), $this->display());
173+
file_put_contents($directoryPath . $this->getUrl($parameters), $this->display($pagesToInclude));
174174
}
175175
}
176176

@@ -179,7 +179,7 @@ public function generate(string $directoryPath, array $pagesToInclude = [Control
179179
foreach ($namespaces as $namespace => $value)
180180
{
181181
$parameters[Controller::NAMESPACE] = $namespace;
182-
file_put_contents($directoryPath . $this->getUrl($parameters), $this->display());
182+
file_put_contents($directoryPath . $this->getUrl($parameters), $this->display($pagesToInclude));
183183
}
184184

185185
$this->generating = '';
@@ -326,7 +326,7 @@ public function getUrl(array $parameters) : string
326326
{
327327
$url = $this->page->getBaseUrl() . '?' . http_build_query($parameters);
328328

329-
return $url;
329+
return str_replace('\\', '%5C', $url);
330330
}
331331

332332
$parts = [];
@@ -340,6 +340,10 @@ public function getUrl(array $parameters) : string
340340
}
341341

342342
$url = implode('_', $parts) . $this->generating;
343+
while ($url[0] == '_')
344+
{
345+
$url = substr($url, 1);
346+
}
343347

344348
return $url;
345349
}

src/PHPFUI/InstaDoc/NamespaceTree.php

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,32 @@ public static function findNamespace(string $namespace) : NamespaceTree
115115
return $node;
116116
}
117117

118+
/**
119+
* Returns array of all classes
120+
*/
121+
public static function getAllClasses(?NamespaceTree $tree = null) : array
122+
{
123+
if (! $tree)
124+
{
125+
$tree = self::getRoot();
126+
}
127+
128+
$classes = [];
129+
foreach ($tree->children as $child)
130+
{
131+
$classes = array_merge($classes, self::getAllClasses($child));
132+
}
133+
134+
$namespace = $tree->getNamespace();
135+
136+
foreach ($tree->classes as $class => $path)
137+
{
138+
$classes[$path] = $namespace . '\\' . $class;
139+
}
140+
141+
return $classes;
142+
}
143+
118144
/**
119145
* Return an array with full paths of all the classes in the
120146
* namespace, indexed by class name

src/PHPFUI/InstaDoc/Page.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ public function create(\PHPFUI\Menu $menu) : void
7878
$menu = new \PHPFUI\Menu();
7979
$menu->addClass('simple');
8080
$menu->addMenuItem(new \PHPFUI\MenuItem('Powered By'));
81-
$menu->addMenuItem(new \PHPFUI\MenuItem('PHPFUI/InstaDoc', 'http://www.phpfui.com/?n=PHPFUI\InstaDoc'));
81+
$menu->addMenuItem(new \PHPFUI\MenuItem('PHPFUI/InstaDoc', 'http://www.phpfui.com/?n=PHPFUI%5CInstaDoc'));
8282
$menu->addMenuItem(new \PHPFUI\MenuItem('github', 'https://github.com/phpfui/InstaDoc'));
8383

8484
$footer->addLeft($menu);

src/PHPFUI/InstaDoc/Section/Git.php

Lines changed: 31 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,38 @@ public function generate(\PHPFUI\Page $page, string $fullClassPath) : \PHPFUI\Co
1212
$gitPage = $this->controller->getParameter(\PHPFUI\InstaDoc\Controller::GIT_ONPAGE, 0);
1313
$limit = $this->controller->getParameter(\PHPFUI\InstaDoc\Controller::GIT_LIMIT, 20);
1414

15-
$repo = new \Gitonomy\Git\Repository($this->controller->getGitRoot());
16-
$result = $repo->run('show-branch');
15+
try
16+
{
17+
$repo = new \Gitonomy\Git\Repository($this->controller->getGitRoot());
18+
$result = $repo->run('show-branch');
19+
}
20+
catch (\Exception $e)
21+
{
22+
$container->add(new \PHPFUI\SubHeader($this->controller->getGitRoot() . " is not a valid git repo in " . getcwd()));
23+
24+
return $container;
25+
}
26+
1727
$branch = substr($result, strpos($result, '[') + 1, strpos($result, ']') - 1);
18-
$log = $repo->getLog($branch, $fullClassPath, 0, 10);
19-
$count = $log->count();
28+
if (! $branch)
29+
{
30+
$container->add(new \PHPFUI\SubHeader("Invalid branch name: {$branch}"));
31+
32+
return $container;
33+
}
34+
35+
try
36+
{
37+
$log = $repo->getLog($branch, $fullClassPath, 0, 10);
38+
$count = $log->count();
39+
}
40+
catch (\Exception $e)
41+
{
42+
$container->add(new \PHPFUI\SubHeader("Error getting git history on {$branch}:{$fullClassPath}"));
43+
44+
return $container;
45+
}
46+
2047
$lastPage = (int)(($count - 1) / $limit) + 1;
2148

2249
$log->setOffset($gitPage * $limit);

tests/SectionTest.php

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,9 @@ class SectionTest extends \PHPFUI\HTMLUnitTester\Extensions
2121
*/
2222
public function setUp() : void
2323
{
24+
// give us easier to debug line numbers
25+
\PHPFUI\Page::setDebug(1);
26+
2427
$rdi = new \RecursiveDirectoryIterator('src/PHPFUI/InstaDoc/Section');
2528
$iterator = new \RecursiveIteratorIterator($rdi, \RecursiveIteratorIterator::CHILD_FIRST);
2629

@@ -61,5 +64,45 @@ public function testSectionsGenerateValidHTML() : void
6164
}
6265
}
6366

67+
public function testClassesGenerateValidHTML() : void
68+
{
69+
foreach ($this->sections as $section)
70+
{
71+
$this->controller->setParameters($this->controller->getClassParts($section));
72+
73+
foreach ([\PHPFUI\InstaDoc\Controller::DOC_PAGE, \PHPFUI\InstaDoc\Controller::FILE_PAGE, \PHPFUI\InstaDoc\Controller::GIT_PAGE] as $page)
74+
{
75+
$this->controller->setParameter(\PHPFUI\InstaDoc\Controller::PAGE, $page);
76+
$page = $this->controller->display();
77+
$this->assertValidHtml("{$page}");
78+
$this->assertNotWarningHtml("{$page}");
79+
}
80+
81+
// should just display landing page
82+
$this->controller->setParameter(\PHPFUI\InstaDoc\Controller::PAGE, '');
83+
$this->controller->setParameter(\PHPFUI\InstaDoc\Controller::CLASS_NAME, '');
84+
$page = $this->controller->display();
85+
$this->assertValidHtml("{$page}");
86+
$this->assertNotWarningHtml("{$page}");
87+
}
88+
}
89+
90+
public function testHomePage() : void
91+
{
92+
// should just display home page
93+
$this->controller->setParameters([]);
94+
$page = $this->controller->display();
95+
$this->assertValidHtml("{$page}");
96+
$this->assertNotWarningHtml("{$page}");
97+
}
98+
99+
public function testInvalidPage() : void
100+
{
101+
$this->controller->setParameters($this->controller->getClassParts('\\Fred\\Flintstone\\Bedrock'));
102+
$page = $this->controller->display();
103+
$this->assertValidHtml("{$page}");
104+
$this->assertNotWarningHtml("{$page}");
105+
}
106+
64107
}
65108

0 commit comments

Comments
 (0)