/**
  * Assert that product rating is displayed on product review(frontend)
  *
  * @param CatalogProductView $catalogProductView
  * @param CatalogProductSimple $product
  * @param Browser $browser
  * @param ReviewInjectable|null $review [optional]
  * @param Rating|null $productRating [optional]
  * @return void
  */
 public function processAssert(CatalogProductView $catalogProductView, CatalogProductSimple $product, Browser $browser, ReviewInjectable $review = null, Rating $productRating = null)
 {
     $product = $review === null ? $product : $review->getDataFieldConfig('entity_id')['source']->getEntity();
     $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.');
 }
 /**
  * Asserts Product Review not available in grid
  *
  * @param ReviewIndex $reviewIndex
  * @param ReviewInjectable $review
  * @param string $gridStatus
  * @param ReviewInjectable $reviewInitial
  * @return void
  */
 public function processAssert(ReviewIndex $reviewIndex, ReviewInjectable $review, $gridStatus = '', ReviewInjectable $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 product review Not available on product page
  *
  * @param CatalogProductView $catalogProductView
  * @param ReviewInjectable $reviewInitial
  * @param Browser $browser
  * @return void
  */
 public function processAssert(CatalogProductView $catalogProductView, ReviewInjectable $reviewInitial, Browser $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.');
 }
 /**
  * Assert that review is visible in review grid for select product
  *
  * @param ReviewIndex $reviewIndex
  * @param ReviewInjectable $review
  * @param ProductReportReview $productReportReview
  * @param AssertProductReviewInGrid $assertProductReviewInGrid
  * @return void
  */
 public function processAssert(ReviewIndex $reviewIndex, ReviewInjectable $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, '');
     \PHPUnit_Framework_Assert::assertTrue($reviewIndex->getReviewGrid()->isRowVisible($filter, false), 'Review for ' . $product->getName() . ' product is not visible in reports grid.');
 }
 /**
  * Assert that product rating is displayed on product review(frontend)
  *
  * @param CatalogProductView $catalogProductView
  * @param CatalogProductSimple $product
  * @param ReviewInjectable|null $review [optional]
  * @param Rating|null $productRating [optional]
  * @return void
  */
 public function processAssert(CatalogProductView $catalogProductView, CatalogProductSimple $product, ReviewInjectable $review = null, Rating $productRating = null)
 {
     $catalogProductView->init($product);
     $catalogProductView->open();
     $catalogProductView->getReviewSummaryBlock()->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.');
 }
 /**
  * Asserts all Product Review variables in the reviews grid on customer page
  *
  * @param CustomerInjectable $customer
  * @param ReviewInjectable $reviewInitial
  * @param ReviewInjectable $review
  * @param CustomerIndexEdit $customerIndexEdit
  * @param CustomerIndex $customerIndex
  * @param AssertProductReviewInGrid $assertProductReviewInGrid
  * @return void
  */
 public function processAssert(CustomerInjectable $customer, ReviewInjectable $reviewInitial, ReviewInjectable $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()->getTabElement('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.');
 }
 /**
  * Assert that product review available on product page
  *
  * @param CatalogProductView $catalogProductView
  * @param ReviewInjectable $review
  * @param ReviewInjectable $reviewInitial
  * @param Browser $browser
  * @return void
  */
 public function processAssert(CatalogProductView $catalogProductView, ReviewInjectable $review, ReviewInjectable $reviewInitial, Browser $browser)
 {
     $errors = [];
     /** @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');
     foreach ($review->getData() as $name => $value) {
         $reviewValue = $reviewBlock->getFieldValue($name);
         if ($reviewValue !== null && 0 !== strcasecmp($value, trim($reviewValue))) {
             $errors[] = '- field "' . $name . '" is not equals submitted one, error value "' . $value . '"';
         }
     }
     \PHPUnit_Framework_Assert::assertEmpty($errors, 'The Review contains the following errors:' . PHP_EOL . implode(PHP_EOL, $errors));
 }
 /**
  * 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];
 }
 /**
  * Assert that Product Review Report is visible in reports grid
  *
  * @param ProductReportReview $productReportReview
  * @param ReviewInjectable $review
  * @return void
  */
 public function processAssert(ProductReportReview $productReportReview, ReviewInjectable $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.');
 }
 /**
  * Injection data
  *
  * @param ReviewIndex $reviewIndex
  * @param RatingIndex $ratingIndex
  * @param RatingEdit $ratingEdit
  * @param ReviewInjectable $review
  * @return array
  */
 public function __inject(ReviewIndex $reviewIndex, RatingIndex $ratingIndex, RatingEdit $ratingEdit, ReviewInjectable $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];
 }
 /**
  * Run create frontend product rating test
  *
  * @param ReviewInjectable $review
  * @param Browser $browser
  * @return void
  */
 public function test(ReviewInjectable $review, Browser $browser)
 {
     // Prepare for tear down
     $this->review = $review;
     // Steps
     $product = $review->getDataFieldConfig('entity_id')['source']->getEntity();
     $browser->open($_ENV['app_frontend_url'] . $product->getUrlKey() . '.html');
     $reviewLink = $this->catalogProductView->getReviewSummary()->getAddReviewLink();
     if ($reviewLink->isVisible()) {
         $reviewLink->click();
     }
     $reviewForm = $this->catalogProductView->getReviewFormBlock();
     $reviewForm->fill($review);
     $reviewForm->submit();
 }
 /**
  * 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();
 }
 /**
  * Run create frontend product rating test
  *
  * @param ReviewInjectable $reviewInitial
  * @param ReviewInjectable $review
  * @return array
  */
 public function test(ReviewInjectable $reviewInitial, ReviewInjectable $review)
 {
     // Precondition
     $reviewInitial->persist();
     // Prepare for tear down
     $this->review = $reviewInitial;
     // 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];
 }
 /**
  * Create review
  *
  * @param ReviewInjectable $review
  * @param int $rating
  * @return ReviewInjectable
  */
 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('reviewInjectable', ['data' => $reviewData]);
 }