/**
  * Assert that product review can do approved.
  *
  * @param ReviewIndex $reviewIndex
  * @param Review $review
  * @param ReviewEdit $reviewEdit
  * @param AssertReviewSuccessSaveMessage $assertReviewSuccessSaveMessage
  * @param AdminCache $cachePage
  * @return void
  */
 public function processAssert(ReviewIndex $reviewIndex, Review $review, ReviewEdit $reviewEdit, AssertReviewSuccessSaveMessage $assertReviewSuccessSaveMessage, AdminCache $cachePage)
 {
     $this->cachePage = $cachePage;
     $reviewIndex->open();
     $reviewGrid = $reviewIndex->getReviewGrid();
     $reviewGrid->searchAndOpen(['title' => $review->getTitle()]);
     $reviewEdit->getReviewForm()->setApproveReview();
     $reviewEdit->getPageActions()->save();
     $assertReviewSuccessSaveMessage->processAssert($reviewIndex);
     $this->flushCacheStorageWithAssert();
 }
 /**
  * Assert that product rating is displayed on product review(backend)
  *
  * @param ReviewIndex $reviewIndex
  * @param ReviewEdit $reviewEdit
  * @param ReviewInjectable $review
  * @param ReviewInjectable|null $reviewInitial [optional]
  * @return void
  */
 public function processAssert(ReviewIndex $reviewIndex, ReviewEdit $reviewEdit, ReviewInjectable $review, ReviewInjectable $reviewInitial = null)
 {
     $filter = ['title' => $review->getTitle()];
     $reviewIndex->open();
     $reviewIndex->getReviewGrid()->searchAndOpen($filter);
     $ratingReview = array_replace($reviewInitial && $reviewInitial->hasData('ratings') ? $reviewInitial->getRatings() : [], $review->hasData('ratings') ? $review->getRatings() : []);
     $ratingReview = $this->sortDataByPath($ratingReview, '::title');
     $ratingForm = $reviewEdit->getReviewForm()->getData();
     $ratingForm = $this->sortDataByPath($ratingForm['ratings'], '::title');
     $error = $this->verifyData($ratingReview, $ratingForm);
     \PHPUnit_Framework_Assert::assertTrue(empty($error), $error);
 }
 /**
  * Run moderate product review test.
  *
  * @param Review $reviewInitial
  * @param Review $review
  * @return array
  */
 public function test(Review $reviewInitial, Review $review)
 {
     // Precondition
     $reviewInitial->persist();
     // Steps
     $this->reviewIndex->open();
     $this->reviewIndex->getReviewGrid()->searchAndOpen(['review_id' => $reviewInitial->getReviewId()]);
     $this->reviewEdit->getReviewForm()->fill($review);
     $this->reviewEdit->getPageActions()->save();
     // Prepare data for asserts
     $product = $reviewInitial->getDataFieldConfig('entity_id')['source']->getEntity();
     return ['product' => $product];
 }
 /**
  * Assert that review data on edit page equals passed from fixture.
  *
  * @param ReviewIndex $reviewIndex
  * @param Review $review
  * @param ReviewEdit $reviewEdit
  * @return void
  */
 public function processAssert(ReviewIndex $reviewIndex, Review $review, ReviewEdit $reviewEdit)
 {
     $reviewIndex->open();
     $reviewGrid = $reviewIndex->getReviewGrid();
     $reviewGrid->searchAndOpen(['title' => $review->getTitle()]);
     $fixtureData = $review->getData();
     $formData = $reviewEdit->getReviewForm()->getData();
     if (isset($fixtureData['type'])) {
         $formData['type'] = $reviewEdit->getReviewForm()->getPostedBy();
     }
     $error = $this->verifyData($fixtureData, $formData);
     \PHPUnit_Framework_Assert::assertEmpty($error, $error);
 }
 /**
  * Run moderate product review test
  *
  * @param ReviewInjectable $reviewInitial
  * @param ReviewInjectable $review
  * @return void
  */
 public function test(ReviewInjectable $reviewInitial, ReviewInjectable $review)
 {
     // Precondition
     $reviewInitial->persist();
     // Steps
     $this->reviewIndex->open();
     $this->reviewIndex->getReviewGrid()->searchAndOpen(['review_id' => $reviewInitial->getReviewId()]);
     $this->reviewEdit->getReviewForm()->fill($review);
     $this->reviewEdit->getPageActions()->save();
 }
 /**
  * Run Create Product Review Entity Backend Test
  *
  * @param ReviewInjectable $review
  * @return void
  */
 public function test(ReviewInjectable $review)
 {
     // Precondition:
     $filter = ['id' => $review->getDataFieldConfig('entity_id')['source']->getEntity()->getId()];
     $this->review = $review;
     // Steps:
     $this->reviewIndex->open();
     $this->reviewIndex->getReviewActions()->addNew();
     $this->reviewEdit->getProductGrid()->searchAndOpen($filter);
     $this->reviewEdit->getReviewForm()->fill($this->review);
     $this->reviewEdit->getPageActions()->save();
 }
 /**
  * Update product review on product page.
  *
  * @param Review $review
  * @param int $rating
  * @return array
  */
 public function test(Review $review, $rating)
 {
     // Steps
     $review = $this->createReview($review, $rating);
     $product = $this->reviewInitial->getDataFieldConfig('entity_id')['source']->getEntity();
     $this->objectManager->create('Magento\\Catalog\\Test\\TestStep\\OpenProductOnBackendStep', ['product' => $product])->run();
     $this->catalogProductEdit->getProductForm()->openTab('product_reviews');
     $filter = ['title' => $this->reviewInitial->getTitle(), 'sku' => $product->getSku()];
     $this->catalogProductEdit->getProductForm()->getTab('product_reviews')->getReviewsGrid()->searchAndOpen($filter);
     $this->reviewEdit->getReviewForm()->fill($review);
     $this->reviewEdit->getPageActions()->save();
     $productRating = $this->reviewInitial->getDataFieldConfig('ratings')['source']->getRatings()[0];
     return ['product' => $product, 'productRating' => $productRating];
 }
 /**
  * Update product review on product page
  *
  * @param Review $review
  * @param int $rating
  * @return array
  */
 public function test(Review $review, $rating)
 {
     // Steps
     $review = $this->createReview($review, $rating);
     $this->catalogProductIndex->open();
     /** @var CatalogProductSimple $product */
     $product = $this->reviewInitial->getDataFieldConfig('entity_id')['source']->getEntity();
     $this->catalogProductIndex->getProductGrid()->searchAndOpen(['sku' => $product->getSku()]);
     $this->catalogProductEdit->getProductForm()->openTab('product_reviews');
     $filter = ['title' => $this->reviewInitial->getTitle(), 'sku' => $product->getSku()];
     $this->catalogProductEdit->getProductForm()->getTabElement('product_reviews')->getReviewsGrid()->searchAndOpen($filter);
     $this->reviewEdit->getReviewForm()->fill($review);
     $this->reviewEdit->getPageActions()->save();
     $productRating = $this->reviewInitial->getDataFieldConfig('ratings')['source']->getRatings()[0];
     return ['product' => $product, 'productRating' => $productRating];
 }
 /**
  * Run manage product review test
  *
  * @param ReviewInjectable $reviewInitial
  * @param ReviewInjectable $review
  * @param CustomerInjectable $customer
  * @return array
  */
 public function test(ReviewInjectable $reviewInitial, ReviewInjectable $review, CustomerInjectable $customer)
 {
     // Preconditions
     $this->login($customer);
     /** @var CatalogProductSimple $product */
     $product = $reviewInitial->getDataFieldConfig('entity_id')['source']->getEntity();
     $this->browser->open($_ENV['app_frontend_url'] . $product->getUrlKey() . '.html');
     $this->catalogProductView->getReviewSummary()->getAddReviewLink()->click();
     $this->catalogProductView->getReviewFormBlock()->fill($reviewInitial);
     $this->catalogProductView->getReviewFormBlock()->submit();
     $this->reviewInitial = $reviewInitial;
     // Steps
     $this->customerIndex->open();
     $this->customerIndex->getCustomerGridBlock()->searchAndOpen(['email' => $customer->getEmail()]);
     $this->customerIndexEdit->getCustomerForm()->openTab('product_reviews');
     $filter = ['title' => $reviewInitial->getTitle(), 'sku' => $product->getSku()];
     $this->customerIndexEdit->getCustomerForm()->getTabElement('product_reviews')->getReviewsGrid()->searchAndOpen($filter);
     $this->reviewEdit->getReviewForm()->fill($review);
     $this->reviewEdit->getPageActions()->save();
     return ['reviewInitial' => $reviewInitial, 'product' => $product];
 }