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