public function setUp() { if (!function_exists('libxml_set_external_entity_loader')) { $this->markTestSkipped('Skipped on HHVM. Will be fixed in MAGETWO-45033'); } $this->customer = $this->getMockForAbstractClass('Magento\\Customer\\Api\\Data\\CustomerInterface', [], '', false, true, true); $this->customer->expects($this->once())->method('getWebsiteId')->willReturn(2); $this->customerDataFactory = $this->getMock('Magento\\Customer\\Api\\Data\\CustomerInterfaceFactory', ['create'], [], '', false); $this->customerDataFactory->expects($this->once())->method('create')->willReturn($this->customer); $this->form = $this->getMock('Magento\\Customer\\Model\\Metadata\\Form', [], [], '', false); $this->request = $this->getMockForAbstractClass('Magento\\Framework\\App\\RequestInterface', [], '', false, true, true, ['getPost']); $this->response = $this->getMockForAbstractClass('Magento\\Framework\\App\\ResponseInterface', [], '', false); $this->formFactory = $this->getMock('Magento\\Customer\\Model\\Metadata\\FormFactory', ['create'], [], '', false); $this->formFactory->expects($this->atLeastOnce())->method('create')->willReturn($this->form); $this->extensibleDataObjectConverter = $this->getMock('Magento\\Framework\\Api\\ExtensibleDataObjectConverter', [], [], '', false); $this->dataObjectHelper = $this->getMock('Magento\\Framework\\Api\\DataObjectHelper', [], [], '', false); $this->dataObjectHelper->expects($this->once())->method('populateWithArray'); $this->customerAccountManagement = $this->getMockForAbstractClass('Magento\\Customer\\Api\\AccountManagementInterface', [], '', false, true, true); $this->resultJson = $this->getMock('Magento\\Framework\\Controller\\Result\\Json', [], [], '', false); $this->resultJson->expects($this->once())->method('setData'); $this->resultJsonFactory = $this->getMock('Magento\\Framework\\Controller\\Result\\JsonFactory', ['create'], [], '', false); $this->resultJsonFactory->expects($this->once())->method('create')->willReturn($this->resultJson); $objectHelper = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this); $this->controller = $objectHelper->getObject('Magento\\Customer\\Controller\\Adminhtml\\Index\\Validate', ['request' => $this->request, 'response' => $this->response, 'customerDataFactory' => $this->customerDataFactory, 'formFactory' => $this->formFactory, 'extensibleDataObjectConverter' => $this->extensibleDataObjectConverter, 'customerAccountManagement' => $this->customerAccountManagement, 'resultJsonFactory' => $this->resultJsonFactory, 'dataObjectHelper' => $this->dataObjectHelper]); }
public function testExecuteWithoutData() { $this->request->expects($this->at(0))->method('getParam')->with('isAjax')->willReturn(true); $this->request->expects($this->at(1))->method('getParam')->with('items', [])->willReturn([]); $this->jsonFactory->expects($this->once())->method('create')->willReturn($this->resultJson); $this->resultJson->expects($this->once())->method('setData')->with(['messages' => ['Please correct the data sent.'], 'error' => true])->willReturnSelf(); $this->controller->execute(); }
public function testExecute() { $searchString = "simple"; $firstItemMock = $this->getMockBuilder('Magento\\Search\\Model\\Autocomplete\\Item')->disableOriginalConstructor()->setMockClassName('FirstItem')->setMethods(['toArray'])->getMock(); $secondItemMock = $this->getMockBuilder('Magento\\Search\\Model\\Autocomplete\\Item')->disableOriginalConstructor()->setMockClassName('SecondItem')->setMethods(['toArray'])->getMock(); $this->request->expects($this->once())->method('getParam')->with('q')->will($this->returnValue($searchString)); $this->autocomplete->expects($this->once())->method('getItems')->will($this->returnValue([$firstItemMock, $secondItemMock])); $this->resultJsonMock->expects($this->once())->method('setData')->willReturnSelf(); $this->assertSame($this->resultJsonMock, $this->controller->execute()); }
/** * Executes the controller action and asserts non exception logic */ public function testExecuteLocalizedException() { $phrase = new \Magento\Framework\Phrase('some error'); $objectManager = new ObjectManager($this); $this->vault->expects($this->once())->method('processNonce')->willThrowException(new LocalizedException($phrase)); $this->resultJson->expects($this->once())->method('setData')->with(['success' => false, 'error_message' => 'some error']); $this->resultFactory->expects($this->once())->method('create')->willReturn($this->resultJson); $this->messageManager->expects($this->once())->method('addError')->with($phrase); $notification = $objectManager->getObject('Magento\\Braintree\\Controller\\Creditcard\\AjaxSave', ['request' => $this->request, 'resultFactory' => $this->resultFactory, 'vault' => $this->vault, 'messageManager' => $this->messageManager]); $this->assertSame($this->resultJson, $notification->execute()); }
public function testExecuteNullProduct() { $this->productMock->expects($this->once())->method('load')->with(59)->willReturn($this->productMock); $this->productModelFactoryMock->expects($this->once())->method('create')->willReturn($this->productMock); $this->swatchHelperMock->expects($this->once())->method('getAttributesFromConfigurable')->with($this->productMock)->willReturn([$this->attributeMock]); $this->swatchHelperMock->expects($this->once())->method('loadVariationByFallback')->with($this->productMock, ['size' => 454])->willReturn(null); $this->swatchHelperMock->expects($this->once())->method('getProductMediaGallery')->with($this->productMock)->willReturn($this->mediaGallery); $this->jsonMock->expects($this->once())->method('setData')->with($this->mediaGallery)->will($this->returnSelf()); $result = $this->controller->execute(); $this->assertInstanceOf('\\Magento\\Framework\\Controller\\Result\\Json', $result); }
public function testExecute() { $this->requestMock->expects($this->any())->method('getParam')->willReturnMap([['frontend_label', null, 'test_frontend_label'], ['attribute_code', null, 'test_attribute_code'], ['new_attribute_set_name', null, 'test_attribute_set_name']]); $this->objectManagerMock->expects($this->exactly(2))->method('create')->willReturnMap([['Magento\\Catalog\\Model\\ResourceModel\\Eav\\Attribute', [], $this->attributeMock], ['Magento\\Eav\\Model\\Entity\\Attribute\\Set', [], $this->attributeSetMock]]); $this->attributeMock->expects($this->once())->method('loadByCode')->willReturnSelf(); $this->requestMock->expects($this->once())->method('has')->with('new_attribute_set_name')->willReturn(true); $this->attributeSetMock->expects($this->once())->method('setEntityTypeId')->willReturnSelf(); $this->attributeSetMock->expects($this->once())->method('load')->willReturnSelf(); $this->attributeSetMock->expects($this->once())->method('getId')->willReturn(false); $this->resultJsonFactoryMock->expects($this->once())->method('create')->willReturn($this->resultJson); $this->resultJson->expects($this->once())->method('setJsonData')->willReturnSelf(); $this->assertInstanceOf(ResultJson::class, $this->getModel()->execute()); }
/** * Executes the controller action and asserts non exception logic */ public function testExecuteInternalLocalizedException() { $phrase = new \Magento\Framework\Phrase('Something went wrong while processing.'); $objectManager = new ObjectManager($this); $this->vault->expects($this->once())->method('generatePaymentMethodToken')->willThrowException(new LocalizedException($phrase)); $this->resultJson->expects($this->once())->method('setData')->with(['success' => false, 'error_message' => 'Something went wrong while processing.']); $this->resultFactory->expects($this->once())->method('create')->willReturn($this->resultJson); $this->messageManager->expects($this->once())->method('addError')->with($phrase); $this->request->expects($this->any())->method('getParam')->willReturn(true); /** @var \Magento\Braintree\Controller\Creditcard\Generate $controller */ $controller = $objectManager->getObject('Magento\\Braintree\\Controller\\Creditcard\\Generate', ['request' => $this->request, 'resultFactory' => $this->resultFactory, 'vault' => $this->vault, 'messageManager' => $this->messageManager]); $this->assertSame($this->resultJson, $controller->executeInternal()); }
public function testUpdate() { $statusInfo = 'some status info'; $data = ['status' => 'success', 'message' => __('Database(s) successfully updated.'), 'status_info' => $statusInfo]; $this->resultJson->expects($this->once())->method('setData')->with($data)->willReturnSelf(); $this->updaterSelected->expects($this->once())->method('update')->willReturnSelf(); $statusBlock = $this->getMockBuilder('Tobai\\GeoIp2\\Block\\Adminhtml\\System\\Config\\Status')->disableOriginalConstructor()->getMock(); $layout = $this->getMock('Magento\\Framework\\View\\LayoutInterface'); $this->layoutFactory->expects($this->once())->method('create')->willReturn($layout); $layout->expects($this->once())->method('createBlock')->with('Tobai\\GeoIp2\\Block\\Adminhtml\\System\\Config\\Status')->willReturn($statusBlock); $statusBlock->expects($this->once())->method('getDbStatus')->willReturn($statusInfo); $this->logger->expects($this->never())->method('critical'); $this->assertSame($this->resultJson, $this->controllerUpdate->execute()); }
public function testExecute() { $this->_getTreeBlock(); $testCategoryId = 1; $this->requestMock->expects($this->any())->method('getPost')->will($this->returnValue($testCategoryId)); $categoryMock = $this->getMock('Magento\\Catalog\\Model\\Category', [], [], '', false); $categoryMock->expects($this->once())->method('load')->will($this->returnValue($categoryMock)); $categoryMock->expects($this->once())->method('getId')->will($this->returnValue($testCategoryId)); $this->objectManagerMock->expects($this->once())->method('create')->with($this->equalTo('Magento\\Catalog\\Model\\Category'))->will($this->returnValue($categoryMock)); $this->chooserBlockMock->expects($this->once())->method('setSelectedCategories')->will($this->returnValue($this->chooserBlockMock)); $testHtml = '<div>Some test html</div>'; $this->chooserBlockMock->expects($this->once())->method('getTreeJson')->will($this->returnValue($testHtml)); $this->resultJson->expects($this->once())->method('setJsonData')->with($testHtml)->willReturnSelf(); $this->controller->execute(); }
public function testExecuteWithoutData() { $this->jsonFactory->expects($this->once())->method('create')->willReturn($this->resultJson); $this->request->expects($this->any())->method('getParam')->willReturnMap([['items', [], []], ['isAjax', null, true]]); $this->resultJson->expects($this->once())->method('setData')->with(['messages' => ['Please correct the data sent.'], 'error' => true])->willReturnSelf(); $this->assertSame($this->resultJson, $this->controller->execute()); }
/** * Test execute exception * * @return void */ public function testExecuteException() { $response = ['error' => true, 'message' => 'Cannot add new comment.']; $e = new \Exception('test'); $this->requestMock->expects($this->once())->method('getParam')->will($this->throwException($e)); $this->resultJsonFactoryMock->expects($this->once())->method('create')->will($this->returnValue($this->resultJsonMock)); $this->resultJsonMock->expects($this->once())->method('setData')->with($response); $this->assertSame($this->resultJsonMock, $this->controller->execute()); }
/** * Test execute no comment * * @return void */ public function testExecuteNoComment() { $message = 'Please enter a comment.'; $response = ['error' => true, 'message' => $message]; $data = []; $this->requestMock->expects($this->once())->method('getPost')->with('comment')->willReturn($data); $this->resultJsonFactoryMock->expects($this->once())->method('create')->willReturn($this->resultJsonMock); $this->resultJsonMock->expects($this->once())->method('setData')->with($response)->willReturnSelf(); $this->assertInstanceOf('Magento\\Framework\\Controller\\Result\\Json', $this->controller->execute()); }
/** * Test execute exception * * @return void */ public function testExecuteException() { $message = 'Cannot update the item\'s quantity.'; $e = new \Exception($message); $response = ['error' => true, 'message' => $message]; $this->requestMock->expects($this->any())->method('getParam')->willReturnArgument(0); $this->loaderMock->expects($this->once())->method('load')->willThrowException($e); $this->resultJsonFactoryMock->expects($this->once())->method('create')->willReturn($this->resultJsonMock); $this->resultJsonMock->expects($this->once())->method('setData')->with($response)->willReturnSelf(); $this->assertInstanceOf('Magento\\Framework\\Controller\\Result\\Json', $this->controller->execute()); }
public function testLoginFailure() { $jsonRequest = '{"username":"******", "password":"******"}'; $loginFailureResponse = '{"message":"Invalid login or password."}'; $this->request->expects($this->any())->method('getContent')->willReturn($jsonRequest); $this->request->expects($this->any())->method('getMethod')->willReturn('POST'); $this->request->expects($this->any())->method('isXmlHttpRequest')->willReturn(true); $this->resultJsonFactory->expects($this->once())->method('create')->willReturn($this->resultJson); $this->jsonHelperMock->expects($this->any())->method('jsonDecode')->with($jsonRequest)->willReturn(['username' => '*****@*****.**', 'password' => 'invalid']); $customerMock = $this->getMockForAbstractClass('Magento\\Customer\\Api\\Data\\CustomerInterface'); $this->customerAccountManagementMock->expects($this->any())->method('authenticate')->with('*****@*****.**', 'invalid')->willThrowException(new InvalidEmailOrPasswordException(__('Invalid login or password.'))); $this->customerSession->expects($this->never())->method('setCustomerDataAsLoggedIn')->with($customerMock); $this->customerSession->expects($this->never())->method('regenerateId'); $result = ['errors' => true, 'message' => __('Invalid login or password.')]; $this->resultJson->expects($this->once())->method('setData')->with($result)->willReturn($loginFailureResponse); $this->assertEquals($loginFailureResponse, $this->object->execute()); }
public function testExecuteWithQuantityArrayAjax() { $refererUrl = $this->prepareExecuteWithQuantityArray(true); $this->resultJsonMock->expects($this->once())->method('setData')->with(['backUrl' => $refererUrl])->willReturnSelf(); $this->assertSame($this->resultJsonMock, $this->model->execute()); }