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