Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
ManageProductReviewFromCustomerPageTest.php
Go to the documentation of this file.
1 <?php
8 
10 use Magento\Catalog\Test\Page\Product\CatalogProductView;
12 use Magento\Customer\Test\Page\Adminhtml\CustomerIndex;
13 use Magento\Customer\Test\Page\Adminhtml\CustomerIndexEdit;
15 use Magento\Review\Test\Page\Adminhtml\RatingEdit;
16 use Magento\Review\Test\Page\Adminhtml\RatingIndex;
17 use Magento\Review\Test\Page\Adminhtml\ReviewEdit;
18 use Magento\Mtf\Client\BrowserInterface;
19 use Magento\Mtf\TestCase\Injectable;
20 
43 {
44  /* tags */
45  const MVP = 'no';
46  const TO_MAINTAIN = 'yes';
47  /* end tags */
48 
54  protected $customerIndex;
55 
61  protected $customerIndexEdit;
62 
69 
75  protected $browser;
76 
82  protected $ratingIndex;
83 
89  protected $ratingEdit;
90 
96  protected $reviewInitial;
97 
103  protected $reviewEdit;
104 
111  public function __prepare(Customer $customer)
112  {
113  $customer->persist();
114  return ['customer' => $customer];
115  }
116 
129  public function __inject(
130  CustomerIndexEdit $customerIndexEdit,
131  CustomerIndex $customerIndex,
132  CatalogProductView $catalogProductView,
133  BrowserInterface $browser,
134  RatingIndex $ratingIndex,
135  RatingEdit $ratingEdit,
136  ReviewEdit $reviewEdit
137  ) {
138  $this->customerIndexEdit = $customerIndexEdit;
139  $this->customerIndex = $customerIndex;
140  $this->catalogProductView = $catalogProductView;
141  $this->browser = $browser;
142  $this->ratingIndex = $ratingIndex;
143  $this->ratingEdit = $ratingEdit;
144  $this->reviewEdit = $reviewEdit;
145  }
146 
155  public function test(
156  Review $reviewInitial,
157  Review $review,
158  Customer $customer
159  ) {
160  // Preconditions
161  $this->login($customer);
163  $product = $reviewInitial->getDataFieldConfig('entity_id')['source']->getEntity();
164  $this->browser->open($_ENV['app_frontend_url'] . $product->getUrlKey() . '.html');
165  $this->catalogProductView->getReviewSummary()->getAddReviewLink()->click();
166  $this->catalogProductView->getReviewFormBlock()->fill($reviewInitial);
167  $this->catalogProductView->getReviewFormBlock()->submit();
168  $this->reviewInitial = $reviewInitial;
169  // Steps
170  $this->customerIndex->open();
171  $this->customerIndex->getCustomerGridBlock()->searchAndOpen(['email' => $customer->getEmail()]);
172  $this->customerIndexEdit->getCustomerForm()->openTab('product_reviews');
173  $filter = [
174  'title' => $reviewInitial->getTitle(),
175  'sku' => $product->getSku(),
176  ];
177  $this->customerIndexEdit->getCustomerForm()->getTab('product_reviews')->getReviewsGrid()
178  ->searchAndOpen($filter);
179  $this->reviewEdit->getReviewForm()->fill($review);
180  $this->reviewEdit->getPageActions()->save();
181 
182  return ['reviewInitial' => $reviewInitial, 'product' => $product];
183  }
184 
191  protected function login(Customer $customer)
192  {
193  $this->objectManager->create(
194  \Magento\Customer\Test\TestStep\LoginCustomerOnFrontendStep::class,
195  ['customer' => $customer]
196  )->run();
197  }
198 
204  public function tearDown()
205  {
206  $this->ratingIndex->open();
207  if ($this->reviewInitial instanceof Review) {
208  foreach ($this->reviewInitial->getRatings() as $rating) {
209  $this->ratingIndex->getRatingGrid()->searchAndOpen(['rating_code' => $rating['title']]);
210  $this->ratingEdit->getPageActions()->delete();
211  $this->ratingEdit->getModalBlock()->acceptAlert();
212  }
213  }
214  }
215 }
$customer
Definition: customers.php:11
$rating
Definition: item.phtml:18
__inject(CustomerIndexEdit $customerIndexEdit, CustomerIndex $customerIndex, CatalogProductView $catalogProductView, BrowserInterface $browser, RatingIndex $ratingIndex, RatingEdit $ratingEdit, ReviewEdit $reviewEdit)