ILIAS  trunk Revision v11.0_alpha-1753-gb21ca8c4367
All Data Structures Namespaces Files Functions Variables Enumerations Enumerator Modules Pages
EntityTest.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
29 use ILIAS\UI\Component as I;
31 
33 {
34  protected function getEntityFactory(): Entity\Factory
35  {
36  return new Entity\Factory();
37  }
38 
39  protected function legacy(string $string): Content
40  {
41  return new Content($string, (new SignalGenerator()));
42  }
43 
44  public function testEntityFactory(): void
45  {
46  $entity = $this->getEntityFactory()->standard('primary', 'secondary');
47  $this->assertInstanceOf("ILIAS\\UI\\Component\\Entity\\Standard", $entity);
48  $this->assertEquals('primary', $entity->getPrimaryIdentifier());
49  $this->assertEquals('secondary', $entity->getSecondaryIdentifier());
50  }
51 
52  public function testEntityBasicProperties(): void
53  {
54  $entity = $this->getEntityFactory()->standard('primary', 'secondary');
55  $this->assertEquals([$this->legacy('bc')], $entity->withBlockingAvailabilityConditions($this->legacy('bc'))->getBlockingAvailabilityConditions());
56  $this->assertEquals([$this->legacy('fp')], $entity->withFeaturedProperties($this->legacy('fp'))->getFeaturedProperties());
57  $this->assertEquals([$this->legacy('md')], $entity->withMainDetails($this->legacy('md'))->getMainDetails());
58  $this->assertEquals([$this->legacy('ps')], $entity->withPersonalStatus($this->legacy('ps'))->getPersonalStatus());
59  $this->assertEquals([$this->legacy('a')], $entity->withAvailability($this->legacy('a'))->getAvailability());
60  $this->assertEquals([$this->legacy('d')], $entity->withDetails($this->legacy('d'))->getDetails());
61  }
62 
63  public static function getEntityAllowedIdentiferTypes(): array
64  {
65  $shy_button = new Button\Shy('the label', '#');
66  $shy_link = new Link\Standard('the label', '#');
67  $image = new Image\Image(I\Image\Image::STANDARD, 'source', 'alt');
68  $icon = new Symbol\Icon\Standard('crs', 'label', 'large', false);
69  return [
70  [$shy_button],
71  [$shy_link],
72  [$image],
73  [$icon],
74  ['some string']
75  ];
76  }
77 
81  public function testEntityIdentifiers($identifier): void
82  {
83  $entity = $this->getEntityFactory()->standard($identifier, $identifier);
84  $this->assertEquals($identifier, $entity->getPrimaryIdentifier());
85  $this->assertEquals($identifier, $entity->getSecondaryIdentifier());
86  }
87 
88  public function testEntityActionProperties(): void
89  {
90  $glyph = new Symbol\Glyph\Glyph('laugh', 'some glyph');
91  $tag = new Button\Tag('tag', '#');
92  $shy = new Button\Shy('shy', '#');
93  $entity = $this->getEntityFactory()->standard('primary', 'secondary')
94  ->withPrioritizedReactions($glyph, $tag)
95  ->withReactions($glyph, $glyph, $glyph)
96  ->withActions($shy);
97 
98  $this->assertEquals([$glyph, $tag], $entity->getPrioritizedReactions());
99  $this->assertEquals([$glyph,$glyph,$glyph], $entity->getReactions());
100  $this->assertEquals([$shy], $entity->getActions());
101  }
102 
103  public function testEntityComponentProperties(): void
104  {
105  $glyph = new Symbol\Glyph\Glyph('laugh', 'some glyph');
106  $tag = new Button\Tag('tag', '#');
107  $shy = new Button\Shy('shy', '#');
108  $entity = $this->getEntityFactory()->standard('primary', 'secondary')
109  ->withPrioritizedReactions($glyph, $tag)
110  ->withReactions($glyph)
111  ->withActions($shy);
112 
113  $this->assertEquals([$glyph, $tag], $entity->getPrioritizedReactions());
114  $this->assertEquals([$glyph], $entity->getReactions());
115  $this->assertEquals([$shy], $entity->getActions());
116  }
117 
118 
119  public function getUIFactory(): NoUIFactory
120  {
121  return new class () extends NoUIFactory {
122  public function dropdown(): Dropdown\Factory
123  {
124  return new Dropdown\Factory();
125  }
126  };
127  }
128  public function testEntityRendering(): void
129  {
130  $glyph = new Symbol\Glyph\Glyph('laugh', 'some glyph');
131  $tag = new Button\Tag('tag', '#');
132  $shy = new Button\Shy('shy', '#');
133  $entity = $this->getEntityFactory()->standard('primary', 'secondary')
134  ->withPrioritizedReactions($glyph, $tag)
135  ->withReactions($glyph, $glyph)
136  ->withActions($shy, $shy)
137  ->withBlockingAvailabilityConditions($this->legacy('bc'))
138  ->withFeaturedProperties($this->legacy('fp'))
139  ->withMainDetails($this->legacy('md'))
140  ->withPersonalStatus($this->legacy('ps'))
141  ->withAvailability($this->legacy('a'))
142  ->withDetails($this->legacy('d'));
143 
144  $r = $this->getDefaultRenderer();
145  $html = $this->brutallyTrimHTML($r->render($entity));
146  $expected = $this->brutallyTrimHTML('
147 <div class="c-entity __container">
148  <div class="c-entity __blocking-conditions">bc</div>
149  <div class="c-entity __actions">
150  <div class="dropdown" id="id_9">
151  <button class="btn btn-default dropdown-toggle" type="button" aria-label="actions" aria-haspopup="true" aria-expanded="false" aria-controls="id_9_menu"><span class="caret"></span></button>
152  <ul id="id_9_menu" class="dropdown-menu">
153  <li><button class="btn btn-link" data-action="#" id="id_7">shy</button></li>
154  <li><button class="btn btn-link" data-action="#" id="id_8">shy</button></li>
155  </ul>
156  </div>
157  </div>
158  <div class="c-entity __secondary-identifier --string ">secondary</div>
159  <div class="c-entity __primary-identifier">primary</div>
160  <div class="c-entity __featured">fp</div>
161  <div class="c-entity __personal-status">ps</div>
162  <div class="c-entity __main-details">md</div>
163  <div class="c-entity __availability">a</div>
164  <div class="c-entity __details">d</div>
165  <div class="c-entity __reactions">
166  <a class="glyph" aria-label="some glyph"><span class="glyphicon il-glyphicon-laugh" aria-hidden="true"></span></a>
167  <a class="glyph" aria-label="some glyph"><span class="glyphicon il-glyphicon-laugh" aria-hidden="true"></span></a>
168  </div>
169  <div class="c-entity __featured-reactions">
170  <a class="glyph" aria-label="some glyph"><span class="glyphicon il-glyphicon-laugh" aria-hidden="true"></span></a>
171  <button class="btn btn-tag btn-tag-relevance-veryhigh" data-action="#" id="id_10">tag</button>
172  </div>
173 </div>
174  ');
175  $this->assertEquals($expected, $html);
176  }
177 }
testEntityComponentProperties()
Definition: EntityTest.php:103
testEntityFactory()
Definition: EntityTest.php:44
getEntityFactory()
Definition: EntityTest.php:34
This is the factory for Entities.
Definition: Factory.php:31
Builds a Color from either hex- or rgb values.
Definition: Factory.php:30
testEntityRendering()
Definition: EntityTest.php:128
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Definition: Bulky.php:21
testEntityActionProperties()
Definition: EntityTest.php:88
legacy(string $string)
Definition: EntityTest.php:39
testEntityIdentifiers($identifier)
getEntityAllowedIdentiferTypes
Definition: EntityTest.php:81
This describes the specific behavior of an ILIAS standard icon.
Definition: Standard.php:26
static getEntityAllowedIdentiferTypes()
Definition: EntityTest.php:63
testEntityBasicProperties()
Definition: EntityTest.php:52
$r