Skip to content

Commit

Permalink
Merge pull request #45 from boly38/feature/reviewsAuthors
Browse files Browse the repository at this point in the history
multiple reviews and authors
  • Loading branch information
Torann authored Jan 16, 2019
2 parents a85d7f6 + 433d9d6 commit fbcdb41
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 7 deletions.
34 changes: 34 additions & 0 deletions src/ContextTypes/CreativeWork.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,23 @@ protected function setTextAttribute($txt)
return $this->truncate($txt, 260);
}

/**
* Set the authors
*
* @param array $items
* @return array
*/
protected function setAuthorAttribute($items)
{
if (is_array($items) === false) {
return $items;
}

return array_map(function ($item) {
return $this->getNestedContext(Person::class, $item);
}, $items);
}

/**
* Set the comments
*
Expand All @@ -72,4 +89,21 @@ protected function setCommentAttribute($items)
return $this->getNestedContext(Comment::class, $item);
}, $items);
}

/**
* Set the reviews
*
* @param array $items
* @return array
*/
protected function setReviewAttribute($items)
{
if (is_array($items) === false) {
return $items;
}

return array_map(function ($item) {
return $this->getNestedContext(Review::class, $item);
}, $items);
}
}
2 changes: 2 additions & 0 deletions tests/ContextTypes/ArticleTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ class ArticleTest extends TestCase
'thumbnailUrl' => 'https://google.com/thumbnail1.jpg',
'text' => 'Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco.',
'review' => [
'@type' => 'Review',
'reviewRating' => 5,
],
'publisher' => [
Expand Down Expand Up @@ -53,6 +54,7 @@ class ArticleTest extends TestCase
'dateModified' => '2013-10-04T00:00',
'datePublished' => '2013-10-04T00:00',
'author' => [
'@type' => 'Person',
'name' => 'Joe Joe',
],
'mainEntityOfPage' => [
Expand Down
29 changes: 22 additions & 7 deletions tests/ContextTypes/CreativeWorkTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,10 @@ class CreativeWorkTest extends TestCase
'ratingCount' => 4,
],
'author' => [
'name' => 'Joe Joe',
['@type' => 'Person',
'name' => 'Joe Joe'],
['@type' => 'Person',
'name' => 'Jammy Joe'],
],
'creator' => [
'name' => 'Joe Joe',
Expand All @@ -37,7 +40,8 @@ class CreativeWorkTest extends TestCase
]
],
'review' => [
'reviewRating' => 5,
['@type' => 'Review', 'name' => 'first review', 'reviewRating' => 3],
['@type' => 'Review', 'name' => 'second review', 'reviewRating' => 5],
],
'video' => [
"url" => 'https://google.com/thumbnail1.mov',
Expand Down Expand Up @@ -66,16 +70,21 @@ public function shouldHaveAggregateRatingObject()
/**
* @test
*/
public function shouldHaveAuthorObject()
public function shouldHave2AuthorsArray()
{
$context = $this->make();

$this->assertEquals([
'@type' => 'Person',
'name' => 'Joe Joe',
], $context->getProperty('author'));
], $context->getProperty('author')[0]);
$this->assertEquals([
'@type' => 'Person',
'name' => 'Jammy Joe',
], $context->getProperty('author')[1]);
}


/**
* @test
*/
Expand Down Expand Up @@ -126,14 +135,20 @@ public function shouldHavePublisherObject()
/**
* @test
*/
public function shouldHaveReviewObject()
public function shouldHave2ReviewsArray()
{
$context = $this->make();

$this->assertEquals([
'@type' => 'Review',
'reviewRating' => 5,
], $context->getProperty('review'));
'name' => 'first review',
'reviewRating' => 3
], $context->getProperty('review')[0]);
$this->assertEquals([
'@type' => 'Review',
'name' => 'second review',
'reviewRating' => 5
], $context->getProperty('review')[1]);
}

/**
Expand Down

0 comments on commit fbcdb41

Please sign in to comment.