Skip to content

Commit 1342849

Browse files
authored
JsonLdMulti - Remove requirement for 2 items (#276)
* Bug - JsonLdMulti - Remove requirement for 2 items Issue #275 * JsonLdMulti - Add unit test for single record output Implementing unit test for single record output
1 parent 55746e0 commit 1342849

File tree

2 files changed

+12
-5
lines changed

2 files changed

+12
-5
lines changed

src/SEOTools/JsonLdMulti.php

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -47,11 +47,9 @@ public function __construct(array $defaultJsonLdData = [])
4747
*/
4848
public function generate($minify = false)
4949
{
50-
if (count($this->list) > 1) {
51-
return array_reduce($this->list, function (string $output, JsonLd $jsonLd) {
52-
return $output . (! $jsonLd->isEmpty() ? $jsonLd->generate() : '');
53-
}, '');
54-
}
50+
return array_reduce($this->list, function (string $output, JsonLd $jsonLd) {
51+
return $output . (! $jsonLd->isEmpty() ? $jsonLd->generate() : '');
52+
}, '');
5553
}
5654

5755
/**

tests/SEOTools/JsonLdMultiTest.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,15 @@ protected function setUp(): void
3030
$this->jsonLdMulti->newJsonLd();
3131
}
3232

33+
public function test_single_instance()
34+
{
35+
$jsonLdSingle = new JsonLdMulti();
36+
37+
$expected = '<html><head>' . $this->defaultJsonLdHtml . '</head></html>';
38+
39+
$this->assertEquals($this->makeDomDocument($expected)->C14N(), $this->makeDomDocument($jsonLdSingle->generate())->C14N());
40+
}
41+
3342
public function test_set_title()
3443
{
3544
$this->jsonLdMulti->setTitle('Kamehamehaaaaaaaa');

0 commit comments

Comments
 (0)