ILIAS  trunk Revision v11.0_alpha-2662-g519ff7d528f
SlateTest.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
21 require_once("vendor/composer/vendor/autoload.php");
22 require_once(__DIR__ . "/../../../Base.php");
23 
24 use ILIAS\UI\Component as C;
28 
32 class TestGenericSlate extends Slate implements C\MainControls\Slate\Slate
33 {
34  public function getContents(): array
35  {
36  return [];
37  }
38  public function withMappedSubNodes(callable $f): C\MainControls\Slate\Slate
39  {
40  return $this;
41  }
42 }
43 
48 {
49  protected I\SignalGenerator $sig_gen;
50  protected I\Button\Factory $button_factory;
51  protected I\Symbol\Icon\Factory $icon_factory;
52 
53  public function setUp(): void
54  {
55  $this->sig_gen = new I\SignalGenerator();
56  $this->button_factory = new I\Button\Factory();
57  $this->icon_factory = new I\Symbol\Icon\Factory();
58  }
59 
61  {
62  $name = 'name';
63  $icon = $this->icon_factory->custom('', '');
64  $slate = new TestGenericSlate($this->sig_gen, $name, $icon);
65 
66  $this->assertInstanceOf(
67  "ILIAS\\UI\\Component\\MainControls\\Slate\\Slate",
68  $slate
69  );
70  $this->assertEquals($name, $slate->getName());
71  $this->assertEquals($icon, $slate->getSymbol());
72  $this->assertFalse($slate->getEngaged());
73  return $slate;
74  }
75 
76  #[\PHPUnit\Framework\Attributes\Depends('testConstruction')]
77  public function testWithEngaged(Slate $slate): void
78  {
79  $slate = $slate->withEngaged(true);
80  $this->assertTrue($slate->getEngaged());
81  }
82 
83  #[\PHPUnit\Framework\Attributes\Depends('testConstruction')]
84  public function testWithAriaRole(Slate $slate): void
85  {
86  try {
87  $slate = $slate->withAriaRole(Slate::MENU);
88  $this->assertEquals("menu", $slate->getAriaRole());
89  } catch (InvalidArgumentException $e) {
90  $this->assertFalse("This should not happen");
91  }
92  }
93 
94  #[\PHPUnit\Framework\Attributes\Depends('testConstruction')]
95  public function testWithAriaRoleIncorrect(Slate $slate): void
96  {
97  try {
98  $slate->withAriaRole("loremipsum");
99  $this->assertFalse("This should not happen");
100  } catch (InvalidArgumentException $e) {
101  $this->assertTrue(true);
102  }
103  }
104 
105  #[\PHPUnit\Framework\Attributes\Depends('testConstruction')]
106  public function testSignals(Slate $slate): array
107  {
108  $signals = [
109  $slate->getToggleSignal(),
110  $slate->getEngageSignal(),
111  $slate->getReplaceSignal()
112  ];
113  foreach ($signals as $signal) {
114  $this->assertInstanceOf(Signal::class, $signal);
115  }
116  return $signals;
117  }
118 
119  #[\PHPUnit\Framework\Attributes\Depends('testSignals')]
120  public function testDifferentSignals(array $signals): void
121  {
122  $this->assertEquals(
123  $signals,
124  array_unique($signals)
125  );
126  }
127 }
getReplaceSignal()
Signal to replace the contents of the slate.
Definition: Slate.php:145
A generic Slate.
Definition: SlateTest.php:32
withMappedSubNodes(callable $f)
Definition: SlateTest.php:38
testWithAriaRoleIncorrect(Slate $slate)
Definition: SlateTest.php:95
getEngaged()
Should the slate be rendered as engaged?
Definition: Slate.php:132
testDifferentSignals(array $signals)
Definition: SlateTest.php:120
withEngaged(bool $state)
Configures the slate to be rendered as engaged (or not).
Definition: Slate.php:122
Tests for the Slate.
Definition: SlateTest.php:47
testWithAriaRole(Slate $slate)
Definition: SlateTest.php:84
I Symbol Icon Factory $icon_factory
Definition: SlateTest.php:51
getAriaRole()
Get the ARIA role on the slate.
Definition: Slate.php:201
I Button Factory $button_factory
Definition: SlateTest.php:50
getEngageSignal()
Signal that engages the slate when triggered.
Definition: Slate.php:114
testSignals(Slate $slate)
Definition: SlateTest.php:106
I SignalGenerator $sig_gen
Definition: SlateTest.php:49
testWithEngaged(Slate $slate)
Definition: SlateTest.php:77
withAriaRole(string $aria_role)
Get a slate like this, but with an additional ARIA role.
Definition: Slate.php:185
testConstruction()
Definition: SlateTest.php:60
getToggleSignal()
Signal that toggles the slate when triggered.
Definition: Slate.php:106