Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
DeleteActionTest.php
Go to the documentation of this file.
1 <?php
7 
12 use Zend\Http\Request;
13 
18 {
23  public function testExecute()
24  {
25  $customerId = 1;
27  $session = $this->_objectManager->get(Session::class);
28  $session->setCustomerId($customerId);
29 
31  $tokenManagement = $this->_objectManager->get(CustomerTokenManagement::class);
32  $tokens = $tokenManagement->getCustomerSessionTokens();
33 
34  static::assertCount(1, $tokens);
35 
36  $vaultToken = array_pop($tokens);
37 
39  $formKey = $this->_objectManager->get(FormKey::class);
40  $this->getRequest()
41  ->setPostValue([
42  'public_hash' => $vaultToken->getPublicHash(),
43  'form_key' => $formKey->getFormKey()
44  ])
45  ->setMethod(Request::METHOD_POST);
46  $this->dispatch('vault/cards/deleteaction');
47 
48  static::assertTrue($this->getResponse()->isRedirect());
49  static::assertRedirect(static::stringContains('vault/cards/listaction'));
50  static::assertSessionMessages(static::equalTo(['Stored Payment Method was successfully removed']));
51  static::assertEmpty($tokenManagement->getCustomerSessionTokens());
52  }
53 }
$tokens
Definition: cards_list.phtml:9