Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
CheckoutWithPersistentShoppingCartTest.php
Go to the documentation of this file.
1 <?php
8 
11 use Magento\Customer\Test\Page\CustomerAccountCreate;
12 use Magento\Cms\Test\Page\CmsIndex;
13 use Magento\Catalog\Test\Page\Product\CatalogProductView;
14 use Magento\Checkout\Test\Page\CheckoutCart;
15 use Magento\Mtf\Client\BrowserInterface;
17 use Magento\Mtf\TestCase\Injectable;
18 use Magento\Mtf\TestStep\TestStepFactory;
19 
39 {
45  private $configData;
46 
52  private $customerAccountCreate;
53 
59  private $cmsIndex;
60 
66  private $catalogProductView;
67 
73  private $browser;
74 
80  private $checkoutCart;
81 
87  private $logoutCustomerOnFrontendStep;
88 
94  private $stepFactory;
95 
108  public function __inject(
109  CustomerAccountCreate $customerAccountCreate,
110  CmsIndex $cmsIndex,
111  LogoutCustomerOnFrontendStep $logoutCustomerOnFrontendStep,
112  CatalogProductView $catalogProductView,
113  BrowserInterface $browser,
114  CheckoutCart $checkoutCart,
115  TestStepFactory $stepFactory
116  ) {
117  $this->customerAccountCreate = $customerAccountCreate;
118  $this->cmsIndex = $cmsIndex;
119  $this->logoutCustomerOnFrontendStep = $logoutCustomerOnFrontendStep;
120  $this->browser = $browser;
121  $this->catalogProductView = $catalogProductView;
122  $this->checkoutCart = $checkoutCart;
123  $this->stepFactory = $stepFactory;
124  }
125 
132  public function __prepare(CatalogProductSimple $product)
133  {
134  $product->persist();
135 
136  return ['product' => $product];
137  }
138 
147  public function test($configData, CatalogProductSimple $product, Customer $customer)
148  {
149  $this->configData = $configData;
150  $this->stepFactory->create(
151  \Magento\Config\Test\TestStep\SetupConfigurationStep::class,
152  ['configData' => $configData]
153  )->run();
154 
155  // Steps
156  $this->cmsIndex->open();
157  $this->cmsIndex->getLinksBlock()->openLink('Create an Account');
158  $this->customerAccountCreate->getRegisterForm()->registerCustomer($customer);
159 
160  // Ensure that shopping cart is empty
161  $this->checkoutCart->open()->getCartBlock()->clearShoppingCart();
162 
163  $this->browser->open($_ENV['app_frontend_url'] . $product->getUrlKey() . '.html');
164  $this->catalogProductView->getViewBlock()->addToCart($product);
165  $this->catalogProductView->getMessagesBlock()->waitSuccessMessage();
166  $this->logoutCustomerOnFrontendStep->run();
167  }
168 
174  public function tearDown()
175  {
176  $this->stepFactory->create(
177  \Magento\Config\Test\TestStep\SetupConfigurationStep::class,
178  ['configData' => $this->configData, 'rollback' => true]
179  )->run();
180  }
181 }
$customer
Definition: customers.php:11
__inject(CustomerAccountCreate $customerAccountCreate, CmsIndex $cmsIndex, LogoutCustomerOnFrontendStep $logoutCustomerOnFrontendStep, CatalogProductView $catalogProductView, BrowserInterface $browser, CheckoutCart $checkoutCart, TestStepFactory $stepFactory)