コード例 #1
0
ファイル: QuoteTest.php プロジェクト: nja78/magento2
 public function testPrepareQuoteForNewCustomer()
 {
     $customerAddressMock = $this->getMockBuilder('Magento\\Customer\\Api\\Data\\AddressInterface')->disableOriginalConstructor()->getMock();
     $this->addressMock->expects($this->any())->method('exportCustomerAddress')->willReturn($customerAddressMock);
     $this->addressMock->expects($this->any())->method('getData')->willReturn([]);
     $this->addressFactoryMock->expects($this->any())->method('create')->willReturn($this->addressMock);
     $this->quoteMock->expects($this->any())->method('isVirtual')->willReturn(false);
     $this->quoteMock->expects($this->once())->method('getBillingAddress')->willReturn($this->addressMock);
     $this->quoteMock->expects($this->once())->method('getShippingAddress')->willReturn($this->addressMock);
     $customerDataMock = $this->getMockBuilder('Magento\\Customer\\Api\\Data\\CustomerInterface')->disableOriginalConstructor()->getMock();
     $this->customerFactoryMock->expects($this->once())->method('create')->willReturn($customerDataMock);
     $this->copyObjectMock->expects($this->any())->method('getDataFromFieldset')->willReturn([]);
     $this->dataObjectHelper->expects($this->any())->method('populateWithArray')->willReturnSelf();
     $this->assertInstanceOf('Magento\\Quote\\Model\\Quote', $this->quote->prepareQuoteForNewCustomer($this->quoteMock));
 }
コード例 #2
0
 public function testSetLayoutWithoutAddress()
 {
     $addressId = 1;
     $customerPrefix = 'prefix';
     $customerFirstName = 'firstname';
     $customerMiddlename = 'middlename';
     $customerLastname = 'lastname';
     $customerSuffix = 'suffix';
     $title = 'title';
     $layoutMock = $this->getMockBuilder('Magento\\Framework\\View\\LayoutInterface')->getMock();
     $this->requestMock->expects($this->once())->method('getParam')->with('id', null)->willReturn($addressId);
     $this->addressRepositoryMock->expects($this->once())->method('getById')->with($addressId)->willThrowException(\Magento\Framework\Exception\NoSuchEntityException::singleField('addressId', $addressId));
     $newAddressMock = $this->getMockBuilder('Magento\\Customer\\Api\\Data\\AddressInterface')->getMock();
     $this->addressDataFactoryMock->expects($this->once())->method('create')->willReturn($newAddressMock);
     $customerMock = $this->getMockBuilder('Magento\\Customer\\Api\\Data\\CustomerInterface')->getMock();
     $this->currentCustomerMock->expects($this->once())->method('getCustomer')->willReturn($customerMock);
     $customerMock->expects($this->once())->method('getPrefix')->willReturn($customerPrefix);
     $customerMock->expects($this->once())->method('getFirstname')->willReturn($customerFirstName);
     $customerMock->expects($this->once())->method('getMiddlename')->willReturn($customerMiddlename);
     $customerMock->expects($this->once())->method('getLastname')->willReturn($customerLastname);
     $customerMock->expects($this->once())->method('getSuffix')->willReturn($customerSuffix);
     $newAddressMock->expects($this->once())->method('setPrefix')->with($customerPrefix)->willReturnSelf();
     $newAddressMock->expects($this->once())->method('setFirstname')->with($customerFirstName)->willReturnSelf();
     $newAddressMock->expects($this->once())->method('setMiddlename')->with($customerMiddlename)->willReturnSelf();
     $newAddressMock->expects($this->once())->method('setLastname')->with($customerLastname)->willReturnSelf();
     $newAddressMock->expects($this->once())->method('setSuffix')->with($customerSuffix)->willReturnSelf();
     $pageTitleMock = $this->getMockBuilder('Magento\\Framework\\View\\Page\\Title')->disableOriginalConstructor()->getMock();
     $this->pageConfigMock->expects($this->once())->method('getTitle')->willReturn($pageTitleMock);
     $this->model->setData('title', $title);
     $pageTitleMock->expects($this->once())->method('set')->with($title)->willReturnSelf();
     $this->assertEquals($this->model, $this->model->setLayout($layoutMock));
     $this->assertEquals($layoutMock, $this->model->getLayout());
 }
コード例 #3
0
ファイル: SaveTest.php プロジェクト: pradeep-wagento/magento2
 /**
  * @covers \Magento\Customer\Controller\Adminhtml\Index\Index::execute
  * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
  */
 public function testExecuteWithNewCustomer()
 {
     $customerId = 22;
     $addressId = 11;
     $subscription = 'false';
     $postValue = ['customer' => ['coolness' => false, 'disable_auto_group_change' => 'false'], 'address' => ['_template_' => '_template_', $addressId => ['entity_id' => $addressId, 'default_billing' => 'false', 'default_shipping' => 'false', 'code' => 'value', 'coolness' => false, 'region' => 'region', 'region_id' => 'region_id']], 'subscription' => $subscription];
     $filteredData = ['coolness' => false, 'disable_auto_group_change' => 'false'];
     $addressFilteredData = ['entity_id' => $addressId, 'default_billing' => 'false', 'default_shipping' => 'false', 'code' => 'value', 'coolness' => false, 'region' => 'region', 'region_id' => 'region_id'];
     $mergedData = ['disable_auto_group_change' => 0, \Magento\Customer\Api\Data\CustomerInterface::DEFAULT_BILLING => null, \Magento\Customer\Api\Data\CustomerInterface::DEFAULT_SHIPPING => null, 'confirmation' => false];
     $mergedAddressData = ['entity_id' => $addressId, 'default_billing' => false, 'default_shipping' => false, 'code' => 'value', 'region' => ['region' => 'region', 'region_id' => 'region_id'], 'region_id' => 'region_id', 'id' => $addressId];
     /** @var AttributeMetadataInterface|\PHPUnit_Framework_MockObject_MockObject $formMock */
     $attributeMock = $this->getMockBuilder('Magento\\Customer\\Api\\Data\\AttributeMetadataInterface')->disableOriginalConstructor()->getMock();
     $attributeMock->expects($this->exactly(2))->method('getAttributeCode')->willReturn('coolness');
     $attributeMock->expects($this->exactly(2))->method('getFrontendInput')->willReturn('int');
     $attributes = [$attributeMock];
     $this->requestMock->expects($this->exactly(3))->method('getPostValue')->willReturn($postValue);
     $this->requestMock->expects($this->exactly(3))->method('getPost')->willReturnMap([['customer', null, $postValue['customer']], ['address', null, $postValue['address']], ['subscription', null, $subscription]]);
     /** @var \Magento\Customer\Model\Metadata\Form|\PHPUnit_Framework_MockObject_MockObject $formMock */
     $formMock = $this->getMockBuilder('Magento\\Customer\\Model\\Metadata\\Form')->disableOriginalConstructor()->getMock();
     $this->formFactoryMock->expects($this->exactly(2))->method('create')->willReturnMap([[\Magento\Customer\Api\CustomerMetadataInterface::ENTITY_TYPE_CUSTOMER, 'adminhtml_customer', [], false, \Magento\Customer\Model\Metadata\Form::DONT_IGNORE_INVISIBLE, [], $formMock], [\Magento\Customer\Api\AddressMetadataInterface::ENTITY_TYPE_ADDRESS, 'adminhtml_customer_address', [], false, \Magento\Customer\Model\Metadata\Form::DONT_IGNORE_INVISIBLE, [], $formMock]]);
     $formMock->expects($this->exactly(2))->method('extractData')->willReturnMap([[$this->requestMock, 'customer', true, $filteredData], [$this->requestMock, 'address/' . $addressId, true, $addressFilteredData]]);
     /** @var \Magento\Framework\DataObject|\PHPUnit_Framework_MockObject_MockObject $objectMock */
     $objectMock = $this->getMockBuilder('Magento\\Framework\\DataObject')->disableOriginalConstructor()->getMock();
     $this->objectFactoryMock->expects($this->exactly(2))->method('create')->with(['data' => $postValue])->willReturn($objectMock);
     $objectMock->expects($this->exactly(2))->method('getData')->willReturnMap([['customer', null, $postValue['customer']], ['address/' . $addressId, null, $postValue['address'][$addressId]]]);
     $formMock->expects($this->exactly(2))->method('getAttributes')->willReturn($attributes);
     /** @var \Magento\Customer\Api\Data\CustomerInterface|\PHPUnit_Framework_MockObject_MockObject $customerMock */
     $customerMock = $this->getMockBuilder('Magento\\Customer\\Api\\Data\\CustomerInterface')->disableOriginalConstructor()->getMock();
     $this->customerDataFactoryMock->expects($this->once())->method('create')->willReturn($customerMock);
     $addressMock = $this->getMockBuilder('\\Magento\\Customer\\Api\\Data\\AddressInterface')->disableOriginalConstructor()->getMock();
     $this->addressDataFactoryMock->expects($this->once())->method('create')->willReturn($addressMock);
     $this->dataHelperMock->expects($this->exactly(2))->method('populateWithArray')->willReturnMap([[$customerMock, $mergedData, '\\Magento\\Customer\\Api\\Data\\CustomerInterface', $this->dataHelperMock], [$addressMock, $mergedAddressData, '\\Magento\\Customer\\Api\\Data\\AddressInterface', $this->dataHelperMock]]);
     $this->managementMock->expects($this->once())->method('createAccount')->with($customerMock, null, '')->willReturn($customerMock);
     $customerMock->expects($this->once())->method('getId')->willReturn($customerId);
     $this->authorizationMock->expects($this->once())->method('isAllowed')->with(null)->willReturn(true);
     /** @var \Magento\Newsletter\Model\Subscriber|\PHPUnit_Framework_MockObject_MockObject $subscriberMock */
     $subscriberMock = $this->getMockBuilder('Magento\\Newsletter\\Model\\Subscriber')->disableOriginalConstructor()->getMock();
     $this->subscriberFactoryMock->expects($this->once())->method('create')->with()->willReturn($subscriberMock);
     $subscriberMock->expects($this->once())->method('unsubscribeCustomerById')->with($customerId);
     $subscriberMock->expects($this->never())->method('subscribeCustomerById');
     $this->sessionMock->expects($this->once())->method('unsCustomerData');
     $this->registryMock->expects($this->once())->method('register')->with(\Magento\Customer\Controller\RegistryConstants::CURRENT_CUSTOMER_ID, $customerId);
     $this->messageManagerMock->expects($this->once())->method('addSuccess')->with(__('You saved the customer.'))->willReturnSelf();
     $this->requestMock->expects($this->once())->method('getParam')->with('back', false)->willReturn(false);
     /** @var Redirect|\PHPUnit_Framework_MockObject_MockObject $redirectMock */
     $redirectMock = $this->getMockBuilder('Magento\\Framework\\Controller\\Result\\Redirect')->disableOriginalConstructor()->getMock();
     $this->redirectFactoryMock->expects($this->once())->method('create')->willReturn($redirectMock);
     $redirectMock->expects($this->once())->method('setPath')->with('customer/index', [])->willReturnSelf();
     $this->assertEquals($redirectMock, $this->model->execute());
 }