public function setUp() { $objectManagerHelper = new ObjectManagerHelper($this); $this->contextMock = $this->getMock('Magento\\Backend\\App\\Action\\Context', [], [], '', false); $resultRedirectFactory = $this->getMock('Magento\\Backend\\Model\\View\\Result\\RedirectFactory', [], [], '', false); $this->responseMock = $this->getMock('Magento\\Framework\\App\\ResponseInterface', [], [], '', false); $this->requestMock = $this->getMockBuilder('Magento\\Framework\\App\\Request\\Http')->disableOriginalConstructor()->getMock(); $this->objectManagerMock = $this->getMock('Magento\\Framework\\ObjectManager\\ObjectManager', ['create'], [], '', false); $this->messageManagerMock = $this->getMock('Magento\\Framework\\Message\\Manager', [], [], '', false); $this->customerCollectionMock = $this->getMockBuilder('Magento\\Customer\\Model\\ResourceModel\\Customer\\Collection')->disableOriginalConstructor()->getMock(); $this->customerCollectionFactoryMock = $this->getMockBuilder('Magento\\Customer\\Model\\ResourceModel\\Customer\\CollectionFactory')->disableOriginalConstructor()->setMethods(['create'])->getMock(); $redirectMock = $this->getMockBuilder('Magento\\Backend\\Model\\View\\Result\\Redirect')->disableOriginalConstructor()->getMock(); $resultFactoryMock = $this->getMockBuilder('Magento\\Framework\\Controller\\ResultFactory')->disableOriginalConstructor()->getMock(); $resultFactoryMock->expects($this->any())->method('create')->with(\Magento\Framework\Controller\ResultFactory::TYPE_REDIRECT)->willReturn($redirectMock); $this->resultRedirectMock = $this->getMockBuilder('Magento\\Backend\\Model\\View\\Result\\Redirect')->disableOriginalConstructor()->getMock(); $resultRedirectFactory->expects($this->any())->method('create')->willReturn($this->resultRedirectMock); $this->contextMock->expects($this->once())->method('getMessageManager')->willReturn($this->messageManagerMock); $this->contextMock->expects($this->once())->method('getRequest')->willReturn($this->requestMock); $this->contextMock->expects($this->once())->method('getResponse')->willReturn($this->responseMock); $this->contextMock->expects($this->once())->method('getObjectManager')->willReturn($this->objectManagerMock); $this->contextMock->expects($this->any())->method('getResultRedirectFactory')->willReturn($resultRedirectFactory); $this->contextMock->expects($this->any())->method('getResultFactory')->willReturn($resultFactoryMock); $this->filterMock = $this->getMock('Magento\\Ui\\Component\\MassAction\\Filter', [], [], '', false); $this->filterMock->expects($this->once())->method('getCollection')->with($this->customerCollectionMock)->willReturnArgument(0); $this->customerCollectionFactoryMock->expects($this->once())->method('create')->willReturn($this->customerCollectionMock); $this->customerRepositoryMock = $this->getMockBuilder('Magento\\Customer\\Api\\CustomerRepositoryInterface')->getMockForAbstractClass(); $this->massAction = $objectManagerHelper->getObject('Magento\\Customer\\Controller\\Adminhtml\\Index\\MassAssignGroup', ['context' => $this->contextMock, 'filter' => $this->filterMock, 'collectionFactory' => $this->customerCollectionFactoryMock, 'customerRepository' => $this->customerRepositoryMock]); }
public function testGetCount() { $customersMock = $this->getMock('\\Magento\\Customer\\Model\\ResourceModel\\Customer\\Collection', [], [], '', false); $this->customersFactoryMock->expects($this->once())->method('create')->willReturn($customersMock); $customersMock->expects($this->once())->method('getSize')->willReturn('expected'); $this->assertEquals('expected', $this->model->getCount()); }
public function testGetDataWithCustomerFormData() { $customerId = 11; $customerFormData = ['customer' => ['email' => '*****@*****.**', 'default_billing' => 3, 'default_shipping' => 3, 'entity_id' => $customerId], 'address' => [3 => ['firstname' => 'firstname1', 'lastname' => 'lastname1', 'street' => ['street1', 'street2'], 'default_billing' => 3, 'default_shipping' => 3]]]; $customer = $this->getMockBuilder('Magento\\Customer\\Model\\Customer')->disableOriginalConstructor()->getMock(); $address = $this->getMockBuilder('Magento\\Customer\\Model\\Address')->disableOriginalConstructor()->getMock(); $collectionMock = $this->getMockBuilder('Magento\\Customer\\Model\\ResourceModel\\Customer\\Collection')->disableOriginalConstructor()->getMock(); $collectionMock->expects($this->once())->method('addAttributeToSelect')->with('*'); $this->customerCollectionFactoryMock->expects($this->once())->method('create')->willReturn($collectionMock); $collectionMock->expects($this->once())->method('getItems')->willReturn([$customer]); $customer->expects($this->once())->method('getData')->willReturn(['email' => '*****@*****.**', 'default_billing' => 2, 'default_shipping' => 2]); $customer->expects($this->once())->method('getId')->willReturn($customerId); $customer->expects($this->once())->method('getAddresses')->willReturn([$address]); $address->expects($this->atLeastOnce())->method('getId')->willReturn(2); $address->expects($this->once())->method('load')->with(2)->willReturnSelf(); $address->expects($this->once())->method('getData')->willReturn(['firstname' => 'firstname', 'lastname' => 'lastname', 'street' => "street\nstreet"]); $helper = new ObjectManager($this); $dataProvider = $helper->getObject('\\Magento\\Customer\\Model\\Customer\\DataProvider', ['name' => 'test-name', 'primaryFieldName' => 'primary-field-name', 'requestFieldName' => 'request-field-name', 'eavValidationRules' => $this->eavValidationRulesMock, 'customerCollectionFactory' => $this->customerCollectionFactoryMock, 'eavConfig' => $this->getEavConfigMock()]); $reflection = new \ReflectionClass(get_class($dataProvider)); $reflectionProperty = $reflection->getProperty('session'); $reflectionProperty->setAccessible(true); $reflectionProperty->setValue($dataProvider, $this->sessionMock); $this->sessionMock->expects($this->once())->method('getCustomerFormData')->willReturn($customerFormData); $this->sessionMock->expects($this->once())->method('unsCustomerFormData'); $this->assertEquals([$customerId => $customerFormData], $dataProvider->getData()); }
public function testGetData() { $customer = $this->getMockBuilder('Magento\\Customer\\Model\\Customer')->disableOriginalConstructor()->getMock(); $address = $this->getMockBuilder('Magento\\Customer\\Model\\Address')->disableOriginalConstructor()->getMock(); $collectionMock = $this->getMockBuilder('Magento\\Customer\\Model\\ResourceModel\\Customer\\Collection')->disableOriginalConstructor()->getMock(); $collectionMock->expects($this->once())->method('addAttributeToSelect')->with('*'); $this->customerCollectionFactoryMock->expects($this->once())->method('create')->willReturn($collectionMock); $collectionMock->expects($this->once())->method('getItems')->willReturn([$customer]); $customer->expects($this->once())->method('getData')->willReturn(['email' => '*****@*****.**', 'default_billing' => 2, 'default_shipping' => 2]); $customer->expects($this->once())->method('getAddresses')->willReturn([$address]); $address->expects($this->atLeastOnce())->method('getId')->willReturn(2); $address->expects($this->once())->method('load')->with(2)->willReturnSelf(); $address->expects($this->once())->method('getData')->willReturn(['firstname' => 'firstname', 'lastname' => 'lastname', 'street' => "street\nstreet"]); $helper = new ObjectManager($this); $dataProvider = $helper->getObject('\\Magento\\Customer\\Model\\Customer\\DataProvider', ['name' => 'test-name', 'primaryFieldName' => 'primary-field-name', 'requestFieldName' => 'request-field-name', 'eavValidationRules' => $this->eavValidationRulesMock, 'customerCollectionFactory' => $this->customerCollectionFactoryMock, 'eavConfig' => $this->getEavConfigMock()]); $this->assertEquals(['' => ['customer' => ['email' => '*****@*****.**', 'default_billing' => 2, 'default_shipping' => 2], 'address' => [2 => ['firstname' => 'firstname', 'lastname' => 'lastname', 'street' => ['street', 'street'], 'default_billing' => 2, 'default_shipping' => 2]]]], $dataProvider->getData()); }