Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
DeleteSavedCreditCardTest.php
Go to the documentation of this file.
1 <?php
7 
8 use Magento\Checkout\Test\Page\CheckoutOnepage;
10 use Magento\Mtf\ObjectManager;
11 use Magento\Mtf\TestCase\Injectable;
13 
31 class DeleteSavedCreditCardTest extends Injectable
32 {
33  /* tags */
34  const MVP = 'yes';
35  const TEST_TYPE = '3rd_party_test';
36  const SEVERITY = 'S1';
37  /* end tags */
38 
44  private $checkoutOnepage;
45 
52  public function __inject(CheckoutOnepage $checkoutOnepage)
53  {
54  $this->checkoutOnepage = $checkoutOnepage;
55  }
56 
71  public function test(
72  AssertCreditCardNotPresentOnCheckout $assertCreditCardNotPresentOnCheckout,
73  $products,
75  $customer,
76  $checkoutMethod,
78  $shipping,
79  array $payments,
80  $creditCardSave
81  ) {
82  // Preconditions
84  $this->setupConfiguration($configData);
86 
87  // Steps
88  foreach ($payments as $key => $payment) {
89  $this->addToCart($products);
90  $this->proceedToCheckout();
91  if ($key < 1) { // if this is the first order to be placed
92  $this->selectCheckoutMethod($checkoutMethod, $customer);
94  }
95  $this->fillShippingMethod($shipping);
96  if ($key >= 2) { // if this order will be placed via stored credit card
97  $this->useSavedCreditCard($payment['vault']);
98  } else {
99  $arguments = isset($payment['arguments']) ? $payment['arguments'] : [];
100  $this->selectPaymentMethod($payment, $payment['creditCard'], $arguments);
101  $this->saveCreditCard($payment, $creditCardSave);
102  }
103  $this->placeOrder();
104  }
105  // Delete credit cards from Stored Payment Methods and verify they are not available on checkout
106  $paymentsCount = count($payments);
107  for ($i = 2; $i < $paymentsCount; $i++) {
108  $deletedCard = $this->deleteCreditCardFromMyAccount(
109  $customer,
110  $payments[$i]['creditCard']
111  );
112  $this->addToCart($products);
113  $this->proceedToCheckout();
114  $this->fillShippingMethod($shipping);
115  $assertCreditCardNotPresentOnCheckout->processAssert(
116  $this->checkoutOnepage,
117  $deletedCard['deletedCreditCard']
118  );
119  }
120  }
121 
128  private function setupConfiguration($configData)
129  {
130  $setupConfigurationStep = ObjectManager::getInstance()->create(
131  \Magento\Config\Test\TestStep\SetupConfigurationStep::class,
132  ['configData' => $configData]
133  );
134 
135  $setupConfigurationStep->run();
136  }
137 
144  protected function prepareProducts($productList)
145  {
146  $addToCartStep = ObjectManager::getInstance()->create(
147  \Magento\Catalog\Test\TestStep\CreateProductsStep::class,
148  ['products' => $productList]
149  );
150 
151  $result = $addToCartStep->run();
152  return $result['products'];
153  }
154 
161  protected function addToCart(array $products)
162  {
163  $addToCartStep = ObjectManager::getInstance()->create(
164  \Magento\Checkout\Test\TestStep\AddProductsToTheCartStep::class,
165  ['products' => $products]
166  );
167  $addToCartStep->run();
168  }
169 
175  protected function proceedToCheckout()
176  {
177  $clickProceedToCheckoutStep = ObjectManager::getInstance()->create(
178  \Magento\Checkout\Test\TestStep\ProceedToCheckoutStep::class
179  );
180  $clickProceedToCheckoutStep->run();
181  }
182 
189  protected function createCustomer(array $customer)
190  {
191  $createCustomerStep = ObjectManager::getInstance()->create(
192  \Magento\Customer\Test\TestStep\CreateCustomerStep::class,
193  ['customer' => $customer]
194  );
195  $result = $createCustomerStep->run();
196  return $result['customer'];
197  }
198 
206  protected function selectCheckoutMethod($checkoutMethod, $customer)
207  {
208  $selectCheckoutMethodStep = ObjectManager::getInstance()->create(
209  \Magento\Checkout\Test\TestStep\SelectCheckoutMethodStep::class,
210  [
211  'checkoutMethod' => $checkoutMethod,
212  'customer' => $customer,
213  ]
214  );
215  $selectCheckoutMethodStep->run();
216  }
217 
224  protected function fillShippingAddress(array $shippingAddress)
225  {
226  $fillShippingAddressStep = ObjectManager::getInstance()->create(
227  \Magento\Checkout\Test\TestStep\FillShippingAddressStep::class,
228  ['shippingAddress' => $shippingAddress]
229  );
230  $fillShippingAddressStep->run();
231  }
232 
239  protected function fillShippingMethod(array $shipping)
240  {
241  $fillShippingMethodStep = ObjectManager::getInstance()->create(
242  \Magento\Checkout\Test\TestStep\FillShippingMethodStep::class,
243  ['shipping' => $shipping]
244  );
245  $fillShippingMethodStep->run();
246  }
247 
256  protected function selectPaymentMethod(array $payment, array $creditCard, array $arguments)
257  {
258  $selectPaymentMethodStep = ObjectManager::getInstance()->create(
259  \Magento\Checkout\Test\TestStep\SelectPaymentMethodStep::class,
260  array_merge(
261  [
262  'payment' => $payment,
263  'creditCard' => $creditCard,
264  ],
265  $arguments
266  )
267  );
268  $selectPaymentMethodStep->run();
269  }
270 
278  protected function saveCreditCard($payment, $creditCardSave)
279  {
280  $saveCreditCardStep = ObjectManager::getInstance()->create(
281  \Magento\Vault\Test\TestStep\SaveCreditCardStep::class,
282  [
283  'creditCardSave' => $creditCardSave,
284  'payment' => $payment
285  ]
286  );
287  $saveCreditCardStep->run();
288  }
289 
295  protected function fillBillingInformation()
296  {
297  $fillBillingInformationStep = ObjectManager::getInstance()->create(
298  \Magento\Checkout\Test\TestStep\FillBillingInformationStep::class
299  );
300  $fillBillingInformationStep->run();
301  }
302 
308  protected function placeOrder()
309  {
310  $placeOrderStep = ObjectManager::getInstance()->create(
311  \Magento\Checkout\Test\TestStep\PlaceOrderStep::class
312  );
313  $placeOrderStep->run();
314  }
315 
322  protected function useSavedCreditCard($payment)
323  {
324  $useSavedCreditCardStep = ObjectManager::getInstance()->create(
325  \Magento\Vault\Test\TestStep\UseSavedPaymentMethodStep::class,
326  ['vault' => $payment]
327  );
328  $useSavedCreditCardStep->run();
329  }
330 
338  protected function deleteCreditCardFromMyAccount($customer, $creditCard)
339  {
340  $deleteCreditCardFromMyAccountStep = ObjectManager::getInstance()->create(
341  \Magento\Vault\Test\TestStep\DeleteCreditCardFromMyAccountStep::class,
342  [
343  'customer' => $customer,
344  'creditCard' => $creditCard
345  ]
346  );
347  $deletedCard = $deleteCreditCardFromMyAccountStep->run();
348  return $deletedCard;
349  }
350 }
selectPaymentMethod(array $payment, array $creditCard, array $arguments)
$customer
Definition: customers.php:11
$shippingAddress
Definition: order.php:40
test(AssertCreditCardNotPresentOnCheckout $assertCreditCardNotPresentOnCheckout, $products, $configData, $customer, $checkoutMethod, $shippingAddress, $shipping, array $payments, $creditCardSave)
$payment
Definition: order.php:17
$arguments
if(empty($quote)) $productList
Definition: items.php:20
$i
Definition: gallery.phtml:31