Merge pull request #13180 from GinkgoFJG/dev/core#559
[civicrm-core.git] / tests / phpunit / api / v3 / ConstantTest.php
CommitLineData
6a488035
TO
1<?php
2/**
3 * File for the TestConstant class
4 *
5 * (PHP 5)
6 *
6c6e6187
TO
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
6a488035 10 * GNU Affero General Public License version 3
6c6e6187
TO
11 * @version $Id: ConstantTest.php 31254 2010-12-15 10:09:29Z eileen $
12 * @package CiviCRM_APIv3
13 * @subpackage API_Constant
6a488035
TO
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
6a488035
TO
32/**
33 * Test APIv3 civicrm_activity_* functions
34 *
6c6e6187
TO
35 * @package CiviCRM_APIv3
36 * @subpackage API_Constant
acb109b7 37 * @group headless
6a488035
TO
38 */
39class api_v3_ConstantTest extends CiviUnitTestCase {
40 protected $_apiversion = 3;
b7c9bc4c 41
6a488035 42 /**
eceb18cc 43 * Test setup for every test.
6a488035 44 *
d177a2a6
EM
45 * Connect to the database, truncate the tables that will be used
46 * and redirect stdin to a temporary file
6a488035
TO
47 */
48 public function setUp() {
49 // Connect to the database
50 parent::setUp();
51 $this->_apiversion = 3;
52 }
53
54 /**
d177a2a6 55 * Test civicrm_constant_get( ) for unknown constant
6a488035
TO
56 */
57 public function testUnknownConstant() {
fc928539 58 $result = $this->callAPIFailure('constant', 'get', array(
6a488035 59 'name' => 'thisTypeDoesNotExist',
fc928539 60 ));
6a488035
TO
61 }
62
63 /**
d177a2a6 64 * Test civicrm_constant_get( 'activityStatus' )
6a488035
TO
65 */
66 public function testActivityStatus() {
67
fc928539 68 $result = $this->callAPISuccess('constant', 'get', array(
6a488035 69 'name' => 'activityStatus',
fc928539 70 ));
6a488035
TO
71
72 $this->assertTrue($result['count'] > 5, "In line " . __LINE__);
73 $this->assertContains('Scheduled', $result['values'], "In line " . __LINE__);
74 $this->assertContains('Completed', $result['values'], "In line " . __LINE__);
75 $this->assertContains('Cancelled', $result['values'], "In line " . __LINE__);
76
6a488035
TO
77 }
78
79 /**
d177a2a6 80 * Test civicrm_constant_get( 'activityType' )
6a488035
TO
81 */
82 public function testActivityType() {
a6ec24c4 83 $result = $this->callAPIAndDocument('constant', 'get', array(
6a488035 84 'name' => 'activityType',
a6ec24c4 85 ), __FUNCTION__, __FILE__, NULL, NULL, 'get');
6a488035
TO
86 $this->assertTrue($result['count'] > 2, "In line " . __LINE__);
87 $this->assertContains('Meeting', $result['values'], "In line " . __LINE__);
6a488035
TO
88 }
89
90 /**
d177a2a6 91 * Test civicrm_address_getoptions( 'location_type_id' )
6a488035
TO
92 */
93 public function testLocationTypeGet() {
94 // needed to get rid of cached values from previous tests
2683ce94 95 CRM_Core_PseudoConstant::flush();
6a488035 96
6a488035 97 $params = array(
1f4bb601 98 'field' => 'location_type_id',
6a488035 99 );
a828d7b8 100 $result = $this->callAPIAndDocument('address', 'getoptions', $params, __FUNCTION__, __FILE__);
6a488035
TO
101 $this->assertTrue($result['count'] > 3, "In line " . __LINE__);
102 $this->assertContains('Home', $result['values'], "In line " . __LINE__);
103 $this->assertContains('Work', $result['values'], "In line " . __LINE__);
104 $this->assertContains('Main', $result['values'], "In line " . __LINE__);
105 $this->assertContains('Billing', $result['values'], "In line " . __LINE__);
6a488035
TO
106 }
107
108 /**
d177a2a6 109 * Test civicrm_phone_getoptions( 'phone_type_id' )
6a488035
TO
110 */
111 public function testPhoneType() {
1f4bb601
CW
112 $params = array(
113 'field' => 'phone_type_id',
1f4bb601 114 );
a828d7b8 115 $result = $this->callAPIAndDocument('phone', 'getoptions', $params, __FUNCTION__, __FILE__);
6a488035
TO
116
117 $this->assertEquals(5, $result['count'], "In line " . __LINE__);
118 $this->assertContains('Phone', $result['values'], "In line " . __LINE__);
119 $this->assertContains('Mobile', $result['values'], "In line " . __LINE__);
120 $this->assertContains('Fax', $result['values'], "In line " . __LINE__);
121 $this->assertContains('Pager', $result['values'], "In line " . __LINE__);
122 $this->assertContains('Voicemail', $result['values'], "In line " . __LINE__);
6a488035
TO
123 }
124
125 /**
d177a2a6 126 * Test civicrm_constant_get( 'mailProtocol' )
6a488035
TO
127 */
128 public function testmailProtocol() {
1f4bb601
CW
129 $params = array(
130 'field' => 'protocol',
1f4bb601 131 );
a828d7b8 132 $result = $this->callAPIAndDocument('mail_settings', 'getoptions', $params, __FUNCTION__, __FILE__);
6a488035
TO
133
134 $this->assertEquals(4, $result['count'], "In line " . __LINE__);
135 $this->assertContains('IMAP', $result['values'], "In line " . __LINE__);
136 $this->assertContains('Maildir', $result['values'], "In line " . __LINE__);
137 $this->assertContains('POP3', $result['values'], "In line " . __LINE__);
138 $this->assertContains('Localdir', $result['values'], "In line " . __LINE__);
6a488035 139 }
96025800 140
6a488035 141}