ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
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 
4 include_once("Services/Style/System/classes/Utilities/class.ilSystemStyleMessage.php");
5 include_once("Services/Style/System/classes/Utilities/class.ilSystemStyleMessageStack.php");
6 
13 
18 
22  protected $messageStringOne = "This is a message";
23 
27  protected $messageStringTwo = "Godzilla has taken over the world.";
28 
32  protected $messageStringThree = "A small, cute cat destroyed Godzilla.";
33 
37  protected $messages = array();
38 
43 
44  public function testPrependMessage() {
45  $this->createTestEnvironment();
46 
48 
51 
52  $this->ilSystemStyleMessage = new ilSystemStyleMessage($this->messageStringThree, ilSystemStyleMessage::TYPE_ERROR);
54  $this->messages = $this->ilSystemStyleMessageStack->getMessages();
55 
56  $this->assertTrue($this->messages[0]->getMessage() === $this->messageStringThree);
57  $this->assertTrue($this->messages[0]->getTypeId() === ilSystemStyleMessage::TYPE_ERROR);
58 
59  $this->assertTrue($this->messages[1]->getMessage() === $this->messageStringTwo);
60  $this->assertTrue($this->messages[1]->getTypeId() === ilSystemStyleMessage::TYPE_SUCCESS);
61 
62  $this->assertTrue($this->messages[2]->getMessage() === $this->messageStringOne);
63  $this->assertTrue($this->messages[2]->getTypeId() === ilSystemStyleMessage::TYPE_INFO);
64  }
65 
66  public function testAddMessage() {
67  $this->createTestEnvironment();
68 
70 
73 
74  $this->ilSystemStyleMessage = new ilSystemStyleMessage($this->messageStringThree, ilSystemStyleMessage::TYPE_ERROR);
76  $this->messages = $this->ilSystemStyleMessageStack->getMessages();
77 
78  $this->assertTrue($this->messages[2]->getMessage() === $this->messageStringThree);
79  $this->assertTrue($this->messages[2]->getTypeId() === ilSystemStyleMessage::TYPE_ERROR);
80 
81  $this->assertTrue($this->messages[1]->getMessage() === $this->messageStringTwo);
82  $this->assertTrue($this->messages[1]->getTypeId() === ilSystemStyleMessage::TYPE_SUCCESS);
83 
84  $this->assertTrue($this->messages[0]->getMessage() === $this->messageStringOne);
85  $this->assertTrue($this->messages[0]->getTypeId() === ilSystemStyleMessage::TYPE_INFO);
86  }
87 
88  public function testJoinedMessages() {
89  $this->createTestEnvironment();
90 
92 
95 
96  $this->ilSystemStyleMessage = new ilSystemStyleMessage("Another SUCCESS message", ilSystemStyleMessage::TYPE_SUCCESS);
98 
99  $this->ilSystemStyleMessage = new ilSystemStyleMessage($this->messageStringThree, ilSystemStyleMessage::TYPE_ERROR);
101 
102  $this->ilSystemStyleMessage = new ilSystemStyleMessage("Another ERROR message", ilSystemStyleMessage::TYPE_ERROR);
104 
105  $this->ilSystemStyleMessage = new ilSystemStyleMessage("YET another ERROR message", ilSystemStyleMessage::TYPE_ERROR);
107 
108  $this->assertTrue(count($this->ilSystemStyleMessageStack->getJoinedMessages()) === 3);
109  $this->assertTrue($this->ilSystemStyleMessageStack->getJoinedMessages()[0] === $this->messageStringOne . "</br>");
110  $this->assertTrue($this->ilSystemStyleMessageStack->getJoinedMessages()[1] === $this->messageStringTwo .
111  "</br>" . "Another SUCCESS message" . "</br>");
112  $this->assertTrue($this->ilSystemStyleMessageStack->getJoinedMessages()[2] === $this->messageStringThree .
113  "</br>" . "Another ERROR message" . "</br>" . "YET another ERROR message" . "</br>");
114  }
115 
116  public function testGetAndSetMessages() {
117  $this->createTestEnvironment();
118 
120 
123 
124  $this->assertTrue($this->ilSystemStyleMessageStack->getMessages()[1]->getMessage() === $this->messageStringTwo);
125  $this->ilSystemStyleMessageStack->getMessages()[1]->setMessage("Godzilla has NOT taken over the world.");
126  $this->assertTrue($this->ilSystemStyleMessageStack->getMessages()[1]->getMessage() === "Godzilla has NOT taken over the world.");
127  }
128 
129  public function testHasMessages() {
130  $this->createTestEnvironment();
131 
132  $this->assertFalse($this->ilSystemStyleMessageStack->hasMessages());
133 
135 
136  $this->assertTrue($this->ilSystemStyleMessageStack->hasMessages());
137  }
138 
139  protected function createTestEnvironment() {
140  $this->ilSystemStyleMessage = new ilSystemStyleMessage($this->messageStringOne, ilSystemStyleMessage::TYPE_INFO);
142  }
143 }
hasMessages()
Return wheter there are any message at all stored in the stack.
addMessage(ilSystemStyleMessage $message)
Add a message to be displayed by the stack.
prependMessage(ilSystemStyleMessage $message)
Add a message to be displayed before all others.
Create styles array
The data for the language used.
Used to stack messages to be shown to the user.
getJoinedMessages()
Return an array containing a string with all messages for each type.