Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
CreateProductReviewFrontendEntityTest.php
Go to the documentation of this file.
1 <?php
8 
9 use Magento\Catalog\Test\Page\Product\CatalogProductView;
12 use Magento\Review\Test\Page\Adminhtml\RatingEdit;
13 use Magento\Review\Test\Page\Adminhtml\RatingIndex;
14 use Magento\Mtf\Client\BrowserInterface;
15 use Magento\Mtf\TestCase\Injectable;
16 
33 class CreateProductReviewFrontendEntityTest extends Injectable
34 {
35  /* tags */
36  const MVP = 'no';
37  const TEST_TYPE = 'acceptance_test, extended_acceptance_test';
38  /* end tags */
39 
46 
52  protected $ratingIndex;
53 
59  protected $ratingEdit;
60 
66  protected $review;
67 
76  public function __inject(
77  CatalogProductView $catalogProductView,
78  RatingIndex $ratingIndex,
79  RatingEdit $ratingEdit
80  ) {
81  $this->catalogProductView = $catalogProductView;
82  $this->ratingIndex = $ratingIndex;
83  $this->ratingEdit = $ratingEdit;
84  }
85 
94  public function test(
95  Review $review,
96  BrowserInterface $browser,
97  AssertProductReviewIsAbsentOnProductPage $assertProductReviewIsAbsentOnProductPage
98  ) {
99  // Prepare for tear down
100  $this->review = $review;
101 
102  // Steps
103  $product = $review->getDataFieldConfig('entity_id')['source']->getEntity();
104  $browser->open($_ENV['app_frontend_url'] . $product->getUrlKey() . '.html');
105  $assertProductReviewIsAbsentOnProductPage->processAssert($this->catalogProductView);
106  $this->catalogProductView->getReviewSummary()->clickAddReviewLink();
107  $reviewForm = $this->catalogProductView->getReviewFormBlock();
108  $reviewForm->fill($review);
109  $reviewForm->submit();
110 
111  return ['product' => $product];
112  }
113 
119  public function tearDown()
120  {
121  if ($this->review instanceof Review) {
122  $ratings = $this->review->getRatings();
123  if (empty($ratings)) {
124  return;
125  }
126  $this->ratingIndex->open();
127  foreach ($ratings as $rating) {
128  $this->ratingIndex->getRatingGrid()->searchAndOpen(['rating_code' => $rating['title']]);
129  $this->ratingEdit->getPageActions()->delete();
130  $this->ratingEdit->getModalBlock()->acceptAlert();
131  }
132  }
133  }
134 }
test(Review $review, BrowserInterface $browser, AssertProductReviewIsAbsentOnProductPage $assertProductReviewIsAbsentOnProductPage)
$rating
Definition: item.phtml:18
__inject(CatalogProductView $catalogProductView, RatingIndex $ratingIndex, RatingEdit $ratingEdit)