|
| 1 | +<?php |
| 2 | +/** |
| 3 | + * Copyright © 2016 Magento. All rights reserved. |
| 4 | + * See COPYING.txt for license details. |
| 5 | + */ |
| 6 | + |
| 7 | +namespace Magento\Persistent\Test\TestCase; |
| 8 | + |
| 9 | +use Magento\Customer\Test\Fixture\Customer; |
| 10 | +use Magento\Catalog\Test\Fixture\CatalogProductSimple; |
| 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; |
| 16 | +use Magento\Customer\Test\TestStep\LogoutCustomerOnFrontendStep; |
| 17 | +use Magento\Mtf\TestCase\Injectable; |
| 18 | +use Magento\Mtf\TestStep\TestStepFactory; |
| 19 | + |
| 20 | +/** |
| 21 | + * Preconditions: |
| 22 | + * Apply configs: |
| 23 | + * 1. Enable Persistent Shopping Cart. |
| 24 | + * 2. Disable Clear Persistence on Sign Out. |
| 25 | + * |
| 26 | + * Steps: |
| 27 | + * 1. Go to frontend. |
| 28 | + * 2. Click Register link. |
| 29 | + * 3. Fill registry form. |
| 30 | + * 4. Click 'Create account' button. |
| 31 | + * 5. Add simple product to shopping cart. |
| 32 | + * 6. Sign out. |
| 33 | + * |
| 34 | + * @ZephyrId MAGETWO-45381 |
| 35 | + */ |
| 36 | +class CheckoutWthPersistentShoppingCartTest extends Injectable |
| 37 | +{ |
| 38 | + /** |
| 39 | + * Config data. |
| 40 | + * |
| 41 | + * @string $configData |
| 42 | + */ |
| 43 | + private $configData; |
| 44 | + |
| 45 | + /** |
| 46 | + * Customer registry page. |
| 47 | + * |
| 48 | + * @var CustomerAccountCreate |
| 49 | + */ |
| 50 | + private $customerAccountCreate; |
| 51 | + |
| 52 | + /** |
| 53 | + * Cms page. |
| 54 | + * |
| 55 | + * @var CmsIndex $cmsIndex. |
| 56 | + */ |
| 57 | + private $cmsIndex; |
| 58 | + |
| 59 | + /** |
| 60 | + * Frontend product view page. |
| 61 | + * |
| 62 | + * @var CatalogProductView |
| 63 | + */ |
| 64 | + private $catalogProductView; |
| 65 | + |
| 66 | + /** |
| 67 | + * Interface Browser. |
| 68 | + * |
| 69 | + * @var BrowserInterface. |
| 70 | + */ |
| 71 | + private $browser; |
| 72 | + |
| 73 | + /** |
| 74 | + * Page of checkout page. |
| 75 | + * |
| 76 | + * @var CheckoutCart |
| 77 | + */ |
| 78 | + private $checkoutCart; |
| 79 | + |
| 80 | + /** |
| 81 | + * Customer log out step. |
| 82 | + * |
| 83 | + * @var LogoutCustomerOnFrontendStep |
| 84 | + */ |
| 85 | + private $logoutCustomerOnFrontendStep; |
| 86 | + |
| 87 | + /** |
| 88 | + * Factory for Test Steps. |
| 89 | + * |
| 90 | + * @var TestStepFactory |
| 91 | + */ |
| 92 | + private $stepFactory; |
| 93 | + |
| 94 | + /** |
| 95 | + * Inject data. |
| 96 | + * |
| 97 | + * @param CustomerAccountCreate $customerAccountCreate |
| 98 | + * @param CmsIndex $cmsIndex |
| 99 | + * @param LogoutCustomerOnFrontendStep $logoutCustomerOnFrontendStep |
| 100 | + * @param CatalogProductView $catalogProductView |
| 101 | + * @param BrowserInterface $browser |
| 102 | + * @param CheckoutCart $checkoutCart |
| 103 | + * @param TestStepFactory $stepFactory |
| 104 | + * @return void |
| 105 | + */ |
| 106 | + public function __inject( |
| 107 | + CustomerAccountCreate $customerAccountCreate, |
| 108 | + CmsIndex $cmsIndex, |
| 109 | + LogoutCustomerOnFrontendStep $logoutCustomerOnFrontendStep, |
| 110 | + CatalogProductView $catalogProductView, |
| 111 | + BrowserInterface $browser, |
| 112 | + CheckoutCart $checkoutCart, |
| 113 | + TestStepFactory $stepFactory |
| 114 | + ) { |
| 115 | + $this->customerAccountCreate = $customerAccountCreate; |
| 116 | + $this->cmsIndex = $cmsIndex; |
| 117 | + $this->logoutCustomerOnFrontendStep = $logoutCustomerOnFrontendStep; |
| 118 | + $this->browser = $browser; |
| 119 | + $this->catalogProductView = $catalogProductView; |
| 120 | + $this->checkoutCart = $checkoutCart; |
| 121 | + $this->stepFactory = $stepFactory; |
| 122 | + } |
| 123 | + |
| 124 | + /** |
| 125 | + * Prepare data. |
| 126 | + * |
| 127 | + * @param CatalogProductSimple $product |
| 128 | + * @return array |
| 129 | + */ |
| 130 | + public function __prepare(CatalogProductSimple $product) |
| 131 | + { |
| 132 | + $product->persist(); |
| 133 | + |
| 134 | + return ['product' => $product]; |
| 135 | + } |
| 136 | + |
| 137 | + /** |
| 138 | + * Create Customer account on Storefront. |
| 139 | + * |
| 140 | + * @param string $configData |
| 141 | + * @param CatalogProductSimple $product |
| 142 | + * @param Customer $customer |
| 143 | + * @return void |
| 144 | + */ |
| 145 | + public function test($configData, CatalogProductSimple $product, Customer $customer) |
| 146 | + { |
| 147 | + $this->configData = $configData; |
| 148 | + $this->stepFactory->create( |
| 149 | + \Magento\Config\Test\TestStep\SetupConfigurationStep::class, |
| 150 | + ['configData' => $configData] |
| 151 | + )->run(); |
| 152 | + |
| 153 | + // Steps |
| 154 | + $this->cmsIndex->open(); |
| 155 | + $this->cmsIndex->getLinksBlock()->openLink('Create an Account'); |
| 156 | + $this->customerAccountCreate->getRegisterForm()->registerCustomer($customer); |
| 157 | + |
| 158 | + // Ensure that shopping cart is empty |
| 159 | + $this->checkoutCart->open()->getCartBlock()->clearShoppingCart(); |
| 160 | + |
| 161 | + $this->browser->open($_ENV['app_frontend_url'] . $product->getUrlKey() . '.html'); |
| 162 | + $this->catalogProductView->getViewBlock()->addToCart($product); |
| 163 | + $this->catalogProductView->getMessagesBlock()->waitSuccessMessage(); |
| 164 | + $this->logoutCustomerOnFrontendStep->run(); |
| 165 | + } |
| 166 | + |
| 167 | + /** |
| 168 | + * Clean data after running test. |
| 169 | + * |
| 170 | + * @return void |
| 171 | + */ |
| 172 | + public function tearDown() |
| 173 | + { |
| 174 | + $this->stepFactory->create( |
| 175 | + \Magento\Config\Test\TestStep\SetupConfigurationStep::class, |
| 176 | + ['configData' => $this->configData, 'rollback' => true] |
| 177 | + )->run(); |
| 178 | + } |
| 179 | +} |
0 commit comments