Skip to content

Commit

Permalink
JsonLdMulti - Remove requirement for 2 items (#276)
Browse files Browse the repository at this point in the history
* Bug - JsonLdMulti - Remove requirement for 2 items

Issue #275

* JsonLdMulti - Add unit test for single record output

Implementing unit test for single record output
  • Loading branch information
J-Brk authored Jul 19, 2022
1 parent 55746e0 commit 1342849
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
8 changes: 3 additions & 5 deletions src/SEOTools/JsonLdMulti.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,9 @@ public function __construct(array $defaultJsonLdData = [])
*/
public function generate($minify = false)
{
if (count($this->list) > 1) {
return array_reduce($this->list, function (string $output, JsonLd $jsonLd) {
return $output . (! $jsonLd->isEmpty() ? $jsonLd->generate() : '');
}, '');
}
return array_reduce($this->list, function (string $output, JsonLd $jsonLd) {
return $output . (! $jsonLd->isEmpty() ? $jsonLd->generate() : '');
}, '');
}

/**
Expand Down
9 changes: 9 additions & 0 deletions tests/SEOTools/JsonLdMultiTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,15 @@ protected function setUp(): void
$this->jsonLdMulti->newJsonLd();
}

public function test_single_instance()
{
$jsonLdSingle = new JsonLdMulti();

$expected = '<html><head>' . $this->defaultJsonLdHtml . '</head></html>';

$this->assertEquals($this->makeDomDocument($expected)->C14N(), $this->makeDomDocument($jsonLdSingle->generate())->C14N());
}

public function test_set_title()
{
$this->jsonLdMulti->setTitle('Kamehamehaaaaaaaa');
Expand Down

0 comments on commit 1342849

Please sign in to comment.