CRM-14370 - API Kernel - Parse options/data/chains for v4
[civicrm-core.git] / tests / phpunit / Civi / API / KernelTest.php
1 <?php
2 namespace Civi\API;
3
4 require_once 'CiviTest/CiviUnitTestCase.php';
5
6 /**
7 */
8 class KernelTest extends \CiviUnitTestCase {
9
10 function v4options() {
11 $cases = array(); // array(0 => $requestParams, 1 => $expectedOptions, 2 => $expectedData, 3 => $expectedChains)
12 $cases[] = array(
13 array('version' => 4), // requestParams
14 array(), // expectedOptions
15 array(), // expectedData
16 array(), // expectedChains
17 );
18 $cases[] = array(
19 array('version' => 4, 'debug' => TRUE), // requestParams
20 array('debug' => TRUE), // expectedOptions
21 array(), // expectedData
22 array(), // expectedChains
23 );
24 $cases[] = array(
25 array('version' => 4, 'format.is_success' => TRUE), // requestParams
26 array('format' => 'is_success'), // expectedOptions
27 array(), // expectedData
28 array(), // expectedChains
29 );
30 $cases[] = array(
31 array('version' => 4, 'option.limit' => 15, 'option.foo' => array('bar'), 'options' => array('whiz' => 'bang'), 'optionnotreally' => 'data'), // requestParams
32 array('limit' => 15, 'foo' => array('bar'), 'whiz' => 'bang'), // expectedOptions
33 array('optionnotreally' => 'data'), // expectedData
34 array(), // expectedChains
35 );
36 $cases[] = array(
37 array('version' => 4, 'return' => array('field1', 'field2'), 'return.field3' => 1, 'return.field4' => 0, 'returnontreally' => 'data'), // requestParams
38 array('return' => array('field1', 'field2', 'field3')), // expectedOptions
39 array('returnontreally' => 'data'), // expectedData
40 array(), // expectedChains
41 );
42 $cases[] = array(
43 array('version' => 4, 'foo' => array('bar'), 'whiz' => 'bang'), // requestParams
44 array(), // expectedOptions
45 array('foo' => array('bar'), 'whiz' => 'bang'), // expectedData
46 array(), // expectedChains
47 );
48 $cases[] = array(
49 array('version' => 4, 'api.foo.bar' => array('whiz' => 'bang')), // requestParams
50 array(), // expectedOptions
51 array(), // expectedData
52 array('api.foo.bar' => array('whiz' => 'bang')), // expectedChains
53 );
54 $cases[] = array(
55 array(
56 'version' => 4,
57 'option.limit' => 15,
58 'options' => array('whiz' => 'bang'),
59 'somedata' => 'data',
60 'moredata' => array('woosh'),
61 'return.field1' => 1,
62 'return' => array('field2'),
63 'api.first' => array('the first call'),
64 'api.second' => array('the second call'),
65 ), // requestParams
66 array('limit' => 15, 'whiz' => 'bang', 'return' => array('field1', 'field2')), // expectedOptions
67 array('somedata' => 'data', 'moredata' => array('woosh')), // expectedData
68 array('api.first' => array('the first call'), 'api.second' => array('the second call')), // expectedChains
69 );
70 return $cases;
71 }
72
73 /**
74 * @param $inputParams
75 * @param $expectedOptions
76 * @param $expectedData
77 * @param $expectedChains
78 * @dataProvider v4options
79 */
80 function testCreateRequest_v4Options($inputParams, $expectedOptions, $expectedData, $expectedChains) {
81 $kernel = new Kernel(NULL);
82 $apiRequest = $kernel->createRequest('MyEntity', 'MyAction', $inputParams, NULL);
83 $this->assertEquals($expectedOptions, $apiRequest['options']->getArray());
84 $this->assertEquals($expectedData, $apiRequest['data']->getArray());
85 $this->assertEquals($expectedChains, $apiRequest['chains']);
86 }
87
88 /**
89 * @expectedException \API_Exception
90 */
91 function testCreateRequest_v4BadEntity() {
92 $kernel = new Kernel(NULL);
93 $kernel->createRequest('Not!Valid', 'create', array('version' => 4), NULL);
94 }
95
96 /**
97 * @expectedException \API_Exception
98 */
99 function testCreateRequest_v4BadAction() {
100 $kernel = new Kernel(NULL);
101 $kernel->createRequest('MyEntity', 'bad!action', array('version' => 4), NULL);
102 }
103 }