Merge pull request #16469 from civicrm/5.22
[civicrm-core.git] / tests / phpunit / api / v3 / NavigationTest.php
1 <?php
2 /*
3 +--------------------------------------------------------------------+
4 | Copyright CiviCRM LLC. All rights reserved. |
5 | |
6 | This work is published under the GNU AGPLv3 license with some |
7 | permitted exceptions and without any warranty. For full license |
8 | and copyright information, see https://civicrm.org/licensing |
9 +--------------------------------------------------------------------+
10 */
11
12 /**
13 * Class api_v3_NavigationTest
14 * @group headless
15 */
16 class api_v3_NavigationTest extends CiviUnitTestCase {
17 protected $_apiversion = 3;
18 protected $_params;
19
20 protected $_entity = 'Navigation';
21
22 /**
23 * Test get function.
24 * @param int $version
25 * @dataProvider versionThreeAndFour
26 */
27 public function testGet($version) {
28 $this->_apiversion = $version;
29 $this->callAPISuccess($this->_entity, 'getsingle', ['label' => 'Manage Groups', 'domain_id' => 1]);
30 }
31
32 /**
33 * Test get specifying parent
34 * FIXME: Api4
35 */
36 public function testGetByParent() {
37 // get by name
38 $this->callAPISuccess($this->_entity, 'get', ['parentID' => 'Administer', 'domain_id' => 1]);
39
40 $params = [
41 'name' => 'Administer',
42 'domain_id' => 1,
43 'return' => 'id',
44 ];
45 $adminId = $this->callAPISuccess($this->_entity, 'getvalue', $params);
46
47 $this->callAPISuccess($this->_entity, 'get', ['parentID' => $adminId, 'domain_id' => 1]);
48 }
49
50 /**
51 * Test create function.
52 * @param int $version
53 * @dataProvider versionThreeAndFour
54 */
55 public function testCreate($version) {
56 $this->_apiversion = $version;
57 $params = ['label' => 'Feed the Goats', 'domain_id' => 1];
58 $result = $this->callAPISuccess($this->_entity, 'create', $params);
59 $this->getAndCheck($params, $result['id'], $this->_entity, TRUE);
60 }
61
62 /**
63 * Test create function.
64 * @param int $version
65 * @dataProvider versionThreeAndFour
66 */
67 public function testDefaultDomain($version) {
68 $this->_apiversion = $version;
69 $params = ['label' => 'Herd the Cats'];
70 $result = $this->callAPISuccess($this->_entity, 'create', $params);
71 // Check domain_id has been set per default
72 $params['domain_id'] = CRM_Core_Config::domainID();
73 $this->getAndCheck($params, $result['id'], $this->_entity, TRUE);
74 }
75
76 /**
77 * Test delete function.
78 * @param int $version
79 * @dataProvider versionThreeAndFour
80 */
81 public function testDelete($version) {
82 $this->_apiversion = $version;
83 $getParams = [
84 'return' => 'id',
85 'options' => ['limit' => 1],
86 ];
87 $result = $this->callAPISuccess('Navigation', 'getvalue', $getParams);
88 $this->callAPISuccess('Navigation', 'delete', ['id' => $result]);
89 $this->callAPIFailure('Navigation', 'getvalue', ['id' => $result]);
90 }
91
92 }