ILIAS  release_7 Revision v7.30-3-g800a261c036
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
7use PHPUnit\Framework\TestCase;
8
14class ilSystemStyleMessageStackTest extends TestCase
15{
16
21
25 protected $messageStringOne = "This is a message";
26
30 protected $messageStringTwo = "Godzilla has taken over the world.";
31
35 protected $messageStringThree = "A small, cute cat destroyed Godzilla.";
36
40 protected $messages = array();
41
46
47 public function testPrependMessage()
48 {
49 $this->createTestEnvironment();
50
52
55
56 $this->ilSystemStyleMessage = new ilSystemStyleMessage($this->messageStringThree, ilSystemStyleMessage::TYPE_ERROR);
58 $this->messages = $this->ilSystemStyleMessageStack->getMessages();
59
60 $this->assertTrue($this->messages[0]->getMessage() === $this->messageStringThree);
61 $this->assertTrue($this->messages[0]->getTypeId() === ilSystemStyleMessage::TYPE_ERROR);
62
63 $this->assertTrue($this->messages[1]->getMessage() === $this->messageStringTwo);
64 $this->assertTrue($this->messages[1]->getTypeId() === ilSystemStyleMessage::TYPE_SUCCESS);
65
66 $this->assertTrue($this->messages[2]->getMessage() === $this->messageStringOne);
67 $this->assertTrue($this->messages[2]->getTypeId() === ilSystemStyleMessage::TYPE_INFO);
68 }
69
70 public function testAddMessage()
71 {
72 $this->createTestEnvironment();
73
75
78
79 $this->ilSystemStyleMessage = new ilSystemStyleMessage($this->messageStringThree, ilSystemStyleMessage::TYPE_ERROR);
81 $this->messages = $this->ilSystemStyleMessageStack->getMessages();
82
83 $this->assertTrue($this->messages[2]->getMessage() === $this->messageStringThree);
84 $this->assertTrue($this->messages[2]->getTypeId() === ilSystemStyleMessage::TYPE_ERROR);
85
86 $this->assertTrue($this->messages[1]->getMessage() === $this->messageStringTwo);
87 $this->assertTrue($this->messages[1]->getTypeId() === ilSystemStyleMessage::TYPE_SUCCESS);
88
89 $this->assertTrue($this->messages[0]->getMessage() === $this->messageStringOne);
90 $this->assertTrue($this->messages[0]->getTypeId() === ilSystemStyleMessage::TYPE_INFO);
91 }
92
93 public function testJoinedMessages()
94 {
95 $this->createTestEnvironment();
96
98
101
104
105 $this->ilSystemStyleMessage = new ilSystemStyleMessage($this->messageStringThree, ilSystemStyleMessage::TYPE_ERROR);
107
110
111 $this->ilSystemStyleMessage = new ilSystemStyleMessage("YET another ERROR message", ilSystemStyleMessage::TYPE_ERROR);
113
114 $this->assertTrue(count($this->ilSystemStyleMessageStack->getJoinedMessages()) === 3);
115 $this->assertTrue($this->ilSystemStyleMessageStack->getJoinedMessages()[0] === $this->messageStringOne . "</br>");
116 $this->assertTrue($this->ilSystemStyleMessageStack->getJoinedMessages()[1] === $this->messageStringTwo .
117 "</br>" . "Another SUCCESS message" . "</br>");
118 $this->assertTrue($this->ilSystemStyleMessageStack->getJoinedMessages()[2] === $this->messageStringThree .
119 "</br>" . "Another ERROR message" . "</br>" . "YET another ERROR message" . "</br>");
120 }
121
122 public function testGetAndSetMessages()
123 {
124 $this->createTestEnvironment();
125
127
130
131 $this->assertTrue($this->ilSystemStyleMessageStack->getMessages()[1]->getMessage() === $this->messageStringTwo);
132 $this->ilSystemStyleMessageStack->getMessages()[1]->setMessage("Godzilla has NOT taken over the world.");
133 $this->assertTrue($this->ilSystemStyleMessageStack->getMessages()[1]->getMessage() === "Godzilla has NOT taken over the world.");
134 }
135
136 public function testHasMessages()
137 {
138 $this->createTestEnvironment();
139
140 $this->assertFalse($this->ilSystemStyleMessageStack->hasMessages());
141
143
144 $this->assertTrue($this->ilSystemStyleMessageStack->hasMessages());
145 }
146
147 protected function createTestEnvironment()
148 {
151 }
152}
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.