ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
JavaScriptBindableTest.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
21use PHPUnit\Framework\TestCase;
23use ILIAS\UI\Implementation\Component\ComponentHelper;
24
25require_once("vendor/composer/vendor/autoload.php");
26
28{
30 use ComponentHelper;
31}
32
36class JavaScriptBindableTest extends TestCase
37{
39
40 public function setUp(): void
41 {
42 $this->mock = new JSComponentMock();
43 }
44
45 public function testWithOnLoadCode(): void
46 {
47 $m = $this->mock->withOnLoadCode(function ($id) {
48 return "Its me, $id!";
49 });
50
51 $binder = $m->getOnLoadCode();
52 $this->assertInstanceOf(Closure::class, $binder);
53 $this->assertEquals("Its me, Mario!", $binder("Mario"));
54 }
55
56 public function testWithOnLoadCodeFalseClosure1(): void
57 {
58 try {
59 $this->mock->withOnLoadCode(function (): void {
60 });
61 $this->assertFalse("This should not happen...");
62 } catch (InvalidArgumentException $exception) {
63 $this->assertTrue(true);
64 }
65 }
66
67 public function testWithOnLoadCodeFalseClosure2(): void
68 {
69 try {
70 $this->mock->withOnLoadCode(function ($id, $some_arg): void {
71 });
72 $this->assertFalse("This should not happen...");
73 } catch (InvalidArgumentException $exception) {
74 $this->assertTrue(true);
75 }
76 }
77
78 public function testWithAdditionalOnLoadCode(): void
79 {
80 $m = $this->mock
81 ->withOnLoadCode(function ($id) {
82 return "Its me, $id!";
83 })
84 ->withAdditionalOnLoadCode(function ($id) {
85 return "And again, me: $id.";
86 });
87
88 $binder = $m->getOnLoadCode();
89 $this->assertInstanceOf(Closure::class, $binder);
90 $this->assertEquals("Its me, Mario!\nAnd again, me: Mario.", $binder("Mario"));
91 }
92
94 {
95 $m = $this->mock
96 ->withAdditionalOnLoadCode(function ($id) {
97 return "And again, me: $id.";
98 });
99
100 $binder = $m->getOnLoadCode();
101 $this->assertInstanceOf(Closure::class, $binder);
102 $this->assertEquals("And again, me: Mario.", $binder("Mario"));
103 }
104}
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
Definition: plugin.php:23
Interface to be extended by components that have the possibility to bind to Javascript.
trait JavaScriptBindable
Trait for components implementing JavaScriptBindable providing standard implementation.