Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Public Member Functions | Protected Member Functions
AddressTest Class Reference
Inheritance diagram for AddressTest:
AbstractController

Public Member Functions

 testIndexAction ()
 
 testFormAction ()
 
 testFormPostAction ()
 
 testFailedFormPostAction ()
 
 testDeleteAction ()
 
 testWrongAddressDeleteAction ()
 
- Public Member Functions inherited from AbstractController
 getRequest ()
 
 getResponse ()
 
 assert404NotFound ()
 
 assertHeaderPcre ($headerName, $valueRegex)
 
 assertRedirect (\PHPUnit\Framework\Constraint\Constraint $urlConstraint=null)
 

Protected Member Functions

 setUp ()
 
- Protected Member Functions inherited from AbstractController
 _getBootstrap ()
 
 setUp ()
 
 tearDown ()
 
 assertPostConditions ()
 
 getMessages ( $messageType=null, $messageManagerClass=\Magento\Framework\Message\Manager::class)
 

Additional Inherited Members

- Protected Attributes inherited from AbstractController
 $_runCode = ''
 
 $_runScope = 'store'
 
 $_runOptions = []
 
 $_request
 
 $_response
 
 $_objectManager
 
 $_assertSessionErrors = false
 

Detailed Description

Definition at line 14 of file AddressTest.php.

Member Function Documentation

◆ setUp()

setUp ( )
protected

@inheritDoc

Definition at line 25 of file AddressTest.php.

26  {
27  parent::setUp();
28  $logger = $this->createMock(\Psr\Log\LoggerInterface::class);
30  \Magento\Customer\Model\Session::class,
31  [$logger]
32  );
33  $this->accountManagement = Bootstrap::getObjectManager()->create(AccountManagementInterface::class);
34  $this->formKey = Bootstrap::getObjectManager()->create(FormKey::class);
35  $customer = $this->accountManagement->authenticate('[email protected]', 'password');
36  $session->setCustomerDataAsLoggedIn($customer);
37  }
$customer
Definition: customers.php:11
$logger

◆ testDeleteAction()

testDeleteAction ( )

@magentoDataFixture Magento/Customer/_files/customer.php @magentoDataFixture Magento/Customer/_files/customer_address.php

Definition at line 169 of file AddressTest.php.

170  {
171  $this->getRequest()->setParam('id', 1);
172  $this->getRequest()->setParam('form_key', $this->formKey->getFormKey())->setMethod(HttpRequest::METHOD_POST);
173  // we are overwriting the address coming from the fixture
174  $this->dispatch('customer/address/delete');
175 
176  $this->assertRedirect($this->stringContains('customer/address/index'));
177  $this->assertSessionMessages(
178  $this->equalTo(['You deleted the address.']),
179  \Magento\Framework\Message\MessageInterface::TYPE_SUCCESS
180  );
181  }
assertRedirect(\PHPUnit\Framework\Constraint\Constraint $urlConstraint=null)

◆ testFailedFormPostAction()

testFailedFormPostAction ( )

@magentoDataFixture Magento/Customer/_files/customer.php @magentoDataFixture Magento/Customer/_files/customer_address.php

Definition at line 125 of file AddressTest.php.

126  {
127  $this->getRequest()->setParam(
128  'id',
129  1
130  )->setMethod(
131  'POST'
132  )->setPostValue(
133  [
134  'form_key' => $this->_objectManager->get(\Magento\Framework\Data\Form\FormKey::class)->getFormKey(),
135  'firstname' => 'James',
136  'lastname' => 'Bond',
137  'company' => 'Magento Commerce Inc.',
138  'telephone' => '1112223333',
139  'fax' => '2223334444',
140  // omit street and city to fail validation
141  'region_id' => '12',
142  'region' => 'California',
143  'postcode' => '55555',
144  'country_id' => 'US',
145  'success_url' => '',
146  'error_url' => '',
147  ]
148  );
149  // we are overwriting the address coming from the fixture
150  $this->dispatch('customer/address/formPost');
151  $this->getCustomerRegistry()->remove(1);
152  $this->assertRedirect($this->stringContains('customer/address/edit'));
153  $this->assertSessionMessages(
154  $this->equalTo(
155  [
156  'One or more input exceptions have occurred.',
157  '"street" is required. Enter and try again.',
158  '"city" is required. Enter and try again.',
159  ]
160  ),
161  \Magento\Framework\Message\MessageInterface::TYPE_ERROR
162  );
163  }
assertRedirect(\PHPUnit\Framework\Constraint\Constraint $urlConstraint=null)

◆ testFormAction()

testFormAction ( )

@magentoDataFixture Magento/Customer/_files/customer.php @magentoDataFixture Magento/Customer/_files/customer_address.php

Definition at line 57 of file AddressTest.php.

58  {
59  $this->dispatch('customer/address/edit');
60 
61  $body = $this->getResponse()->getBody();
62  $this->assertContains('value="John"', $body);
63  $this->assertContains('value="Smith"', $body);
64  }

◆ testFormPostAction()

testFormPostAction ( )

@magentoDataFixture Magento/Customer/_files/customer.php @magentoDataFixture Magento/Customer/_files/customer_two_addresses.php

Definition at line 70 of file AddressTest.php.

71  {
72  $this->getRequest()->setParam(
73  'id',
74  2
75  )->setMethod(
76  'POST'
77  )->setPostValue(
78  [
79  'form_key' => $this->_objectManager->get(\Magento\Framework\Data\Form\FormKey::class)->getFormKey(),
80  'firstname' => 'James',
81  'lastname' => 'Bond',
82  'company' => 'Magento Commerce Inc.',
83  'telephone' => '1112223333',
84  'fax' => '2223334444',
85  'street' => ['1234 Monterey Rd', 'Apt 13'],
86  'city' => 'Kyiv',
87  'region' => 'Kiev',
88  'postcode' => '55555',
89  'country_id' => 'UA',
90  'success_url' => '',
91  'error_url' => '',
92  'default_billing' => true,
93  'default_shipping' => true,
94  ]
95  );
96  // we are overwriting the address coming from the fixture
97  $this->dispatch('customer/address/formPost');
98  $this->getCustomerRegistry()->remove(1);
99  $this->assertRedirect($this->stringContains('customer/address/index'));
100  $this->assertSessionMessages(
101  $this->equalTo(['You saved the address.']),
102  \Magento\Framework\Message\MessageInterface::TYPE_SUCCESS
103  );
104  $address = $this->accountManagement->getDefaultBillingAddress(1);
105 
106  $this->assertEquals('UA', $address->getCountryId());
107  $this->assertEquals('Kyiv', $address->getCity());
108  $this->assertEquals('Kiev', $address->getRegion()->getRegion());
109  $this->assertTrue($address->isDefaultBilling());
110  $this->assertTrue($address->isDefaultShipping());
111  }
assertRedirect(\PHPUnit\Framework\Constraint\Constraint $urlConstraint=null)
$address
Definition: customer.php:38

◆ testIndexAction()

testIndexAction ( )

@magentoDataFixture Magento/Customer/_files/customer.php @magentoDataFixture Magento/Customer/_files/customer_address.php

Definition at line 43 of file AddressTest.php.

44  {
45  $this->dispatch('customer/address/index');
46 
47  $body = $this->getResponse()->getBody();
48  $this->assertContains('Default Billing Address', $body);
49  $this->assertContains('Default Shipping Address', $body);
50  $this->assertContains('Green str, 67', $body);
51  }

◆ testWrongAddressDeleteAction()

testWrongAddressDeleteAction ( )

@magentoDataFixture Magento/Customer/_files/customer.php @magentoDataFixture Magento/Customer/_files/customer_address.php

Definition at line 187 of file AddressTest.php.

188  {
189  $this->getRequest()->setParam('id', 555);
190  $this->getRequest()->setParam('form_key', $this->formKey->getFormKey())->setMethod(HttpRequest::METHOD_POST);
191  // we are overwriting the address coming from the fixture
192  $this->dispatch('customer/address/delete');
193 
194  $this->assertRedirect($this->stringContains('customer/address/index'));
195  $this->assertSessionMessages(
196  $this->equalTo(['We can\'t delete the address right now.']),
197  \Magento\Framework\Message\MessageInterface::TYPE_ERROR
198  );
199  }
assertRedirect(\PHPUnit\Framework\Constraint\Constraint $urlConstraint=null)

The documentation for this class was generated from the following file: