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 testSaveActionThrowsException() { $this->requestMock->expects($this->any())->method('getPostValue')->willReturn(['page_id' => $this->pageId]); $this->requestMock->expects($this->atLeastOnce())->method('getParam')->willReturnMap([['page_id', null, $this->pageId], ['back', null, true]]); $this->dataProcessorMock->expects($this->any())->method('filter')->willReturnArgument(0); $this->objectManagerMock->expects($this->atLeastOnce())->method('create')->with($this->equalTo('Magento\\Cms\\Model\\Page'))->willReturn($this->pageMock); $this->pageMock->expects($this->any())->method('load')->willReturnSelf(); $this->pageMock->expects($this->any())->method('getId')->willReturn(true); $this->pageMock->expects($this->once())->method('setData'); $this->pageMock->expects($this->once())->method('save')->willThrowException(new \Exception('Error message.')); $this->messageManagerMock->expects($this->never())->method('addSuccess'); $this->messageManagerMock->expects($this->once())->method('addException'); $this->dataPersistorMock->expects($this->any())->method('set')->with('cms_page', ['page_id' => $this->pageId]); $this->resultRedirect->expects($this->atLeastOnce())->method('setPath')->with('*/*/edit', ['page_id' => $this->pageId])->willReturnSelf(); $this->assertSame($this->resultRedirect, $this->saveController->execute()); }