Commit | Line | Data |
---|---|---|
6a488035 TO |
1 | <?php |
2 | /* | |
3 | +--------------------------------------------------------------------+ | |
81621fee | 4 | | CiviCRM version 4.7 | |
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 | 27 | |
6a488035 TO |
28 | /** |
29 | * Test APIv3 civicrm_tag_* functions | |
30 | * | |
6c6e6187 TO |
31 | * @package CiviCRM_APIv3 |
32 | * @subpackage API_Core | |
acb109b7 | 33 | * @group headless |
6a488035 | 34 | */ |
6a488035 | 35 | class api_v3_TagTest extends CiviUnitTestCase { |
6c6e6187 | 36 | protected $_apiversion = 3; |
fb32de45 | 37 | /** |
38 | * @ids array of values to be cleaned up in the tear down | |
39 | */ | |
40 | protected $ids = array(); | |
41 | /** | |
eceb18cc | 42 | * Tag id. |
fb32de45 | 43 | * @var integer |
44 | */ | |
45 | protected $tag = array(); | |
46 | ||
47 | protected $tagID; | |
b7c9bc4c | 48 | |
00be9182 | 49 | public function setUp() { |
6a488035 | 50 | parent::setUp(); |
1166fbea | 51 | $this->useTransaction(TRUE); |
fb32de45 | 52 | $this->tag = $this->tagCreate(); |
53 | $this->ids['tag'][] = $this->tagID = $this->tag['id']; | |
6a488035 TO |
54 | } |
55 | ||
fb32de45 | 56 | ///////////////// civicrm_tag_get methods |
6a488035 TO |
57 | /** |
58 | * Test civicrm_tag_get with wrong params. | |
59 | */ | |
60 | public function testGetWrongParams() { | |
641cb0ba | 61 | $params = array('name' => 'Wrong Tag Name'); |
62 | $result = $this->callAPISuccess('tag', 'get', $params); | |
fb32de45 | 63 | $this->assertEquals(0, $result['count']); |
6a488035 TO |
64 | } |
65 | ||
66 | /** | |
67 | * Test civicrm_tag_get - success expected. | |
68 | */ | |
69 | public function testGet() { | |
6a488035 | 70 | $params = array( |
fb32de45 | 71 | 'id' => $this->tagID, |
72 | 'name' => $this->tag['name'], | |
6a488035 | 73 | ); |
641cb0ba | 74 | $result = $this->callAPIAndDocument('tag', 'get', $params, __FUNCTION__, __FILE__); |
ba4a1892 | 75 | $this->assertEquals($this->tag['description'], $result['values'][$this->tagID]['description']); |
fb32de45 | 76 | $this->assertEquals($this->tag['name'], $result['values'][$this->tagID]['name']); |
6a488035 TO |
77 | } |
78 | ||
79 | /** | |
80 | * Test civicrm_tag_get - success expected. | |
81 | */ | |
82 | public function testGetReturnArray() { | |
5c49fee0 | 83 | $description = "Demonstrates use of Return as an array."; |
a828d7b8 | 84 | $subfile = "GetReturnArray"; |
6a488035 TO |
85 | |
86 | $params = array( | |
fb32de45 | 87 | 'id' => $this->tagID, |
88 | 'name' => $this->tag['name'], | |
6a488035 TO |
89 | 'return' => array('name'), |
90 | ); | |
641cb0ba | 91 | $result = $this->callAPIAndDocument('tag', 'get', $params, __FUNCTION__, __FILE__, $description, $subfile); |
fb32de45 | 92 | $this->assertTrue(empty($result['values'][$this->tagID]['description'])); |
93 | $this->assertEquals($this->tag['name'], $result['values'][$this->tagID]['name']); | |
6a488035 TO |
94 | } |
95 | ||
96 | ///////////////// civicrm_tag_create methods | |
97 | ||
6a488035 TO |
98 | /** |
99 | * Test civicrm_tag_create with empty params. | |
100 | */ | |
00be9182 | 101 | public function testCreateEmptyParams() { |
6c6e6187 | 102 | $result = $this->callAPIFailure('tag', 'create', array(), 'Mandatory key(s) missing from params array: name'); |
6a488035 TO |
103 | } |
104 | ||
105 | /** | |
fe482240 | 106 | * Test civicrm_tag_create. |
6a488035 | 107 | */ |
00be9182 | 108 | public function testCreatePasstagInParams() { |
6a488035 TO |
109 | $params = array( |
110 | 'tag' => 10, | |
111 | 'name' => 'New Tag23', | |
112 | 'description' => 'This is description for New Tag 02', | |
6a488035 | 113 | ); |
641cb0ba | 114 | $result = $this->callAPISuccess('tag', 'create', $params); |
ba4a1892 | 115 | $this->assertEquals(10, $result['id']); |
6a488035 TO |
116 | } |
117 | ||
118 | /** | |
119 | * Test civicrm_tag_create - success expected. | |
120 | */ | |
00be9182 | 121 | public function testCreate() { |
6a488035 | 122 | $params = array( |
fb32de45 | 123 | 'name' => 'Super Heros', |
124 | 'description' => 'Outside undie-wearers', | |
6a488035 | 125 | ); |
641cb0ba | 126 | $result = $this->callAPIAndDocument('tag', 'create', $params, __FUNCTION__, __FILE__); |
61ef23bd | 127 | $this->assertNotNull($result['id']); |
6a488035 TO |
128 | $params['used_for'] = 'civicrm_contact'; |
129 | $this->getAndCheck($params, $result['id'], 'tag'); | |
130 | } | |
131 | ||
132 | /** | |
fe482240 EM |
133 | * Test civicrm_tag_create activity tag- success expected. |
134 | * | |
135 | * Test checks that used_for is set and not over-written by default on update. | |
6a488035 | 136 | */ |
00be9182 | 137 | public function testCreateEntitySpecificTag() { |
6a488035 TO |
138 | $params = array( |
139 | 'name' => 'New Tag4', | |
710ec471 CW |
140 | 'description' => 'This is description for New Activity tag', |
141 | 'used_for' => 'civicrm_activity', | |
6a488035 | 142 | ); |
641cb0ba | 143 | $result = $this->callAPISuccess('tag', 'create', $params); |
710ec471 | 144 | $this->callAPISuccess('tag', 'get', array()); |
6a488035 TO |
145 | $this->getAndCheck($params, $result['id'], 'tag', 0, __FUNCTION__ . ' tag first created'); |
146 | unset($params['used_for']); | |
6a488035 | 147 | $params['id'] = $result['id']; |
641cb0ba | 148 | $result = $this->callAPISuccess('tag', 'create', $params); |
710ec471 | 149 | $params['used_for'] = 'civicrm_activity'; |
6a488035 TO |
150 | $this->getAndCheck($params, $result['id'], 'tag', 1, __FUNCTION__ . ' tag updated in line ' . __LINE__); |
151 | } | |
152 | ///////////////// civicrm_tag_delete methods | |
153 | ||
6a488035 TO |
154 | /** |
155 | * Test civicrm_tag_delete without tag id. | |
156 | */ | |
00be9182 | 157 | public function testDeleteWithoutTagId() { |
641cb0ba | 158 | $result = $this->callAPIFailure('tag', 'delete', array(), 'Mandatory key(s) missing from params array: id'); |
6a488035 TO |
159 | } |
160 | ||
161 | /** | |
162 | * Test civicrm_tag_delete . | |
163 | */ | |
00be9182 | 164 | public function testTagDeleteOldSyntax() { |
6a488035 | 165 | $params = array( |
fb32de45 | 166 | 'tag_id' => $this->tagID, |
6a488035 | 167 | ); |
641cb0ba | 168 | $result = $this->callAPISuccess('tag', 'delete', $params); |
fb32de45 | 169 | unset($this->ids['tag']); |
6a488035 TO |
170 | } |
171 | ||
172 | /** | |
173 | * Test civicrm_tag_delete = $params['id'] is correct | |
174 | */ | |
00be9182 | 175 | public function testTagDeleteCorrectSyntax() { |
6a488035 | 176 | $params = array( |
fb32de45 | 177 | 'id' => $this->tagID, |
6a488035 | 178 | ); |
641cb0ba | 179 | $result = $this->callAPIAndDocument('tag', 'delete', $params, __FUNCTION__, __FILE__); |
fb32de45 | 180 | unset($this->ids['tag']); |
6a488035 TO |
181 | } |
182 | ||
00be9182 | 183 | public function testTagGetfields() { |
5c49fee0 | 184 | $description = "Demonstrate use of getfields to interrogate api."; |
92915c55 | 185 | $params = array('action' => 'create'); |
a828d7b8 | 186 | $result = $this->callAPIAndDocument('tag', 'getfields', $params, __FUNCTION__, __FILE__, $description, NULL); |
6a488035 TO |
187 | $this->assertEquals('civicrm_contact', $result['values']['used_for']['api.default']); |
188 | } | |
76ec9ca7 | 189 | |
00be9182 | 190 | public function testTagGetList() { |
5c49fee0 | 191 | $description = "Demonstrates use of api.getlist for autocomplete and quicksearch applications."; |
76ec9ca7 CW |
192 | $params = array( |
193 | 'input' => $this->tag['name'], | |
21dfd5f5 | 194 | 'extra' => array('used_for'), |
76ec9ca7 | 195 | ); |
8250601e | 196 | $result = $this->callAPIAndDocument('tag', 'getlist', $params, __FUNCTION__, __FILE__, $description); |
ba4a1892 TM |
197 | $this->assertEquals($this->tag['id'], $result['values'][0]['id']); |
198 | $this->assertEquals($this->tag['description'], $result['values'][0]['description'][0]); | |
199 | $this->assertEquals($this->tag['used_for'], $result['values'][0]['extra']['used_for']); | |
76ec9ca7 | 200 | } |
96025800 | 201 | |
6a488035 | 202 | } |