3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.5 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2014 |
7 +--------------------------------------------------------------------+
8 | This file is a part of CiviCRM. |
10 | CiviCRM is free software; you can copy, modify, and distribute it |
11 | under the terms of the GNU Affero General Public License |
12 | Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
14 | CiviCRM is distributed in the hope that it will be useful, but |
15 | WITHOUT ANY WARRANTY; without even the implied warranty of |
16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
17 | See the GNU Affero General Public License for more details. |
19 | You should have received a copy of the GNU Affero General Public |
20 | License and the CiviCRM Licensing Exception along |
21 | with this program; if not, contact CiviCRM LLC |
22 | at info[AT]civicrm[DOT]org. If you have questions about the |
23 | GNU Affero General Public License or the licensing of CiviCRM, |
24 | see the CiviCRM license FAQ at http://civicrm.org/licensing |
25 +--------------------------------------------------------------------+
28 require_once 'CiviTest/CiviUnitTestCase.php';
31 * Test class for Domain API - civicrm_domain_*
33 * @package CiviCRM_APIv3
34 * @subpackage API_Domain
36 class api_v3_DomainTest
extends CiviUnitTestCase
{
38 /* This test case doesn't require DB reset - apart from
39 where cleanDB() is called. */
43 public $DBResetRequired = FALSE;
45 protected $_apiversion = 3;
52 * Initialize configuration
53 */ function __construct() {
54 parent
::__construct();
58 * Sets up the fixture, for example, opens a network connection.
59 * This method is called before a test is executed.
63 protected function setUp() {
66 // taken from form code - couldn't find good method to use
67 $params['entity_id'] = 1;
68 $params['entity_table'] = CRM_Core_BAO_Domain
::getTableName();
70 $defaultLocationType = CRM_Core_BAO_LocationType
::getDefault();
72 $domContact = $this->callAPISuccess('contact', 'create', array(
73 'contact_type' => 'Organization',
74 'organization_name' => 'new org',
75 'api.phone.create' => array(
76 'location_type_id' => $defaultLocationType->id
,
80 'api.address.create' => array(
81 'location_type_id' => $defaultLocationType->id
,
82 'street_address' => '45 Penny Lane',
84 'api.email.create' => array(
85 'location_type_id' => $defaultLocationType->id
,
86 'email' => 'my@email.com',
91 $this->callAPISuccess('domain','create',array(
93 'contact_id' => $domContact['id'],
96 $this->params
= array(
97 'name' => 'A-team domain',
98 'description' => 'domain of chaos',
99 'domain_version' => '4.2',
100 'contact_id' => $domContact['id'],
105 * Tears down the fixture, for example, closes a network connection.
106 * This method is called after a test is executed.
110 protected function tearDown() {
114 ///////////////// civicrm_domain_get methods
117 * Test civicrm_domain_get. Takes no params.
118 * Testing mainly for format.
120 public function testGet() {
122 $params = array('sequential' => 1,);
123 $result = $this->callAPIAndDocument('domain', 'get', $params, __FUNCTION__
, __FILE__
);
125 $this->assertType('array', $result);
127 $domain = $result['values'][0];
128 $this->assertEquals("info@EXAMPLE.ORG", $domain['from_email'], 'In line ' . __LINE__
);
129 $this->assertEquals("FIXME", $domain['from_name']);
130 // checking other important parts of domain information
131 // test will fail if backward incompatible changes happen
132 $this->assertArrayHasKey('id', $domain);
133 $this->assertArrayHasKey('name', $domain);
134 $this->assertArrayHasKey('domain_email', $domain);
135 $this->assertArrayHasKey('domain_phone', $domain);
136 $this->assertArrayHasKey('domain_address', $domain);
139 public function testGetCurrentDomain() {
140 $params = array('current_domain' => 1);
141 $result = $this->callAPISuccess('domain', 'get', $params);
143 $this->assertType('array', $result);
145 foreach ($result['values'] as $key => $domain) {
146 if ($key == 'version') {
150 $this->assertEquals("info@EXAMPLE.ORG", $domain['from_email'], 'In line ' . __LINE__
);
151 $this->assertEquals("FIXME", $domain['from_name']);
153 // checking other important parts of domain information
154 // test will fail if backward incompatible changes happen
155 $this->assertArrayHasKey('id', $domain);
156 $this->assertArrayHasKey('name', $domain);
157 $this->assertArrayHasKey('domain_email', $domain);
158 $this->assertArrayHasKey('domain_phone', $domain);
159 $this->assertArrayHasKey('domain_address', $domain);
160 $this->assertEquals("my@email.com",$domain['domain_email']);
161 $this->assertEquals("456-456",$domain['domain_phone']['phone']);
162 $this->assertEquals("45 Penny Lane",$domain['domain_address']['street_address']);
166 ///////////////// civicrm_domain_create methods
168 * This test checks for a memory leak observed when doing 2 gets on current domain
173 public function testGetCurrentDomainTwice() {
174 $domain = $this->callAPISuccess('domain', 'getvalue', array(
175 'current_domain' => 1,
178 $this->assertEquals('Default Domain Name', $domain, print_r($domain, TRUE));
179 $domain = $this->callAPISuccess('domain', 'getvalue', array(
180 'current_domain' => 1,
183 $this->assertEquals('Default Domain Name', $domain, print_r($domain, TRUE));
187 * Test civicrm_domain_create.
189 public function testCreate() {
190 $result = $this->callAPIAndDocument('domain', 'create', $this->params
, __FUNCTION__
, __FILE__
);
191 $this->assertEquals($result['count'], 1);
192 $this->assertNotNull($result['id']);
193 $this->assertEquals($result['values'][$result['id']]['name'], $this->params
['name']);
194 $this->assertEquals($result['values'][$result['id']]['version'], $this->params
['domain_version']);
198 * Test civicrm_domain_create with empty params.
201 public function testCreateWithEmptyParams() {
202 $result = $this->callAPIFailure('domain', 'create', array());