Skip to content

Commit 2577a87

Browse files
MC-37438: Customer Configurations: Create new account options
1 parent e1c5c1d commit 2577a87

13 files changed

+935
-268
lines changed

dev/tests/integration/testsuite/Magento/Customer/Block/Address/EditTest.php

Lines changed: 105 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -3,126 +3,175 @@
33
* Copyright © Magento, Inc. All rights reserved.
44
* See COPYING.txt for license details.
55
*/
6+
declare(strict_types=1);
7+
68
namespace Magento\Customer\Block\Address;
79

10+
use Magento\Customer\Model\AddressRegistry;
11+
use Magento\Customer\Model\CustomerRegistry;
12+
use Magento\Customer\Model\Session;
13+
use Magento\Framework\App\RequestInterface;
14+
use Magento\Framework\ObjectManagerInterface;
15+
use Magento\Framework\View\Result\Page;
16+
use Magento\Framework\View\Result\PageFactory;
17+
use Magento\TestFramework\Helper\Bootstrap;
18+
use Magento\TestFramework\Helper\Xpath;
19+
use PHPUnit\Framework\TestCase;
20+
821
/**
922
* Tests Address Edit Block
23+
*
24+
* @magentoAppArea frontend
25+
* @magentoAppIsolation enabled
1026
*/
11-
class EditTest extends \PHPUnit\Framework\TestCase
27+
class EditTest extends TestCase
1228
{
29+
/** @var ObjectManagerInterface */
30+
private $objectManager;
31+
1332
/** @var Edit */
14-
protected $_block;
33+
private $block;
1534

16-
/** @var \Magento\Customer\Model\Session */
17-
protected $_customerSession;
35+
/** @var Session */
36+
private $customerSession;
1837

19-
/** @var \Magento\Backend\Block\Template\Context */
20-
protected $_context;
38+
/** @var AddressRegistry */
39+
private $addressRegistry;
2140

22-
/** @var string */
23-
protected $_requestId;
41+
/** @var CustomerRegistry */
42+
private $customerRegistry;
2443

44+
/** @var RequestInterface */
45+
private $request;
46+
47+
/**
48+
* @inheritdoc
49+
*/
2550
protected function setUp(): void
2651
{
27-
$objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager();
28-
29-
$this->_customerSession = $objectManager->get(\Magento\Customer\Model\Session::class);
30-
$this->_customerSession->setCustomerId(1);
31-
32-
$this->_context = $objectManager->get(\Magento\Backend\Block\Template\Context::class);
33-
$this->_requestId = $this->_context->getRequest()->getParam('id');
34-
$this->_context->getRequest()->setParam('id', '1');
35-
36-
$objectManager->get(\Magento\Framework\App\State::class)->setAreaCode('frontend');
37-
38-
/** @var $layout \Magento\Framework\View\Layout */
39-
$layout = $objectManager->get(\Magento\Framework\View\LayoutInterface::class);
40-
$currentCustomer = $objectManager->create(
41-
\Magento\Customer\Helper\Session\CurrentCustomer::class,
42-
['customerSession' => $this->_customerSession]
43-
);
44-
$this->_block = $layout->createBlock(
45-
\Magento\Customer\Block\Address\Edit::class,
46-
'',
47-
['customerSession' => $this->_customerSession, 'currentCustomer' => $currentCustomer]
48-
);
52+
parent::setUp();
53+
$this->objectManager = Bootstrap::getObjectManager();
54+
$this->customerSession = $this->objectManager->get(Session::class);
55+
$this->customerSession->setCustomerId(1);
56+
$this->request = $this->objectManager->get(RequestInterface::class);
57+
$this->request->setParam('id', '1');
58+
/** @var Page $page */
59+
$page = $this->objectManager->get(PageFactory::class)->create();
60+
$page->addHandle(['default', 'customer_address_form']);
61+
$page->getLayout()->generateXml();
62+
$this->block = $page->getLayout()->getBlock('customer_address_edit');
63+
$this->addressRegistry = $this->objectManager->get(AddressRegistry::class);
64+
$this->customerRegistry = $this->objectManager->get(CustomerRegistry::class);
4965
}
5066

67+
/**
68+
* @inheritdoc
69+
*/
5170
protected function tearDown(): void
5271
{
53-
$objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager();
54-
$this->_customerSession->setCustomerId(null);
55-
$this->_context->getRequest()->setParam('id', $this->_requestId);
56-
/** @var \Magento\Customer\Model\AddressRegistry $addressRegistry */
57-
$addressRegistry = $objectManager->get(\Magento\Customer\Model\AddressRegistry::class);
72+
parent::tearDown();
73+
$this->customerSession->setCustomerId(null);
74+
$this->request->setParam('id', null);
5875
//Cleanup address from registry
59-
$addressRegistry->remove(1);
60-
$addressRegistry->remove(2);
61-
62-
/** @var \Magento\Customer\Model\CustomerRegistry $customerRegistry */
63-
$customerRegistry = $objectManager->get(\Magento\Customer\Model\CustomerRegistry::class);
76+
$this->addressRegistry->remove(1);
77+
$this->addressRegistry->remove(2);
6478
//Cleanup customer from registry
65-
$customerRegistry->remove(1);
79+
$this->customerRegistry->remove(1);
6680
}
6781

6882
/**
6983
* @magentoDataFixture Magento/Customer/_files/customer.php
84+
* @return void
7085
*/
71-
public function testGetSaveUrl()
86+
public function testGetSaveUrl(): void
7287
{
73-
$this->assertEquals('http://localhost/index.php/customer/address/formPost/', $this->_block->getSaveUrl());
88+
$this->assertEquals('http://localhost/index.php/customer/address/formPost/', $this->block->getSaveUrl());
7489
}
7590

7691
/**
7792
* @magentoDataFixture Magento/Customer/_files/customer.php
7893
* @magentoDataFixture Magento/Customer/_files/customer_address.php
94+
* @return void
7995
*/
80-
public function testGetRegionId()
96+
public function testGetRegionId(): void
8197
{
82-
$this->assertEquals(1, $this->_block->getRegionId());
98+
$this->assertEquals(1, $this->block->getRegionId());
8399
}
84100

85101
/**
86102
* @magentoDataFixture Magento/Customer/_files/customer.php
87103
* @magentoDataFixture Magento/Customer/_files/customer_address.php
104+
* @return void
88105
*/
89-
public function testGetCountryId()
106+
public function testGetCountryId(): void
90107
{
91-
$this->assertEquals('US', $this->_block->getCountryId());
108+
$this->assertEquals('US', $this->block->getCountryId());
92109
}
93110

94111
/**
95112
* @magentoDataFixture Magento/Customer/_files/customer.php
96113
* @magentoDataFixture Magento/Customer/_files/customer_two_addresses.php
114+
* @return void
97115
*/
98-
public function testGetCustomerAddressCount()
116+
public function testGetCustomerAddressCount(): void
99117
{
100-
$this->assertEquals(2, $this->_block->getCustomerAddressCount());
118+
$this->assertEquals(2, $this->block->getCustomerAddressCount());
101119
}
102120

103121
/**
104122
* @magentoDataFixture Magento/Customer/_files/customer.php
123+
* @return void
105124
*/
106-
public function testCanSetAsDefaultShipping()
125+
public function testCanSetAsDefaultShipping(): void
107126
{
108-
$this->assertEquals(0, $this->_block->canSetAsDefaultShipping());
127+
$this->assertEquals(0, $this->block->canSetAsDefaultShipping());
109128
}
110129

111130
/**
112131
* @magentoDataFixture Magento/Customer/_files/customer.php
132+
* @return void
113133
*/
114-
public function testIsDefaultBilling()
134+
public function testIsDefaultBilling(): void
115135
{
116-
$this->assertFalse($this->_block->isDefaultBilling());
136+
$this->assertFalse($this->block->isDefaultBilling());
117137
}
118138

119139
/**
120140
* @magentoDataFixture Magento/Customer/_files/customer.php
121141
* @magentoDataFixture Magento/Customer/_files/customer_address.php
142+
* @return void
143+
*/
144+
public function testGetStreetLine(): void
145+
{
146+
$this->assertEquals('Green str, 67', $this->block->getStreetLine(1));
147+
$this->assertEquals('', $this->block->getStreetLine(2));
148+
}
149+
150+
/**
151+
* @magentoDataFixture Magento/Customer/_files/customer.php
152+
* @magentoConfigFixture current_store customer/create_account/vat_frontend_visibility 1
153+
* @return void
154+
*/
155+
public function testVatIdFieldVisible(): void
156+
{
157+
$html = $this->block->toHtml();
158+
$labelXpath = "//div[contains(@class, 'taxvat')]//label/span[normalize-space(text()) = '%s']";
159+
$this->assertEquals(1, Xpath::getElementsCountForXpath(sprintf($labelXpath, __('VAT Number')), $html));
160+
$inputXpath = "//div[contains(@class, 'taxvat')]//div/input[contains(@id,'vat_id') and @type='text']";
161+
$this->assertEquals(1, Xpath::getElementsCountForXpath($inputXpath, $html));
162+
}
163+
164+
/**
165+
* @magentoDataFixture Magento/Customer/_files/customer.php
166+
* @magentoConfigFixture current_store customer/create_account/vat_frontend_visibility 0
167+
* @return void
122168
*/
123-
public function testGetStreetLine()
169+
public function testVatIdFieldNotVisible(): void
124170
{
125-
$this->assertEquals('Green str, 67', $this->_block->getStreetLine(1));
126-
$this->assertEquals('', $this->_block->getStreetLine(2));
171+
$html = $this->block->toHtml();
172+
$labelXpath = "//div[contains(@class, 'taxvat')]//label/span[normalize-space(text()) = '%s']";
173+
$this->assertEquals(0, Xpath::getElementsCountForXpath(sprintf($labelXpath, __('VAT Number')), $html));
174+
$inputXpath = "//div[contains(@class, 'taxvat')]//div/input[contains(@id,'vat_id') and @type='text']";
175+
$this->assertEquals(0, Xpath::getElementsCountForXpath($inputXpath, $html));
127176
}
128177
}

0 commit comments

Comments
 (0)