136 $objectManager = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this);
141 $this->markTestSkipped(
'Cannot be unit tested with the auto generated builder dependencies');
142 $this->customerSessionMock = $this->createMock(\
Magento\Customer\Model\Session::class);
143 $this->redirectMock = $this->createMock(\
Magento\Framework\
App\
Response\RedirectInterface::class);
144 $this->responseMock = $this->createMock(\
Magento\Framework\Webapi\Response::class);
145 $this->requestMock = $this->createMock(\
Magento\Framework\
App\Request\Http::class);
147 $this->urlMock = $this->createMock(\
Magento\Framework\Url::class);
148 $urlFactoryMock = $this->createMock(\
Magento\Framework\UrlFactory::class);
149 $urlFactoryMock->expects($this->once())
151 ->will($this->returnValue($this->urlMock));
153 $this->customerMock = $this->createMock(\
Magento\Customer\Api\Data\CustomerInterface::class);
154 $this->customerDetailsMock = $this->createMock(\
Magento\Customer\Api\Data\CustomerInterface::class);
155 $this->customerDetailsFactoryMock = $this->createMock(
156 \
Magento\Customer\Api\Data\CustomerInterfaceFactory::class
159 $this->messageManagerMock = $this->createMock(\
Magento\Framework\Message\Manager::class);
160 $this->scopeConfigMock = $this->createMock(\
Magento\Framework\
App\Config\ScopeConfigInterface::class);
162 $this->storeManagerMock = $this->createMock(\
Magento\Store\Model\StoreManager::class);
163 $this->storeMock = $this->createMock(\
Magento\Store\Model\Store::class);
165 $this->customerRepository = $this->createMock(\
Magento\Customer\Api\CustomerRepositoryInterface::class);
166 $this->accountManagement = $this->createMock(\
Magento\Customer\Api\AccountManagementInterface::class);
167 $this->addressHelperMock = $this->createMock(\
Magento\Customer\Helper\Address::class);
168 $formFactoryMock = $this->createMock(\
Magento\Customer\Model\Metadata\FormFactory::class);
170 $this->subscriberMock = $this->createMock(\
Magento\Newsletter\Model\Subscriber::class);
171 $subscriberFactoryMock = $this->createPartialMock(
172 \
Magento\Newsletter\Model\SubscriberFactory::class,
175 $subscriberFactoryMock->expects($this->any())
177 ->will($this->returnValue($this->subscriberMock));
179 $regionFactoryMock = $this->createMock(\
Magento\Customer\Api\Data\RegionInterfaceFactory::class);
180 $addressFactoryMock = $this->createMock(\
Magento\Customer\Api\Data\AddressInterfaceFactory::class);
181 $this->customerUrl = $this->createMock(\
Magento\Customer\Model\Url::class);
182 $this->registration = $this->createMock(\
Magento\Customer\Model\Registration::class);
183 $escaperMock = $this->createMock(\
Magento\Framework\Escaper::class);
184 $this->customerExtractorMock = $this->createMock(\
Magento\Customer\Model\CustomerExtractor::class);
185 $this->dataObjectHelperMock = $this->createMock(\
Magento\Framework\Api\DataObjectHelper::class);
187 $eventManagerMock = $this->createMock(\
Magento\Framework\Event\ManagerInterface::class);
189 $this->resultRedirectFactoryMock = $this->getMockBuilder(
190 \
Magento\Framework\Controller\Result\RedirectFactory::class
192 ->setMethods([
'create'])
193 ->disableOriginalConstructor()
195 $this->resultRedirectFactoryMock->expects($this->any())
197 ->willReturn($this->redirectMock);
199 $contextMock = $this->createMock(\
Magento\Framework\
App\Action\Context::class);
200 $contextMock->expects($this->any())
201 ->method(
'getRequest')
202 ->willReturn($this->requestMock);
203 $contextMock->expects($this->any())
204 ->method(
'getResponse')
205 ->willReturn($this->responseMock);
206 $contextMock->expects($this->any())
207 ->method(
'getRedirect')
208 ->willReturn($this->redirectMock);
209 $contextMock->expects($this->any())
210 ->method(
'getMessageManager')
211 ->willReturn($this->messageManagerMock);
212 $contextMock->expects($this->any())
213 ->method(
'getEventManager')
214 ->willReturn($eventManagerMock);
215 $contextMock->expects($this->any())
216 ->method(
'getResultRedirectFactory')
217 ->willReturn($this->resultRedirectFactoryMock);
220 \
Magento\Customer\Controller\Account\CreatePost::class,
222 'context' => $contextMock,
223 'customerSession' => $this->customerSessionMock,
224 'scopeConfig' => $this->scopeConfigMock,
225 'storeManager' => $this->storeManagerMock,
226 'accountManagement' => $this->accountManagement,
227 'addressHelper' => $this->addressHelperMock,
228 'urlFactory' => $urlFactoryMock,
229 'formFactory' => $formFactoryMock,
230 'subscriberFactory' => $subscriberFactoryMock,
231 'regionDataFactory' => $regionFactoryMock,
232 'addressDataFactory' => $addressFactoryMock,
233 'customerDetailsFactory' => $this->customerDetailsFactoryMock,
234 'customerUrl' => $this->customerUrl,
235 'registration' => $this->registration,
236 'escape' => $escaperMock,
237 'customerExtractor' => $this->customerExtractorMock,
238 'dataObjectHelper' => $this->dataObjectHelperMock,
248 $this->customerSessionMock->expects($this->once())
249 ->method(
'isLoggedIn')
250 ->will($this->returnValue(
false));
252 $this->registration->expects($this->once())
253 ->method(
'isAllowed')
254 ->will($this->returnValue(
false));
256 $this->redirectMock->expects($this->once())
258 ->with($this->responseMock,
'*/*/', [])
259 ->will($this->returnValue(
false));
261 $this->customerRepository->expects($this->never())
264 $this->model->execute();
269 $this->customerSessionMock->expects($this->once())
270 ->method(
'regenerateId');
271 $this->customerSessionMock->expects($this->once())
272 ->method(
'isLoggedIn')
273 ->will($this->returnValue(
false));
275 $this->registration->expects($this->once())
276 ->method(
'isAllowed')
277 ->will($this->returnValue(
true));
278 $this->requestMock->expects($this->once())
280 ->will($this->returnValue(
true));
282 $this->customerExtractorMock->expects($this->once())
284 ->willReturn($this->customerMock);
285 $this->accountManagement->expects($this->once())
286 ->method(
'createAccount')
287 ->willReturn($this->customerMock);
288 $this->storeManagerMock->expects($this->once())
290 ->willReturn($this->storeMock);
291 $this->model->execute();
310 $vatValidationEnabled,
314 $this->customerSessionMock->expects($this->once())
315 ->method(
'isLoggedIn')
316 ->will($this->returnValue(
false));
318 $this->registration->expects($this->once())
319 ->method(
'isAllowed')
320 ->will($this->returnValue(
true));
321 $this->customerUrl->expects($this->once())
322 ->method(
'getEmailConfirmationUrl')
325 $this->customerSessionMock->expects($this->once())
326 ->method(
'regenerateId');
328 $this->customerMock->expects($this->any())
331 $this->customerMock->expects($this->any())
335 $this->customerExtractorMock->expects($this->any())
337 ->with($this->equalTo(
'customer_account_create'), $this->equalTo($this->requestMock))
338 ->will($this->returnValue($this->customerMock));
340 $this->requestMock->expects($this->once())
342 ->will($this->returnValue(
true));
343 $this->requestMock->expects($this->any())
345 ->will($this->returnValue(
false));
347 $this->requestMock->expects($this->any())
350 [
'password',
null, $password],
351 [
'password_confirmation',
null, $password],
352 [
'is_subscribed',
false,
true],
355 $this->customerMock->expects($this->once())
356 ->method(
'setAddresses')
357 ->with($this->equalTo([]))
358 ->will($this->returnSelf());
360 $this->accountManagement->expects($this->once())
361 ->method(
'createAccount')
362 ->with($this->equalTo($this->customerDetailsMock), $this->equalTo($password),
'')
363 ->will($this->returnValue($this->customerMock));
364 $this->accountManagement->expects($this->once())
365 ->method(
'getConfirmationStatus')
367 ->will($this->returnValue($confirmationStatus));
369 $this->subscriberMock->expects($this->once())
370 ->method(
'subscribeCustomerById')
373 $this->messageManagerMock->expects($this->any())
374 ->method(
'addSuccess')
375 ->with($this->stringContains($successMessage))
376 ->will($this->returnSelf());
378 $this->addressHelperMock->expects($this->any())
379 ->method(
'isVatValidationEnabled')
380 ->will($this->returnValue($vatValidationEnabled));
381 $this->addressHelperMock->expects($this->any())
382 ->method(
'getTaxCalculationAddressType')
383 ->will($this->returnValue($addressType));
385 $this->model->execute();
401 'An account confirmation is required',
410 'Thank you for registering with',
419 'enter you shipping address for proper VAT calculation',
428 'enter you billing address for proper VAT calculation',
451 $this->customerSessionMock->expects($this->once())
452 ->method(
'isLoggedIn')
453 ->will($this->returnValue(
false));
455 $this->registration->expects($this->once())
456 ->method(
'isAllowed')
457 ->will($this->returnValue(
true));
459 $this->customerSessionMock->expects($this->once())
460 ->method(
'regenerateId');
462 $this->customerMock->expects($this->any())
466 $this->customerExtractorMock->expects($this->any())
468 ->with($this->equalTo(
'customer_account_create'), $this->equalTo($this->requestMock))
469 ->will($this->returnValue($this->customerMock));
471 $this->requestMock->expects($this->once())
473 ->will($this->returnValue(
true));
474 $this->requestMock->expects($this->any())
476 ->will($this->returnValue(
false));
478 $this->requestMock->expects($this->any())
481 [
'password',
null, $password],
482 [
'password_confirmation',
null, $password],
483 [
'is_subscribed',
false,
true],
486 $this->customerMock->expects($this->once())
487 ->method(
'setAddresses')
488 ->with($this->equalTo([]))
489 ->will($this->returnSelf());
491 $this->accountManagement->expects($this->once())
492 ->method(
'createAccount')
493 ->with($this->equalTo($this->customerDetailsMock), $this->equalTo($password),
'')
494 ->will($this->returnValue($this->customerMock));
495 $this->accountManagement->expects($this->once())
496 ->method(
'getConfirmationStatus')
498 ->will($this->returnValue($confirmationStatus));
500 $this->subscriberMock->expects($this->once())
501 ->method(
'subscribeCustomerById')
504 $this->messageManagerMock->expects($this->any())
505 ->method(
'addSuccess')
506 ->with($this->stringContains($successMessage))
507 ->will($this->returnSelf());
509 $this->urlMock->expects($this->any())
512 [
'*/*/index', [
'_secure' =>
true], $successUrl],
513 [
'*/*/create', [
'_secure' =>
true], $successUrl],
515 $this->redirectMock->expects($this->once())
517 ->with($this->equalTo($successUrl))
518 ->will($this->returnValue($successUrl));
519 $this->scopeConfigMock->expects($this->once())
520 ->method(
'isSetFlag')
525 ->will($this->returnValue($isSetFlag));
526 $this->storeMock->expects($this->any())
527 ->method(
'getFrontendName')
528 ->will($this->returnValue(
'frontend'));
529 $this->storeManagerMock->expects($this->any())
531 ->will($this->returnValue($this->storeMock));
533 $this->model->execute();
546 'http://example.com/success',
548 'Thank you for registering with',
554 'http://example.com/success',
556 'Thank you for registering with',
getSuccessRedirectDataProvider()
$resultRedirectFactoryMock
testRegenerateIdOnExecution()
testSuccessMessage( $customerId, $customerEmail, $password, $confirmationStatus, $vatValidationEnabled, $addressType, $successMessage)
testSuccessRedirect( $customerId, $password, $confirmationStatus, $successUrl, $isSetFlag, $successMessage)
getSuccessMessageDataProvider()
testCreatePostActionRegistrationDisabled()
const ACCOUNT_CONFIRMATION_NOT_REQUIRED
const XML_PATH_CUSTOMER_STARTUP_REDIRECT_TO_DASHBOARD
$customerDetailsFactoryMock
const ACCOUNT_CONFIRMATION_REQUIRED