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