ILIAS  trunk Revision v11.0_alpha-2638-g80c1d007f79
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 
78  #[\PHPUnit\Framework\Attributes\DataProvider('getEntityAllowedIdentiferTypes')]
79  public function testEntityIdentifiers($identifier): void
80  {
81  $entity = $this->getEntityFactory()->standard($identifier, $identifier);
82  $this->assertEquals($identifier, $entity->getPrimaryIdentifier());
83  $this->assertEquals($identifier, $entity->getSecondaryIdentifier());
84  }
85 
86  public function testEntityActionProperties(): void
87  {
88  $glyph = new Symbol\Glyph\Glyph('laugh', 'some glyph');
89  $tag = new Button\Tag('tag', '#');
90  $shy = new Button\Shy('shy', '#');
91  $entity = $this->getEntityFactory()->standard('primary', 'secondary')
92  ->withPrioritizedReactions($glyph, $tag)
93  ->withReactions($glyph, $glyph, $glyph)
94  ->withActions($shy);
95 
96  $this->assertEquals([$glyph, $tag], $entity->getPrioritizedReactions());
97  $this->assertEquals([$glyph,$glyph,$glyph], $entity->getReactions());
98  $this->assertEquals([$shy], $entity->getActions());
99  }
100 
101  public function testEntityComponentProperties(): void
102  {
103  $glyph = new Symbol\Glyph\Glyph('laugh', 'some glyph');
104  $tag = new Button\Tag('tag', '#');
105  $shy = new Button\Shy('shy', '#');
106  $entity = $this->getEntityFactory()->standard('primary', 'secondary')
107  ->withPrioritizedReactions($glyph, $tag)
108  ->withReactions($glyph)
109  ->withActions($shy);
110 
111  $this->assertEquals([$glyph, $tag], $entity->getPrioritizedReactions());
112  $this->assertEquals([$glyph], $entity->getReactions());
113  $this->assertEquals([$shy], $entity->getActions());
114  }
115 
116 
117  public function getUIFactory(): NoUIFactory
118  {
119  return new class () extends NoUIFactory {
120  public function dropdown(): Dropdown\Factory
121  {
122  return new Dropdown\Factory();
123  }
124  };
125  }
126  public function testEntityRendering(): void
127  {
128  $glyph = new Symbol\Glyph\Glyph('laugh', 'some glyph');
129  $tag = new Button\Tag('tag', '#');
130  $shy = new Button\Shy('shy', '#');
131  $entity = $this->getEntityFactory()->standard('primary', 'secondary')
132  ->withPrioritizedReactions($glyph, $tag)
133  ->withReactions($glyph, $glyph)
134  ->withActions($shy, $shy)
135  ->withBlockingAvailabilityConditions($this->legacy('bc'))
136  ->withFeaturedProperties($this->legacy('fp'))
137  ->withMainDetails($this->legacy('md'))
138  ->withPersonalStatus($this->legacy('ps'))
139  ->withAvailability($this->legacy('a'))
140  ->withDetails($this->legacy('d'));
141 
142  $r = $this->getDefaultRenderer();
143  $html = $this->brutallyTrimHTML($r->render($entity));
144  $expected = $this->brutallyTrimHTML('
145 <div class="c-entity __container">
146  <div class="c-entity __blocking-conditions">bc</div>
147  <div class="c-entity __actions">
148  <div class="dropdown" id="id_9">
149  <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>
150  <ul id="id_9_menu" class="dropdown-menu">
151  <li><button class="btn btn-link" data-action="#" id="id_7">shy</button></li>
152  <li><button class="btn btn-link" data-action="#" id="id_8">shy</button></li>
153  </ul>
154  </div>
155  </div>
156  <div class="c-entity __secondary-identifier --string ">secondary</div>
157  <div class="c-entity __primary-identifier">primary</div>
158  <div class="c-entity __featured">fp</div>
159  <div class="c-entity __personal-status">ps</div>
160  <div class="c-entity __main-details">md</div>
161  <div class="c-entity __availability">a</div>
162  <div class="c-entity __details">d</div>
163  <div class="c-entity __reactions">
164  <a class="glyph" aria-label="some glyph"><span class="glyphicon il-glyphicon-laugh" aria-hidden="true"></span></a>
165  <a class="glyph" aria-label="some glyph"><span class="glyphicon il-glyphicon-laugh" aria-hidden="true"></span></a>
166  </div>
167  <div class="c-entity __featured-reactions">
168  <a class="glyph" aria-label="some glyph"><span class="glyphicon il-glyphicon-laugh" aria-hidden="true"></span></a>
169  <button class="btn btn-tag btn-tag-relevance-veryhigh" data-action="#" id="id_10">tag</button>
170  </div>
171 </div>
172  ');
173  $this->assertEquals($expected, $html);
174  }
175 }
testEntityComponentProperties()
Definition: EntityTest.php:101
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:126
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:86
legacy(string $string)
Definition: EntityTest.php:39
testEntityIdentifiers($identifier)
Definition: EntityTest.php:79
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