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 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()); }
public function testExecuteNoComment() { $message = 'The Comment Text field cannot be empty.'; $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()); }
public function testLoginFailure() { $jsonRequest = '{"username":"******", "password":"******"}'; $loginFailureResponse = '{"message":"Invalid login or password."}'; $this->request->expects($this->any())->method('getRawBody')->willReturn($jsonRequest); $this->request->expects($this->any())->method('getMethod')->willReturn('POST'); $this->request->expects($this->any())->method('isXmlHttpRequest')->willReturn(true); $this->resultJsonFactory->expects($this->never())->method('create')->willReturn($this->resultJson); $this->dataHelper->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'); $this->resultJson->expects($this->never())->method('setData')->with(['message' => 'Invalid login or password.'])->willReturn($loginFailureResponse); $this->resultRaw->expects($this->once())->method('setHttpResponseCode')->with(401); $this->object->execute(); }