Skip to content
This repository was archived by the owner on Apr 29, 2019. It is now read-only.

Commit 2b83742

Browse files
committed
Merge remote-tracking branch 'austin/MAGETWO-75457' into MAGETWO-80201
2 parents 6bb8c45 + 6599fc7 commit 2b83742

File tree

3 files changed

+36
-3
lines changed

3 files changed

+36
-3
lines changed

app/code/Magento/Review/Block/Product/ReviewRenderer.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,10 @@ public function getReviewsSummaryHtml(
5757
$templateType = self::DEFAULT_VIEW,
5858
$displayIfNoReviews = false
5959
) {
60+
if (!$product->getRatingSummary()) {
61+
$this->_reviewFactory->create()->getEntitySummary($product, $this->_storeManager->getStore()->getId());
62+
}
63+
6064
if (!$product->getRatingSummary() && !$displayIfNoReviews) {
6165
return '';
6266
}
@@ -68,9 +72,6 @@ public function getReviewsSummaryHtml(
6872

6973
$this->setDisplayIfEmpty($displayIfNoReviews);
7074

71-
if (!$product->getRatingSummary()) {
72-
$this->_reviewFactory->create()->getEntitySummary($product, $this->_storeManager->getStore()->getId());
73-
}
7475
$this->setProduct($product);
7576

7677
return $this->toHtml();
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
7+
namespace Magento\Review\Block\Product;
8+
9+
class ReviewRendererTest extends \PHPUnit\Framework\TestCase
10+
{
11+
/**
12+
* Test verifies ReviewRenderer::getReviewsSummaryHtml call with $displayIfNoReviews = false
13+
* The reviews summary will be shown as expected only if there is at least one review available
14+
*
15+
* @magentoDataFixture Magento/Review/_files/different_reviews.php
16+
* @magentoAppArea frontend
17+
*/
18+
public function testGetReviewSummaryHtml()
19+
{
20+
$productSku = 'simple';
21+
$objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager();
22+
/** @var \Magento\Catalog\Api\ProductRepositoryInterface $productRepository */
23+
$productRepository = $objectManager->create(\Magento\Catalog\Api\ProductRepositoryInterface::class);
24+
$product = $productRepository->get($productSku);
25+
/** @var ReviewRenderer $reviewRenderer */
26+
$reviewRenderer = $objectManager->create(ReviewRenderer::class);
27+
$actualResult = $reviewRenderer->getReviewsSummaryHtml($product);
28+
$this->assertEquals(2, $reviewRenderer->getReviewsCount());
29+
$this->assertContains('<span itemprop="reviewCount">2</span>', $actualResult);
30+
}
31+
}

dev/tests/integration/testsuite/Magento/Review/_files/different_reviews.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,3 +71,4 @@
7171
)->getStore()->getId()
7272
]
7373
)->save();
74+
$review->aggregate();

0 commit comments

Comments
 (0)