Skip to content

Commit ee9bc9f

Browse files
MC-31434: Customer Configurations: Create new account options
1 parent e18ee73 commit ee9bc9f

13 files changed

+891
-264
lines changed

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

Lines changed: 94 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -3,126 +3,164 @@
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()
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+
$this->objectManager = Bootstrap::getObjectManager();
53+
$this->customerSession = $this->objectManager->get(Session::class);
54+
$this->customerSession->setCustomerId(1);
55+
$this->request = $this->objectManager->get(RequestInterface::class);
56+
$this->request->setParam('id', '1');
57+
/** @var Page $page */
58+
$page = $this->objectManager->get(PageFactory::class)->create();
59+
$page->addHandle(['default', 'customer_address_form']);
60+
$page->getLayout()->generateXml();
61+
$this->block = $page->getLayout()->getBlock('customer_address_edit');
62+
$this->addressRegistry = $this->objectManager->get(AddressRegistry::class);
63+
$this->customerRegistry = $this->objectManager->get(CustomerRegistry::class);
4964
}
5065

66+
/**
67+
* @inheritdoc
68+
*/
5169
protected function tearDown()
5270
{
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);
71+
$this->customerSession->setCustomerId(null);
72+
$this->request->setParam('id', null);
5873
//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);
74+
$this->addressRegistry->remove(1);
75+
$this->addressRegistry->remove(2);
6476
//Cleanup customer from registry
65-
$customerRegistry->remove(1);
77+
$this->customerRegistry->remove(1);
6678
}
6779

6880
/**
6981
* @magentoDataFixture Magento/Customer/_files/customer.php
7082
*/
71-
public function testGetSaveUrl()
83+
public function testGetSaveUrl(): void
7284
{
73-
$this->assertEquals('http://localhost/index.php/customer/address/formPost/', $this->_block->getSaveUrl());
85+
$this->assertEquals('http://localhost/index.php/customer/address/formPost/', $this->block->getSaveUrl());
7486
}
7587

7688
/**
7789
* @magentoDataFixture Magento/Customer/_files/customer.php
7890
* @magentoDataFixture Magento/Customer/_files/customer_address.php
7991
*/
80-
public function testGetRegionId()
92+
public function testGetRegionId(): void
8193
{
82-
$this->assertEquals(1, $this->_block->getRegionId());
94+
$this->assertEquals(1, $this->block->getRegionId());
8395
}
8496

8597
/**
8698
* @magentoDataFixture Magento/Customer/_files/customer.php
8799
* @magentoDataFixture Magento/Customer/_files/customer_address.php
88100
*/
89-
public function testGetCountryId()
101+
public function testGetCountryId(): void
90102
{
91-
$this->assertEquals('US', $this->_block->getCountryId());
103+
$this->assertEquals('US', $this->block->getCountryId());
92104
}
93105

94106
/**
95107
* @magentoDataFixture Magento/Customer/_files/customer.php
96108
* @magentoDataFixture Magento/Customer/_files/customer_two_addresses.php
97109
*/
98-
public function testGetCustomerAddressCount()
110+
public function testGetCustomerAddressCount(): void
99111
{
100-
$this->assertEquals(2, $this->_block->getCustomerAddressCount());
112+
$this->assertEquals(2, $this->block->getCustomerAddressCount());
101113
}
102114

103115
/**
104116
* @magentoDataFixture Magento/Customer/_files/customer.php
105117
*/
106-
public function testCanSetAsDefaultShipping()
118+
public function testCanSetAsDefaultShipping(): void
107119
{
108-
$this->assertEquals(0, $this->_block->canSetAsDefaultShipping());
120+
$this->assertEquals(0, $this->block->canSetAsDefaultShipping());
109121
}
110122

111123
/**
112124
* @magentoDataFixture Magento/Customer/_files/customer.php
113125
*/
114-
public function testIsDefaultBilling()
126+
public function testIsDefaultBilling(): void
115127
{
116-
$this->assertFalse($this->_block->isDefaultBilling());
128+
$this->assertFalse($this->block->isDefaultBilling());
117129
}
118130

119131
/**
120132
* @magentoDataFixture Magento/Customer/_files/customer.php
121133
* @magentoDataFixture Magento/Customer/_files/customer_address.php
122134
*/
123-
public function testGetStreetLine()
135+
public function testGetStreetLine(): void
136+
{
137+
$this->assertEquals('Green str, 67', $this->block->getStreetLine(1));
138+
$this->assertEquals('', $this->block->getStreetLine(2));
139+
}
140+
141+
/**
142+
* @magentoDataFixture Magento/Customer/_files/customer.php
143+
* @magentoConfigFixture current_store customer/create_account/vat_frontend_visibility 1
144+
*/
145+
public function testVatIdFieldVisible(): void
146+
{
147+
$html = $this->block->toHtml();
148+
$labelXpath = "//div[contains(@class, 'taxvat')]//label/span[normalize-space(text()) = '%s']";
149+
$this->assertEquals(1, Xpath::getElementsCountForXpath(sprintf($labelXpath, __('VAT Number')), $html));
150+
$inputXpath = "//div[contains(@class, 'taxvat')]//div/input[contains(@id,'vat_id') and @type='text']";
151+
$this->assertEquals(1, Xpath::getElementsCountForXpath($inputXpath, $html));
152+
}
153+
154+
/**
155+
* @magentoDataFixture Magento/Customer/_files/customer.php
156+
* @magentoConfigFixture current_store customer/create_account/vat_frontend_visibility 0
157+
*/
158+
public function testVatIdFieldNotVisible(): void
124159
{
125-
$this->assertEquals('Green str, 67', $this->_block->getStreetLine(1));
126-
$this->assertEquals('', $this->_block->getStreetLine(2));
160+
$html = $this->block->toHtml();
161+
$labelXpath = "//div[contains(@class, 'taxvat')]//label/span[normalize-space(text()) = '%s']";
162+
$this->assertEquals(0, Xpath::getElementsCountForXpath(sprintf($labelXpath, __('VAT Number')), $html));
163+
$inputXpath = "//div[contains(@class, 'taxvat')]//div/input[contains(@id,'vat_id') and @type='text']";
164+
$this->assertEquals(0, Xpath::getElementsCountForXpath($inputXpath, $html));
127165
}
128166
}

0 commit comments

Comments
 (0)