public function testMergeAddsAllMessagesFromOtherMessageList() { $this->messageList->add(new Message('message', 'type')); $otherMessageList = new MessageList(); $otherMessageList->add(new Message('somemessage', 'sometype')); $otherMessageList->add(new Message('someothermessage', 'someothertype')); $this->messageList->merge($otherMessageList); $this->assertEquals(3, count($this->messageList)); $i = 0; foreach ($this->messageList as $message) { switch ($i) { case 0: $this->assertEquals('message', $message->getMessage()); $this->assertEquals('type', $message->getType()); break; case 1: $this->assertEquals('somemessage', $message->getMessage()); $this->assertEquals('sometype', $message->getType()); break; case 2: $this->assertEquals('someothermessage', $message->getMessage()); $this->assertEquals('someothertype', $message->getType()); break; } $i++; } }
/** * Handles the response messages. If a redirect is detected, the messages are stored to the * session for a next request. If the view is a smarty view, the messages will be set to * the view. You can display them using the {messages} smarty function. * @return null */ private function handleResponseMessages() { $response = Zibo::getInstance()->getResponse(); $session = Session::getInstance(); $messages = $session->get(self::SESSION_MESSAGES); if ($messages == null) { $messages = new MessageList(); } if ($response->willRedirect()) { $messages->merge($response->getMessages()); $session->set(self::SESSION_MESSAGES, $messages); return; } $view = $response->getView(); if (!$view instanceof SmartyView) { return; } $session->set(self::SESSION_MESSAGES); $messages->merge($response->getMessages()); $view->set('_messages', $messages); }