11 use Magento\Customer\Api\Data\AddressInterfaceFactory;
13 use Magento\Customer\Api\Data\RegionInterfaceFactory;
25 use Magento\Framework\Controller\Result\ForwardFactory;
164 private $customerAddressMapper;
173 $this->session = $this->getMockBuilder(\
Magento\Customer\Model\Session::class)
174 ->disableOriginalConstructor()
176 'setAddressFormData',
181 $this->formKeyValidator = $this->getMockBuilder(\
Magento\Framework\Data\
Form\FormKey\Validator::class)
182 ->disableOriginalConstructor()
189 $this->dataProcessor = $this->getMockBuilder(\
Magento\Framework\Reflection\DataObjectProcessor::class)
190 ->disableOriginalConstructor()
193 $this->dataObjectHelper = $this->getMockBuilder(\
Magento\Framework\Api\DataObjectHelper::class)
194 ->disableOriginalConstructor()
197 $this->resultForwardFactory = $this->getMockBuilder(\
Magento\Framework\Controller\Result\ForwardFactory::class)
198 ->disableOriginalConstructor()
201 $this->resultPageFactory = $this->getMockBuilder(\
Magento\Framework\View\Result\PageFactory::class)
202 ->disableOriginalConstructor()
205 $this->helperData = $this->getMockBuilder(\
Magento\Directory\Helper\Data::class)
206 ->disableOriginalConstructor()
209 $this->customerAddressMapper = $this->getMockBuilder(\
Magento\Customer\Model\Address\Mapper::class)
210 ->disableOriginalConstructor()
216 $this->formKeyValidator,
218 $this->addressRepository,
219 $this->addressDataFactory,
220 $this->regionDataFactory,
221 $this->dataProcessor,
222 $this->dataObjectHelper,
223 $this->resultForwardFactory,
224 $this->resultPageFactory,
225 $this->regionFactory,
229 $objectManager = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this);
232 'customerAddressMapper',
233 $this->customerAddressMapper
242 $this->context = $this->getMockBuilder(\
Magento\Framework\
App\Action\Context::class)
243 ->disableOriginalConstructor()
246 $this->request = $this->getMockBuilder(\
Magento\Framework\
App\RequestInterface::class)
252 ->getMockForAbstractClass();
254 $this->context->expects($this->any())
255 ->method(
'getRequest')
256 ->willReturn($this->request);
258 $this->redirect = $this->getMockBuilder(\
Magento\Framework\
App\
Response\RedirectInterface::class)
259 ->getMockForAbstractClass();
261 $this->context->expects($this->any())
262 ->method(
'getRedirect')
263 ->willReturn($this->redirect);
265 $this->resultRedirect = $this->getMockBuilder(\
Magento\Framework\Controller\Result\Redirect::class)
266 ->disableOriginalConstructor()
268 $this->resultRedirectFactory = $this->getMockBuilder(
269 \
Magento\Framework\Controller\Result\RedirectFactory::class
270 )->disableOriginalConstructor()->getMock();
271 $this->resultRedirectFactory->expects($this->any())
273 ->willReturn($this->resultRedirect);
275 $this->context->expects($this->any())
276 ->method(
'getResultRedirectFactory')
277 ->willReturn($this->resultRedirectFactory);
279 $this->objectManager = $this->getMockBuilder(\
Magento\Framework\ObjectManagerInterface::class)
280 ->getMockForAbstractClass();
282 $this->context->expects($this->any())
283 ->method(
'getObjectManager')
284 ->willReturn($this->objectManager);
286 $this->messageManager = $this->getMockBuilder(\
Magento\Framework\Message\ManagerInterface::class)
287 ->getMockForAbstractClass();
289 $this->context->expects($this->any())
290 ->method(
'getMessageManager')
291 ->willReturn($this->messageManager);
299 $this->addressRepository = $this->getMockBuilder(\
Magento\Customer\Api\AddressRepositoryInterface::class)
300 ->getMockForAbstractClass();
302 $this->addressData = $this->getMockBuilder(\
Magento\Customer\Api\Data\AddressInterface::class)
303 ->getMockForAbstractClass();
305 $this->addressDataFactory = $this->getMockBuilder(\
Magento\Customer\Api\Data\AddressInterfaceFactory::class)
306 ->disableOriginalConstructor()
311 $this->addressDataFactory->expects($this->any())
313 ->willReturn($this->addressData);
321 $this->region = $this->getMockBuilder(\
Magento\Directory\Model\Region::class)
322 ->disableOriginalConstructor()
330 $this->regionFactory = $this->getMockBuilder(\
Magento\Directory\Model\RegionFactory::class)
331 ->disableOriginalConstructor()
333 $this->regionFactory->expects($this->any())
335 ->willReturn($this->region);
337 $this->regionData = $this->getMockBuilder(\
Magento\Customer\Api\Data\RegionInterface::class)
338 ->getMockForAbstractClass();
340 $this->regionDataFactory = $this->getMockBuilder(\
Magento\Customer\Api\Data\RegionInterfaceFactory::class)
341 ->disableOriginalConstructor()
346 $this->regionDataFactory->expects($this->any())
348 ->willReturn($this->regionData);
356 $this->
form = $this->getMockBuilder(\
Magento\Customer\Model\Metadata\Form::class)
357 ->disableOriginalConstructor()
360 $this->formFactory = $this->getMockBuilder(\
Magento\Customer\Model\Metadata\FormFactory::class)
361 ->disableOriginalConstructor()
370 $this->formKeyValidator->expects($this->once())
372 ->with($this->request)
375 $this->resultRedirect->expects($this->once())
380 $this->assertEquals($this->resultRedirect, $this->model->execute());
388 $postValue =
'post_value';
391 $this->formKeyValidator->expects($this->once())
393 ->with($this->request)
396 $this->request->expects($this->once())
399 $this->request->expects($this->once())
400 ->method(
'getPostValue')
401 ->willReturn($postValue);
403 $this->session->expects($this->once())
404 ->method(
'setAddressFormData')
408 $urlBuilder = $this->getMockBuilder(\
Magento\Framework\UrlInterface::class)
409 ->getMockForAbstractClass();
410 $urlBuilder->expects($this->once())
412 ->with(
'*/*/edit', [])
415 $this->objectManager->expects($this->once())
417 ->with(\
Magento\Framework\UrlInterface::class)
418 ->willReturn($urlBuilder);
420 $this->redirect->expects($this->once())
425 $this->resultRedirect->expects($this->once())
430 $this->assertEquals($this->resultRedirect, $this->model->execute());
460 $existingAddressData = [
461 'country_id' => $countryId,
462 'region_id' => $regionId,
464 'region_code' => $regionCode,
468 'country_id' => $countryId,
469 'region_id' => $newRegionId,
470 'region' => $newRegion,
471 'region_code' => $newRegionCode,
475 $url =
'success_url';
477 $this->formKeyValidator->expects($this->once())
479 ->with($this->request)
482 $this->request->expects($this->once())
485 $this->request->expects($this->exactly(3))
488 [
'id',
null, $addressId],
489 [
'default_billing',
false, $addressId],
490 [
'default_shipping',
false, $addressId],
493 $this->addressRepository->expects($this->once())
496 ->willReturn($this->addressData);
497 $this->addressRepository->expects($this->once())
499 ->with($this->addressData)
502 $this->customerAddressMapper->expects($this->once())
503 ->method(
'toFlatArray')
504 ->with($this->addressData)
505 ->willReturn($existingAddressData);
507 $this->formFactory->expects($this->once())
509 ->with(
'customer_address',
'customer_address_edit', $existingAddressData)
510 ->willReturn($this->
form);
512 $this->
form->expects($this->once())
513 ->method(
'extractData')
514 ->with($this->request)
515 ->willReturn($newAddressData);
516 $this->
form->expects($this->once())
517 ->method(
'compactData')
518 ->with($newAddressData)
519 ->willReturn($newAddressData);
521 $this->region->expects($this->any())
524 ->willReturn($this->region);
525 $this->region->expects($this->any())
527 ->willReturn($newRegionCode);
528 $this->region->expects($this->any())
529 ->method(
'getDefaultName')
530 ->willReturn($newRegion);
538 $this->dataObjectHelper->expects($this->exactly(2))
539 ->method(
'populateWithArray')
544 \
Magento\Customer\Api\Data\RegionInterface::class,
545 $this->dataObjectHelper,
549 array_merge($existingAddressData, $newAddressData),
550 \
Magento\Customer\Api\Data\AddressInterface::class,
551 $this->dataObjectHelper,
555 $this->session->expects($this->atLeastOnce())
556 ->method(
'getCustomerId')
558 $this->addressData->expects($this->any())
559 ->method(
'getCustomerId')
562 $this->addressData->expects($this->once())
563 ->method(
'setCustomerId')
566 $this->addressData->expects($this->once())
567 ->method(
'setIsDefaultBilling')
570 $this->addressData->expects($this->once())
571 ->method(
'setIsDefaultShipping')
575 $this->messageManager->expects($this->once())
576 ->method(
'addSuccessMessage')
577 ->with(
__(
'You saved the address.'))
580 $urlBuilder = $this->getMockBuilder(\
Magento\Framework\UrlInterface::class)
581 ->getMockForAbstractClass();
582 $urlBuilder->expects($this->once())
584 ->with(
'*/*/index', [
'_secure' =>
true])
587 $this->objectManager->expects($this->once())
589 ->with(\
Magento\Framework\UrlInterface::class)
590 ->willReturn($urlBuilder);
592 $this->redirect->expects($this->once())
597 $this->resultRedirect->expects($this->once())
602 $this->assertEquals($this->resultRedirect, $this->model->execute());
611 [1, 1, 1,
null,
'',
null,
'',
null,
''],
612 [1, 1, 1,
'',
null,
'',
null,
'',
null],
614 [1, 1, 1,
null,
null,
null, 12,
null,
null],
615 [1, 1, 1,
null,
null,
null, 1,
'California',
null],
616 [1, 1, 1,
null,
null,
null, 1,
'California',
'CA'],
618 [1, 1, 1,
null,
null,
null, 1,
null,
'CA'],
619 [1, 1, 1,
null,
null,
null,
null,
null,
'CA'],
621 [1, 1, 1, 2,
null,
null,
null,
null,
null],
622 [1, 1, 1, 2,
'Alaska',
null,
null,
null,
null],
623 [1, 1, 1, 2,
'Alaska',
'AK',
null,
null,
null],
625 [1, 1, 1, 2,
null,
null,
null,
null,
null],
626 [1, 1, 1, 2,
'Alaska',
null,
null,
null,
null],
627 [1, 1, 1, 2,
'Alaska',
'AK',
null,
null,
null],
629 [1, 1, 1, 2,
null,
null, 12,
null,
null],
630 [1, 1, 1, 2,
'Alaska',
null, 12,
null,
'CA'],
631 [1, 1, 1, 2,
'Alaska',
'AK', 12,
'California',
null],
633 [1, 1, 1, 2,
null,
null, 12,
null,
null],
634 [1, 1, 1, 2,
'Alaska',
null, 12,
null,
'CA'],
635 [1, 1, 1, 2,
'Alaska',
'AK', 12,
'California',
null],
645 $postValue =
'post_value';
648 $this->formKeyValidator->expects($this->once())
650 ->with($this->request)
653 $this->request->expects($this->once())
656 $this->request->expects($this->exactly(2))
659 ->willReturn($addressId);
660 $this->request->expects($this->once())
661 ->method(
'getPostValue')
662 ->willReturn($postValue);
664 $this->addressRepository->expects($this->once())
669 $this->messageManager->expects($this->once())
670 ->method(
'addErrorMessage')
671 ->with(
'InputException')
674 $this->session->expects($this->once())
675 ->method(
'setAddressFormData')
679 $urlBuilder = $this->getMockBuilder(\
Magento\Framework\UrlInterface::class)
680 ->getMockForAbstractClass();
681 $urlBuilder->expects($this->once())
683 ->with(
'*/*/edit', [
'id' => $addressId])
686 $this->objectManager->expects($this->once())
688 ->with(\
Magento\Framework\UrlInterface::class)
689 ->willReturn($urlBuilder);
691 $this->redirect->expects($this->once())
696 $this->resultRedirect->expects($this->once())
701 $this->assertEquals($this->resultRedirect, $this->model->execute());
710 $postValue =
'post_value';
713 $this->formKeyValidator->expects($this->once())
715 ->with($this->request)
718 $this->request->expects($this->once())
721 $this->request->expects($this->once())
724 ->willReturn($addressId);
725 $this->request->expects($this->never())
726 ->method(
'getPostValue')
727 ->willReturn($postValue);
729 $exception = new \Exception(
__(
'Exception'));
730 $this->addressRepository->expects($this->once())
733 ->willThrowException($exception);
735 $this->messageManager->expects($this->once())
736 ->method(
'addExceptionMessage')
737 ->with($exception,
__(
'We can\'t save the address.'))
740 $this->session->expects($this->never())
741 ->method(
'setAddressFormData')
745 $urlBuilder = $this->getMockBuilder(\
Magento\Framework\UrlInterface::class)
746 ->getMockForAbstractClass();
747 $urlBuilder->expects($this->once())
752 $this->objectManager->expects($this->once())
754 ->with(\
Magento\Framework\UrlInterface::class)
755 ->willReturn($urlBuilder);
757 $this->redirect->expects($this->once())
762 $this->resultRedirect->expects($this->once())
767 $this->assertEquals($this->resultRedirect, $this->model->execute());
jquery extjs ext tree mage adminhtml form
dataProviderTestExecute()
testExecuteInputException()
testExecute( $addressId, $countryId, $customerId, $regionId, $region, $regionCode, $newRegionId, $newRegion, $newRegionCode)