CRM-15855 - Allow mailings to be saved (but not sent) without name+subject.
[civicrm-core.git] / tests / phpunit / api / v3 / GroupTest.php
1 <?php
2 /*
3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.6 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2014 |
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 class api_v3_GroupTest extends CiviUnitTestCase {
36 protected $_apiversion;
37 protected $_groupID;
38
39 public function setUp() {
40 $this->_apiversion = 3;
41
42 parent::setUp();
43 $this->_groupID = $this->groupCreate();
44 }
45
46 public function tearDown() {
47
48 $this->groupDelete($this->_groupID);
49 }
50
51 public function testgroupCreateNoTitle() {
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
64 $group = $this->callAPIFailure('group', 'create', $params, 'Mandatory key(s) missing from params array: title');
65 }
66
67
68 public function testGetGroupWithEmptyParams() {
69 $group = $this->callAPISuccess('group', 'get', $params = array());
70
71 $group = $group["values"];
72 $this->assertNotNull(count($group));
73 $this->assertEquals($group[$this->_groupID]['name'], "Test Group 1");
74 $this->assertEquals($group[$this->_groupID]['is_active'], 1);
75 $this->assertEquals($group[$this->_groupID]['visibility'], 'Public Pages');
76 }
77
78 public function testGetGroupParamsWithGroupId() {
79 $params = array('id' => $this->_groupID);
80 $group = $this->callAPISuccess('group', 'get', $params);
81
82 foreach ($group['values'] as $v) {
83 $this->assertEquals($v['name'], "Test Group 1");
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
91 public function testGetGroupParamsWithGroupName() {
92 $params = array(
93 'name' => "Test Group 1",
94 );
95 $group = $this->callAPIAndDocument('group', 'get', $params, __FUNCTION__, __FILE__);
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
107 public function testGetGroupParamsWithReturnName() {
108 $params = array();
109 $params['id'] = $this->_groupID;
110 $params['return.name'] = 1;
111 $group = $this->callAPISuccess('group', 'get', $params);
112 $this->assertEquals($group['values'][$this->_groupID]['name'],
113 "Test Group 1"
114 );
115 }
116
117 public function testGetGroupParamsWithGroupTitle() {
118 $params = array();
119 $params['title'] = 'New Test Group Created';
120 $group = $this->callAPISuccess('group', 'get', $params);
121
122 foreach ($group['values'] as $v) {
123 $this->assertEquals($v['id'], $this->_groupID);
124 $this->assertEquals($v['name'], "Test Group 1");
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
131 public function testGetNonExistingGroup() {
132 $params = array();
133 $params['title'] = 'No such group Exist';
134 $group = $this->callAPISuccess('group', 'get', $params);
135 $this->assertEquals(0, $group['count']);
136 }
137
138 public function testgroupdeleteParamsnoId() {
139 $group = $this->callAPIFailure('group', 'delete', array(), 'Mandatory key(s) missing from params array: id');
140 }
141
142 public function testgetfields() {
143 $description = "demonstrate use of getfields to interrogate api";
144 $params = array('action' => 'create');
145 $result = $this->callAPIAndDocument('group', 'getfields', $params, __FUNCTION__, __FILE__, $description, 'getfields', 'getfields');
146 $this->assertEquals(1, $result['values']['is_active']['api.default']);
147 }
148
149 }