ILIAS  release_7 Revision v7.30-3-g800a261c036
All Data Structures Namespaces Files Functions Variables Modules Pages
NotificationSlateTest.php
Go to the documentation of this file.
1 <?php
2 
3 /* Copyright (c) 2019 Timon Amstutz <timon.amstutz@ilub.unibe.ch Extended GPL, see docs/LICENSE */
4 
5 require_once("libs/composer/vendor/autoload.php");
6 require_once(__DIR__ . "/../../../Base.php");
7 
8 use \ILIAS\UI\Component as C;
9 use \ILIAS\UI\Implementation\Component as I;
10 use \ILIAS\UI\Implementation\Component\MainControls\Slate\Notification;
11 
16 {
17  public function setUp() : void
18  {
19  $this->sig_gen = new I\SignalGenerator();
20  }
21 
22  public function getIcon()
23  {
24  return $this->getUIFactory()->symbol()->icon()->standard("name", "aria_label", "small", false);
25  }
26 
27  public function getUIFactory()
28  {
29  $factory = new class extends NoUIFactory {
30  public function button()
31  {
32  return new I\Button\Factory($this->sig_gen);
33  }
34  public function symbol() : ILIAS\UI\Component\Symbol\Factory
35  {
36  return new I\Symbol\Factory(
37  new I\Symbol\Icon\Factory(),
38  new I\Symbol\Glyph\Factory(),
39  new I\Symbol\Avatar\Factory()
40  );
41  }
42  public function item()
43  {
44  return new I\Item\Factory();
45  }
46  public function mainControls() : C\MainControls\Factory
47  {
48  return new I\MainControls\Factory(
49  $this->sig_gen,
50  new I\MainControls\Slate\Factory(
51  $this->sig_gen,
52  new \ILIAS\UI\Implementation\Component\Counter\Factory(),
53  $this->symbol()
54  )
55  );
56  }
57  public function icon() : I\Symbol\Icon\Factory
58  {
59  new I\Symbol\Icon\Factory();
60  }
61  };
62  $factory->sig_gen = $this->sig_gen;
63 
64  return $factory;
65  }
66 
68  {
69  $notificatino_slate = $this->getUIFactory()->mainControls()->slate()->notification("title", []);
70 
71  $this->assertInstanceOf("ILIAS\\UI\\Component\\MainControls\\Slate\\Notification", $notificatino_slate);
72  }
73 
74  public function testGenerationByFactory()
75  {
76  $item = $this->getUIFactory()->item()->notification("title", $this->getIcon())
77  ->withDescription("description");
78 
79  $notification_slate = $this->getUIFactory()->mainControls()->slate()->notification("title", [$item,$item]);
80  $this->assertEquals($notification_slate->getName(), "title");
81  $this->assertEquals($notification_slate->getContents(), [$item,$item]);
82  }
83 
84 
85  public function testWithAdditionalEntry()
86  {
87  $item = $this->getUIFactory()->item()->notification("title", $this->getIcon())
88  ->withDescription("description");
89  $notification_slate = $this->getUIFactory()->mainControls()->slate()->notification("title", [$item,$item]);
90  $this->assertEquals($notification_slate->getContents(), [$item,$item]);
91  $notification_slate = $notification_slate->withAdditionalEntry($item);
92  $this->assertEquals($notification_slate->getContents(), [$item,$item,$item]);
93  }
94 
96  {
97  $item = $this->getUIFactory()->item()->notification("item title", $this->getIcon());
98  $notification_slate = $this->getUIFactory()->mainControls()->slate()->notification("slate title", [$item]);
99 
100 
101  $r = $this->getDefaultRenderer();
102  $html = $r->render($notification_slate);
103 
104  $expected = <<<EOT
105 <div class="il-maincontrols-slate il-maincontrols-slate-notification">
106  <div class="il-maincontrols-slate-notification-title">slate title</div>
107  <div class="il-maincontrols-slate-content">
108  <div class="il-item-notification-replacement-container">
109  <div class="il-item il-notification-item" id="id_1">
110  <div class="media">
111  <div class="media-left">
112  <img class="icon name small" src="./templates/default/images/icon_default.svg" alt="aria_label"/>
113  </div>
114  <div class="media-body">
115  <h4 class="il-item-notification-title">item title</h4>
116  <div class="il-aggregate-notifications" data-aggregatedby="id_1">
117  <div class="il-maincontrols-slate il-maincontrols-slate-notification">
118  <div class="il-maincontrols-slate-notification-title">
119  <button class="btn btn-bulky" data-action="">
120  <span class="glyph" aria-label="back" role="img">
121  <span class="glyphicon glyphicon-chevron-left" aria-hidden="true"></span>
122  </span>
123  <span class="bulky-label">back</span>
124  </button>
125  </div>
126  <div class="il-maincontrols-slate-content"></div>
127  </div>
128  </div>
129  </div>
130  </div>
131  </div>
132  </div>
133  </div>
134 </div>
135 EOT;
136  $this->assertEquals(
137  $this->brutallyTrimHTML($expected),
138  $this->brutallyTrimHTML($html)
139  );
140  }
141 }
Class Factory.
Class ChatMainBarProvider .
back()
Definition: back.php:2
Provides common functionality for UI tests.
Definition: Base.php:262
Tests for the Slate.
brutallyTrimHTML($html)
A more radical version of normalizeHTML.
Definition: Base.php:392
$factory
Definition: metadata.php:58
getDefaultRenderer(JavaScriptBinding $js_binding=null, $with_stub_renderings=[])
Definition: Base.php:311