public function prepareMocksForTestExecute() { $postData = [1 => ['title' => '404 Not Found', 'identifier' => 'no-route', 'custom_theme' => '1', 'custom_root_template' => '2']]; $this->request->expects($this->any())->method('getParam')->willReturnMap([['isAjax', null, true], ['items', [], $postData]]); $this->pageRepository->expects($this->once())->method('getById')->with(1)->willReturn($this->cmsPage); $this->dataProcessor->expects($this->once())->method('filter')->with($postData[1])->willReturnArgument(0); $this->dataProcessor->expects($this->once())->method('validate')->with($postData[1])->willReturn(false); $this->messageManager->expects($this->once())->method('getMessages')->with(true)->willReturn($this->messageCollection); $this->messageCollection->expects($this->once())->method('getItems')->willReturn([$this->message]); $this->message->expects($this->once())->method('getText')->willReturn('Error message'); $this->cmsPage->expects($this->atLeastOnce())->method('getId')->willReturn('1'); $this->cmsPage->expects($this->atLeastOnce())->method('getData')->willReturn(['layout' => '1column', 'identifier' => 'test-identifier']); $this->cmsPage->expects($this->once())->method('setData')->with(['layout' => '1column', 'title' => '404 Not Found', 'identifier' => 'no-route', 'custom_theme' => '1', 'custom_root_template' => '2']); $this->jsonFactory->expects($this->once())->method('create')->willReturn($this->resultJson); }
public function testAdminAuthenticate() { $password = "******"; $uid = 123; $authResult = true; $lockExpires = false; $userPassword = ['expires' => 1]; /** @var Observer|\PHPUnit_Framework_MockObject_MockObject $eventObserverMock */ $eventObserverMock = $this->getMockBuilder('Magento\\Framework\\Event\\Observer')->disableOriginalConstructor()->setMethods([])->getMock(); /** @var Event|\PHPUnit_Framework_MockObject_MockObject */ $eventMock = $this->getMockBuilder('Magento\\Framework\\Event')->disableOriginalConstructor()->setMethods(['getPassword', 'getUser', 'getResult'])->getMock(); /** @var ModelUser|\PHPUnit_Framework_MockObject_MockObject $userMock */ $userMock = $this->getMockBuilder('Magento\\User\\Model\\User')->disableOriginalConstructor()->setMethods(['getId', 'getLockExpires', 'getPassword', 'save'])->getMock(); $eventObserverMock->expects($this->atLeastOnce())->method('getEvent')->willReturn($eventMock); $eventMock->expects($this->once())->method('getPassword')->willReturn($password); $eventMock->expects($this->once())->method('getUser')->willReturn($userMock); $eventMock->expects($this->once())->method('getResult')->willReturn($authResult); $userMock->expects($this->atLeastOnce())->method('getId')->willReturn($uid); $userMock->expects($this->once())->method('getLockExpires')->willReturn($lockExpires); $this->userMock->expects($this->once())->method('unlock'); $this->userMock->expects($this->once())->method('getLatestPassword')->willReturn($userPassword); $this->configInterfaceMock->expects($this->atLeastOnce())->method('getValue')->willReturn(1); /** @var Collection|\PHPUnit_Framework_MockObject_MockObject $collectionMock */ $collectionMock = $this->getMockBuilder('Magento\\Framework\\Message\\Collection')->disableOriginalConstructor()->setMethods([])->getMock(); $this->managerInterfaceMock->expects($this->once())->method('getMessages')->willReturn($collectionMock); $collectionMock->expects($this->once())->method('getLastAddedMessage')->willReturn($this->messageInterfaceMock); $this->messageInterfaceMock->expects($this->once())->method('setIdentifier')->willReturnSelf(); $this->authSessionMock->expects($this->once())->method('setPciAdminUserIsPasswordExpired'); $this->encryptorMock->expects($this->once())->method('validateHashVersion')->willReturn(false); $this->model->execute($eventObserverMock); }
protected function prepareMocksForErrorMessagesProcessing() { $this->messageManager->expects($this->atLeastOnce())->method('getMessages')->willReturn($this->messageCollection); $this->messageCollection->expects($this->once())->method('getItems')->willReturn([$this->message]); $this->messageCollection->expects($this->once())->method('getCount')->willReturn(1); $this->message->expects($this->once())->method('getText')->willReturn('Error text'); $this->resultJson->expects($this->once())->method('setData')->with(['messages' => ['Error text'], 'error' => true])->willReturnSelf(); }