Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
ReviewReportEntityTest.php
Go to the documentation of this file.
1 <?php
7 
9 use Magento\Catalog\Test\Page\Category\CatalogCategoryView;
10 use Magento\Catalog\Test\Page\Product\CatalogProductView;
11 use Magento\Cms\Test\Page\CmsIndex;
14 use Magento\Reports\Test\Page\Adminhtml\ProductReportReview;
16 use Magento\Mtf\Client\BrowserInterface;
17 use Magento\Mtf\Fixture\FixtureFactory;
18 use Magento\Mtf\TestCase\Injectable;
19 
38 class ReviewReportEntityTest extends Injectable
39 {
40  /* tags */
41  const MVP = 'no';
42  /* end tags */
43 
50 
57 
64 
70  protected $cmsIndex;
71 
78 
85  public function __prepare(FixtureFactory $fixtureFactory)
86  {
87  $customer = $fixtureFactory->createByCode('customer', ['dataset' => 'johndoe_unique']);
88  $customer->persist();
89  return ['customer' => $customer];
90  }
91 
102  public function __inject(
103  ProductReportReview $productReportReview,
104  CatalogProductView $pageCatalogProductView,
105  CmsIndex $cmsIndex,
106  CatalogCategoryView $catalogCategoryView,
108  ) {
109  $this->productReportReview = $productReportReview;
110  $this->pageCatalogProductView = $pageCatalogProductView;
111  $this->cmsIndex = $cmsIndex;
112  $this->catalogCategoryView = $catalogCategoryView;
113  $this->customerAccountLogout = $customerAccountLogout;
114  }
115 
126  public function test(
127  Review $review,
128  Customer $customer,
129  BrowserInterface $browser,
130  CatalogProductSimple $product = null,
131  $isCustomerLoggedIn = false
132  ) {
133  // Preconditions
134  $this->cmsIndex->open();
135  if ($isCustomerLoggedIn) {
136  $this->loginCustomer($customer);
137  }
138  // Steps
139  if ($review->getType() === "Administrator") {
140  $review->persist();
141  $product = $review->getDataFieldConfig('entity_id')['source']->getEntity();
142  } else {
143  $product->persist();
144  $browser->open($_ENV['app_frontend_url'] . $product->getUrlKey() . '.html');
145  $this->pageCatalogProductView->getReviewSummary()->getAddReviewLink()->click();
146  $this->pageCatalogProductView->getReviewFormBlock()->fill($review);
147  $this->pageCatalogProductView->getReviewFormBlock()->submit();
148  }
149 
150  return ['product' => $product];
151  }
152 
159  private function loginCustomer(Customer $customer)
160  {
161  $this->objectManager->create(
162  'Magento\Customer\Test\TestStep\LoginCustomerOnFrontendStep',
163  ['customer' => $customer]
164  )->run();
165  }
166 
172  public function tearDown()
173  {
174  $this->customerAccountLogout->open();
175  }
176 }
$customer
Definition: customers.php:11
__inject(ProductReportReview $productReportReview, CatalogProductView $pageCatalogProductView, CmsIndex $cmsIndex, CatalogCategoryView $catalogCategoryView, CustomerAccountLogout $customerAccountLogout)
test(Review $review, Customer $customer, BrowserInterface $browser, CatalogProductSimple $product=null, $isCustomerLoggedIn=false)