5
5
*/
6
6
class RequestTest extends \CiviUnitTestCase {
7
7
8
- /**
9
- * @return array
10
- */
11
- public function v4options () {
12
- $ cases = array (); // array(0 => $requestParams, 1 => $expectedOptions, 2 => $expectedData, 3 => $expectedChains)
13
- $ cases [] = array (
14
- array ('version ' => 4 ), // requestParams
15
- array (), // expectedOptions
16
- array (), // expectedData
17
- array (), // expectedChains
18
- );
19
- $ cases [] = array (
20
- array ('version ' => 4 , 'debug ' => TRUE ), // requestParams
21
- array ('debug ' => TRUE ), // expectedOptions
22
- array (), // expectedData
23
- array (), // expectedChains
24
- );
25
- $ cases [] = array (
26
- array ('version ' => 4 , 'format.is_success ' => TRUE ), // requestParams
27
- array ('format ' => 'is_success ' ), // expectedOptions
28
- array (), // expectedData
29
- array (), // expectedChains
30
- );
31
- $ cases [] = array (
32
- array (
33
- 'version ' => 4 ,
34
- 'option.limit ' => 15 ,
35
- 'option.foo ' => array ('bar ' ),
36
- 'options ' => array ('whiz ' => 'bang ' ),
37
- 'optionnotreally ' => 'data ' ,
38
- ), // requestParams
39
- array ('limit ' => 15 , 'foo ' => array ('bar ' ), 'whiz ' => 'bang ' ), // expectedOptions
40
- array ('optionnotreally ' => 'data ' ), // expectedData
41
- array (), // expectedChains
42
- );
43
- $ cases [] = array (
44
- array (
45
- 'version ' => 4 ,
46
- 'return ' => array ('field1 ' , 'field2 ' ),
47
- 'return.field3 ' => 1 ,
48
- 'return.field4 ' => 0 ,
49
- 'returnontreally ' => 'data ' ,
50
- ), // requestParams
51
- array ('return ' => array ('field1 ' , 'field2 ' , 'field3 ' )), // expectedOptions
52
- array ('returnontreally ' => 'data ' ), // expectedData
53
- array (), // expectedChains
54
- );
55
- $ cases [] = array (
56
- array ('version ' => 4 , 'foo ' => array ('bar ' ), 'whiz ' => 'bang ' ), // requestParams
57
- array (), // expectedOptions
58
- array ('foo ' => array ('bar ' ), 'whiz ' => 'bang ' ), // expectedData
59
- array (), // expectedChains
60
- );
61
- $ cases [] = array (
62
- array ('version ' => 4 , 'api.foo.bar ' => array ('whiz ' => 'bang ' )), // requestParams
63
- array (), // expectedOptions
64
- array (), // expectedData
65
- array ('api.foo.bar ' => array ('whiz ' => 'bang ' )), // expectedChains
66
- );
67
- $ cases [] = array (
68
- array (
69
- 'version ' => 4 ,
70
- 'option.limit ' => 15 ,
71
- 'options ' => array ('whiz ' => 'bang ' ),
72
- 'somedata ' => 'data ' ,
73
- 'moredata ' => array ('woosh ' ),
74
- 'return.field1 ' => 1 ,
75
- 'return ' => array ('field2 ' ),
76
- 'api.first ' => array ('the first call ' ),
77
- 'api.second ' => array ('the second call ' ),
78
- ), // requestParams
79
- array ('limit ' => 15 , 'whiz ' => 'bang ' , 'return ' => array ('field1 ' , 'field2 ' )), // expectedOptions
80
- array ('somedata ' => 'data ' , 'moredata ' => array ('woosh ' )), // expectedData
81
- array ('api.first ' => array ('the first call ' ), 'api.second ' => array ('the second call ' )), // expectedChains
82
- );
83
- return $ cases ;
84
- }
85
-
86
- /**
87
- * @param array $inputParams
88
- * @param $expectedOptions
89
- * @param $expectedData
90
- * @param $expectedChains
91
- * @dataProvider v4options
92
- */
93
- public function testCreateRequest_v4Options ($ inputParams , $ expectedOptions , $ expectedData , $ expectedChains ) {
94
- $ apiRequest = Request::create ('MyEntity ' , 'MyAction ' , $ inputParams , NULL );
95
- $ this ->assertEquals ($ expectedOptions , $ apiRequest ['options ' ]->getArray ());
96
- $ this ->assertEquals ($ expectedData , $ apiRequest ['data ' ]->getArray ());
97
- $ this ->assertEquals ($ expectedChains , $ apiRequest ['chains ' ]);
98
- }
99
-
100
- /**
101
- * @expectedException \API_Exception
102
- */
103
- public function testCreateRequest_v4BadEntity () {
104
- Request::create ('Not!Valid ' , 'create ' , array ('version ' => 4 ), NULL );
105
- }
106
-
107
- /**
108
- * @expectedException \API_Exception
109
- */
110
- public function testCreateRequest_v4BadAction () {
111
- Request::create ('MyEntity ' , 'bad!action ' , array ('version ' => 4 ), NULL );
112
- }
113
-
114
8
/**
115
9
* @return array
116
10
*/
@@ -132,10 +26,6 @@ public function validEntityActionPairs() {
132
26
array ('u_f_match ' , 'get Something ' , 3 ),
133
27
array ('UFMatch ' , 'get_something ' , 3 ),
134
28
);
135
- $ cases [] = array (
136
- array ('MyEntity ' , 'MyAction ' , 4 ),
137
- array ('MyEntity ' , 'myAction ' , 4 ),
138
- );
139
29
return $ cases ;
140
30
}
141
31
@@ -156,6 +46,7 @@ public function testCreateRequest_EntityActionMunging($input, $expected) {
156
46
*/
157
47
public function invalidEntityActionPairs () {
158
48
$ cases = array ();
49
+ $ cases [] = array ('Not!Valid ' , 'create ' , 4 );
159
50
$ cases [] = array ('My+Entity ' , 'MyAction ' , 4 );
160
51
$ cases [] = array ('My Entity ' , 'MyAction ' , 4 );
161
52
$ cases [] = array ('2MyEntity ' , 'MyAction ' , 4 );
@@ -167,11 +58,11 @@ public function invalidEntityActionPairs() {
167
58
168
59
/**
169
60
* @dataProvider invalidEntityActionPairs
170
- * @expectedException \API_Exception
61
+ * @expectedException \Civi\API\Exception\NotImplementedException
171
62
* @param $inEntity
172
63
* @param $inAction
173
64
* @param $inVersion
174
- * @throws \API_Exception
65
+ * @throws \Civi\API\Exception\NotImplementedException
175
66
*/
176
67
public function testCreateRequest_InvalidEntityAction ($ inEntity , $ inAction , $ inVersion ) {
177
68
Request::create ($ inEntity , $ inAction , array ('version ' => $ inVersion ), NULL );
0 commit comments