public function testSetMessages() { $collection = $this->getMockBuilder('Magento\\Framework\\Message\\Collection')->disableOriginalConstructor()->getMock(); $this->collectionFactory->expects($this->never())->method('create'); $this->messages->setMessages($collection); $this->assertSame($collection, $this->messages->getMessageCollection()); }
public function testGetMessages() { $messageCollection = $this->getMockBuilder('Magento\\Framework\\Message\\Collection')->disableOriginalConstructor()->setMethods(['addMessage'])->getMock(); $this->messagesFactory->expects($this->atLeastOnce())->method('create')->will($this->returnValue($messageCollection)); $this->session->expects($this->at(0))->method('getData')->with(Manager::DEFAULT_GROUP)->will($this->returnValue(null)); $this->session->expects($this->at(1))->method('setData')->with(Manager::DEFAULT_GROUP, $messageCollection)->will($this->returnValue($this->session)); $this->session->expects($this->at(2))->method('getData')->with(Manager::DEFAULT_GROUP)->will($this->returnValue($messageCollection)); $this->eventManager->expects($this->never())->method('dispatch'); $this->assertEquals($messageCollection, $this->model->getMessages()); }
/** * Retrieve messages collection * * @return \Magento\Framework\Message\Collection */ public function getMessageCollection() { if (!$this->messages instanceof \Magento\Framework\Message\Collection) { $this->messages = $this->collectionFactory->create(); } return $this->messages; }
/** * Retrieve messages * * @param string|null $group * @param bool $clear * @return Collection */ public function getMessages($clear = false, $group = null) { $group = $this->prepareGroup($group); if (!$this->session->getData($group)) { $this->session->setData($group, $this->messagesFactory->create()); } if ($clear) { $messages = clone $this->session->getData($group); $this->session->getData($group)->clear(); $this->eventManager->dispatch('session_abstract_clear_messages'); return $messages; } return $this->session->getData($group); }
public function testCreate() { $message = $this->model->create(); $this->assertInstanceOf('\\Magento\\Framework\\Message\\Collection', $message); }