ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
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
5require_once("libs/composer/vendor/autoload.php");
6
8{
10}
11
16{
17 public function setUp()
18 {
19 $this->mock = new JSComponentMock();
20 }
21
22 public function test_withOnLoadCode()
23 {
24 $m = $this->mock->withOnLoadCode(function ($id) {
25 return "Its me, $id!";
26 });
27
28 $binder = $m->getOnLoadCode();
29 $this->assertInstanceOf(\Closure::class, $binder);
30 $this->assertEquals("Its me, Mario!", $binder("Mario"));
31 }
32
34 {
35 try {
36 $this->mock->withOnLoadCode(function () {
37 });
38 $this->assertFalse("This should not happen...");
39 } catch (\InvalidArgumentException $exception) {
40 $this->assertTrue(true);
41 }
42 }
43
45 {
46 try {
47 $this->mock->withOnLoadCode(function ($id, $some_arg) {
48 });
49 $this->assertFalse("This should not happen...");
50 } catch (\InvalidArgumentException $exception) {
51 $this->assertTrue(true);
52 }
53 }
54
56 {
57 $m = $this->mock
58 ->withOnLoadCode(function ($id) {
59 return "Its me, $id!";
60 })
61 ->withAdditionalOnLoadCode(function ($id) {
62 return "And again, me: $id.";
63 });
64
65 $binder = $m->getOnLoadCode();
66 $this->assertInstanceOf(\Closure::class, $binder);
67 $this->assertEquals("Its me, Mario!\nAnd again, me: Mario.", $binder("Mario"));
68 }
69
71 {
72 $m = $this->mock
73 ->withAdditionalOnLoadCode(function ($id) {
74 return "And again, me: $id.";
75 });
76
77 $binder = $m->getOnLoadCode();
78 $this->assertInstanceOf(\Closure::class, $binder);
79 $this->assertEquals("And again, me: Mario.", $binder("Mario"));
80 }
81}
An exception for terminatinating execution or to throw for unit testing.
if(!array_key_exists('StateId', $_REQUEST)) $id
trait JavaScriptBindable
Trait for components implementing JavaScriptBindable providing standard implementation.