ILIAS  release_8 Revision v8.19
All Data Structures Namespaces Files Functions Variables Modules Pages
ilSystemStyleMessageStackTest.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
21 require_once('libs/composer/vendor/autoload.php');
22 include_once('./tests/UI/UITestHelper.php');
23 
26 
27 class ilSystemStyleMessageStackTest extends TestCase
28 {
30 
31  protected string $messageStringOne = 'This is a message';
32  protected string $messageStringTwo = 'Godzilla has taken over the world.';
33  protected string $messageStringThree = 'A small, cute cat destroyed Godzilla.';
37  protected array $messages = [];
39 
40  public function testPrependMessage(): void
41  {
42  $this->createTestEnvironment();
43 
45 
47  $this->messageStringTwo,
49  );
51 
53  $this->messageStringThree,
55  );
57  $this->messages = $this->ilSystemStyleMessageStack->getMessages();
58 
59  $this->assertTrue($this->messages[0]->getMessage() === $this->messageStringThree);
60  $this->assertTrue($this->messages[0]->getTypeId() === ilSystemStyleMessage::TYPE_ERROR);
61 
62  $this->assertTrue($this->messages[1]->getMessage() === $this->messageStringTwo);
63  $this->assertTrue($this->messages[1]->getTypeId() === ilSystemStyleMessage::TYPE_SUCCESS);
64 
65  $this->assertTrue($this->messages[2]->getMessage() === $this->messageStringOne);
66  $this->assertTrue($this->messages[2]->getTypeId() === ilSystemStyleMessage::TYPE_INFO);
67  }
68 
69  public function testAddMessage(): void
70  {
71  $this->createTestEnvironment();
72 
74 
76  $this->messageStringTwo,
78  );
80 
82  $this->messageStringThree,
84  );
86  $this->messages = $this->ilSystemStyleMessageStack->getMessages();
87 
88  $this->assertTrue($this->messages[2]->getMessage() === $this->messageStringThree);
89  $this->assertTrue($this->messages[2]->getTypeId() === ilSystemStyleMessage::TYPE_ERROR);
90 
91  $this->assertTrue($this->messages[1]->getMessage() === $this->messageStringTwo);
92  $this->assertTrue($this->messages[1]->getTypeId() === ilSystemStyleMessage::TYPE_SUCCESS);
93 
94  $this->assertTrue($this->messages[0]->getMessage() === $this->messageStringOne);
95  $this->assertTrue($this->messages[0]->getTypeId() === ilSystemStyleMessage::TYPE_INFO);
96  }
97 
98  public function testJoinedMessages(): void
99  {
100  $this->createTestEnvironment();
101 
103 
105  $this->messageStringTwo,
107  );
109 
111  'Another SUCCESS message',
113  );
115 
117  $this->messageStringThree,
119  );
121 
123  'Another ERROR message',
125  );
127 
129  'YET another ERROR message',
131  );
133 
134  $this->assertTrue(count($this->ilSystemStyleMessageStack->getJoinedMessages()) === 3);
135  $this->assertTrue($this->ilSystemStyleMessageStack->getJoinedMessages()[0] === $this->messageStringOne . '</br>');
136  $this->assertTrue($this->ilSystemStyleMessageStack->getJoinedMessages()[1] === $this->messageStringTwo .
137  '</br>' . 'Another SUCCESS message' . '</br>');
138  $this->assertTrue($this->ilSystemStyleMessageStack->getJoinedMessages()[2] === $this->messageStringThree .
139  '</br>' . 'Another ERROR message' . '</br>' . 'YET another ERROR message' . '</br>');
140  }
141 
142  public function testGetUIComponentsMessages(): void
143  {
144  $this->createTestEnvironment();
145 
147 
149  $this->messageStringTwo,
151  );
153 
155  'Another SUCCESS message',
157  );
159 
161  $this->messageStringThree,
163  );
165 
167  'Another ERROR message',
169  );
171 
173  'YET another ERROR message',
175  );
177 
178  $ui_helper = new UITestHelper();
179 
180  $message_components = $this->ilSystemStyleMessageStack->getUIComponentsMessages($ui_helper->factory());
181 
182  $this->assertCount(3, $message_components);
183  $this->assertInstanceOf(IMessageBox::class, $message_components[0]);
184  $this->assertInstanceOf(IMessageBox::class, $message_components[1]);
185  $this->assertInstanceOf(IMessageBox::class, $message_components[2]);
186 
187  $this->assertEquals(ILIAS\UI\Component\MessageBox\MessageBox::INFO, $message_components[0]->getType());
188  $this->assertEquals(ILIAS\UI\Component\MessageBox\MessageBox::SUCCESS, $message_components[1]->getType());
189  $this->assertEquals(ILIAS\UI\Component\MessageBox\MessageBox::FAILURE, $message_components[2]->getType());
190 
191  $this->assertEquals('This is a message</br>', $message_components[0]->getMessageText());
192  }
193 
194  public function testGetAndSetMessages(): void
195  {
196  $this->createTestEnvironment();
197 
199 
201  $this->messageStringTwo,
203  );
205 
206  $this->assertTrue($this->ilSystemStyleMessageStack->getMessages()[1]->getMessage() === $this->messageStringTwo);
207  $this->ilSystemStyleMessageStack->getMessages()[1]->setMessage('Godzilla has NOT taken over the world.');
208  $this->assertTrue($this->ilSystemStyleMessageStack->getMessages()[1]->getMessage() === 'Godzilla has NOT taken over the world.');
209  }
210 
211  public function testHasMessages(): void
212  {
213  $this->createTestEnvironment();
214 
215  $this->assertFalse($this->ilSystemStyleMessageStack->hasMessages());
216 
218 
219  $this->assertTrue($this->ilSystemStyleMessageStack->hasMessages());
220  }
221 
222  protected function createTestEnvironment(): void
223  {
225  $this->messageStringOne,
227  );
229  $this->getMockBuilder(ilGlobalTemplateInterface::class)->getMock()
230  );
231  }
232 }
Class Factory.
Class ChatMainBarProvider .
hasMessages()
Return wheter there are any message at all stored in the stack.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
addMessage(ilSystemStyleMessage $message)
Add a message to be displayed by the stack.
prependMessage(ilSystemStyleMessage $message)
Add a message to be displayed before all others.
getUIComponentsMessages(\ILIAS\UI\Factory $f)
Return Messages as UI Component.
ilSystemStyleMessageStack $ilSystemStyleMessageStack
Used to stack messages to be shown to the user.
getJoinedMessages()
Return an array containing a string with all messages for each type.
Class UITestHelper can be helpful for test cases outside the UI Components, to inject a working facto...