ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
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 
5 require_once("libs/composer/vendor/autoload.php");
6 
9 }
10 
15  public function setUp() {
16  $this->mock = new JSComponentMock();
17  }
18 
19  public function test_withOnLoadCode() {
20  $m = $this->mock->withOnLoadCode(function($id) {
21  return "Its me, $id!";
22  });
23 
24  $binder = $m->getOnLoadCode();
25  $this->assertInstanceOf(\Closure::class, $binder);
26  $this->assertEquals("Its me, Mario!", $binder("Mario"));
27  }
28 
30  try {
31  $this->mock->withOnLoadCode(function() {});
32  $this->assertFalse("This should not happen...");
33  }
34  catch (\InvalidArgumentException $exception) {
35  $this->assertTrue(true);
36  }
37  }
38 
40  try {
41  $this->mock->withOnLoadCode(function($id, $some_arg) {});
42  $this->assertFalse("This should not happen...");
43  }
44  catch (\InvalidArgumentException $exception) {
45  $this->assertTrue(true);
46  }
47  }
48 }
trait JavaScriptBindable
Trait for components implementing JavaScriptBindable providing standard implementation.