ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
ilSystemStyleMessageStackTest.php
Go to the documentation of this file.
1<?php
2/* Copyright (c) 2016 Tomasz Kolonko <thomas.kolonko@ilub.unibe.ch> Extended GPL, see docs/LICENSE */
3
4include_once("Services/Style/System/classes/Utilities/class.ilSystemStyleMessage.php");
5include_once("Services/Style/System/classes/Utilities/class.ilSystemStyleMessageStack.php");
6
13{
14
19
23 protected $messageStringOne = "This is a message";
24
28 protected $messageStringTwo = "Godzilla has taken over the world.";
29
33 protected $messageStringThree = "A small, cute cat destroyed Godzilla.";
34
38 protected $messages = array();
39
44
45 public function testPrependMessage()
46 {
47 $this->createTestEnvironment();
48
50
53
54 $this->ilSystemStyleMessage = new ilSystemStyleMessage($this->messageStringThree, ilSystemStyleMessage::TYPE_ERROR);
56 $this->messages = $this->ilSystemStyleMessageStack->getMessages();
57
58 $this->assertTrue($this->messages[0]->getMessage() === $this->messageStringThree);
59 $this->assertTrue($this->messages[0]->getTypeId() === ilSystemStyleMessage::TYPE_ERROR);
60
61 $this->assertTrue($this->messages[1]->getMessage() === $this->messageStringTwo);
62 $this->assertTrue($this->messages[1]->getTypeId() === ilSystemStyleMessage::TYPE_SUCCESS);
63
64 $this->assertTrue($this->messages[2]->getMessage() === $this->messageStringOne);
65 $this->assertTrue($this->messages[2]->getTypeId() === ilSystemStyleMessage::TYPE_INFO);
66 }
67
68 public function testAddMessage()
69 {
70 $this->createTestEnvironment();
71
73
76
77 $this->ilSystemStyleMessage = new ilSystemStyleMessage($this->messageStringThree, ilSystemStyleMessage::TYPE_ERROR);
79 $this->messages = $this->ilSystemStyleMessageStack->getMessages();
80
81 $this->assertTrue($this->messages[2]->getMessage() === $this->messageStringThree);
82 $this->assertTrue($this->messages[2]->getTypeId() === ilSystemStyleMessage::TYPE_ERROR);
83
84 $this->assertTrue($this->messages[1]->getMessage() === $this->messageStringTwo);
85 $this->assertTrue($this->messages[1]->getTypeId() === ilSystemStyleMessage::TYPE_SUCCESS);
86
87 $this->assertTrue($this->messages[0]->getMessage() === $this->messageStringOne);
88 $this->assertTrue($this->messages[0]->getTypeId() === ilSystemStyleMessage::TYPE_INFO);
89 }
90
91 public function testJoinedMessages()
92 {
93 $this->createTestEnvironment();
94
96
99
102
103 $this->ilSystemStyleMessage = new ilSystemStyleMessage($this->messageStringThree, ilSystemStyleMessage::TYPE_ERROR);
105
108
109 $this->ilSystemStyleMessage = new ilSystemStyleMessage("YET another ERROR message", ilSystemStyleMessage::TYPE_ERROR);
111
112 $this->assertTrue(count($this->ilSystemStyleMessageStack->getJoinedMessages()) === 3);
113 $this->assertTrue($this->ilSystemStyleMessageStack->getJoinedMessages()[0] === $this->messageStringOne . "</br>");
114 $this->assertTrue($this->ilSystemStyleMessageStack->getJoinedMessages()[1] === $this->messageStringTwo .
115 "</br>" . "Another SUCCESS message" . "</br>");
116 $this->assertTrue($this->ilSystemStyleMessageStack->getJoinedMessages()[2] === $this->messageStringThree .
117 "</br>" . "Another ERROR message" . "</br>" . "YET another ERROR message" . "</br>");
118 }
119
120 public function testGetAndSetMessages()
121 {
122 $this->createTestEnvironment();
123
125
128
129 $this->assertTrue($this->ilSystemStyleMessageStack->getMessages()[1]->getMessage() === $this->messageStringTwo);
130 $this->ilSystemStyleMessageStack->getMessages()[1]->setMessage("Godzilla has NOT taken over the world.");
131 $this->assertTrue($this->ilSystemStyleMessageStack->getMessages()[1]->getMessage() === "Godzilla has NOT taken over the world.");
132 }
133
134 public function testHasMessages()
135 {
136 $this->createTestEnvironment();
137
138 $this->assertFalse($this->ilSystemStyleMessageStack->hasMessages());
139
141
142 $this->assertTrue($this->ilSystemStyleMessageStack->hasMessages());
143 }
144
145 protected function createTestEnvironment()
146 {
149 }
150}
An exception for terminatinating execution or to throw for unit testing.
Used to stack messages to be shown to the user.
hasMessages()
Return wheter there are any message at all stored in the stack.
prependMessage(ilSystemStyleMessage $message)
Add a message to be displayed before all others.
getJoinedMessages()
Return an array containing a string with all messages for each type.
addMessage(ilSystemStyleMessage $message)
Add a message to be displayed by the stack.