3 +--------------------------------------------------------------------+
4 | Copyright CiviCRM LLC. All rights reserved. |
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 +--------------------------------------------------------------------+
13 * Test class for GroupOrganization API - civicrm_group_organization_*
18 class api_v3_GroupOrganizationTest
extends CiviUnitTestCase
{
19 protected $_apiversion;
22 * Sets up the fixture, for example, opens a network connection.
23 * This method is called before a test is executed.
25 protected function setUp() {
26 $this->_apiversion
= 3;
28 $this->useTransaction(TRUE);
29 $this->_groupID
= $this->groupCreate();
31 $this->_orgID
= $this->organizationCreate(NULL);
34 ///////////////// civicrm_group_organization_get methods
37 * Test civicrm_group_organization_get with valid params.
39 * @dataProvider versionThreeAndFour
41 public function testGroupOrganizationGet() {
44 'organization_id' => $this->_orgID
,
45 'group_id' => $this->_groupID
,
47 $result = $this->callAPISuccess('group_organization', 'create', $params);
49 'organization_id' => $result['id'],
51 $result = $this->callAPIAndDocument('group_organization', 'get', $paramsGet, __FUNCTION__
, __FILE__
);
55 * Test civicrm_group_organization_get with group_id.
57 * @dataProvider versionThreeAndFour
59 public function testGroupOrganizationGetWithGroupId() {
61 'organization_id' => $this->_orgID
,
62 'group_id' => $this->_groupID
,
64 $createResult = $this->callAPISuccess('group_organization', 'create', $createParams);
67 'group_id' => $this->_groupID
,
70 $getResult = $this->callAPISuccess('group_organization', 'get', $getParams);
71 $this->assertEquals($createResult['values'][$createResult['id']], $getResult['values'][0]);
75 * Test civicrm_group_organization_get with empty params.
77 * @dataProvider versionThreeAndFour
79 public function testGroupOrganizationGetWithEmptyParams() {
81 $result = $this->callAPISuccess('group_organization', 'get', $params);
83 $this->assertAPISuccess($result);
87 * Test civicrm_group_organization_get invalid keys.
89 * @dataProvider versionThreeAndFour
91 public function testGroupOrganizationGetWithInvalidKeys() {
95 $result = $this->callAPISuccess('group_organization', 'get', $params);
97 $this->assertAPISuccess($result);
100 ///////////////// civicrm_group_organization_create methods
103 * Check with valid params.
105 * @dataProvider versionThreeAndFour
107 public function testGroupOrganizationCreate() {
109 'organization_id' => $this->_orgID
,
110 'group_id' => $this->_groupID
,
112 $result = $this->callAPIAndDocument('group_organization', 'create', $params, __FUNCTION__
, __FILE__
);
116 * CRM-13841 - Load Group Org before save
118 * @dataProvider versionThreeAndFour
120 public function testGroupOrganizationCreateTwice() {
122 'organization_id' => $this->_orgID
,
123 'group_id' => $this->_groupID
,
125 $result = $this->callAPISuccess('group_organization', 'create', $params);
126 $result2 = $this->callAPISuccess('group_organization', 'create', $params);
127 $this->assertEquals($result['values'], $result2['values']);
131 * Check with empty params array.
133 * @dataProvider versionThreeAndFour
135 public function testGroupOrganizationCreateWithEmptyParams() {
137 $result = $this->callAPIFailure('group_organization', 'create', $params);
138 $this->assertEquals($result['error_message'], 'Mandatory key(s) missing from params array: group_id, organization_id');
142 * Check with invalid params keys.
144 * @dataProvider versionThreeAndFour
146 public function testGroupOrganizationCreateWithInvalidKeys() {
150 $result = $this->callAPIFailure('group_organization', 'create', $params);
151 $this->assertEquals($result['error_message'], 'Mandatory key(s) missing from params array: group_id, organization_id');
154 ///////////////// civicrm_group_organization_remove methods
157 * Test civicrm_group_organization_remove with empty params.
159 * @dataProvider versionThreeAndFour
161 public function testGroupOrganizationDeleteWithEmptyParams() {
163 $result = $this->callAPIFailure('group_organization', 'delete', $params);
164 $this->assertEquals($result['error_message'], 'Mandatory key(s) missing from params array: id');
168 * Test civicrm_group_organization_remove with valid params.
170 * @dataProvider versionThreeAndFour
172 public function testGroupOrganizationDelete() {
174 'organization_id' => $this->_orgID
,
175 'group_id' => $this->_groupID
,
177 $result = $this->callAPISuccess('group_organization', 'create', $paramsC);
180 'id' => $result['id'],
182 $result = $this->callAPIAndDocument('group_organization', 'delete', $params, __FUNCTION__
, __FILE__
);
186 * Test civicrm_group_organization_remove with invalid params key.
188 * @dataProvider versionThreeAndFour
190 public function testGroupOrganizationDeleteWithInvalidKey() {
194 $result = $this->callAPIFailure('group_organization', 'delete', $paramsDelete);
195 $this->assertEquals($result['error_message'], 'Mandatory key(s) missing from params array: id');