Skip to content

Commit

Permalink
add JsonLd::addValues() (#164)
Browse files Browse the repository at this point in the history
  • Loading branch information
klimov-paul authored and vinicius73 committed Sep 5, 2019
1 parent c466475 commit 656fb1c
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 1 deletion.
7 changes: 7 additions & 0 deletions src/SEOTools/Contracts/JsonLd.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,13 @@ public function generate($minify = false);
*/
public function addValue($key, $value);

/**
* @param array $values
*
* @return static
*/
public function addValues(array $values);

/**
* @param string $type
*
Expand Down
12 changes: 12 additions & 0 deletions src/SEOTools/JsonLd.php
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,18 @@ public function addValue($key, $value)
return $this;
}

/**
* {@inheritdoc}
*/
public function addValues(array $values)
{
foreach ($values as $key => $value) {
$this->addValue($key, $value);
}

return $this;
}

/**
* {@inheritdoc}
*/
Expand Down
17 changes: 16 additions & 1 deletion tests/SEOTools/JsonLdTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -121,8 +121,23 @@ public function test_array_add_value()
$this->setRightAssertion($expected);
}

public function test_add_values()
{
$this->jsonLd->addValues([
'test' => '1-2-3',
'author' => [
'@type' => 'Organization',
'name' => 'SeoTools',
],
]);

$expected = '<html><head><script type="application/ld+json">{"@context":"https:\/\/schema.org","@type":"WebPage","name":"Over 9000 Thousand!","description":"For those who helped create the Genki Dama","test":"1-2-3","author":{"@type":"Organization","name":"SeoTools"}}</script></head></html>';

$this->setRightAssertion($expected);
}

/**
* @param $expectedString
* @param string $expectedString
*/
protected function setRightAssertion($expectedString)
{
Expand Down

0 comments on commit 656fb1c

Please sign in to comment.