From 9321c166206a935b7eddfc3500e9b6e2de548b0b Mon Sep 17 00:00:00 2001 From: Paul Klimov Date: Tue, 13 Aug 2019 14:20:34 +0300 Subject: [PATCH] add `JsonLd::addValues()` --- src/SEOTools/Contracts/JsonLd.php | 7 +++++++ src/SEOTools/JsonLd.php | 12 ++++++++++++ tests/SEOTools/JsonLdTest.php | 17 ++++++++++++++++- 3 files changed, 35 insertions(+), 1 deletion(-) diff --git a/src/SEOTools/Contracts/JsonLd.php b/src/SEOTools/Contracts/JsonLd.php index 3b428a8..f7a2336 100644 --- a/src/SEOTools/Contracts/JsonLd.php +++ b/src/SEOTools/Contracts/JsonLd.php @@ -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 * diff --git a/src/SEOTools/JsonLd.php b/src/SEOTools/JsonLd.php index 6c005ce..06c69f6 100644 --- a/src/SEOTools/JsonLd.php +++ b/src/SEOTools/JsonLd.php @@ -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} */ diff --git a/tests/SEOTools/JsonLdTest.php b/tests/SEOTools/JsonLdTest.php index c4b6225..6ce700b 100644 --- a/tests/SEOTools/JsonLdTest.php +++ b/tests/SEOTools/JsonLdTest.php @@ -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 = ''; + + $this->setRightAssertion($expected); + } + /** - * @param $expectedString + * @param string $expectedString */ protected function setRightAssertion($expectedString) {