102 $this->customerSessionMock = $this->createMock(\
Magento\Customer\Model\Session::class);
103 $this->requestMock = $this->createMock(\
Magento\Framework\
App\RequestInterface::class);
104 $this->responseMock = $this->createPartialMock(
106 [
'setRedirect',
'__wakeup']
108 $viewMock = $this->createMock(\
Magento\Framework\
App\ViewInterface::class);
109 $this->redirectMock = $this->createMock(\
Magento\Framework\
App\
Response\RedirectInterface::class);
111 $this->urlMock = $this->createMock(\
Magento\Framework\Url::class);
112 $urlFactoryMock = $this->createMock(\
Magento\Framework\UrlFactory::class);
113 $urlFactoryMock->expects($this->any())
115 ->will($this->returnValue($this->urlMock));
117 $this->customerAccountManagementMock =
118 $this->getMockForAbstractClass(\
Magento\Customer\Api\AccountManagementInterface::class);
119 $this->customerDataMock = $this->createMock(\
Magento\Customer\Api\Data\CustomerInterface::class);
121 $this->customerRepositoryMock =
122 $this->getMockForAbstractClass(\
Magento\Customer\Api\CustomerRepositoryInterface::class);
124 $this->messageManagerMock = $this->createMock(\
Magento\Framework\Message\Manager::class);
125 $this->addressHelperMock = $this->createMock(\
Magento\Customer\Helper\Address::class);
126 $this->storeManagerMock = $this->createMock(\
Magento\Store\Model\StoreManager::class);
127 $this->storeMock = $this->createMock(\
Magento\Store\Model\Store::class);
128 $this->redirectResultMock = $this->createMock(\
Magento\Framework\Controller\Result\Redirect::class);
130 $resultFactoryMock = $this->createPartialMock(\
Magento\Framework\Controller\ResultFactory::class, [
'create']);
131 $resultFactoryMock->expects($this->once())
133 ->with(\
Magento\Framework\Controller\ResultFactory::TYPE_REDIRECT)
134 ->willReturn($this->redirectResultMock);
136 $this->scopeConfigMock = $this->createMock(\
Magento\Framework\
App\Config\ScopeConfigInterface::class);
137 $this->contextMock = $this->createMock(\
Magento\Framework\
App\Action\Context::class);
138 $this->contextMock->expects($this->any())
139 ->method(
'getRequest')
140 ->willReturn($this->requestMock);
141 $this->contextMock->expects($this->any())
142 ->method(
'getResponse')
143 ->willReturn($this->responseMock);
144 $this->contextMock->expects($this->any())
145 ->method(
'getRedirect')
146 ->willReturn($this->redirectMock);
147 $this->contextMock->expects($this->any())
149 ->willReturn($viewMock);
150 $this->contextMock->expects($this->any())
151 ->method(
'getMessageManager')
152 ->willReturn($this->messageManagerMock);
153 $this->contextMock->expects($this->any())
154 ->method(
'getResultFactory')
155 ->willReturn($resultFactoryMock);
157 $objectManagerHelper = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this);
159 $this->model = $objectManagerHelper->getObject(
160 \
Magento\Customer\Controller\Account\Confirm::class,
162 'context' => $this->contextMock,
163 'customerSession' => $this->customerSessionMock,
164 'scopeConfig' => $this->scopeConfigMock,
165 'storeManager' => $this->storeManagerMock,
166 'customerAccountManagement' => $this->customerAccountManagementMock,
167 'customerRepository' => $this->customerRepositoryMock,
168 'addressHelper' => $this->addressHelperMock,
169 'urlFactory' => $urlFactoryMock,
176 $this->customerSessionMock->expects($this->once())
177 ->method(
'isLoggedIn')
178 ->will($this->returnValue(
true));
180 $this->redirectResultMock->expects($this->once())
185 $this->assertInstanceOf(\
Magento\Framework\Controller\Result\Redirect::class, $this->model->execute());
193 $this->customerSessionMock->expects($this->once())
194 ->method(
'isLoggedIn')
195 ->will($this->returnValue(
false));
197 $this->requestMock->expects($this->at(0))
199 ->with($this->equalTo(
'id'),
false)
201 $this->requestMock->expects($this->at(1))
203 ->with($this->equalTo(
'key'),
false)
204 ->will($this->returnValue($key));
206 $exception = new \Exception(
'Bad request.');
207 $this->messageManagerMock->expects($this->once())
208 ->method(
'addException')
209 ->with($this->equalTo($exception), $this->equalTo(
'There was an error confirming the account'));
211 $testUrl =
'http://example.com';
212 $this->urlMock->expects($this->once())
214 ->with($this->equalTo(
'*/*/index'), [
'_secure' =>
true])
215 ->will($this->returnValue($testUrl));
217 $this->redirectMock->expects($this->once())
219 ->with($this->equalTo($testUrl))
220 ->will($this->returnValue($testUrl));
222 $this->redirectResultMock->expects($this->once())
224 ->with($this->equalTo($testUrl))
227 $this->assertInstanceOf(\
Magento\Framework\Controller\Result\Redirect::class, $this->model->execute());
252 $this->customerSessionMock->expects($this->once())
253 ->method(
'isLoggedIn')
254 ->will($this->returnValue(
false));
256 $this->requestMock->expects($this->any())
260 [
'key',
false, $key],
263 $this->customerRepositoryMock->expects($this->any())
266 ->will($this->returnValue($this->customerDataMock));
269 $this->customerDataMock->expects($this->once())
271 ->will($this->returnValue(
$email));
273 $this->customerAccountManagementMock->expects($this->once())
275 ->with($this->equalTo(
$email), $this->equalTo($key))
276 ->will($this->returnValue($this->customerDataMock));
278 $this->customerSessionMock->expects($this->any())
279 ->method(
'setCustomerDataAsLoggedIn')
280 ->with($this->equalTo($this->customerDataMock))
283 $this->messageManagerMock->expects($this->any())
284 ->method(
'addSuccess')
285 ->with($this->stringContains($successMessage))
288 $this->addressHelperMock->expects($this->once())
289 ->method(
'isVatValidationEnabled')
290 ->will($this->returnValue($vatValidationEnabled));
291 $this->addressHelperMock->expects($this->any())
292 ->method(
'getTaxCalculationAddressType')
293 ->will($this->returnValue($addressType));
295 $this->storeMock->expects($this->any())
296 ->method(
'getFrontendName')
297 ->will($this->returnValue(
'frontend'));
298 $this->storeManagerMock->expects($this->any())
300 ->will($this->returnValue($this->storeMock));
302 $cookieMetadataManager = $this->getMockBuilder(\
Magento\Framework\Stdlib\Cookie\PhpCookieManager::class)
303 ->disableOriginalConstructor()
305 $cookieMetadataManager->expects($this->once())
306 ->method(
'getCookie')
307 ->with(
'mage-cache-sessid')
309 $cookieMetadataFactory = $this->getMockBuilder(\
Magento\Framework\Stdlib\Cookie\CookieMetadataFactory::class)
310 ->disableOriginalConstructor()
312 $cookieMetadata = $this->getMockBuilder(\
Magento\Framework\Stdlib\Cookie\CookieMetadata::class)
313 ->disableOriginalConstructor()
315 $cookieMetadataFactory->expects($this->once())
316 ->method(
'createCookieMetadata')
317 ->willReturn($cookieMetadata);
318 $cookieMetadata->expects($this->once())
321 $cookieMetadataManager->expects($this->once())
322 ->method(
'deleteCookie')
323 ->with(
'mage-cache-sessid', $cookieMetadata);
325 $refClass = new \ReflectionClass(Confirm::class);
326 $cookieMetadataManagerProperty = $refClass->getProperty(
'cookieMetadataManager');
327 $cookieMetadataManagerProperty->setAccessible(
true);
328 $cookieMetadataManagerProperty->setValue($this->model, $cookieMetadataManager);
330 $cookieMetadataFactoryProperty = $refClass->getProperty(
'cookieMetadataFactory');
331 $cookieMetadataFactoryProperty->setAccessible(
true);
332 $cookieMetadataFactoryProperty->setValue($this->model, $cookieMetadataFactory);
334 $this->model->execute();
343 [1, 1,
false,
null,
__(
'Thank you for registering with')],
369 $this->customerSessionMock->expects($this->once())
370 ->method(
'isLoggedIn')
371 ->will($this->returnValue(
false));
373 $this->requestMock->expects($this->any())
377 [
'key',
false, $key],
378 [
'back_url',
false, $backUrl],
381 $this->customerRepositoryMock->expects($this->any())
384 ->will($this->returnValue($this->customerDataMock));
387 $this->customerDataMock->expects($this->once())
389 ->will($this->returnValue(
$email));
391 $this->customerAccountManagementMock->expects($this->once())
393 ->with($this->equalTo(
$email), $this->equalTo($key))
394 ->will($this->returnValue($this->customerDataMock));
396 $this->customerSessionMock->expects($this->any())
397 ->method(
'setCustomerDataAsLoggedIn')
398 ->with($this->equalTo($this->customerDataMock))
401 $this->messageManagerMock->expects($this->any())
402 ->method(
'addSuccess')
403 ->with($this->stringContains($successMessage))
406 $this->storeMock->expects($this->any())
407 ->method(
'getFrontendName')
408 ->will($this->returnValue(
'frontend'));
409 $this->storeManagerMock->expects($this->any())
411 ->will($this->returnValue($this->storeMock));
413 $this->urlMock->expects($this->any())
415 ->with($this->equalTo(
'*/*/index'), [
'_secure' =>
true])
416 ->will($this->returnValue($successUrl));
418 $this->redirectMock->expects($this->once())
420 ->with($this->equalTo($resultUrl))
421 ->willReturn($resultUrl);
423 $this->scopeConfigMock->expects($this->any())
424 ->method(
'isSetFlag')
429 ->willReturn($isSetFlag);
431 $cookieMetadataManager = $this->getMockBuilder(\
Magento\Framework\Stdlib\Cookie\PhpCookieManager::class)
432 ->disableOriginalConstructor()
434 $cookieMetadataManager->expects($this->once())
435 ->method(
'getCookie')
436 ->with(
'mage-cache-sessid')
439 $refClass = new \ReflectionClass(Confirm::class);
440 $refProperty = $refClass->getProperty(
'cookieMetadataManager');
441 $refProperty->setAccessible(
true);
442 $refProperty->setValue($this->model, $cookieMetadataManager);
444 $this->model->execute();
456 'http://example.com/back',
458 'http://example.com/back',
460 __(
'Thank you for registering with'),
466 'http://example.com/success',
467 'http://example.com/success',
469 __(
'Thank you for registering with'),
475 'http://example.com/success',
476 'http://example.com/success',
478 __(
'Thank you for registering with'),
testNoCustomerIdInRequest($customerId, $key)
getSuccessRedirectDataProvider()
$customerAccountManagementMock
getSuccessMessageDataProvider()
testSuccessMessage($customerId, $key, $vatValidationEnabled, $addressType, $successMessage)
const XML_PATH_CUSTOMER_STARTUP_REDIRECT_TO_DASHBOARD
getParametersDataProvider()
testSuccessRedirect( $customerId, $key, $backUrl, $successUrl, $resultUrl, $isSetFlag, $successMessage)