Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
customer_review_with_rating.php
Go to the documentation of this file.
1 <?php
8  \Magento\Backend\App\Area\FrontNameResolver::AREA_CODE
9 );
10 
11 require __DIR__ . '/../../../Magento/Customer/_files/customer.php';
12 require __DIR__ . '/../../../Magento/Catalog/_files/product_simple.php';
13 
15  \Magento\Store\Model\StoreManagerInterface::class
16 )->getStore()->getId();
17 
19  \Magento\Review\Model\Review::class,
20  ['data' => [
21  'customer_id' => $customer->getId(),
22  'title' => 'Review Summary',
23  'detail' => 'Review text',
24  'nickname' => 'Nickname',
25  ]]
26 );
27 
28 $review
29  ->setEntityId($review->getEntityIdByCode(\Magento\Review\Model\Review::ENTITY_PRODUCT_CODE))
30  ->setEntityPkValue($product->getId())
31  ->setStatusId(\Magento\Review\Model\Review::STATUS_APPROVED)
32  ->setStoreId($storeId)
33  ->setStores([$storeId])
34  ->save();
35 
36 \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->get(\Magento\Framework\Registry::class)->register(
37  'review_data',
38  $review
39 );
40 
43  \Magento\Review\Model\Rating::class
44 )->getCollection()
45  ->setPageSize(2)
46  ->setCurPage(1);
47 
48 foreach ($ratingCollection as $rating) {
49  $rating->setStores([$storeId])->setIsActive(1)->save();
50 }
51 
52 foreach ($ratingCollection as $rating) {
54  ->create(\Magento\Review\Model\Rating\Option::class)
55  ->getCollection()
56  ->setPageSize(1)
57  ->setCurPage(2)
58  ->addRatingFilter($rating->getId())
59  ->getFirstItem();
60  $rating->setReviewId($review->getId())
61  ->addOptionVote($ratingOption->getId(), $product->getId());
62 }
63 
64 \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->get(\Magento\Framework\Registry::class)->register(
65  'rating_data',
66  $ratingCollection->getFirstItem()
67 );
$customer
Definition: customers.php:11
defined('TESTS_BP')||define('TESTS_BP' __DIR__
Definition: _bootstrap.php:60
$rating
Definition: item.phtml:18