Commit | Line | Data |
---|---|---|
6a488035 TO |
1 | <?php |
2 | /** | |
3 | * File for the TestConstant class | |
4 | * | |
5 | * (PHP 5) | |
6 | * | |
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 | |
14 | * | |
15 | * This file is part of CiviCRM | |
16 | * | |
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. | |
21 | * | |
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. | |
26 | * | |
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/>. | |
30 | */ | |
31 | ||
32 | /** | |
33 | * Include class definitions | |
34 | */ | |
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'; | |
39 | ||
40 | /** | |
41 | * Test APIv3 civicrm_activity_* functions | |
42 | * | |
43 | * @package CiviCRM_APIv3 | |
44 | * @subpackage API_Constant | |
45 | */ | |
46 | class api_v3_ConstantTest extends CiviUnitTestCase { | |
47 | protected $_apiversion = 3; | |
48 | public $_eNoticeCompliant = TRUE; | |
49 | ||
50 | /** | |
51 | * Constructor | |
52 | * | |
53 | * Initialize configuration | |
54 | */ function __construct() { | |
55 | parent::__construct(); | |
56 | } | |
57 | ||
58 | /** | |
59 | * Test setup for every test | |
60 | * | |
61 | * Connect to the database, truncate the tables that will be used | |
62 | * and redirect stdin to a temporary file | |
63 | */ | |
64 | public function setUp() { | |
65 | // Connect to the database | |
66 | parent::setUp(); | |
67 | $this->_apiversion = 3; | |
68 | } | |
69 | ||
70 | /** | |
71 | * Test civicrm_constant_get( ) for unknown constant | |
72 | */ | |
73 | public function testUnknownConstant() { | |
74 | $result = civicrm_api('constant', 'get', array( | |
75 | 'name' => 'thisTypeDoesNotExist', | |
76 | 'version' => $this->_apiversion, | |
77 | )); | |
78 | $this->assertEquals(1, $result['is_error'], "In line " . __LINE__); | |
79 | } | |
80 | ||
81 | /** | |
82 | * Test civicrm_constant_get( 'activityStatus' ) | |
83 | */ | |
84 | public function testActivityStatus() { | |
85 | ||
86 | $result = civicrm_api('constant', 'get', array( | |
87 | 'name' => 'activityStatus', | |
88 | 'version' => $this->_apiversion, | |
89 | )); | |
90 | ||
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__); | |
95 | ||
96 | $this->assertTrue(empty($result['is_error']), | |
97 | "In line " . __LINE__ | |
98 | ); | |
99 | } | |
100 | ||
101 | /** | |
102 | * Test civicrm_constant_get( 'activityType' ) | |
103 | */ | |
104 | public function testActivityType() { | |
105 | ||
106 | $parameters = array(TRUE, FALSE, TRUE); | |
107 | ||
108 | $result = civicrm_api('constant', 'get', array( | |
109 | 'name' => 'activityType', | |
110 | 'version' => $this->_apiversion, | |
111 | )); | |
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__ | |
116 | ); | |
117 | } | |
118 | ||
119 | /** | |
120 | * Test civicrm_constant_get( 'locationType' ) | |
121 | */ | |
122 | public function testLocationTypeGet() { | |
123 | // needed to get rid of cached values from previous tests | |
124 | CRM_Core_PseudoConstant::flush('locationType'); | |
125 | ||
126 | ||
127 | ||
128 | $params = array( | |
129 | 'name' => 'locationType', | |
130 | 'version' => $this->_apiversion, | |
131 | ); | |
132 | $result = civicrm_api('constant', 'get', $params); | |
133 | $this->documentMe($params, $result, __FUNCTION__, __FILE__); | |
134 | $this->assertTrue($result['count'] > 3, "In line " . __LINE__); | |
135 | $this->assertContains('Home', $result['values'], "In line " . __LINE__); | |
136 | $this->assertContains('Work', $result['values'], "In line " . __LINE__); | |
137 | $this->assertContains('Main', $result['values'], "In line " . __LINE__); | |
138 | $this->assertContains('Billing', $result['values'], "In line " . __LINE__); | |
139 | $this->assertTrue(empty($result['is_error']), | |
140 | "In line " . __LINE__ | |
141 | ); | |
142 | } | |
143 | ||
144 | /** | |
145 | * Test civicrm_constant_get( 'phoneType' ) | |
146 | */ | |
147 | public function testPhoneType() { | |
148 | $parameters = array(TRUE, FALSE, TRUE); | |
149 | $result = civicrm_api('constant', 'get', array( | |
150 | 'name' => 'phoneType', | |
151 | 'version' => $this->_apiversion, | |
152 | )); | |
153 | ||
154 | $this->assertEquals(5, $result['count'], "In line " . __LINE__); | |
155 | $this->assertContains('Phone', $result['values'], "In line " . __LINE__); | |
156 | $this->assertContains('Mobile', $result['values'], "In line " . __LINE__); | |
157 | $this->assertContains('Fax', $result['values'], "In line " . __LINE__); | |
158 | $this->assertContains('Pager', $result['values'], "In line " . __LINE__); | |
159 | $this->assertContains('Voicemail', $result['values'], "In line " . __LINE__); | |
160 | ||
161 | $this->assertTrue(empty($result['is_error']), | |
162 | "In line " . __LINE__ | |
163 | ); | |
164 | } | |
165 | ||
166 | /** | |
167 | * Test civicrm_constant_get( 'mailProtocol' ) | |
168 | */ | |
169 | public function testmailProtocol() { | |
170 | ||
171 | ||
172 | $parameters = array(TRUE, FALSE, TRUE); | |
173 | ||
174 | $result = civicrm_api('constant', 'get', array( | |
175 | 'name' => 'mailProtocol', | |
176 | 'version' => $this->_apiversion, | |
177 | )); | |
178 | ||
179 | $this->assertEquals(4, $result['count'], "In line " . __LINE__); | |
180 | $this->assertContains('IMAP', $result['values'], "In line " . __LINE__); | |
181 | $this->assertContains('Maildir', $result['values'], "In line " . __LINE__); | |
182 | $this->assertContains('POP3', $result['values'], "In line " . __LINE__); | |
183 | $this->assertContains('Localdir', $result['values'], "In line " . __LINE__); | |
184 | $this->assertTrue(empty($result['is_error']), | |
185 | "In line " . __LINE__ | |
186 | ); | |
187 | } | |
188 | } |