ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
SplitStringTest.php
Go to the documentation of this file.
1 <?php
2 
3 /* Copyright (c) 2017 Stefan Hecken <stefan.hecken@concepts-and-training.de> Extended GPL, see docs/LICENSE */
4 
6 
13 {
14  const STRING_TO_SPLIT = "I am#a test string#for split";
15  protected static $result = array("I am", "a test string", "for split");
16 
17  protected function setUp()
18  {
19  $this->f = new Transformation\Factory();
20  $this->split_string = $this->f->splitString("#");
21  }
22 
23  protected function tearDown()
24  {
25  $this->f = null;
26  $this->split_string = null;
27  }
28 
29  public function testTransform()
30  {
31  $arr = $this->split_string->transform(self::STRING_TO_SPLIT);
32  $this->assertEquals(static::$result, $arr);
33  }
34 
35  public function testTransformFails()
36  {
37  $raised = false;
38  try {
39  $arr = [];
40  $next_arr = $this->split_string->transform($arr);
41  } catch (InvalidArgumentException $e) {
42  $raised = true;
43  }
44  $this->assertTrue($raised);
45 
46  $raised = false;
47  try {
48  $without = 1001;
49  $with = $this->split_string->transform($without);
50  } catch (InvalidArgumentException $e) {
51  $raised = true;
52  }
53  $this->assertTrue($raised);
54 
55  $raised = false;
56  try {
57  $std_class = new stdClass();
58  $with = $this->split_string->transform($std_class);
59  } catch (InvalidArgumentException $e) {
60  $raised = true;
61  }
62  $this->assertTrue($raised);
63  }
64 
65  public function testInvoke()
66  {
67  $split_string = $this->f->splitString("#");
68  $arr = $split_string(self::STRING_TO_SPLIT);
69  $this->assertEquals(static::$result, $arr);
70  }
71 
72  public function testInvokeFails()
73  {
74  $split_string = $this->f->splitString("#");
75 
76  $raised = false;
77  try {
78  $arr = [];
79  $next_arr = $split_string($arr);
80  } catch (InvalidArgumentException $e) {
81  $raised = true;
82  }
83  $this->assertTrue($raised);
84 
85  $raised = false;
86  try {
87  $number = 1001;
88  $with = $split_string($number);
89  } catch (InvalidArgumentException $e) {
90  $raised = true;
91  }
92  $this->assertTrue($raised);
93 
94  $raised = false;
95  try {
96  $std_class = new stdClass();
97  $with = $split_string($std_class);
98  } catch (InvalidArgumentException $e) {
99  $raised = true;
100  }
101  $this->assertTrue($raised);
102  }
103 }
$result
Create styles array
The data for the language used.
TestCase for SplitString transformations.