Merge pull request #15595 from eileenmcnaughton/dedupe3
[civicrm-core.git] / tests / phpunit / api / v3 / NavigationTest.php
1 <?php
2 /**
3 * +--------------------------------------------------------------------+
4 * | CiviCRM version 5 |
5 * +--------------------------------------------------------------------+
6 * | Copyright CiviCRM LLC (c) 2004-2020 |
7 * +--------------------------------------------------------------------+
8 * | This file is a part of CiviCRM. |
9 * | |
10 * | CiviCRM is free software; you can copy, modify, and distribute it |
11 * | under the terms of the GNU Affero General Public License |
12 * | Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
13 * | |
14 * | CiviCRM is distributed in the hope that it will be useful, but |
15 * | WITHOUT ANY WARRANTY; without even the implied warranty of |
16 * | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
17 * | See the GNU Affero General Public License for more details. |
18 * | |
19 * | You should have received a copy of the GNU Affero General Public |
20 * | License and the CiviCRM Licensing Exception along |
21 * | with this program; if not, contact CiviCRM LLC |
22 * | at info[AT]civicrm[DOT]org. If you have questions about the |
23 * | GNU Affero General Public License or the licensing of CiviCRM, |
24 * | see the CiviCRM license FAQ at http://civicrm.org/licensing |
25 * +--------------------------------------------------------------------+
26 */
27
28 /**
29 * Class api_v3_NavigationTest
30 * @group headless
31 */
32 class api_v3_NavigationTest extends CiviUnitTestCase {
33 protected $_apiversion = 3;
34 protected $_params;
35
36 protected $_entity = 'Navigation';
37
38 /**
39 * Test get function.
40 * @param int $version
41 * @dataProvider versionThreeAndFour
42 */
43 public function testGet($version) {
44 $this->_apiversion = $version;
45 $this->callAPISuccess($this->_entity, 'getsingle', ['label' => 'Manage Groups', 'domain_id' => 1]);
46 }
47
48 /**
49 * Test get specifying parent
50 * FIXME: Api4
51 */
52 public function testGetByParent() {
53 // get by name
54 $this->callAPISuccess($this->_entity, 'get', ['parentID' => 'Administer', 'domain_id' => 1]);
55
56 $params = [
57 'name' => 'Administer',
58 'domain_id' => 1,
59 'return' => 'id',
60 ];
61 $adminId = $this->callAPISuccess($this->_entity, 'getvalue', $params);
62
63 $this->callAPISuccess($this->_entity, 'get', ['parentID' => $adminId, 'domain_id' => 1]);
64 }
65
66 /**
67 * Test create function.
68 * @param int $version
69 * @dataProvider versionThreeAndFour
70 */
71 public function testCreate($version) {
72 $this->_apiversion = $version;
73 $params = ['label' => 'Feed the Goats', 'domain_id' => 1];
74 $result = $this->callAPISuccess($this->_entity, 'create', $params);
75 $this->getAndCheck($params, $result['id'], $this->_entity, TRUE);
76 }
77
78 /**
79 * Test create function.
80 * @param int $version
81 * @dataProvider versionThreeAndFour
82 */
83 public function testDefaultDomain($version) {
84 $this->_apiversion = $version;
85 $params = ['label' => 'Herd the Cats'];
86 $result = $this->callAPISuccess($this->_entity, 'create', $params);
87 // Check domain_id has been set per default
88 $params['domain_id'] = CRM_Core_Config::domainID();
89 $this->getAndCheck($params, $result['id'], $this->_entity, TRUE);
90 }
91
92 /**
93 * Test delete function.
94 * @param int $version
95 * @dataProvider versionThreeAndFour
96 */
97 public function testDelete($version) {
98 $this->_apiversion = $version;
99 $getParams = [
100 'return' => 'id',
101 'options' => ['limit' => 1],
102 ];
103 $result = $this->callAPISuccess('Navigation', 'getvalue', $getParams);
104 $this->callAPISuccess('Navigation', 'delete', ['id' => $result]);
105 $this->callAPIFailure('Navigation', 'getvalue', ['id' => $result]);
106 }
107
108 }