3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.5 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2014 |
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 +--------------------------------------------------------------------+
28 require_once 'CiviTest/CiviUnitTestCase.php';
32 * Test APIv3 civicrm_tag_* functions
34 * @package CiviCRM_APIv3
35 * @subpackage API_Core
38 class api_v3_TagTest
extends CiviUnitTestCase
{
39 protected $_apiversion =3;
41 * @ids array of values to be cleaned up in the tear down
43 protected $ids = array();
48 protected $tag = array();
54 $this->tag
= $this->tagCreate();
55 $this->ids
['tag'][] = $this->tagID
= $this->tag
['id'];
59 $this->deleteFromIDSArray();
62 ///////////////// civicrm_tag_get methods
64 * Test civicrm_tag_get with wrong params.
66 public function testGetWrongParams() {
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 public function testGet() {
78 'name' => $this->tag
['name'],
80 $result = $this->callAPIAndDocument('tag', 'get', $params, __FUNCTION__
, __FILE__
);
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']);
86 * Test civicrm_tag_get - success expected.
88 public function testGetReturnArray() {
89 $description = "demonstrates use of Return as an array";
90 $subfile = "getReturnArray";
94 'name' => $this->tag
['name'],
95 'return' => array('name'),
97 $result = $this->callAPIAndDocument('tag', 'get', $params, __FUNCTION__
, __FILE__
, $description, $subfile);
98 $this->assertTrue(empty($result['values'][$this->tagID
]['description']));
99 $this->assertEquals($this->tag
['name'], $result['values'][$this->tagID
]['name']);
102 ///////////////// civicrm_tag_create methods
105 * Test civicrm_tag_create with empty params.
107 function testCreateEmptyParams() {
108 $result = $this->callAPIFailure('tag', 'create', array(),'Mandatory key(s) missing from params array: name');
112 * Test civicrm_tag_create
114 function testCreatePasstagInParams() {
117 'name' => 'New Tag23',
118 'description' => 'This is description for New Tag 02',
120 $result = $this->callAPISuccess('tag', 'create', $params);
121 $this->assertEquals(10, $result['id'], 'In line ' . __LINE__
);
125 * Test civicrm_tag_create - success expected.
127 function testCreate() {
129 'name' => 'Super Heros',
130 'description' => 'Outside undie-wearers',
132 $result = $this->callAPIAndDocument('tag', 'create', $params, __FUNCTION__
, __FILE__
);
133 $this->assertNotNull($result['id'], 'In line ' . __LINE__
);
134 $params['used_for'] = 'civicrm_contact';
135 $this->getAndCheck($params, $result['id'], 'tag');
139 * Test civicrm_tag_create activity tag- success expected. Test checks that used_for is set
140 * and not over-written by default on update
142 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', array());
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__
);
157 ///////////////// civicrm_tag_delete methods
160 * Test civicrm_tag_delete without tag id.
162 function testDeleteWithoutTagId() {
163 $result = $this->callAPIFailure('tag', 'delete', array(), 'Mandatory key(s) missing from params array: id');
167 * Test civicrm_tag_delete .
169 function testTagDeleteOldSyntax() {
171 'tag_id' => $this->tagID
,
173 $result = $this->callAPISuccess('tag', 'delete', $params);
174 unset($this->ids
['tag']);
178 * Test civicrm_tag_delete = $params['id'] is correct
180 function testTagDeleteCorrectSyntax() {
182 'id' => $this->tagID
,
184 $result = $this->callAPIAndDocument('tag', 'delete', $params, __FUNCTION__
, __FILE__
);
185 unset($this->ids
['tag']);
188 function testTagGetfields() {
189 $description = "demonstrate use of getfields to interogate api";
190 $params = array('action' => 'create');
191 $result = $this->callAPIAndDocument('tag', 'getfields', $params, __FUNCTION__
, __FILE__
, $description, NULL, 'getfields');
192 $this->assertEquals('civicrm_contact', $result['values']['used_for']['api.default']);
195 function testTagGetList() {
196 $description = "Demonstrates use of api.getlist for autocomplete and quicksearch applications";
198 'input' => $this->tag
['name'],
199 'extra' => array('used_for')
201 $result = $this->callAPIAndDocument('tag', 'getlist', $params, __FUNCTION__
, __FILE__
, $description);
202 $this->assertEquals($this->tag
['id'], $result['values'][0]['id'], 'In line ' . __LINE__
);
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__
);