b1df9ed2d3508c0dba75424308d3b4c10b8431a7
3 +--------------------------------------------------------------------+
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2019 |
7 +--------------------------------------------------------------------+
8 | This file is a part of CiviCRM. |
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. |
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. |
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 +--------------------------------------------------------------------+
29 * Test APIv3 civicrm_tag_* functions
31 * @package CiviCRM_APIv3
32 * @subpackage API_Core
35 class api_v3_TagTest
extends CiviUnitTestCase
{
36 protected $_apiversion = 3;
39 * @ids array of values to be cleaned up in the tear down
41 protected $ids = array();
47 protected $tag = array();
51 public function setUp() {
53 $this->useTransaction(TRUE);
54 $this->tag
= $this->tagCreate();
55 $this->ids
['tag'][] = $this->tagID
= $this->tag
['id'];
58 ///////////////// civicrm_tag_get methods
61 * Test civicrm_tag_get with wrong params.
63 * @dataProvider versionThreeAndFour
65 public function testGetWrongParams($version) {
66 $this->_apiversion
= $version;
67 $params = array('name' => 'Wrong Tag Name');
68 $result = $this->callAPISuccess('tag', 'get', $params);
69 $this->assertEquals(0, $result['count']);
73 * Test civicrm_tag_get - success expected.
75 * @dataProvider versionThreeAndFour
77 public function testGet($version) {
78 $this->_apiversion
= $version;
81 'name' => $this->tag
['name'],
83 $result = $this->callAPIAndDocument('tag', 'get', $params, __FUNCTION__
, __FILE__
);
84 $this->assertEquals($this->tag
['description'], $result['values'][$this->tagID
]['description']);
85 $this->assertEquals($this->tag
['name'], $result['values'][$this->tagID
]['name']);
89 * Test civicrm_tag_get - success expected.
91 * @dataProvider versionThreeAndFour
93 public function testGetReturnArray($version) {
94 $this->_apiversion
= $version;
95 $description = "Demonstrates use of Return as an array.";
96 $subfile = "GetReturnArray";
100 'name' => $this->tag
['name'],
101 'return' => array('name'),
103 $result = $this->callAPIAndDocument('tag', 'get', $params, __FUNCTION__
, __FILE__
, $description, $subfile);
104 $this->assertTrue(empty($result['values'][$this->tagID
]['description']));
105 $this->assertEquals($this->tag
['name'], $result['values'][$this->tagID
]['name']);
108 ///////////////// civicrm_tag_create methods
111 * Test civicrm_tag_create with empty params.
112 * @param int $version
113 * @dataProvider versionThreeAndFour
115 public function testCreateEmptyParams($version) {
116 $this->_apiversion
= $version;
117 $result = $this->callAPIFailure('tag', 'create', array(), 'name');
121 * Test civicrm_tag_create.
122 * @param int $version
123 * @dataProvider versionThreeAndFour
125 public function testCreatePasstagInParams($version) {
126 $this->_apiversion
= $version;
129 'name' => 'New Tag23',
130 'description' => 'This is description for New Tag 02',
132 $result = $this->callAPISuccess('tag', 'create', $params);
133 $this->assertEquals(10, $result['id']);
137 * Test civicrm_tag_create - success expected.
138 * Skipping v4 because used_for is an array
140 public function testCreate() {
142 'name' => 'Super Heros',
143 'description' => 'Outside undie-wearers',
145 $result = $this->callAPIAndDocument('tag', 'create', $params, __FUNCTION__
, __FILE__
);
146 $this->assertNotNull($result['id']);
147 $params['used_for'] = 'civicrm_contact';
148 $this->getAndCheck($params, $result['id'], 'tag');
152 * Test civicrm_tag_create activity tag- success expected.
154 * Test checks that used_for is set and not over-written by default on update.
156 * Skipping v4 because used_for is an array
158 public function testCreateEntitySpecificTag() {
160 'name' => 'New Tag4',
161 'description' => 'This is description for New Activity tag',
162 'used_for' => 'civicrm_activity',
164 $result = $this->callAPISuccess('tag', 'create', $params);
165 $this->callAPISuccess('tag', 'get', array());
166 $this->getAndCheck($params, $result['id'], 'tag', 0, __FUNCTION__
. ' tag first created');
167 unset($params['used_for']);
168 $params['id'] = $result['id'];
169 $result = $this->callAPISuccess('tag', 'create', $params);
170 $params['used_for'] = 'civicrm_activity';
171 $this->getAndCheck($params, $result['id'], 'tag', 1, __FUNCTION__
. ' tag updated in line ' . __LINE__
);
174 ///////////////// civicrm_tag_delete methods
177 * Test civicrm_tag_delete without tag id.
178 * @param int $version
179 * @dataProvider versionThreeAndFour
181 public function testDeleteWithoutTagId($version) {
182 $this->_apiversion
= $version;
183 $result = $this->callAPIFailure('tag', 'delete', array());
187 * Test civicrm_tag_delete .
188 * @param int $version
189 * @dataProvider versionThreeAndFour
191 public function testTagDeleteOldSyntax($version) {
192 $this->_apiversion
= $version;
194 'tag_id' => $this->tagID
,
196 $result = $this->callAPISuccess('tag', 'delete', $params);
197 unset($this->ids
['tag']);
201 * Test civicrm_tag_delete = $params['id'] is correct
202 * @param int $version
203 * @dataProvider versionThreeAndFour
205 public function testTagDeleteCorrectSyntax($version) {
206 $this->_apiversion
= $version;
208 'id' => $this->tagID
,
210 $result = $this->callAPIAndDocument('tag', 'delete', $params, __FUNCTION__
, __FILE__
);
211 unset($this->ids
['tag']);
214 public function testTagGetfields() {
215 $description = "Demonstrate use of getfields to interrogate api.";
216 $params = array('action' => 'create');
217 $result = $this->callAPIAndDocument('tag', 'getfields', $params, __FUNCTION__
, __FILE__
, $description, NULL);
218 $this->assertEquals('civicrm_contact', $result['values']['used_for']['api.default']);
221 public function testTagGetList() {
222 $description = "Demonstrates use of api.getlist for autocomplete and quicksearch applications.";
224 'input' => $this->tag
['name'],
225 'extra' => array('used_for'),
227 $result = $this->callAPIAndDocument('tag', 'getlist', $params, __FUNCTION__
, __FILE__
, $description);
228 $this->assertEquals($this->tag
['id'], $result['values'][0]['id']);
229 $this->assertEquals($this->tag
['description'], $result['values'][0]['description'][0]);
230 $this->assertEquals($this->tag
['used_for'], $result['values'][0]['extra']['used_for']);