4 +--------------------------------------------------------------------+
5 | CiviCRM version 4.3 |
6 +--------------------------------------------------------------------+
7 | Copyright CiviCRM LLC (c) 2004-2013 |
8 +--------------------------------------------------------------------+
9 | This file is a part of CiviCRM. |
11 | CiviCRM is free software; you can copy, modify, and distribute it |
12 | under the terms of the GNU Affero General Public License |
13 | Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
15 | CiviCRM is distributed in the hope that it will be useful, but |
16 | WITHOUT ANY WARRANTY; without even the implied warranty of |
17 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
18 | See the GNU Affero General Public License for more details. |
20 | You should have received a copy of the GNU Affero General Public |
21 | License and the CiviCRM Licensing Exception along |
22 | with this program; if not, contact CiviCRM LLC |
23 | at info[AT]civicrm[DOT]org. If you have questions about the |
24 | GNU Affero General Public License or the licensing of CiviCRM, |
25 | see the CiviCRM license FAQ at http://civicrm.org/licensing |
26 +--------------------------------------------------------------------+
29 require_once 'CiviTest/CiviUnitTestCase.php';
32 * Test class for Domain API - civicrm_domain_*
34 * @package CiviCRM_APIv3
35 * @subpackage API_Domain
37 class api_v3_DomainTest
extends CiviUnitTestCase
{
39 /* This test case doesn't require DB reset - apart from
40 where cleanDB() is called. */
44 public $DBResetRequired = FALSE;
46 protected $_apiversion = 3;
48 public $_eNoticeCompliant = TRUE;
53 * Initialize configuration
54 */ function __construct() {
55 parent
::__construct();
59 * Sets up the fixture, for example, opens a network connection.
60 * This method is called before a test is executed.
64 protected function setUp() {
67 // taken from form code - couldn't find good method to use
68 $params['entity_id'] = 1;
69 $params['entity_table'] = CRM_Core_BAO_Domain
::getTableName();
71 $defaultLocationType = CRM_Core_BAO_LocationType
::getDefault();
73 $domContact = civicrm_api('contact', 'create', array(
74 'version' => $this->_apiversion
,
75 'contact_type' => 'Organization',
76 'organization_name' => 'new org',
77 'api.phone.create' => array(
78 'location_type_id' => $defaultLocationType->id
,
82 'api.address.create' => array(
83 'location_type_id' => $defaultLocationType->id
,
84 'street_address' => '45 Penny Lane',
86 'api.email.create' => array(
87 'location_type_id' => $defaultLocationType->id
,
88 'email' => 'my@email.com',
93 civicrm_api('domain','create',array(
95 'contact_id' => $domContact['id'],
96 'version' => $this->_apiversion
99 $this->_apiversion
= 3;
100 $this->params
= array(
101 'name' => 'A-team domain',
102 'description' => 'domain of chaos',
103 'version' => $this->_apiversion
,
104 'domain_version' => '4.2',
105 'contact_id' => $domContact['id'],
110 * Tears down the fixture, for example, closes a network connection.
111 * This method is called after a test is executed.
115 protected function tearDown() {
119 ///////////////// civicrm_domain_get methods
122 * Test civicrm_domain_get. Takes no params.
123 * Testing mainly for format.
125 public function testGet() {
128 $params = array('version' => 3, 'sequential' => 1,);
129 $result = civicrm_api('domain', 'get', $params);
130 $this->documentMe($params, $result, __FUNCTION__
, __FILE__
);
132 $this->assertType('array', $result, 'In line' . __LINE__
);
134 $domain = $result['values'][0];
135 $this->assertEquals("info@EXAMPLE.ORG", $domain['from_email'], 'In line ' . __LINE__
);
136 $this->assertEquals("FIXME", $domain['from_name'], 'In line' . __LINE__
);
137 // checking other important parts of domain information
138 // test will fail if backward incompatible changes happen
139 $this->assertArrayHasKey('id', $domain, 'In line' . __LINE__
);
140 $this->assertArrayHasKey('name', $domain, 'In line' . __LINE__
);
141 $this->assertArrayHasKey('domain_email', $domain, 'In line' . __LINE__
);
142 $this->assertArrayHasKey('domain_phone', $domain, 'In line' . __LINE__
);
143 $this->assertArrayHasKey('domain_address', $domain, 'In line' . __LINE__
);
146 public function testGetCurrentDomain() {
147 $params = array('version' => 3, 'current_domain' => 1);
148 $result = civicrm_api('domain', 'get', $params);
150 $this->assertType('array', $result, 'In line' . __LINE__
);
152 foreach ($result['values'] as $key => $domain) {
153 if ($key == 'version') {
157 $this->assertEquals("info@EXAMPLE.ORG", $domain['from_email'], 'In line ' . __LINE__
);
158 $this->assertEquals("FIXME", $domain['from_name'], 'In line' . __LINE__
);
160 // checking other important parts of domain information
161 // test will fail if backward incompatible changes happen
162 $this->assertArrayHasKey('id', $domain, 'In line' . __LINE__
);
163 $this->assertArrayHasKey('name', $domain, 'In line' . __LINE__
);
164 $this->assertArrayHasKey('domain_email', $domain, 'In line' . __LINE__
);
165 $this->assertArrayHasKey('domain_phone', $domain, 'In line' . __LINE__
);
166 $this->assertArrayHasKey('domain_address', $domain, 'In line' . __LINE__
);
167 $this->assertEquals("my@email.com",$domain['domain_email']);
168 $this->assertEquals("456-456",$domain['domain_phone']['phone']);
169 $this->assertEquals("45 Penny Lane",$domain['domain_address']['street_address']);
173 ///////////////// civicrm_domain_create methods
175 * This test checks for a memory leak observed when doing 2 gets on current domain
180 public function testGetCurrentDomainTwice() {
181 $domain = civicrm_api('domain', 'getvalue', array(
183 'current_domain' => 1,
186 $this->assertEquals('Default Domain Name', $domain, print_r($domain, TRUE) . 'in line ' . __LINE__
);
187 $domain = civicrm_api('domain', 'getvalue', array(
189 'current_domain' => 1,
192 $this->assertEquals('Default Domain Name', $domain, print_r($domain, TRUE) . 'in line ' . __LINE__
);
196 * Test civicrm_domain_create.
198 public function testCreate() {
199 $result = civicrm_api('domain', 'create', $this->params
);
200 $this->documentMe($this->params
, $result, __FUNCTION__
, __FILE__
);
201 $this->assertAPISuccess($result);
202 $this->assertEquals($result['count'], 1);
203 $this->assertNotNull($result['id']);
204 $this->assertEquals($result['values'][$result['id']]['name'], $this->params
['name']);
205 $this->assertEquals($result['values'][$result['id']]['version'], $this->params
['domain_version']);
209 * Test civicrm_domain_create with empty params.
212 public function testCreateWithEmptyParams() {
213 $params = array('version' => $this->_apiversion
);
214 $result = civicrm_api('domain', 'create', $params);
215 $this->assertAPIFailure($result,
216 "In line " . __LINE__
221 * Test civicrm_domain_create with wrong parameter type.
223 public function testCreateWithWrongParams() {
225 $result = civicrm_api('domain', 'create', $params);
226 $this->assertAPIFailure($result,
227 "In line " . __LINE__