This repository was archived by the owner on Apr 29, 2019. It is now read-only.
File tree Expand file tree Collapse file tree 3 files changed +36
-3
lines changed
app/code/Magento/Review/Block/Product
dev/tests/integration/testsuite/Magento/Review Expand file tree Collapse file tree 3 files changed +36
-3
lines changed Original file line number Diff line number Diff line change @@ -57,6 +57,10 @@ public function getReviewsSummaryHtml(
57
57
$ templateType = self ::DEFAULT_VIEW ,
58
58
$ displayIfNoReviews = false
59
59
) {
60
+ if (!$ product ->getRatingSummary ()) {
61
+ $ this ->_reviewFactory ->create ()->getEntitySummary ($ product , $ this ->_storeManager ->getStore ()->getId ());
62
+ }
63
+
60
64
if (!$ product ->getRatingSummary () && !$ displayIfNoReviews ) {
61
65
return '' ;
62
66
}
@@ -68,9 +72,6 @@ public function getReviewsSummaryHtml(
68
72
69
73
$ this ->setDisplayIfEmpty ($ displayIfNoReviews );
70
74
71
- if (!$ product ->getRatingSummary ()) {
72
- $ this ->_reviewFactory ->create ()->getEntitySummary ($ product , $ this ->_storeManager ->getStore ()->getId ());
73
- }
74
75
$ this ->setProduct ($ product );
75
76
76
77
return $ this ->toHtml ();
Original file line number Diff line number Diff line change
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
+ }
Original file line number Diff line number Diff line change 71
71
)->getStore ()->getId ()
72
72
]
73
73
)->save ();
74
+ $ review ->aggregate ();
You can’t perform that action at this time.
0 commit comments