ILIAS  trunk Revision v11.0_alpha-2638-g80c1d007f79
ilStudyProgrammeGUIMessagesTest.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
22 
24 {
26  protected string $topic;
29 
30  public function setUp(): void
31  {
32  $collection = new ilPRGMessageCollection();
33  $lng = $this->createMock(ilLanguage::class);
34  $tpl = $this->createMock(ilGlobalTemplateInterface::class);
35  $this->messages = new ilPRGMessagePrinter($collection, $lng, $tpl);
36  $this->topic = 'a test topic';
37 
38  $this->collection = $this->messages->getMessageCollection($this->topic);
39  $this->collection2 = $this->messages->getMessageCollection($this->topic);
40  }
41 
42  public function testMessageFactory(): void
43  {
44  $this->assertInstanceOf(ilPRGMessageCollection::class, $this->collection);
45  $this->assertEquals($this->collection, $this->collection2);
46  $this->assertNotSame($this->collection, $this->collection2);
47  }
48 
49  public function testCollectionDefaults(): void
50  {
51  $this->assertEquals($this->topic, $this->collection->getDescription());
52 
53  $this->assertFalse($this->collection->hasErrors());
54  $this->assertEquals([], $this->collection->getErrors());
55 
56  $this->assertFalse($this->collection->hasSuccess());
57  $this->assertEquals([], $this->collection->getSuccess());
58 
59  $this->assertFalse($this->collection->hasAnyMessages());
60  }
61 
62  public function testAddMessages(): void
63  {
64  $ok_message = 'looks good';
65  $ok_id = 'some good record';
66  $this->collection->add(true, $ok_message, $ok_id);
67 
68  $this->assertTrue($this->collection->hasAnyMessages());
69 
70  $this->assertFalse($this->collection->hasErrors());
71  $this->assertEquals([], $this->collection->getErrors());
72 
73  $this->assertTrue($this->collection->hasSuccess());
74  $this->assertEquals(
75  [[$ok_message, $ok_id]],
76  $this->collection->getSuccess()
77  );
78  }
79 
80  public function testAddErrorMessages(): void
81  {
82  $message = 'looks bad';
83  $id = 'some record';
84 
85  $this->assertFalse($this->collection->hasAnyMessages());
86  $collection = $this->collection->withNewTopic($this->topic);
87  $this->assertFalse($collection->hasAnyMessages());
88 
89  $collection->add(false, $message, $id);
90  $collection->add(false, $message, $id);
91 
92  $this->assertTrue($collection->hasAnyMessages());
93 
94  $this->assertTrue($collection->hasErrors());
95  $this->assertEquals(
96  [[$message, $id],[$message, $id]],
97  $collection->getErrors()
98  );
99 
100  $this->assertEquals([], $collection->getSuccess());
101  $this->assertFalse($collection->hasSuccess());
102  }
103 }
Util around ilPRGMessageCollection factors and output collections.
withNewTopic(string $description)
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
Definition: plugin.php:23
global $lng
Definition: privfeed.php:31
$message
Definition: xapiexit.php:31
Holds information about multi-actions, mainly in context of member-assignemnts and status changes...