5 require_once(
"libs/composer/vendor/autoload.php");
7 require_once(__DIR__ .
"/../Renderer/TestComponent.php");
53 $this->called_gcnbfqn++;
80 $c = new \ILIAS\UI\Component\Test\TestComponent(
"foo");
81 $this->assertEquals(
"Test Component Test", $c->getCanonicalName());
86 $name1 = $this->mock->getCanonicalName();
87 $name2 = $this->mock->getCanonicalName();
88 $this->assertEquals($name1, $name2);
89 $this->assertEquals(1, $this->mock->called_gcnbfqn);
95 $this->mock->_checkArg(
"some_arg",
true,
"some message");
97 $this->assertFalse(
"This should not happen.");
104 $this->mock->_checkArg(
"some_arg",
false,
"some message");
105 $this->assertFalse(
"This should not happen.");
107 $this->assertEquals(
"Argument 'some_arg': some message", $e->getMessage());
114 $this->mock->_checkIntArg(
"some_arg", 1);
116 $this->assertFalse(
"This should not happen.");
123 $this->mock->_checkIntArg(
"some_arg",
"foo");
124 $this->assertFalse(
"This should not happen.");
126 $this->assertEquals(
"Argument 'some_arg': expected integer, got string 'foo'", $e->getMessage());
133 $this->mock->_checkStringArg(
"some_arg",
"bar");
135 $this->assertFalse(
"This should not happen.");
142 $this->mock->_checkStringArg(
"some_arg", 1);
143 $this->assertFalse(
"This should not happen.");
145 $this->assertEquals(
"Argument 'some_arg': expected string, got integer '1'", $e->getMessage());
152 $this->mock->_checkArgInstanceOf(
"some_arg", $this->mock, ComponentMock::class);
154 $this->assertFalse(
"This should not happen.");
161 $this->mock->_checkArgInstanceOf(
"some_arg", $this, ComponentMock::class);
162 $this->assertFalse(
"This should not happen.");
164 $this->assertEquals(
"Argument 'some_arg': expected ComponentMock, got ComponentHelperTest", $e->getMessage());
173 $this->mock->_checkArgIsElement(
"some_arg",
"bar",
array(
"foo",
"bar"),
"foobar");
175 $this->assertFalse(
"This should not happen.");
182 $this->mock->_checkArgIsElement(
"some_arg",
"baz",
array(
"foo",
"bar"),
"foobar");
183 $this->assertFalse(
"This should not happen.");
185 $this->assertEquals(
"Argument 'some_arg': expected foobar, got 'baz'", $e->getMessage());
191 $foo =
array(
"foo",
"bar");
192 $res = $this->mock->_toArray($foo);
194 $this->assertEquals($foo,
$res);
200 $res = $this->mock->_toArray($foo);
208 $this->mock->_checkArgListElements(
"some_arg",
$l,
array(
"Class1"));
210 $this->assertFalse(
"This should not happen.");
218 $this->mock->_checkArgListElements(
"some_arg",
$l,
array(
"Class1"));
219 $this->assertFalse(
"This should not happen.");
221 $this->assertEquals(
"Argument 'some_arg': expected Class1, got Class2", $e->getMessage());
229 $this->mock->_checkArgListElements(
"some_arg",
$l,
array(
"Class1",
"Class2"));
231 $this->assertFalse(
"This should not happen.");
239 $this->mock->_checkArgListElements(
"some_arg",
$l,
array(
"Class1",
"Class2"));
240 $this->assertFalse(
"This should not happen.");
242 $this->assertEquals(
"Argument 'some_arg': expected Class1, Class2, got Class3", $e->getMessage());
250 $this->mock->_checkArgListElements(
"some_arg",
$l,
array(
"string",
"int"));
252 $this->assertFalse(
"This should not happen.");
260 $this->mock->_checkArgListElements(
"some_arg",
$l,
array(
"string",
"int"));
261 $this->assertFalse(
"This should not happen.");
263 $this->assertEquals(
"Argument 'some_arg': expected string, int, got Class1", $e->getMessage());
269 $l =
array(
"a" => 1,
"b" => 2,
"c" => 3);
271 $this->mock->_checkArgList(
"some_arg",
$l,
function ($k, $v) {
272 return is_string($k) && is_int($v);
273 },
function ($k, $v) {
274 return "expected keys of type string and integer values, got ($k => $v)";
277 $this->assertFalse(
"This should not happen.");
283 $l =
array(
"a" => 1,
"b" => 2, 4 => 3);
285 $this->mock->_checkArgList(
"some_arg",
$l,
function ($k, $v) {
286 return is_string($k) && is_int($v);
287 },
function ($k, $v) {
288 return "expected keys of type string and integer values, got ($k => $v)";
290 $this->assertFalse(
"This should not happen.");
292 $m =
"expected keys of type string and integer values, got (4 => 3)";
293 $this->assertEquals(
"Argument 'some_arg': $m", $e->getMessage());
299 $l =
array(
"a" => 1,
"b" => 2,
"c" =>
"d");
301 $this->mock->_checkArgList(
"some_arg",
$l,
function ($k, $v) {
302 return is_string($k) && is_int($v);
303 },
function ($k, $v) {
304 return "expected keys of type string and integer values, got ($k => $v)";
307 $this->assertFalse(
"This should not happen.");
309 $m =
"expected keys of type string and integer values, got (c => d)";
310 $this->assertEquals(
"Argument 'some_arg': $m", $e->getMessage());
317 $this->mock->_checkFloatArg(
"some_arg", 1.73);
319 $this->assertFalse(
"This should not happen.");
326 $this->mock->_checkFloatArg(
"some_arg",
"foo");
327 $this->assertFalse(
"This should not happen.");
329 $this->assertEquals(
"Argument 'some_arg': expected float, got string 'foo'", $e->getMessage());
_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_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()
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.
Create styles array
The data for the language used.
_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()