3 +--------------------------------------------------------------------+
4 | Copyright CiviCRM LLC. All rights reserved. |
6 | This work is published under the GNU AGPLv3 license with some |
7 | permitted exceptions and without any warranty. For full license |
8 | and copyright information, see https://civicrm.org/licensing |
9 +--------------------------------------------------------------------+
13 * Test APIv3 civicrm_tag_* functions
15 * @package CiviCRM_APIv3
16 * @subpackage API_Core
19 class api_v3_TagTest
extends CiviUnitTestCase
{
20 protected $_apiversion = 3;
23 * @ids array of values to be cleaned up in the tear down
35 public function setUp() {
37 $this->useTransaction(TRUE);
38 $this->tag
= $this->tagCreate();
39 $this->ids
['tag'][] = $this->tagID
= $this->tag
['id'];
42 ///////////////// civicrm_tag_get methods
45 * Test civicrm_tag_get with wrong params.
47 * @dataProvider versionThreeAndFour
49 public function testGetWrongParams($version) {
50 $this->_apiversion
= $version;
51 $params = ['name' => 'Wrong Tag Name'];
52 $result = $this->callAPISuccess('tag', 'get', $params);
53 $this->assertEquals(0, $result['count']);
57 * Test civicrm_tag_get - success expected.
59 * @dataProvider versionThreeAndFour
61 public function testGet($version) {
62 $this->_apiversion
= $version;
65 'name' => $this->tag
['name'],
67 $result = $this->callAPIAndDocument('tag', 'get', $params, __FUNCTION__
, __FILE__
);
68 $this->assertEquals($this->tag
['description'], $result['values'][$this->tagID
]['description']);
69 $this->assertEquals($this->tag
['name'], $result['values'][$this->tagID
]['name']);
73 * Test civicrm_tag_get - success expected.
75 * @dataProvider versionThreeAndFour
77 public function testGetReturnArray($version) {
78 $this->_apiversion
= $version;
79 $description = "Demonstrates use of Return as an array.";
80 $subfile = "GetReturnArray";
84 'name' => $this->tag
['name'],
87 $result = $this->callAPIAndDocument('tag', 'get', $params, __FUNCTION__
, __FILE__
, $description, $subfile);
88 $this->assertTrue(empty($result['values'][$this->tagID
]['description']));
89 $this->assertEquals($this->tag
['name'], $result['values'][$this->tagID
]['name']);
92 ///////////////// civicrm_tag_create methods
95 * Test civicrm_tag_create with empty params.
97 * @dataProvider versionThreeAndFour
99 public function testCreateEmptyParams($version) {
100 $this->_apiversion
= $version;
101 $result = $this->callAPIFailure('tag', 'create', [], 'name');
105 * Test civicrm_tag_create.
106 * @param int $version
107 * @dataProvider versionThreeAndFour
109 public function testCreatePasstagInParams($version) {
110 $this->_apiversion
= $version;
113 'name' => 'New Tag23',
114 'description' => 'This is description for New Tag 02',
116 $result = $this->callAPISuccess('tag', 'create', $params);
117 $this->assertEquals(10, $result['id']);
121 * Test civicrm_tag_create - success expected.
122 * Skipping v4 because used_for is an array
124 public function testCreate() {
126 'name' => 'Super Heros',
127 'description' => 'Outside undie-wearers',
129 $result = $this->callAPIAndDocument('tag', 'create', $params, __FUNCTION__
, __FILE__
);
130 $this->assertNotNull($result['id']);
131 $params['used_for'] = 'civicrm_contact';
132 $this->getAndCheck($params, $result['id'], 'tag');
136 * Test civicrm_tag_create activity tag- success expected.
138 * Test checks that used_for is set and not over-written by default on update.
140 * Skipping v4 because used_for is an array
142 public function testCreateEntitySpecificTag() {
144 'name' => 'New Tag4',
145 'description' => 'This is description for New Activity tag',
146 'used_for' => 'civicrm_activity',
148 $result = $this->callAPISuccess('tag', 'create', $params);
149 $this->callAPISuccess('tag', 'get', []);
150 $this->getAndCheck($params, $result['id'], 'tag', 0, __FUNCTION__
. ' tag first created');
151 unset($params['used_for']);
152 $params['id'] = $result['id'];
153 $result = $this->callAPISuccess('tag', 'create', $params);
154 $params['used_for'] = 'civicrm_activity';
155 $this->getAndCheck($params, $result['id'], 'tag', 1, __FUNCTION__
. ' tag updated in line ' . __LINE__
);
158 ///////////////// civicrm_tag_delete methods
161 * Test civicrm_tag_delete without tag id.
162 * @param int $version
163 * @dataProvider versionThreeAndFour
165 public function testDeleteWithoutTagId($version) {
166 $this->_apiversion
= $version;
167 $result = $this->callAPIFailure('tag', 'delete', []);
171 * Test civicrm_tag_delete .
172 * @param int $version
173 * @dataProvider versionThreeAndFour
175 public function testTagDeleteOldSyntax($version) {
176 $this->_apiversion
= $version;
178 'tag_id' => $this->tagID
,
180 $result = $this->callAPISuccess('tag', 'delete', $params);
181 unset($this->ids
['tag']);
185 * Test civicrm_tag_delete = $params['id'] is correct
186 * @param int $version
187 * @dataProvider versionThreeAndFour
189 public function testTagDeleteCorrectSyntax($version) {
190 $this->_apiversion
= $version;
192 'id' => $this->tagID
,
194 $result = $this->callAPIAndDocument('tag', 'delete', $params, __FUNCTION__
, __FILE__
);
195 unset($this->ids
['tag']);
198 public function testTagGetfields() {
199 $description = "Demonstrate use of getfields to interrogate api.";
200 $params = ['action' => 'create'];
201 $result = $this->callAPIAndDocument('tag', 'getfields', $params, __FUNCTION__
, __FILE__
, $description, NULL);
202 $this->assertEquals('civicrm_contact', $result['values']['used_for']['api.default']);
205 public function testTagGetList() {
206 $description = "Demonstrates use of api.getlist for autocomplete and quicksearch applications.";
208 'input' => $this->tag
['name'],
209 'extra' => ['used_for'],
211 $result = $this->callAPIAndDocument('tag', 'getlist', $params, __FUNCTION__
, __FILE__
, $description);
212 $this->assertEquals($this->tag
['id'], $result['values'][0]['id']);
213 $this->assertEquals($this->tag
['description'], $result['values'][0]['description'][0]);
214 $this->assertEquals($this->tag
['used_for'], $result['values'][0]['extra']['used_for']);