/**
  * Create review.
  *
  * @param Review $review
  * @param int $rating
  * @return Review
  */
 protected function createReview($review, $rating)
 {
     $reviewData = $review->getData();
     $fixtureRating = $this->reviewInitial->getDataFieldConfig('ratings')['source']->getRatings()[0];
     $reviewData['ratings'][0] = ['fixtureRating' => $fixtureRating, 'rating' => $rating];
     return $this->fixtureFactory->createByCode('review', ['data' => $reviewData]);
 }
 /**
  * Asserts Product Review not available in grid
  *
  * @param ReviewIndex $reviewIndex
  * @param Review $review
  * @param string $gridStatus
  * @param Review $reviewInitial
  * @return void
  */
 public function processAssert(ReviewIndex $reviewIndex, Review $review, $gridStatus = '', Review $reviewInitial = null)
 {
     $product = $reviewInitial === null ? $review->getDataFieldConfig('entity_id')['source']->getEntity() : $reviewInitial->getDataFieldConfig('entity_id')['source']->getEntity();
     $filter = $this->prepareFilter($product, $review, $gridStatus);
     $reviewIndex->getReviewGrid()->search($filter);
     unset($filter['visible_in']);
     \PHPUnit_Framework_Assert::assertFalse($reviewIndex->getReviewGrid()->isRowVisible($filter, false), 'Review available in grid');
 }
 /**
  * Assert that review is visible in review grid for select product
  *
  * @param ReviewIndex $reviewIndex
  * @param Review $review
  * @param ProductReportReview $productReportReview
  * @param AssertProductReviewInGrid $assertProductReviewInGrid
  * @return void
  */
 public function processAssert(ReviewIndex $reviewIndex, Review $review, ProductReportReview $productReportReview, AssertProductReviewInGrid $assertProductReviewInGrid)
 {
     $productReportReview->open();
     $product = $review->getDataFieldConfig('entity_id')['source']->getEntity();
     $productReportReview->getGridBlock()->openReview($product->getName());
     unset($assertProductReviewInGrid->filter['visible_in']);
     $filter = $assertProductReviewInGrid->prepareFilter($product, $review->getData(), '');
     \PHPUnit_Framework_Assert::assertTrue($reviewIndex->getReviewGrid()->isRowVisible($filter, false), 'Review for ' . $product->getName() . ' product is not visible in reports grid.');
 }
 /**
  * Assert that product review Not available on product page
  *
  * @param CatalogProductView $catalogProductView
  * @param Review $reviewInitial
  * @param BrowserInterface $browser
  * @return void
  */
 public function processAssert(CatalogProductView $catalogProductView, Review $reviewInitial, BrowserInterface $browser)
 {
     /** @var CatalogProductSimple $product */
     $product = $reviewInitial->getDataFieldConfig('entity_id')['source']->getEntity();
     $browser->open($_ENV['app_frontend_url'] . $product->getUrlKey() . '.html');
     $reviewBlock = $catalogProductView->getCustomerReviewBlock();
     $catalogProductView->getViewBlock()->selectTab('Reviews');
     \PHPUnit_Framework_Assert::assertFalse($reviewBlock->isVisibleReviewItem(), 'Error, product review is displayed.');
 }
 /**
  * Injection data.
  *
  * @param ReviewIndex $reviewIndex
  * @param RatingIndex $ratingIndex
  * @param RatingEdit $ratingEdit
  * @param Review $review
  * @return array
  */
 public function __inject(ReviewIndex $reviewIndex, RatingIndex $ratingIndex, RatingEdit $ratingEdit, Review $review)
 {
     $this->reviewIndex = $reviewIndex;
     $this->ratingIndex = $ratingIndex;
     $this->ratingEdit = $ratingEdit;
     $this->review = $review;
     $this->review->persist();
     $product = $review->getDataFieldConfig('entity_id')['source']->getEntity();
     return ['review' => $this->review, 'product' => $product];
 }
 /**
  * Assert that product rating is displayed on product review(frontend)
  *
  * @param CatalogProductView $catalogProductView
  * @param BrowserInterface $browser
  * @param CatalogProductSimple $product
  * @param Review|null $review [optional]
  * @param Rating|null $productRating [optional]
  * @return void
  */
 public function processAssert(CatalogProductView $catalogProductView, BrowserInterface $browser, CatalogProductSimple $product, Review $review = null, Rating $productRating = null)
 {
     $browser->open($_ENV['app_frontend_url'] . $product->getUrlKey() . '.html');
     $reviewSummaryBlock = $catalogProductView->getReviewSummary();
     if ($reviewSummaryBlock->isVisible()) {
         $reviewSummaryBlock->getAddReviewLink()->click();
     }
     $rating = $productRating ? $productRating : $review->getDataFieldConfig('ratings')['source']->getRatings()[0];
     $reviewForm = $catalogProductView->getReviewFormBlock();
     \PHPUnit_Framework_Assert::assertTrue($reviewForm->isVisibleRating($rating), 'Product rating "' . $rating->getRatingCode() . '" is not displayed.');
 }
 /**
  * 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];
 }
 /**
  * Asserts all Product Review variables in the reviews grid on customer page
  *
  * @param Customer $customer
  * @param Review $reviewInitial
  * @param Review $review
  * @param CustomerIndexEdit $customerIndexEdit
  * @param CustomerIndex $customerIndex
  * @param AssertProductReviewInGrid $assertProductReviewInGrid
  * @return void
  */
 public function processAssert(Customer $customer, Review $reviewInitial, Review $review, CustomerIndexEdit $customerIndexEdit, CustomerIndex $customerIndex, AssertProductReviewInGrid $assertProductReviewInGrid)
 {
     /** var CatalogProductSimple $product */
     $product = $reviewInitial->getDataFieldConfig('entity_id')['source']->getEntity();
     $customerIndex->open();
     $customerIndex->getCustomerGridBlock()->searchAndOpen(['email' => $customer->getEmail()]);
     $customerIndexEdit->getCustomerForm()->openTab('product_reviews');
     $filter = $assertProductReviewInGrid->prepareFilter($product, $this->prepareData($review, $reviewInitial));
     /** @var ReviewsGrid $reviewsGrid */
     $reviewsGrid = $customerIndexEdit->getCustomerForm()->getTab('product_reviews')->getReviewsGrid();
     $reviewsGrid->search($filter);
     unset($filter['visible_in']);
     \PHPUnit_Framework_Assert::assertTrue($reviewsGrid->isRowVisible($filter, false), 'Review is absent in Review grid on customer page.');
 }
 /**
  * Run create frontend product rating test.
  *
  * @param Review $review
  * @param BrowserInterface $browser
  * @param AssertProductReviewIsAbsentOnProductPage $assertProductReviewIsAbsentOnProductPage
  * @return array
  */
 public function test(Review $review, BrowserInterface $browser, AssertProductReviewIsAbsentOnProductPage $assertProductReviewIsAbsentOnProductPage)
 {
     // Prepare for tear down
     $this->review = $review;
     // Steps
     $product = $review->getDataFieldConfig('entity_id')['source']->getEntity();
     $browser->open($_ENV['app_frontend_url'] . $product->getUrlKey() . '.html');
     $assertProductReviewIsAbsentOnProductPage->processAssert($this->catalogProductView);
     $this->catalogProductView->getReviewSummary()->clickAddReviewLink();
     $reviewForm = $this->catalogProductView->getReviewFormBlock();
     $reviewForm->fill($review);
     $reviewForm->submit();
     return ['product' => $product];
 }
 /**
  * Run manage product review test
  *
  * @param Review $reviewInitial
  * @param Review $review
  * @param Customer $customer
  * @return array
  */
 public function test(Review $reviewInitial, Review $review, Customer $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];
 }
 /**
  * Run Create Product Review Entity Backend Test.
  *
  * @param Review $review
  * @return array
  */
 public function test(Review $review)
 {
     // Precondition:
     $product = $review->getDataFieldConfig('entity_id')['source']->getEntity();
     $filter = ['id' => $product->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();
     return ['product' => $product];
 }
 /**
  * Assert that Product Review Report is visible in reports grid
  *
  * @param ProductReportReview $productReportReview
  * @param Review $review
  * @return void
  */
 public function processAssert(ProductReportReview $productReportReview, Review $review)
 {
     $productReportReview->open();
     $name = $review->getDataFieldConfig('entity_id')['source']->getEntity()->getName();
     \PHPUnit_Framework_Assert::assertTrue($productReportReview->getGridBlock()->isRowVisible(['title' => $name], false), 'Review for ' . $name . ' product is not visible in reports grid.');
 }