Merge pull request #14077 from pradpnayak/AutoComplete
[civicrm-core.git] / tests / phpunit / Civi / API / RequestTest.php
CommitLineData
70be69e2
TO
1<?php
2namespace Civi\API;
3
70be69e2
TO
4/**
5 */
d3159a21 6class RequestTest extends \CiviUnitTestCase {
70be69e2 7
4cbe18b8
EM
8 /**
9 * @return array
10 */
00be9182 11 public function validEntityActionPairs() {
d3159a21
TO
12 $cases = array();
13 $cases[] = array(
14 array('MyEntity', 'MyAction', 3),
6730d7a1 15 array('MyEntity', 'myaction', 3),
d3159a21
TO
16 );
17 $cases[] = array(
18 array('my+entity', 'MyAction', 3),
6730d7a1
CW
19 array('MyEntity', 'myaction', 3),
20 );
21 $cases[] = array(
22 array('my entity with under_scores', 'My_Action', 3),
23 array('MyEntityWithUnderScores', 'my_action', 3),
24 );
25 $cases[] = array(
26 array('u_f_match', 'get Something', 3),
27 array('UFMatch', 'get_something', 3),
d3159a21 28 );
d3159a21
TO
29 return $cases;
30 }
31
32 /**
33 * @dataProvider validEntityActionPairs
1e1fdcf6
EM
34 * @param $input
35 * @param $expected
36 * @throws \API_Exception
d3159a21 37 */
00be9182 38 public function testCreateRequest_EntityActionMunging($input, $expected) {
d3159a21
TO
39 list ($inEntity, $inAction, $inVersion) = $input;
40 $apiRequest = Request::create($inEntity, $inAction, array('version' => $inVersion), NULL);
41 $this->assertEquals($expected, array($apiRequest['entity'], $apiRequest['action'], $apiRequest['version']));
42 }
43
4cbe18b8
EM
44 /**
45 * @return array
46 */
00be9182 47 public function invalidEntityActionPairs() {
d3159a21 48 $cases = array();
34e21ce8 49 $cases[] = array('Not!Valid', 'create', 4);
d3159a21
TO
50 $cases[] = array('My+Entity', 'MyAction', 4);
51 $cases[] = array('My Entity', 'MyAction', 4);
52 $cases[] = array('2MyEntity', 'MyAction', 4);
53 $cases[] = array('MyEntity', 'My+Action', 4);
54 $cases[] = array('MyEntity', 'My Action', 4);
55 $cases[] = array('MyEntity', '2Action', 4);
56 return $cases;
57 }
58
59 /**
60 * @dataProvider invalidEntityActionPairs
34e21ce8 61 * @expectedException \Civi\API\Exception\NotImplementedException
1e1fdcf6
EM
62 * @param $inEntity
63 * @param $inAction
64 * @param $inVersion
34e21ce8 65 * @throws \Civi\API\Exception\NotImplementedException
d3159a21 66 */
00be9182 67 public function testCreateRequest_InvalidEntityAction($inEntity, $inAction, $inVersion) {
d3159a21
TO
68 Request::create($inEntity, $inAction, array('version' => $inVersion), NULL);
69 }
70
4cbe18b8 71}