Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
UpdateProductReviewEntityOnProductPageTest.php
Go to the documentation of this file.
1 <?php
8 
9 use Magento\Catalog\Test\Page\Adminhtml\CatalogProductEdit;
11 use Magento\Review\Test\Page\Adminhtml\RatingEdit;
12 use Magento\Review\Test\Page\Adminhtml\RatingIndex;
13 use Magento\Review\Test\Page\Adminhtml\ReviewEdit;
14 use Magento\Mtf\Fixture\FixtureFactory;
15 use Magento\Mtf\TestCase\Injectable;
16 
36 {
37  /* tags */
38  const MVP = 'no';
39  /* end tags */
40 
47 
53  protected $ratingIndex;
54 
60  protected $ratingEdit;
61 
67  protected $reviewInitial;
68 
74  protected $reviewEdit;
75 
81  protected $fixtureFactory;
82 
89  public function __prepare(FixtureFactory $fixtureFactory)
90  {
91  $this->reviewInitial = $fixtureFactory->createByCode(
92  'review',
93  ['dataset' => 'review_for_simple_product_with_rating']
94  );
95  $this->reviewInitial->persist();
96  $this->fixtureFactory = $fixtureFactory;
97  }
98 
108  public function __inject(
109  RatingIndex $ratingIndex,
110  RatingEdit $ratingEdit,
111  CatalogProductEdit $catalogProductEdit,
112  ReviewEdit $reviewEdit
113  ) {
114  $this->ratingIndex = $ratingIndex;
115  $this->ratingEdit = $ratingEdit;
116  $this->catalogProductEdit = $catalogProductEdit;
117  $this->reviewEdit = $reviewEdit;
118  }
119 
127  public function test(Review $review, $rating)
128  {
129  // Steps
130  $review = $this->createReview($review, $rating);
131  $product = $this->reviewInitial->getDataFieldConfig('entity_id')['source']->getEntity();
132  $this->objectManager->create(
133  \Magento\Catalog\Test\TestStep\OpenProductOnBackendStep::class,
134  ['product' => $product]
135  )->run();
136 
137  $this->catalogProductEdit->getProductForm()->openSection('product_reviews');
138  $filter = [
139  'title' => $this->reviewInitial->getTitle(),
140  'sku' => $product->getSku(),
141  ];
142  $this->catalogProductEdit->getProductForm()->getSection('product_reviews')->getReviewsGrid()
143  ->searchAndOpen($filter);
144  $this->reviewEdit->getReviewForm()->fill($review);
145  $this->reviewEdit->getPageActions()->save();
146  $productRating = $this->reviewInitial->getDataFieldConfig('ratings')['source']->getRatings()[0];
147 
148  return ['product' => $product, 'productRating' => $productRating];
149  }
150 
158  protected function createReview($review, $rating)
159  {
160  $reviewData = $review->getData();
161  $fixtureRating = $this->reviewInitial->getDataFieldConfig('ratings')['source']->getRatings()[0];
162  $reviewData['ratings'][0] = ['fixtureRating' => $fixtureRating, 'rating' => $rating];
163 
164  return $this->fixtureFactory->createByCode('review', ['data' => $reviewData]);
165  }
166 
172  public function tearDown()
173  {
174  if (!$this->reviewInitial instanceof Review) {
175  return;
176  }
177  $this->ratingIndex->open();
178  foreach ($this->reviewInitial->getRatings() as $rating) {
179  $this->ratingIndex->getRatingGrid()->searchAndOpen(['rating_code' => $rating['title']]);
180  $this->ratingEdit->getPageActions()->delete();
181  $this->ratingEdit->getModalBlock()->acceptAlert();
182  }
183  }
184 }
$rating
Definition: item.phtml:18
__inject(RatingIndex $ratingIndex, RatingEdit $ratingEdit, CatalogProductEdit $catalogProductEdit, ReviewEdit $reviewEdit)