5 +--------------------------------------------------------------------+
6 | CiviCRM version 4.3 |
7 +--------------------------------------------------------------------+
8 | Copyright CiviCRM LLC (c) 2004-2013 |
9 +--------------------------------------------------------------------+
10 | This file is a part of CiviCRM. |
12 | CiviCRM is free software; you can copy, modify, and distribute it |
13 | under the terms of the GNU Affero General Public License |
14 | Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
16 | CiviCRM is distributed in the hope that it will be useful, but |
17 | WITHOUT ANY WARRANTY; without even the implied warranty of |
18 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
19 | See the GNU Affero General Public License for more details. |
21 | You should have received a copy of the GNU Affero General Public |
22 | License and the CiviCRM Licensing Exception along |
23 | with this program; if not, contact CiviCRM LLC |
24 | at info[AT]civicrm[DOT]org. If you have questions about the |
25 | GNU Affero General Public License or the licensing of CiviCRM, |
26 | see the CiviCRM license FAQ at http://civicrm.org/licensing |
27 +--------------------------------------------------------------------+
30 require_once 'CiviTest/CiviUnitTestCase.php';
33 * Test class for Domain API - civicrm_domain_*
35 * @package CiviCRM_APIv3
36 * @subpackage API_Domain
38 class api_v3_DomainTest
extends CiviUnitTestCase
{
40 /* This test case doesn't require DB reset - apart from
41 where cleanDB() is called. */
45 public $DBResetRequired = FALSE;
47 protected $_apiversion = 3;
49 public $_eNoticeCompliant = TRUE;
54 * Initialize configuration
55 */ function __construct() {
56 parent
::__construct();
60 * Sets up the fixture, for example, opens a network connection.
61 * This method is called before a test is executed.
65 protected function setUp() {
68 // taken from form code - couldn't find good method to use
69 $params['entity_id'] = 1;
70 $params['entity_table'] = CRM_Core_BAO_Domain
::getTableName();
72 $defaultLocationType = CRM_Core_BAO_LocationType
::getDefault();
74 $domContact = civicrm_api('contact', 'create', array(
75 'version' => $this->_apiversion
,
76 'contact_type' => 'Organization',
77 'organization_name' => 'new org',
78 'api.phone.create' => array(
79 'location_type_id' => $defaultLocationType->id
,
83 'api.address.create' => array(
84 'location_type_id' => $defaultLocationType->id
,
85 'street_address' => '45 Penny Lane',
87 'api.email.create' => array(
88 'location_type_id' => $defaultLocationType->id
,
89 'email' => 'my@email.com',
94 civicrm_api('domain','create',array(
96 'contact_id' => $domContact['id'],
97 'version' => $this->_apiversion
100 $this->_apiversion
= 3;
101 $this->params
= array(
102 'name' => 'A-team domain',
103 'description' => 'domain of chaos',
104 'version' => $this->_apiversion
,
105 'domain_version' => '4.2',
106 'contact_id' => $domContact['id'],
111 * Tears down the fixture, for example, closes a network connection.
112 * This method is called after a test is executed.
116 protected function tearDown() {
120 ///////////////// civicrm_domain_get methods
123 * Test civicrm_domain_get. Takes no params.
124 * Testing mainly for format.
126 public function testGet() {
129 $params = array('version' => 3, 'sequential' => 1,);
130 $result = civicrm_api('domain', 'get', $params);
131 $this->documentMe($params, $result, __FUNCTION__
, __FILE__
);
133 $this->assertType('array', $result, 'In line' . __LINE__
);
135 $domain = $result['values'][0];
136 $this->assertEquals("info@EXAMPLE.ORG", $domain['from_email'], 'In line ' . __LINE__
);
137 $this->assertEquals("FIXME", $domain['from_name'], 'In line' . __LINE__
);
138 // checking other important parts of domain information
139 // test will fail if backward incompatible changes happen
140 $this->assertArrayHasKey('id', $domain, 'In line' . __LINE__
);
141 $this->assertArrayHasKey('name', $domain, 'In line' . __LINE__
);
142 $this->assertArrayHasKey('domain_email', $domain, 'In line' . __LINE__
);
143 $this->assertArrayHasKey('domain_phone', $domain, 'In line' . __LINE__
);
144 $this->assertArrayHasKey('domain_address', $domain, 'In line' . __LINE__
);
147 public function testGetCurrentDomain() {
148 $params = array('version' => 3, 'current_domain' => 1);
149 $result = civicrm_api('domain', 'get', $params);
151 $this->assertType('array', $result, 'In line' . __LINE__
);
153 foreach ($result['values'] as $key => $domain) {
154 if ($key == 'version') {
158 $this->assertEquals("info@EXAMPLE.ORG", $domain['from_email'], 'In line ' . __LINE__
);
159 $this->assertEquals("FIXME", $domain['from_name'], 'In line' . __LINE__
);
161 // checking other important parts of domain information
162 // test will fail if backward incompatible changes happen
163 $this->assertArrayHasKey('id', $domain, 'In line' . __LINE__
);
164 $this->assertArrayHasKey('name', $domain, 'In line' . __LINE__
);
165 $this->assertArrayHasKey('domain_email', $domain, 'In line' . __LINE__
);
166 $this->assertArrayHasKey('domain_phone', $domain, 'In line' . __LINE__
);
167 $this->assertArrayHasKey('domain_address', $domain, 'In line' . __LINE__
);
168 $this->assertEquals("my@email.com",$domain['domain_email']);
169 $this->assertEquals("456-456",$domain['domain_phone']['phone']);
170 $this->assertEquals("45 Penny Lane",$domain['domain_address']['street_address']);
174 ///////////////// civicrm_domain_create methods
176 * This test checks for a memory leak observed when doing 2 gets on current domain
181 public function testGetCurrentDomainTwice() {
182 $domain = civicrm_api('domain', 'getvalue', array(
184 'current_domain' => 1,
187 $this->assertEquals('Default Domain Name', $domain, print_r($domain, TRUE) . 'in line ' . __LINE__
);
188 $domain = civicrm_api('domain', 'getvalue', array(
190 'current_domain' => 1,
193 $this->assertEquals('Default Domain Name', $domain, print_r($domain, TRUE) . 'in line ' . __LINE__
);
197 * Test civicrm_domain_create.
199 public function testCreate() {
200 $result = civicrm_api('domain', 'create', $this->params
);
201 $this->documentMe($this->params
, $result, __FUNCTION__
, __FILE__
);
202 $this->assertEquals($result['is_error'], 0);
203 $this->assertEquals($result['count'], 1);
204 $this->assertNotNull($result['id']);
205 $this->assertEquals($result['values'][$result['id']]['name'], $this->params
['name']);
206 $this->assertEquals($result['values'][$result['id']]['version'], $this->params
['domain_version']);
210 * Test civicrm_domain_create with empty params.
213 public function testCreateWithEmptyParams() {
214 $params = array('version' => $this->_apiversion
);
215 $result = civicrm_api('domain', 'create', $params);
216 $this->assertEquals($result['is_error'], 1,
217 "In line " . __LINE__
222 * Test civicrm_domain_create with wrong parameter type.
224 public function testCreateWithWrongParams() {
226 $result = civicrm_api('domain', 'create', $params);
227 $this->assertEquals($result['is_error'], 1,
228 "In line " . __LINE__