ILIAS  release_7 Revision v7.30-3-g800a261c036
JavaScriptBindableTest.php
Go to the documentation of this file.
1<?php
2
3/* Copyright (c) 2016 Richard Klees <richard.klees@concepts-and-training.de> Extended GPL, see docs/LICENSE */
4
5use PHPUnit\Framework\TestCase;
6
7require_once("libs/composer/vendor/autoload.php");
8
10{
12}
13
17class JavaScriptBindableTest extends TestCase
18{
19 public function setUp() : void
20 {
21 $this->mock = new JSComponentMock();
22 }
23
24 public function test_withOnLoadCode()
25 {
26 $m = $this->mock->withOnLoadCode(function ($id) {
27 return "Its me, $id!";
28 });
29
30 $binder = $m->getOnLoadCode();
31 $this->assertInstanceOf(\Closure::class, $binder);
32 $this->assertEquals("Its me, Mario!", $binder("Mario"));
33 }
34
36 {
37 try {
38 $this->mock->withOnLoadCode(function () {
39 });
40 $this->assertFalse("This should not happen...");
41 } catch (\InvalidArgumentException $exception) {
42 $this->assertTrue(true);
43 }
44 }
45
47 {
48 try {
49 $this->mock->withOnLoadCode(function ($id, $some_arg) {
50 });
51 $this->assertFalse("This should not happen...");
52 } catch (\InvalidArgumentException $exception) {
53 $this->assertTrue(true);
54 }
55 }
56
58 {
59 $m = $this->mock
60 ->withOnLoadCode(function ($id) {
61 return "Its me, $id!";
62 })
63 ->withAdditionalOnLoadCode(function ($id) {
64 return "And again, me: $id.";
65 });
66
67 $binder = $m->getOnLoadCode();
68 $this->assertInstanceOf(\Closure::class, $binder);
69 $this->assertEquals("Its me, Mario!\nAnd again, me: Mario.", $binder("Mario"));
70 }
71
73 {
74 $m = $this->mock
75 ->withAdditionalOnLoadCode(function ($id) {
76 return "And again, me: $id.";
77 });
78
79 $binder = $m->getOnLoadCode();
80 $this->assertInstanceOf(\Closure::class, $binder);
81 $this->assertEquals("And again, me: Mario.", $binder("Mario"));
82 }
83}
An exception for terminatinating execution or to throw for unit testing.
trait JavaScriptBindable
Trait for components implementing JavaScriptBindable providing standard implementation.