diff --git a/classes/Skin.class.php b/classes/Skin.class.php index b885d924..0ad3cd81 100644 --- a/classes/Skin.class.php +++ b/classes/Skin.class.php @@ -55,7 +55,7 @@ abstract class Skin * @return self * @throws Exception */ - public static function factory(NanoApp $app, $skinName) + public static function factory(NanoApp $app, string $skinName): Skin { $className = sprintf('Skin%s', ucfirst($skinName)); @@ -72,7 +72,7 @@ public static function factory(NanoApp $app, $skinName) * @param NanoApp $app * @param string $skinName */ - public function __construct(NanoApp $app, $skinName) + public function __construct(NanoApp $app, string $skinName) { $this->app = $app; $this->skinName = $skinName; @@ -134,7 +134,7 @@ public function getPageTitle() /** * Add tag entry */ - public function addMeta($name, $value) + public function addMeta(string $name, ?string $value): void { $this->meta[] = [ 'name' => $name, @@ -306,7 +306,7 @@ protected function getAssetsUrls($type) /** * Renders set of elements to be used in page's head section */ - public function renderHead($sep = "\n") + public function renderHead(string $sep = "\n"): string { // render elements $elements = []; @@ -315,7 +315,7 @@ public function renderHead($sep = "\n") $node = ' $value) { - $value = htmlspecialchars($value); + $value = htmlspecialchars($value ?? ''); $node .= " {$name}=\"{$value}\""; } @@ -329,7 +329,7 @@ public function renderHead($sep = "\n") $node = ' $value) { - $value = htmlspecialchars($value); + $value = htmlspecialchars($value ?? ''); $node .= " {$name}=\"{$value}\""; } diff --git a/tests/SkinTest.php b/tests/SkinTest.php new file mode 100644 index 00000000..262a85ae --- /dev/null +++ b/tests/SkinTest.php @@ -0,0 +1,40 @@ +skin = new TestSkin($app, TestSkin::NAME); + } + + public function testRenderHeadNullHandling() + { + $this->skin->addMeta('null', null); + $this->skin->addMeta('empty_string', ''); + $this->skin->addMeta('a_string', 'Foo Bar'); + $this->skin->addMeta('a_number', 42); + + $this->skin->addLink('foo', null); + $this->skin->addLink('bar', 'test', ['type' => 'some/thing']); + + $head = $this->skin->renderHead(); + + $this->assertStringContainsString('', $head, ); + $this->assertStringContainsString('', $head, ); + $this->assertStringContainsString('', $head, ); + $this->assertStringContainsString('', $head, ); + + $this->assertStringContainsString('', $head, ); + $this->assertStringContainsString('', $head, ); + } +}