Commit | Line | Data |
---|---|---|
6a488035 TO |
1 | <?php |
2 | /* | |
3 | +--------------------------------------------------------------------+ | |
39de6fd5 | 4 | | CiviCRM version 4.6 | |
6a488035 | 5 | +--------------------------------------------------------------------+ |
e7112fa7 | 6 | | Copyright CiviCRM LLC (c) 2004-2015 | |
6a488035 TO |
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 | +--------------------------------------------------------------------+ | |
d25dd0ee | 26 | */ |
6a488035 TO |
27 | |
28 | require_once 'CiviTest/CiviUnitTestCase.php'; | |
29 | ||
30 | /** | |
31 | * Test class for Group API - civicrm_group_* | |
32 | * | |
6c6e6187 | 33 | * @package CiviCRM_APIv3 |
6a488035 | 34 | */ |
6a488035 TO |
35 | class api_v3_GroupTest extends CiviUnitTestCase { |
36 | protected $_apiversion; | |
37 | protected $_groupID; | |
6a488035 | 38 | |
00be9182 | 39 | public function setUp() { |
6a488035 TO |
40 | $this->_apiversion = 3; |
41 | ||
42 | parent::setUp(); | |
fadb804f | 43 | $this->_groupID = $this->groupCreate(); |
6a488035 TO |
44 | } |
45 | ||
00be9182 | 46 | public function tearDown() { |
6a488035 TO |
47 | |
48 | $this->groupDelete($this->_groupID); | |
49 | } | |
50 | ||
00be9182 | 51 | public function testgroupCreateNoTitle() { |
6a488035 TO |
52 | $params = array( |
53 | 'name' => 'Test Group No title ', | |
54 | 'domain_id' => 1, | |
55 | 'description' => 'New Test Group Created', | |
56 | 'is_active' => 1, | |
57 | 'visibility' => 'Public Pages', | |
58 | 'group_type' => array( | |
59 | '1' => 1, | |
60 | '2' => 1, | |
61 | ), | |
62 | ); | |
63 | ||
b26e776b | 64 | $group = $this->callAPIFailure('group', 'create', $params, 'Mandatory key(s) missing from params array: title'); |
6a488035 TO |
65 | } |
66 | ||
6a488035 | 67 | |
00be9182 | 68 | public function testGetGroupWithEmptyParams() { |
b26e776b | 69 | $group = $this->callAPISuccess('group', 'get', $params = array()); |
6a488035 TO |
70 | |
71 | $group = $group["values"]; | |
72 | $this->assertNotNull(count($group)); | |
5667b84b | 73 | $this->assertEquals($group[$this->_groupID]['name'], "Test Group 1"); |
6a488035 TO |
74 | $this->assertEquals($group[$this->_groupID]['is_active'], 1); |
75 | $this->assertEquals($group[$this->_groupID]['visibility'], 'Public Pages'); | |
76 | } | |
77 | ||
00be9182 | 78 | public function testGetGroupParamsWithGroupId() { |
b26e776b | 79 | $params = array('id' => $this->_groupID); |
80 | $group = $this->callAPISuccess('group', 'get', $params); | |
6a488035 TO |
81 | |
82 | foreach ($group['values'] as $v) { | |
5667b84b | 83 | $this->assertEquals($v['name'], "Test Group 1"); |
6a488035 TO |
84 | $this->assertEquals($v['title'], 'New Test Group Created'); |
85 | $this->assertEquals($v['description'], 'New Test Group Created'); | |
86 | $this->assertEquals($v['is_active'], 1); | |
87 | $this->assertEquals($v['visibility'], 'Public Pages'); | |
88 | } | |
89 | } | |
90 | ||
00be9182 | 91 | public function testGetGroupParamsWithGroupName() { |
b26e776b | 92 | $params = array( |
5667b84b | 93 | 'name' => "Test Group 1", |
b26e776b | 94 | ); |
95 | $group = $this->callAPIAndDocument('group', 'get', $params, __FUNCTION__, __FILE__); | |
6a488035 TO |
96 | $group = $group['values']; |
97 | ||
98 | foreach ($group as $v) { | |
99 | $this->assertEquals($v['id'], $this->_groupID); | |
100 | $this->assertEquals($v['title'], 'New Test Group Created'); | |
101 | $this->assertEquals($v['description'], 'New Test Group Created'); | |
102 | $this->assertEquals($v['is_active'], 1); | |
103 | $this->assertEquals($v['visibility'], 'Public Pages'); | |
104 | } | |
105 | } | |
106 | ||
00be9182 | 107 | public function testGetGroupParamsWithReturnName() { |
b26e776b | 108 | $params = array(); |
6a488035 TO |
109 | $params['id'] = $this->_groupID; |
110 | $params['return.name'] = 1; | |
b26e776b | 111 | $group = $this->callAPISuccess('group', 'get', $params); |
6a488035 | 112 | $this->assertEquals($group['values'][$this->_groupID]['name'], |
5667b84b | 113 | "Test Group 1" |
6a488035 TO |
114 | ); |
115 | } | |
116 | ||
00be9182 | 117 | public function testGetGroupParamsWithGroupTitle() { |
5667b84b | 118 | $params = array(); |
6a488035 | 119 | $params['title'] = 'New Test Group Created'; |
5667b84b | 120 | $group = $this->callAPISuccess('group', 'get', $params); |
6a488035 TO |
121 | |
122 | foreach ($group['values'] as $v) { | |
123 | $this->assertEquals($v['id'], $this->_groupID); | |
5667b84b | 124 | $this->assertEquals($v['name'], "Test Group 1"); |
6a488035 TO |
125 | $this->assertEquals($v['description'], 'New Test Group Created'); |
126 | $this->assertEquals($v['is_active'], 1); | |
127 | $this->assertEquals($v['visibility'], 'Public Pages'); | |
128 | } | |
129 | } | |
130 | ||
00be9182 | 131 | public function testGetNonExistingGroup() { |
5667b84b | 132 | $params = array(); |
6a488035 | 133 | $params['title'] = 'No such group Exist'; |
5667b84b | 134 | $group = $this->callAPISuccess('group', 'get', $params); |
d0e1eff2 | 135 | $this->assertEquals(0, $group['count']); |
6a488035 TO |
136 | } |
137 | ||
00be9182 | 138 | public function testgroupdeleteParamsnoId() { |
b26e776b | 139 | $group = $this->callAPIFailure('group', 'delete', array(), 'Mandatory key(s) missing from params array: id'); |
6a488035 TO |
140 | } |
141 | ||
00be9182 | 142 | public function testgetfields() { |
5c49fee0 | 143 | $description = "Demonstrate use of getfields to interrogate api."; |
5667b84b | 144 | $params = array('action' => 'create'); |
a828d7b8 | 145 | $result = $this->callAPIAndDocument('group', 'getfields', $params, __FUNCTION__, __FILE__, $description); |
6a488035 TO |
146 | $this->assertEquals(1, $result['values']['is_active']['api.default']); |
147 | } | |
96025800 | 148 | |
6a488035 | 149 | } |