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