ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
AddLabelTest.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 protected static $labels = array("A", "B", "C");
15 protected static $test_array = array(1, 2, 3);
16 protected static $result_array = array("A" => 1, "B" => 2, "C" => 3);
17
18 protected function setUp()
19 {
20 $this->f = new Transformation\Factory();
21 $this->add_label = $this->f->addLabels(self::$labels);
22 }
23
24 protected function tearDown()
25 {
26 $this->f = null;
27 $this->add_label = null;
28 }
29
30 public function testTransform()
31 {
32 $with = $this->add_label->transform(self::$test_array);
33 $this->assertEquals(self::$result_array, $with);
34 }
35
36 public function testTransformFails()
37 {
38 $raised = false;
39 try {
40 $with = null;
41 $next_with = $this->add_label->transform($with);
42 } catch (InvalidArgumentException $e) {
43 $raised = true;
44 }
45 $this->assertTrue($raised);
46
47 $raised = false;
48 try {
49 $without = array(1, 2, 3, 4);
50 $with = $this->add_label->transform($without);
51 } catch (InvalidArgumentException $e) {
52 $raised = true;
53 }
54 $this->assertTrue($raised);
55
56 $raised = false;
57 try {
58 $without = "1, 2, 3";
59 $with = $this->add_label->transform($without);
60 } catch (InvalidArgumentException $e) {
61 $raised = true;
62 }
63 $this->assertTrue($raised);
64
65 $raised = false;
66 try {
67 $std_class = new stdClass();
68 $with = $this->add_label->transform($std_class);
69 } catch (InvalidArgumentException $e) {
70 $raised = true;
71 }
72 $this->assertTrue($raised);
73 }
74
75 public function testInvoke()
76 {
77 $add_label = $this->f->addLabels(self::$labels);
78 $with = $add_label(self::$test_array);
79 $this->assertEquals(self::$result_array, $with);
80 }
81
82 public function testInvokeFails()
83 {
84 $add_label = $this->f->addLabels(self::$labels);
85
86 $raised = false;
87 try {
88 $with = null;
89 $next_with = $add_label($with);
90 } catch (InvalidArgumentException $e) {
91 $raised = true;
92 }
93 $this->assertTrue($raised);
94
95 $raised = false;
96 try {
97 $without = array(1, 2, 3, 4);
98 $with = $add_label($without);
99 } catch (InvalidArgumentException $e) {
100 $raised = true;
101 }
102 $this->assertTrue($raised);
103
104 $raised = false;
105 try {
106 $without = "1, 2, 3";
107 $with = $add_label($without);
108 } catch (InvalidArgumentException $e) {
109 $raised = true;
110 }
111 $this->assertTrue($raised);
112
113 $raised = false;
114 try {
115 $std_class = new stdClass();
116 $with = $add_label($std_class);
117 } catch (InvalidArgumentException $e) {
118 $raised = true;
119 }
120 $this->assertTrue($raised);
121 }
122}
TestCase for AddLabel transformations.
static $labels
static $test_array
static $result_array
An exception for terminatinating execution or to throw for unit testing.
Factory for basic transformations.
Definition: Factory.php:12