ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
ComponentHelperTest Class Reference
+ Inheritance diagram for ComponentHelperTest:
+ Collaboration diagram for ComponentHelperTest:

Public Member Functions

 setUp ()
 
 test_getCanonicalName ()
 
 test_cachesCanonicalName ()
 
 test_check_arg_ok ()
 
 test_check_arg_not_ok ()
 
 test_check_int_arg_ok ()
 
 test_check_int_arg_not_ok ()
 
 test_check_string_arg_ok ()
 
 test_check_string_arg_not_ok ()
 
 test_check_arg_instanceof_ok ()
 
 test_check_arg_instanceof_not_ok ()
 
 test_check_arg_is_element_ok ()
 
 test_check_string_arg_is_element_not_ok ()
 
 test_to_array_with_array ()
 
 test_to_array_with_int ()
 
 test_check_arg_list_elements_ok ()
 
 test_check_arg_list_elements_no_ok ()
 
 test_check_arg_list_elements_multi_class_ok ()
 
 test_check_arg_list_elements_multi_class_not_ok ()
 
 test_check_arg_list_elements_string_or_int_ok ()
 
 test_check_arg_list_elements_string_or_int_not_ok ()
 
 test_check_arg_list_ok ()
 
 test_check_arg_list_not_ok_1 ()
 
 test_check_arg_list_not_ok_2 ()
 
 test_check_float_arg_ok ()
 
 test_check_float_arg_not_ok ()
 

Detailed Description

Member Function Documentation

◆ setUp()

ComponentHelperTest::setUp ( )

Definition at line 73 of file ComponentHelperTest.php.

74  {
75  $this->mock = new ComponentMock();
76  }

◆ test_cachesCanonicalName()

ComponentHelperTest::test_cachesCanonicalName ( )

Definition at line 84 of file ComponentHelperTest.php.

85  {
86  $name1 = $this->mock->getCanonicalName();
87  $name2 = $this->mock->getCanonicalName();
88  $this->assertEquals($name1, $name2);
89  $this->assertEquals(1, $this->mock->called_gcnbfqn);
90  }

◆ test_check_arg_instanceof_not_ok()

ComponentHelperTest::test_check_arg_instanceof_not_ok ( )

Definition at line 158 of file ComponentHelperTest.php.

159  {
160  try {
161  $this->mock->_checkArgInstanceOf("some_arg", $this, ComponentMock::class);
162  $this->assertFalse("This should not happen.");
163  } catch (\InvalidArgumentException $e) {
164  $this->assertEquals("Argument 'some_arg': expected ComponentMock, got ComponentHelperTest", $e->getMessage());
165  }
166  }

◆ test_check_arg_instanceof_ok()

ComponentHelperTest::test_check_arg_instanceof_ok ( )

Definition at line 149 of file ComponentHelperTest.php.

150  {
151  try {
152  $this->mock->_checkArgInstanceOf("some_arg", $this->mock, ComponentMock::class);
153  } catch (\InvalidArgumentException $e) {
154  $this->assertFalse("This should not happen.");
155  }
156  }

◆ test_check_arg_is_element_ok()

ComponentHelperTest::test_check_arg_is_element_ok ( )

Definition at line 170 of file ComponentHelperTest.php.

References array.

171  {
172  try {
173  $this->mock->_checkArgIsElement("some_arg", "bar", array("foo", "bar"), "foobar");
174  } catch (\InvalidArgumentException $e) {
175  $this->assertFalse("This should not happen.");
176  }
177  }
Create styles array
The data for the language used.

◆ test_check_arg_list_elements_multi_class_not_ok()

ComponentHelperTest::test_check_arg_list_elements_multi_class_not_ok ( )

Definition at line 235 of file ComponentHelperTest.php.

References $l, and array.

236  {
237  $l = array(new Class1(), new Class2(), new Class3(), new Class2());
238  try {
239  $this->mock->_checkArgListElements("some_arg", $l, array("Class1", "Class2"));
240  $this->assertFalse("This should not happen.");
241  } catch (\InvalidArgumentException $e) {
242  $this->assertEquals("Argument 'some_arg': expected Class1, Class2, got Class3", $e->getMessage());
243  }
244  }
Create styles array
The data for the language used.
global $l
Definition: afr.php:30

◆ test_check_arg_list_elements_multi_class_ok()

ComponentHelperTest::test_check_arg_list_elements_multi_class_ok ( )

Definition at line 225 of file ComponentHelperTest.php.

References $l, and array.

226  {
227  $l = array(new Class1(), new Class2(), new Class1());
228  try {
229  $this->mock->_checkArgListElements("some_arg", $l, array("Class1", "Class2"));
230  } catch (\InvalidArgumentException $e) {
231  $this->assertFalse("This should not happen.");
232  }
233  }
Create styles array
The data for the language used.
global $l
Definition: afr.php:30

◆ test_check_arg_list_elements_no_ok()

ComponentHelperTest::test_check_arg_list_elements_no_ok ( )

Definition at line 214 of file ComponentHelperTest.php.

References $l, and array.

215  {
216  $l = array(new Class1(), new Class1(), new Class2());
217  try {
218  $this->mock->_checkArgListElements("some_arg", $l, array("Class1"));
219  $this->assertFalse("This should not happen.");
220  } catch (\InvalidArgumentException $e) {
221  $this->assertEquals("Argument 'some_arg': expected Class1, got Class2", $e->getMessage());
222  }
223  }
Create styles array
The data for the language used.
global $l
Definition: afr.php:30

◆ test_check_arg_list_elements_ok()

ComponentHelperTest::test_check_arg_list_elements_ok ( )

Definition at line 204 of file ComponentHelperTest.php.

References $l, and array.

205  {
206  $l = array(new Class1(), new Class1(), new Class1());
207  try {
208  $this->mock->_checkArgListElements("some_arg", $l, array("Class1"));
209  } catch (\InvalidArgumentException $e) {
210  $this->assertFalse("This should not happen.");
211  }
212  }
Create styles array
The data for the language used.
global $l
Definition: afr.php:30

◆ test_check_arg_list_elements_string_or_int_not_ok()

ComponentHelperTest::test_check_arg_list_elements_string_or_int_not_ok ( )

Definition at line 256 of file ComponentHelperTest.php.

References $l, and array.

257  {
258  $l = array(1, new Class1());
259  try {
260  $this->mock->_checkArgListElements("some_arg", $l, array("string", "int"));
261  $this->assertFalse("This should not happen.");
262  } catch (\InvalidArgumentException $e) {
263  $this->assertEquals("Argument 'some_arg': expected string, int, got Class1", $e->getMessage());
264  }
265  }
Create styles array
The data for the language used.
global $l
Definition: afr.php:30

◆ test_check_arg_list_elements_string_or_int_ok()

ComponentHelperTest::test_check_arg_list_elements_string_or_int_ok ( )

Definition at line 246 of file ComponentHelperTest.php.

References $l, and array.

247  {
248  $l = array(1, "foo");
249  try {
250  $this->mock->_checkArgListElements("some_arg", $l, array("string", "int"));
251  } catch (\InvalidArgumentException $e) {
252  $this->assertFalse("This should not happen.");
253  }
254  }
Create styles array
The data for the language used.
global $l
Definition: afr.php:30

◆ test_check_arg_list_not_ok_1()

ComponentHelperTest::test_check_arg_list_not_ok_1 ( )

Definition at line 281 of file ComponentHelperTest.php.

References $l, $m, and array.

282  {
283  $l = array("a" => 1, "b" => 2, 4 => 3);
284  try {
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)";
289  });
290  $this->assertFalse("This should not happen.");
291  } catch (\InvalidArgumentException $e) {
292  $m = "expected keys of type string and integer values, got (4 => 3)";
293  $this->assertEquals("Argument 'some_arg': $m", $e->getMessage());
294  }
295  }
Create styles array
The data for the language used.
global $l
Definition: afr.php:30

◆ test_check_arg_list_not_ok_2()

ComponentHelperTest::test_check_arg_list_not_ok_2 ( )

Definition at line 297 of file ComponentHelperTest.php.

References $l, $m, and array.

298  {
299  $l = array("a" => 1, "b" => 2, "c" => "d");
300  try {
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)";
305  });
306 
307  $this->assertFalse("This should not happen.");
308  } catch (\InvalidArgumentException $e) {
309  $m = "expected keys of type string and integer values, got (c => d)";
310  $this->assertEquals("Argument 'some_arg': $m", $e->getMessage());
311  }
312  }
Create styles array
The data for the language used.
global $l
Definition: afr.php:30

◆ test_check_arg_list_ok()

ComponentHelperTest::test_check_arg_list_ok ( )

Definition at line 267 of file ComponentHelperTest.php.

References $l, and array.

268  {
269  $l = array("a" => 1, "b" => 2, "c" => 3);
270  try {
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)";
275  });
276  } catch (\InvalidArgumentException $e) {
277  $this->assertFalse("This should not happen.");
278  }
279  }
Create styles array
The data for the language used.
global $l
Definition: afr.php:30

◆ test_check_arg_not_ok()

ComponentHelperTest::test_check_arg_not_ok ( )

Definition at line 101 of file ComponentHelperTest.php.

102  {
103  try {
104  $this->mock->_checkArg("some_arg", false, "some message");
105  $this->assertFalse("This should not happen.");
106  } catch (\InvalidArgumentException $e) {
107  $this->assertEquals("Argument 'some_arg': some message", $e->getMessage());
108  }
109  }

◆ test_check_arg_ok()

ComponentHelperTest::test_check_arg_ok ( )

Definition at line 92 of file ComponentHelperTest.php.

93  {
94  try {
95  $this->mock->_checkArg("some_arg", true, "some message");
96  } catch (\InvalidArgumentException $e) {
97  $this->assertFalse("This should not happen.");
98  }
99  }

◆ test_check_float_arg_not_ok()

ComponentHelperTest::test_check_float_arg_not_ok ( )

Definition at line 323 of file ComponentHelperTest.php.

324  {
325  try {
326  $this->mock->_checkFloatArg("some_arg", "foo");
327  $this->assertFalse("This should not happen.");
328  } catch (\InvalidArgumentException $e) {
329  $this->assertEquals("Argument 'some_arg': expected float, got string 'foo'", $e->getMessage());
330  }
331  }

◆ test_check_float_arg_ok()

ComponentHelperTest::test_check_float_arg_ok ( )

Definition at line 314 of file ComponentHelperTest.php.

315  {
316  try {
317  $this->mock->_checkFloatArg("some_arg", 1.73);
318  } catch (\InvalidArgumentException $e) {
319  $this->assertFalse("This should not happen.");
320  }
321  }

◆ test_check_int_arg_not_ok()

ComponentHelperTest::test_check_int_arg_not_ok ( )

Definition at line 120 of file ComponentHelperTest.php.

121  {
122  try {
123  $this->mock->_checkIntArg("some_arg", "foo");
124  $this->assertFalse("This should not happen.");
125  } catch (\InvalidArgumentException $e) {
126  $this->assertEquals("Argument 'some_arg': expected integer, got string 'foo'", $e->getMessage());
127  }
128  }

◆ test_check_int_arg_ok()

ComponentHelperTest::test_check_int_arg_ok ( )

Definition at line 111 of file ComponentHelperTest.php.

112  {
113  try {
114  $this->mock->_checkIntArg("some_arg", 1);
115  } catch (\InvalidArgumentException $e) {
116  $this->assertFalse("This should not happen.");
117  }
118  }

◆ test_check_string_arg_is_element_not_ok()

ComponentHelperTest::test_check_string_arg_is_element_not_ok ( )

Definition at line 179 of file ComponentHelperTest.php.

References array.

180  {
181  try {
182  $this->mock->_checkArgIsElement("some_arg", "baz", array("foo", "bar"), "foobar");
183  $this->assertFalse("This should not happen.");
184  } catch (\InvalidArgumentException $e) {
185  $this->assertEquals("Argument 'some_arg': expected foobar, got 'baz'", $e->getMessage());
186  }
187  }
Create styles array
The data for the language used.

◆ test_check_string_arg_not_ok()

ComponentHelperTest::test_check_string_arg_not_ok ( )

Definition at line 139 of file ComponentHelperTest.php.

140  {
141  try {
142  $this->mock->_checkStringArg("some_arg", 1);
143  $this->assertFalse("This should not happen.");
144  } catch (\InvalidArgumentException $e) {
145  $this->assertEquals("Argument 'some_arg': expected string, got integer '1'", $e->getMessage());
146  }
147  }

◆ test_check_string_arg_ok()

ComponentHelperTest::test_check_string_arg_ok ( )

Definition at line 130 of file ComponentHelperTest.php.

131  {
132  try {
133  $this->mock->_checkStringArg("some_arg", "bar");
134  } catch (\InvalidArgumentException $e) {
135  $this->assertFalse("This should not happen.");
136  }
137  }

◆ test_getCanonicalName()

ComponentHelperTest::test_getCanonicalName ( )

Definition at line 78 of file ComponentHelperTest.php.

79  {
80  $c = new \ILIAS\UI\Component\Test\TestComponent("foo");
81  $this->assertEquals("Test Component Test", $c->getCanonicalName());
82  }

◆ test_to_array_with_array()

ComponentHelperTest::test_to_array_with_array ( )

Definition at line 189 of file ComponentHelperTest.php.

References $res, and array.

190  {
191  $foo = array("foo", "bar");
192  $res = $this->mock->_toArray($foo);
193 
194  $this->assertEquals($foo, $res);
195  }
foreach($_POST as $key=> $value) $res
Create styles array
The data for the language used.

◆ test_to_array_with_int()

ComponentHelperTest::test_to_array_with_int ( )

Definition at line 197 of file ComponentHelperTest.php.

References $res, and array.

198  {
199  $foo = 1;
200  $res = $this->mock->_toArray($foo);
201  $this->assertEquals(array($foo), $res);
202  }
foreach($_POST as $key=> $value) $res
Create styles array
The data for the language used.

The documentation for this class was generated from the following file: