ILIAS  trunk Revision v11.0_alpha-2638-g80c1d007f79
LegacyTest.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
21 require_once(__DIR__ . "/../../../../../../vendor/composer/vendor/autoload.php");
22 require_once(__DIR__ . "/../../Base.php");
23 
24 use ILIAS\UI\Component as C;
26 
31 {
32  public function getUIFactory(): NoUIFactory
33  {
34  return new class () extends NoUIFactory {
35  public function legacy(): IC\Legacy\Factory
36  {
37  return new IC\Legacy\Factory(new IC\SignalGenerator());
38  }
39  };
40  }
41 
42  public function testImplementsFactoryInterface(): void
43  {
44  $f = $this->getUIFactory();
45 
46  $this->assertInstanceOf("ILIAS\\UI\\Factory", $f);
47  $this->assertInstanceOf(
48  "ILIAS\\UI\\Component\\Legacy\\Content",
49  $f->legacy()->content("Legacy Content")
50  );
51  $this->assertInstanceOf(
52  "ILIAS\\UI\\Component\\Legacy\\LatexContent",
53  $f->legacy()->latexContent("Latex Content")
54  );
55  }
56 
57  public function testGetContent(): void
58  {
59  $f = $this->getUIFactory();
60  $g = $f->legacy()->content("Legacy Content");
61  $l = $f->legacy()->latexContent("Latex Content");
62 
63  $this->assertEquals("Legacy Content", $g->getContent());
64  $this->assertEquals("Latex Content", $l->getContent());
65  }
66 
67 
68  public function testRenderContent(): void
69  {
70  $f = $this->getUIFactory();
71  $r = $this->getDefaultRenderer();
72 
73  $g = $f->legacy()->content("Legacy Content");
74  $l = $f->legacy()->latexContent("Latex Content");
75 
76  $rendered_latex = '<div style="display: inherit;" class="c-legacy__content--latex">Latex Content</div>';
77 
78  $this->assertEquals("Legacy Content", $r->render($g));
79  $this->assertEquals($rendered_latex, $r->render($l));
80  }
81 
82  #[\PHPUnit\Framework\Attributes\DoesNotPerformAssertions]
83  public function testCreateWithCustomSignal(): void
84  {
85  $f = $this->getUIFactory();
86  $signal_name = 'Custom Signal';
87 
88  $f->legacy()->content('')->withCustomSignal($signal_name, '');
89  }
90 
91  public function testGetExistingCustomSignal(): void
92  {
93  $f = $this->getUIFactory();
94  $signal_name = 'Custom Signal';
95  $g = $f->legacy()->content('')->withCustomSignal($signal_name, '');
96 
97  $this->assertNotNull($g->getCustomSignal($signal_name));
98  }
99 
100  public function testGetNonExistingCustomSignal(): void
101  {
102  $f = $this->getUIFactory();
103  $signal_name = 'Custom Signal';
104  $g = $f->legacy()->content('');
105 
106  $this->expectException(InvalidArgumentException::class);
107  $this->expectExceptionMessage("Signal with name $signal_name is not registered");
108  $g->getCustomSignal($signal_name);
109  }
110 
111  public function testGetListOfSignals(): void
112  {
113  $f = $this->getUIFactory();
114  $signal_name_1 = 'Custom Signal 1';
115  $signal_name_2 = 'Custom Signal 2';
116 
117  $g = $f->legacy()->content('')->withCustomSignal($signal_name_1, '')->withCustomSignal($signal_name_2, '');
118  $l = $g->getAllCustomSignals();
119 
120  $this->assertIsArray($l);
121  }
122 
123  public function testGetListWithCustomSignalsAndCode(): void
124  {
125  $f = $this->getUIFactory();
126  $signal_name_1 = 'Custom Signal 1';
127  $custom_code_1 = 'custom_js1();';
128  $signal_name_2 = 'Custom Signal 2';
129  $custom_code_2 = 'custom_js2();';
130 
131  $g = $f->legacy()->content('')
132  ->withCustomSignal($signal_name_1, $custom_code_1)
133  ->withCustomSignal($signal_name_2, $custom_code_2);
134  $signal_list = $g->getAllCustomSignals();
135 
136  $this->assertEquals(2, count($signal_list));
137  $this->assertEquals($signal_list[$signal_name_1]['js_code'], $custom_code_1);
138  $this->assertEquals($signal_list[$signal_name_2]['js_code'], $custom_code_2);
139  }
140 }
testCreateWithCustomSignal()
Definition: LegacyTest.php:83
testRenderContent()
Definition: LegacyTest.php:68
testGetListOfSignals()
Definition: LegacyTest.php:111
testImplementsFactoryInterface()
Definition: LegacyTest.php:42
testGetNonExistingCustomSignal()
Definition: LegacyTest.php:100
legacy()
expected output: > ILIAS shows the rendered Component.
Definition: legacy.php:29
testGetContent()
Definition: LegacyTest.php:57
Test on button implementation.
Definition: LegacyTest.php:30
testGetListWithCustomSignalsAndCode()
Definition: LegacyTest.php:123
testGetExistingCustomSignal()
Definition: LegacyTest.php:91
$r