5 require_once(
"libs/composer/vendor/autoload.php");
7 require_once(__DIR__ .
"/../Renderer/TestComponent.php");
57 $this->called_gcnbfqn++;
84 $c = new \ILIAS\UI\Component\Test\TestComponent(
"foo");
85 $this->assertEquals(
"Test Component Test",
$c->getCanonicalName());
90 $name1 = $this->mock->getCanonicalName();
91 $name2 = $this->mock->getCanonicalName();
92 $this->assertEquals($name1, $name2);
93 $this->assertEquals(1, $this->mock->called_gcnbfqn);
99 $this->mock->_checkArg(
"some_arg",
true,
"some message");
101 $this->assertFalse(
"This should not happen.");
108 $this->mock->_checkArg(
"some_arg",
false,
"some message");
109 $this->assertFalse(
"This should not happen.");
111 $this->assertEquals(
"Argument 'some_arg': some message", $e->getMessage());
118 $this->mock->_checkIntArg(
"some_arg", 1);
120 $this->assertFalse(
"This should not happen.");
127 $this->mock->_checkIntArg(
"some_arg",
"foo");
128 $this->assertFalse(
"This should not happen.");
130 $this->assertEquals(
"Argument 'some_arg': expected integer, got string 'foo'", $e->getMessage());
137 $this->mock->_checkStringArg(
"some_arg",
"bar");
139 $this->assertFalse(
"This should not happen.");
146 $this->mock->_checkStringArg(
"some_arg", 1);
147 $this->assertFalse(
"This should not happen.");
149 $this->assertEquals(
"Argument 'some_arg': expected string, got integer '1'", $e->getMessage());
156 $this->mock->_checkBoolArg(
"some_arg",
true);
158 $this->assertFalse(
"This should not happen.");
165 $this->mock->_checkBoolArg(
"some_arg", 1);
166 $this->assertFalse(
"This should not happen.");
168 $this->assertEquals(
"Argument 'some_arg': expected bool, got integer '1'", $e->getMessage());
175 $this->mock->_checkArgInstanceOf(
"some_arg", $this->mock, ComponentMock::class);
177 $this->assertFalse(
"This should not happen.");
184 $this->mock->_checkArgInstanceOf(
"some_arg", $this, ComponentMock::class);
185 $this->assertFalse(
"This should not happen.");
187 $this->assertEquals(
"Argument 'some_arg': expected ComponentMock, got ComponentHelperTest", $e->getMessage());
196 $this->mock->_checkArgIsElement(
"some_arg",
"bar", array(
"foo",
"bar"),
"foobar");
198 $this->assertFalse(
"This should not happen.");
205 $this->mock->_checkArgIsElement(
"some_arg",
"baz", array(
"foo",
"bar"),
"foobar");
206 $this->assertFalse(
"This should not happen.");
208 $this->assertEquals(
"Argument 'some_arg': expected foobar, got 'baz'", $e->getMessage());
214 $foo = array(
"foo",
"bar");
215 $res = $this->mock->_toArray($foo);
217 $this->assertEquals($foo,
$res);
223 $res = $this->mock->_toArray($foo);
224 $this->assertEquals(array($foo),
$res);
231 $this->mock->_checkArgListElements(
"some_arg",
$l, array(
"Class1"));
233 $this->assertFalse(
"This should not happen.");
241 $this->mock->_checkArgListElements(
"some_arg",
$l, array(
"Class1"));
242 $this->assertFalse(
"This should not happen.");
244 $this->assertEquals(
"Argument 'some_arg': expected Class1, got Class2", $e->getMessage());
252 $this->mock->_checkArgListElements(
"some_arg",
$l, array(
"Class1",
"Class2"));
254 $this->assertFalse(
"This should not happen.");
262 $this->mock->_checkArgListElements(
"some_arg",
$l, array(
"Class1",
"Class2"));
263 $this->assertFalse(
"This should not happen.");
265 $this->assertEquals(
"Argument 'some_arg': expected Class1, Class2, got Class3", $e->getMessage());
271 $l = array(1,
"foo");
273 $this->mock->_checkArgListElements(
"some_arg",
$l, array(
"string",
"int"));
275 $this->assertFalse(
"This should not happen.");
283 $this->mock->_checkArgListElements(
"some_arg",
$l, array(
"string",
"int"));
284 $this->assertFalse(
"This should not happen.");
286 $this->assertEquals(
"Argument 'some_arg': expected string, int, got Class1", $e->getMessage());
292 $l = array(
"a" => 1,
"b" => 2,
"c" => 3);
294 $this->mock->_checkArgList(
"some_arg",
$l,
function ($k, $v) {
295 return is_string($k) && is_int($v);
296 },
function ($k, $v) {
297 return "expected keys of type string and integer values, got ($k => $v)";
300 $this->assertFalse(
"This should not happen.");
306 $l = array(
"a" => 1,
"b" => 2, 4 => 3);
308 $this->mock->_checkArgList(
"some_arg",
$l,
function ($k, $v) {
309 return is_string($k) && is_int($v);
310 },
function ($k, $v) {
311 return "expected keys of type string and integer values, got ($k => $v)";
313 $this->assertFalse(
"This should not happen.");
315 $m =
"expected keys of type string and integer values, got (4 => 3)";
316 $this->assertEquals(
"Argument 'some_arg': $m", $e->getMessage());
322 $l = array(
"a" => 1,
"b" => 2,
"c" =>
"d");
324 $this->mock->_checkArgList(
"some_arg",
$l,
function ($k, $v) {
325 return is_string($k) && is_int($v);
326 },
function ($k, $v) {
327 return "expected keys of type string and integer values, got ($k => $v)";
330 $this->assertFalse(
"This should not happen.");
332 $m =
"expected keys of type string and integer values, got (c => d)";
333 $this->assertEquals(
"Argument 'some_arg': $m", $e->getMessage());
340 $this->mock->_checkFloatArg(
"some_arg", 1.73);
342 $this->assertFalse(
"This should not happen.");
349 $this->mock->_checkFloatArg(
"some_arg",
"foo");
350 $this->assertFalse(
"This should not happen.");
352 $this->assertEquals(
"Argument 'some_arg': expected float, got string 'foo'", $e->getMessage());
_checkBoolArg($which, $value)
_checkArgList($which, &$value, $check, $message)
test_check_int_arg_not_ok()
checkArgIsElement($which, $value, $array, $name)
Throw an InvalidArgumentException if $value is not an element of array.
checkArg($which, $check, $message)
/** Throw an InvalidArgumentException containing the message if $check is false.
_checkArgListElements($which, &$value, $classes)
test_check_arg_list_elements_multi_class_not_ok()
checkArgInstanceOf($which, $value, $class)
Throw an InvalidArgumentException if $value is not an instance of $class.
trait ComponentHelper
Provides common functionality for component implementations.
checkStringArg($which, $value)
Throw an InvalidArgumentException if $value is no string.
test_check_string_arg_is_element_not_ok()
test_check_float_arg_ok()
test_cachesCanonicalName()
test_check_arg_list_elements_no_ok()
checkArgList($which, array &$values, \Closure $check, \Closure $message)
Check every key and value of the list with a supplied closure.
test_check_bool_arg_not_ok()
test_check_arg_list_elements_ok()
test_check_arg_instanceof_ok()
checkArgListElements($which, array &$values, &$classes)
Check every element of the list if it is an instance of one of the given classes. ...
test_check_arg_list_elements_string_or_int_not_ok()
checkBoolArg($which, $value)
Throw an InvalidArgumentException if $value is not a bool.
catch(Exception $e) $message
_checkArg($which, $check, $message)
foreach($_POST as $key=> $value) $res
test_check_arg_list_not_ok_1()
test_check_string_arg_not_ok()
test_to_array_with_array()
test_check_arg_list_elements_string_or_int_ok()
test_check_arg_list_elements_multi_class_ok()
getCanonicalNameByFullyQualifiedName()
_checkArgIsElement($which, $value, $array, $name)
test_check_arg_instanceof_not_ok()
checkFloatArg($which, $value)
Throw an InvalidArgumentException if $value is not a float.
_checkStringArg($which, $value)
_checkArgInstanceOf($which, $value, $class)
test_check_string_arg_ok()
toArray($value)
Wrap the given value in an array if it is no array.
_checkIntArg($which, $value)
_checkFloatArg($which, $value)
checkIntArg($which, $value)
Throw an InvalidArgumentException if $value is no int.
test_check_arg_is_element_ok()
test_check_arg_list_not_ok_2()
test_check_float_arg_not_ok()