3 * File for the TestConstant class
7 * @author Walt Haas <walt@dharmatech.org> (801) 534-1262
8 * @copyright Copyright CiviCRM LLC (C) 2009
9 * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html
10 * GNU Affero General Public License version 3
11 * @version $Id: ConstantTest.php 31254 2010-12-15 10:09:29Z eileen $
12 * @package CiviCRM_APIv3
13 * @subpackage API_Constant
15 * This file is part of CiviCRM
17 * CiviCRM is free software; you can redistribute it and/or
18 * modify it under the terms of the GNU Affero General Public License
19 * as published by the Free Software Foundation; either version 3 of
20 * the License, or (at your option) any later version.
22 * CiviCRM is distributed in the hope that it will be useful,
23 * but WITHOUT ANY WARRANTY; without even the implied warranty of
24 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25 * GNU Affero General Public License for more details.
27 * You should have received a copy of the GNU Affero General Public
28 * License along with this program. If not, see
29 * <http://www.gnu.org/licenses/>.
33 * Include class definitions
35 require_once 'CiviTest/CiviUnitTestCase.php';
36 require_once 'api/v3/Constant.php';
37 require_once 'CRM/Core/I18n.php';
38 require_once 'CRM/Utils/Cache.php';
41 * Test APIv3 civicrm_activity_* functions
43 * @package CiviCRM_APIv3
44 * @subpackage API_Constant
46 class api_v3_ConstantTest
extends CiviUnitTestCase
{
47 protected $_apiversion = 3;
48 public $_eNoticeCompliant = TRUE;
53 * Initialize configuration
54 */ function __construct() {
55 parent
::__construct();
59 * Test setup for every test
61 * Connect to the database, truncate the tables that will be used
62 * and redirect stdin to a temporary file
64 public function setUp() {
65 // Connect to the database
67 $this->_apiversion
= 3;
71 * Test civicrm_constant_get( ) for unknown constant
73 public function testUnknownConstant() {
74 $result = civicrm_api('constant', 'get', array(
75 'name' => 'thisTypeDoesNotExist',
76 'version' => $this->_apiversion
,
78 $this->assertEquals(1, $result['is_error'], "In line " . __LINE__
);
82 * Test civicrm_constant_get( 'activityStatus' )
84 public function testActivityStatus() {
86 $result = civicrm_api('constant', 'get', array(
87 'name' => 'activityStatus',
88 'version' => $this->_apiversion
,
91 $this->assertTrue($result['count'] > 5, "In line " . __LINE__
);
92 $this->assertContains('Scheduled', $result['values'], "In line " . __LINE__
);
93 $this->assertContains('Completed', $result['values'], "In line " . __LINE__
);
94 $this->assertContains('Cancelled', $result['values'], "In line " . __LINE__
);
96 $this->assertTrue(empty($result['is_error']),
102 * Test civicrm_constant_get( 'activityType' )
104 public function testActivityType() {
106 $parameters = array(TRUE, FALSE, TRUE);
108 $result = civicrm_api('constant', 'get', array(
109 'name' => 'activityType',
110 'version' => $this->_apiversion
,
112 $this->assertTrue($result['count'] > 2, "In line " . __LINE__
);
113 $this->assertContains('Meeting', $result['values'], "In line " . __LINE__
);
114 $this->assertTrue(empty($result['is_error']),
115 "In line " . __LINE__
120 * Test civicrm_constant_get( 'locationType' )
122 public function testLocationTypeGet() {
123 // needed to get rid of cached values from previous tests
124 CRM_Core_PseudoConstant
::flush();
129 'name' => 'locationType',
130 'version' => $this->_apiversion
,
132 $result = civicrm_api('constant', 'get', $params);
133 $this->assertAPISuccess($result);
134 $this->documentMe($params, $result, __FUNCTION__
, __FILE__
);
135 $this->assertTrue($result['count'] > 3, "In line " . __LINE__
);
136 $this->assertContains('Home', $result['values'], "In line " . __LINE__
);
137 $this->assertContains('Work', $result['values'], "In line " . __LINE__
);
138 $this->assertContains('Main', $result['values'], "In line " . __LINE__
);
139 $this->assertContains('Billing', $result['values'], "In line " . __LINE__
);
140 $this->assertTrue(empty($result['is_error']),
141 "In line " . __LINE__
146 * Test civicrm_constant_get( 'phoneType' )
148 public function testPhoneType() {
149 $parameters = array(TRUE, FALSE, TRUE);
150 $result = civicrm_api('constant', 'get', array(
151 'name' => 'phoneType',
152 'version' => $this->_apiversion
,
154 $this->assertAPISuccess($result);
156 $this->assertEquals(5, $result['count'], "In line " . __LINE__
);
157 $this->assertContains('Phone', $result['values'], "In line " . __LINE__
);
158 $this->assertContains('Mobile', $result['values'], "In line " . __LINE__
);
159 $this->assertContains('Fax', $result['values'], "In line " . __LINE__
);
160 $this->assertContains('Pager', $result['values'], "In line " . __LINE__
);
161 $this->assertContains('Voicemail', $result['values'], "In line " . __LINE__
);
163 $this->assertTrue(empty($result['is_error']),
164 "In line " . __LINE__
169 * Test civicrm_constant_get( 'mailProtocol' )
171 public function testmailProtocol() {
174 $parameters = array(TRUE, FALSE, TRUE);
176 $result = civicrm_api('constant', 'get', array(
177 'name' => 'mailProtocol',
178 'version' => $this->_apiversion
,
180 $this->assertAPISuccess($result);
182 $this->assertEquals(4, $result['count'], "In line " . __LINE__
);
183 $this->assertContains('IMAP', $result['values'], "In line " . __LINE__
);
184 $this->assertContains('Maildir', $result['values'], "In line " . __LINE__
);
185 $this->assertContains('POP3', $result['values'], "In line " . __LINE__
);
186 $this->assertContains('Localdir', $result['values'], "In line " . __LINE__
);
187 $this->assertTrue(empty($result['is_error']),
188 "In line " . __LINE__