public function testAddProductNameFilter() { $collection = $this->collection->addProductNameFilter('TestProductName'); $sql = $collection->getSelect()->__toString(); $sql = trim(preg_replace('/\\s+/', ' ', $sql)); $this->assertEquals(trim(preg_replace('/\\s+/', ' ', $this->sql)), $sql); }
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); }
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(); }
/** * @covers \Magento\Framework\Message\Collection::clear */ public function testClearWithSticky() { $messages = array($this->objectManager->getObject('Magento\\Framework\\Message\\Error'), $this->objectManager->getObject('Magento\\Framework\\Message\\Warning'), $this->objectManager->getObject('Magento\\Framework\\Message\\Notice')->setIsSticky(true), $this->objectManager->getObject('Magento\\Framework\\Message\\Success')); foreach ($messages as $message) { $this->model->addMessage($message); } $this->assertEquals(count($messages), $this->model->getCount()); $this->model->clear(); $this->assertEquals(1, $this->model->getCount()); }
/** * Add messages to display * * @param \Magento\Framework\Message\Collection $messages * @return $this */ public function addMessages(\Magento\Framework\Message\Collection $messages) { foreach ($messages->getItems() as $message) { $this->getMessageCollection()->addMessage($message); } return $this; }