19declare(strict_types=1);
21use PHPUnit\Framework\TestCase;
23use ILIAS\UI\Implementation\Component\ComponentHelper;
25require_once(
"vendor/composer/vendor/autoload.php");
47 $m = $this->mock->withOnLoadCode(
function (
$id) {
48 return "Its me, $id!";
51 $binder = $m->getOnLoadCode();
52 $this->assertInstanceOf(Closure::class, $binder);
53 $this->assertEquals(
"Its me, Mario!", $binder(
"Mario"));
59 $this->mock->withOnLoadCode(
function ():
void {
61 $this->assertFalse(
"This should not happen...");
62 }
catch (InvalidArgumentException $exception) {
63 $this->assertTrue(
true);
70 $this->mock->withOnLoadCode(
function (
$id, $some_arg):
void {
72 $this->assertFalse(
"This should not happen...");
73 }
catch (InvalidArgumentException $exception) {
74 $this->assertTrue(
true);
80 $java_script_id =
'js-id-1';
81 $java_script_code_1 =
'first piece of JavaScript code with id: ';
82 $java_script_code_2 =
'second piece of JavaScript code with id: ';
84 $java_script_bindable = $this
86 ->withOnLoadCode(
static fn(
$id) => $java_script_code_1 .
$id)
87 ->withAdditionalOnLoadCode(
static fn(
$id) => $java_script_code_2 .
$id);
89 $java_script_binder = $java_script_bindable->getOnLoadCode();
90 $this->assertInstanceOf(Closure::class, $java_script_binder);
92 $java_script_code_2 . $java_script_id .
"\n" .
93 $java_script_code_1 . $java_script_id,
94 $java_script_binder($java_script_id)
101 ->withAdditionalOnLoadCode(
function (
$id) {
102 return "And again, me: $id.";
105 $binder = $m->getOnLoadCode();
106 $this->assertInstanceOf(Closure::class, $binder);
107 $this->assertEquals(
"And again, me: Mario.", $binder(
"Mario"));
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
testWithOnLoadCodeFalseClosure2()
testWithAdditionalOnLoadCode()
testWithAdditionalOnLoadCodeNoPrevious()
testWithOnLoadCodeFalseClosure1()
Interface to be extended by components that have the possibility to bind to Javascript.
trait JavaScriptBindable
Trait for components implementing JavaScriptBindable providing standard implementation.