Skip to content

Commit 8ff6626

Browse files
committed
Verify invalid info link
1 parent 7a866dd commit 8ff6626

2 files changed

Lines changed: 62 additions & 1 deletion

File tree

src/Views/debugbar/debugbar.php

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,17 @@ class_exists('Aplus')
3838
<?= Debugger::roundVersion(\PHP_VERSION) ?>.
3939
</p>
4040
<p>★
41-
<?php if (isset($options['info_link'])): ?>
41+
<?php
42+
$hasInfoLink = isset($options['info_link']);
43+
if ($hasInfoLink) {
44+
if(!isset($options['info_link']['href'])
45+
|| !isset($options['info_link']['text'])
46+
) {
47+
throw new LogicException('Info link must contain "href" and "text" keys');
48+
}
49+
}
50+
?>
51+
<?php if ($hasInfoLink): ?>
4252
<a href="<?= $options['info_link']['href'] ?>"
4353
target="_blank"><?= $options['info_link']['text'] ?>
4454
</a>

tests/DebuggerTest.php

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -239,6 +239,57 @@ public function testInfoLinkOption() : void
239239
self::assertStringContainsString('Foo Website', $debugbar);
240240
}
241241

242+
public function testInvalidInfoLinkOption() : void
243+
{
244+
$this->debugger->setOption('info_link', []);
245+
try {
246+
$this->debugger->renderDebugbar();
247+
} catch (\LogicException $e) {
248+
self::assertSame(
249+
'Info link must contain "href" and "text" keys',
250+
$e->getMessage()
251+
);
252+
}
253+
if (\ob_get_level()) {
254+
\ob_end_clean();
255+
}
256+
$this->debugger->setOption('info_link', [
257+
'href' => '#',
258+
]);
259+
try {
260+
$this->debugger->renderDebugbar();
261+
} catch (\LogicException $e) {
262+
self::assertSame(
263+
'Info link must contain "href" and "text" keys',
264+
$e->getMessage()
265+
);
266+
}
267+
if (\ob_get_level()) {
268+
\ob_end_clean();
269+
}
270+
$this->debugger->setOption('info_link', [
271+
'text' => '#',
272+
]);
273+
try {
274+
$this->debugger->renderDebugbar();
275+
} catch (\LogicException $e) {
276+
self::assertSame(
277+
'Info link must contain "href" and "text" keys',
278+
$e->getMessage()
279+
);
280+
}
281+
if (\ob_get_level()) {
282+
\ob_end_clean();
283+
}
284+
$this->debugger->setOption('info_link', [
285+
'href' => 'https://foo.com',
286+
'text' => 'Foo Website',
287+
]);
288+
$debugbar = $this->debugger->renderDebugbar();
289+
self::assertStringContainsString('https://foo.com', $debugbar);
290+
self::assertStringContainsString('Foo Website', $debugbar);
291+
}
292+
242293
public function testMakeSafeName() : void
243294
{
244295
self::assertSame(

0 commit comments

Comments
 (0)