Skip to content

Commit f9f5980

Browse files
MC-31434: Customer Configurations: Create new account options
1 parent 7c8e4cf commit f9f5980

File tree

3 files changed

+63
-21
lines changed

3 files changed

+63
-21
lines changed

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

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ class EditTest extends TestCase
4949
*/
5050
protected function setUp()
5151
{
52+
parent::setUp();
5253
$this->objectManager = Bootstrap::getObjectManager();
5354
$this->customerSession = $this->objectManager->get(Session::class);
5455
$this->customerSession->setCustomerId(1);
@@ -68,6 +69,7 @@ protected function setUp()
6869
*/
6970
protected function tearDown()
7071
{
72+
parent::tearDown();
7173
$this->customerSession->setCustomerId(null);
7274
$this->request->setParam('id', null);
7375
//Cleanup address from registry
@@ -79,6 +81,7 @@ protected function tearDown()
7981

8082
/**
8183
* @magentoDataFixture Magento/Customer/_files/customer.php
84+
* @return void
8285
*/
8386
public function testGetSaveUrl(): void
8487
{
@@ -88,6 +91,7 @@ public function testGetSaveUrl(): void
8891
/**
8992
* @magentoDataFixture Magento/Customer/_files/customer.php
9093
* @magentoDataFixture Magento/Customer/_files/customer_address.php
94+
* @return void
9195
*/
9296
public function testGetRegionId(): void
9397
{
@@ -97,6 +101,7 @@ public function testGetRegionId(): void
97101
/**
98102
* @magentoDataFixture Magento/Customer/_files/customer.php
99103
* @magentoDataFixture Magento/Customer/_files/customer_address.php
104+
* @return void
100105
*/
101106
public function testGetCountryId(): void
102107
{
@@ -106,6 +111,7 @@ public function testGetCountryId(): void
106111
/**
107112
* @magentoDataFixture Magento/Customer/_files/customer.php
108113
* @magentoDataFixture Magento/Customer/_files/customer_two_addresses.php
114+
* @return void
109115
*/
110116
public function testGetCustomerAddressCount(): void
111117
{
@@ -114,6 +120,7 @@ public function testGetCustomerAddressCount(): void
114120

115121
/**
116122
* @magentoDataFixture Magento/Customer/_files/customer.php
123+
* @return void
117124
*/
118125
public function testCanSetAsDefaultShipping(): void
119126
{
@@ -122,6 +129,7 @@ public function testCanSetAsDefaultShipping(): void
122129

123130
/**
124131
* @magentoDataFixture Magento/Customer/_files/customer.php
132+
* @return void
125133
*/
126134
public function testIsDefaultBilling(): void
127135
{
@@ -131,6 +139,7 @@ public function testIsDefaultBilling(): void
131139
/**
132140
* @magentoDataFixture Magento/Customer/_files/customer.php
133141
* @magentoDataFixture Magento/Customer/_files/customer_address.php
142+
* @return void
134143
*/
135144
public function testGetStreetLine(): void
136145
{
@@ -141,6 +150,7 @@ public function testGetStreetLine(): void
141150
/**
142151
* @magentoDataFixture Magento/Customer/_files/customer.php
143152
* @magentoConfigFixture current_store customer/create_account/vat_frontend_visibility 1
153+
* @return void
144154
*/
145155
public function testVatIdFieldVisible(): void
146156
{
@@ -154,6 +164,7 @@ public function testVatIdFieldVisible(): void
154164
/**
155165
* @magentoDataFixture Magento/Customer/_files/customer.php
156166
* @magentoConfigFixture current_store customer/create_account/vat_frontend_visibility 0
167+
* @return void
157168
*/
158169
public function testVatIdFieldNotVisible(): void
159170
{

dev/tests/integration/testsuite/Magento/Customer/Controller/Account/CreatePostTest.php

Lines changed: 34 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -11,16 +11,20 @@
1111
use Magento\Customer\Api\Data\CustomerInterface;
1212
use Magento\Customer\Model\CustomerRegistry;
1313
use Magento\Framework\App\Http;
14+
use Magento\Framework\App\Request\Http as HttpRequest;
1415
use Magento\Framework\Exception\NoSuchEntityException;
1516
use Magento\Framework\Message\MessageInterface;
1617
use Magento\Framework\Stdlib\CookieManagerInterface;
18+
use Magento\Framework\UrlInterface;
1719
use Magento\Store\Model\StoreManagerInterface;
1820
use Magento\TestFramework\Mail\Template\TransportBuilderMock;
1921
use Magento\TestFramework\Request;
2022
use Magento\TestFramework\TestCase\AbstractController;
2123
use Magento\Theme\Controller\Result\MessagePlugin;
2224

2325
/**
26+
* Tests from customer account create post action.
27+
*
2428
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
2529
*/
2630
class CreatePostTest extends AbstractController
@@ -50,6 +54,11 @@ class CreatePostTest extends AbstractController
5054
*/
5155
private $cookieManager;
5256

57+
/**
58+
* @var UrlInterface
59+
*/
60+
private $urlBuilder;
61+
5362
/**
5463
* @inheritdoc
5564
*/
@@ -62,6 +71,7 @@ protected function setUp()
6271
$this->customerRepository = $this->_objectManager->get(CustomerRepositoryInterface::class);
6372
$this->customerRegistry = $this->_objectManager->get(CustomerRegistry::class);
6473
$this->cookieManager = $this->_objectManager->get(CookieManagerInterface::class);
74+
$this->urlBuilder = $this->_objectManager->get(UrlInterface::class);
6575
}
6676

6777
/**
@@ -81,7 +91,7 @@ public function testNoFormKeyCreatePostAction(): void
8191
$this->assertCustomerNotExists('test1@email.com');
8292
$this->assertRedirect($this->stringEndsWith('customer/account/create/'));
8393
$this->assertSessionMessages(
84-
$this->equalTo([__('Invalid Form Key. Please refresh the page.')]),
94+
$this->contains(__('Invalid Form Key. Please refresh the page.')),
8595
MessageInterface::TYPE_ERROR
8696
);
8797
}
@@ -101,7 +111,9 @@ public function testNoConfirmCreatePostAction(): void
101111
$this->dispatch('customer/account/createPost');
102112
$this->assertRedirect($this->stringEndsWith('customer/account/'));
103113
$this->assertSessionMessages(
104-
$this->equalTo([__('Thank you for registering with Main Website Store.')]),
114+
$this->contains(
115+
(string)__('Thank you for registering with %1.', $this->storeManager->getStore()->getFrontendName())
116+
),
105117
MessageInterface::TYPE_SUCCESS
106118
);
107119
$customer = $this->customerRegistry->retrieveByEmail('test1@email.com');
@@ -125,7 +137,9 @@ public function testCreatePostWithCustomConfiguration(): void
125137
$this->dispatch('customer/account/createPost');
126138
$this->assertRedirect($this->stringEndsWith('customer/account/'));
127139
$this->assertSessionMessages(
128-
$this->equalTo([__('Thank you for registering with Main Website Store.')]),
140+
$this->contains(
141+
(string)__('Thank you for registering with %1.', $this->storeManager->getStore()->getFrontendName())
142+
),
129143
MessageInterface::TYPE_SUCCESS
130144
);
131145
$customer = $this->customerRegistry->retrieveByEmail('test@email.com');
@@ -145,13 +159,17 @@ public function testCreatePostWithCustomConfiguration(): void
145159
*/
146160
public function testWithConfirmCreatePostAction(): void
147161
{
148-
$this->fillRequestWithAccountData('test2@email.com');
162+
$email = 'test2@email.com';
163+
$this->fillRequestWithAccountData($email);
149164
$this->dispatch('customer/account/createPost');
150165
$this->assertRedirect($this->stringContains('customer/account/index/'));
151166
$message = 'You must confirm your account.'
152167
. ' Please check your email for the confirmation link or <a href="%1">click here</a> for a new link.';
153-
$url = 'http://localhost/index.php/customer/account/confirmation/?email=test2%40email.com';
154-
$this->assertSessionMessages($this->equalTo([__($message, $url)]), MessageInterface::TYPE_SUCCESS);
168+
$url = $this->urlBuilder->getUrl('customer/account/confirmation', ['_query' => ['email' => $email]]);
169+
$this->assertSessionMessages(
170+
$this->contains((string)__($message, $url)),
171+
MessageInterface::TYPE_SUCCESS
172+
);
155173
}
156174

157175
/**
@@ -167,8 +185,8 @@ public function testExistingEmailCreatePostAction(): void
167185
$message = 'There is already an account with this email address.'
168186
. ' If you are sure that it is your email address, <a href="%1">click here</a> '
169187
. 'to get your password and access your account.';
170-
$url = 'http://localhost/index.php/customer/account/forgotpassword/';
171-
$this->assertSessionMessages($this->equalTo([(string)__($message, $url)]), MessageInterface::TYPE_ERROR);
188+
$url = $this->urlBuilder->getUrl('customer/account/forgotpassword');
189+
$this->assertSessionMessages($this->contains((string)__($message, $url)), MessageInterface::TYPE_ERROR);
172190
}
173191

174192
/**
@@ -186,12 +204,14 @@ public function testRegisterCustomerWithEmailConfirmation(): void
186204
$this->assertRedirect($this->stringContains('customer/account/index/'));
187205
$message = 'You must confirm your account.'
188206
. ' Please check your email for the confirmation link or <a href="%1">click here</a> for a new link.';
189-
$url = 'http://localhost/index.php/customer/account/confirmation/?email=test_example%40email.com';
207+
$url = $this->urlBuilder->getUrl('customer/account/confirmation', ['_query' => ['email' => $email]]);
190208
$this->assertSessionMessages($this->equalTo([(string)__($message, $url)]), MessageInterface::TYPE_SUCCESS);
191209
/** @var CustomerInterface $customer */
192210
$customer = $this->customerRepository->get($email);
193211
$confirmation = $customer->getConfirmation();
194-
$rawMessage = $this->transportBuilderMock->getSentMessage()->getBody()->getParts()[0]->getRawContent();
212+
$sendMessage = $this->transportBuilderMock->getSentMessage();
213+
$this->assertNotNull($sendMessage);
214+
$rawMessage = $sendMessage->getBody()->getParts()[0]->getRawContent();
195215
$this->assertContains(
196216
(string)__(
197217
'You must confirm your %customer_email email before you can sign in (link is only valid once):',
@@ -210,8 +230,8 @@ public function testRegisterCustomerWithEmailConfirmation(): void
210230
$this->dispatch('customer/account/confirm');
211231
$this->assertRedirect($this->stringContains('customer/account/index/'));
212232
$this->assertSessionMessages(
213-
$this->equalTo(
214-
[__('Thank you for registering with %1.', $this->storeManager->getStore()->getFrontendName())]
233+
$this->contains(
234+
(string)__('Thank you for registering with %1.', $this->storeManager->getStore()->getFrontendName())
215235
),
216236
MessageInterface::TYPE_SUCCESS
217237
);
@@ -224,10 +244,10 @@ public function testRegisterCustomerWithEmailConfirmation(): void
224244
* @param string $email
225245
* @return void
226246
*/
227-
private function fillRequestWithAccountData($email): void
247+
private function fillRequestWithAccountData(string $email): void
228248
{
229249
$this->getRequest()
230-
->setMethod('POST')
250+
->setMethod(HttpRequest::METHOD_POST)
231251
->setParam(CustomerInterface::FIRSTNAME, 'firstname1')
232252
->setParam(CustomerInterface::LASTNAME, 'lastname1')
233253
->setParam(CustomerInterface::EMAIL, $email)

dev/tests/integration/testsuite/Magento/Customer/Model/Address/CreateAddressTest.php

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
use Magento\Customer\Observer\AfterAddressSaveObserver;
1919
use Magento\Framework\App\Config\ScopeConfigInterface;
2020
use Magento\Framework\DataObject;
21+
use Magento\Framework\DataObjectFactory;
2122
use Magento\Framework\Exception\InputException;
2223
use Magento\TestFramework\Directory\Model\GetRegionIdByName;
2324
use Magento\TestFramework\Helper\Bootstrap;
@@ -93,6 +94,11 @@ class CreateAddressTest extends TestCase
9394
*/
9495
private $createdAddressesIds = [];
9596

97+
/**
98+
* @var DataObjectFactory
99+
*/
100+
private $dataObjectFactory;
101+
96102
/**
97103
* @inheritdoc
98104
*/
@@ -106,6 +112,7 @@ protected function setUp()
106112
$this->customerRepository = $this->objectManager->get(CustomerRepositoryInterface::class);
107113
$this->addressRegistry = $this->objectManager->get(AddressRegistry::class);
108114
$this->addressResource = $this->objectManager->get(Address::class);
115+
$this->dataObjectFactory = $this->objectManager->get(DataObjectFactory::class);
109116
parent::setUp();
110117
}
111118

@@ -463,13 +470,17 @@ protected function createAddress(
463470
*/
464471
private function createVatMock(bool $isValid = false, bool $isRequestSuccess = false): void
465472
{
466-
$gatewayResponse = new DataObject([
467-
'is_valid' => $isValid,
468-
'request_date' => '',
469-
'request_identifier' => '123123123',
470-
'request_success' => $isRequestSuccess,
471-
'request_message' => __(''),
472-
]);
473+
$gatewayResponse = $this->dataObjectFactory->create(
474+
[
475+
'data' => [
476+
'is_valid' => $isValid,
477+
'request_date' => '',
478+
'request_identifier' => '123123123',
479+
'request_success' => $isRequestSuccess,
480+
'request_message' => __(''),
481+
],
482+
]
483+
);
473484
$customerVat = $this->getMockBuilder(Vat::class)
474485
->setConstructorArgs(
475486
[

0 commit comments

Comments
 (0)