3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.6 |
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. */
42 public $DBResetRequired = FALSE;
44 protected $_apiversion = 3;
48 * Sets up the fixture, for example, opens a network connection.
49 * This method is called before a test is executed.
51 protected function setUp() {
53 $this->useTransaction(TRUE);
55 // taken from form code - couldn't find good method to use
56 $params['entity_id'] = 1;
57 $params['entity_table'] = CRM_Core_BAO_Domain
::getTableName();
59 $defaultLocationType = CRM_Core_BAO_LocationType
::getDefault();
61 $domContact = $this->callAPISuccess('contact', 'create', array(
62 'contact_type' => 'Organization',
63 'organization_name' => 'new org',
64 'api.phone.create' => array(
65 'location_type_id' => $defaultLocationType->id
,
69 'api.address.create' => array(
70 'location_type_id' => $defaultLocationType->id
,
71 'street_address' => '45 Penny Lane',
73 'api.email.create' => array(
74 'location_type_id' => $defaultLocationType->id
,
75 'email' => 'my@email.com',
80 $this->callAPISuccess('domain', 'create', array(
82 'contact_id' => $domContact['id'],
85 $this->params
= array(
86 'name' => 'A-team domain',
87 'description' => 'domain of chaos',
88 'domain_version' => '4.2',
89 'contact_id' => $domContact['id'],
93 ///////////////// civicrm_domain_get methods
96 * Test civicrm_domain_get. Takes no params.
97 * Testing mainly for format.
99 public function testGet() {
101 $params = array('sequential' => 1);
102 $result = $this->callAPIAndDocument('domain', 'get', $params, __FUNCTION__
, __FILE__
);
104 $this->assertType('array', $result);
106 $domain = $result['values'][0];
107 $this->assertEquals("info@EXAMPLE.ORG", $domain['from_email'], 'In line ' . __LINE__
);
108 $this->assertEquals("FIXME", $domain['from_name']);
109 // checking other important parts of domain information
110 // test will fail if backward incompatible changes happen
111 $this->assertArrayHasKey('id', $domain);
112 $this->assertArrayHasKey('name', $domain);
113 $this->assertArrayHasKey('domain_email', $domain);
114 $this->assertArrayHasKey('domain_phone', $domain);
115 $this->assertArrayHasKey('domain_address', $domain);
118 public function testGetCurrentDomain() {
119 $params = array('current_domain' => 1);
120 $result = $this->callAPISuccess('domain', 'get', $params);
122 $this->assertType('array', $result);
124 foreach ($result['values'] as $key => $domain) {
125 if ($key == 'version') {
129 $this->assertEquals("info@EXAMPLE.ORG", $domain['from_email'], 'In line ' . __LINE__
);
130 $this->assertEquals("FIXME", $domain['from_name']);
132 // checking other important parts of domain information
133 // test will fail if backward incompatible changes happen
134 $this->assertArrayHasKey('id', $domain);
135 $this->assertArrayHasKey('name', $domain);
136 $this->assertArrayHasKey('domain_email', $domain);
137 $this->assertArrayHasKey('domain_phone', $domain);
138 $this->assertArrayHasKey('domain_address', $domain);
139 $this->assertEquals("my@email.com", $domain['domain_email']);
140 $this->assertEquals("456-456", $domain['domain_phone']['phone']);
141 $this->assertEquals("45 Penny Lane", $domain['domain_address']['street_address']);
145 ///////////////// civicrm_domain_create methods
147 * This test checks for a memory leak observed when doing 2 gets on current domain
151 public function testGetCurrentDomainTwice() {
152 $domain = $this->callAPISuccess('domain', 'getvalue', array(
153 'current_domain' => 1,
156 $this->assertEquals('Default Domain Name', $domain, print_r($domain, TRUE));
157 $domain = $this->callAPISuccess('domain', 'getvalue', array(
158 'current_domain' => 1,
161 $this->assertEquals('Default Domain Name', $domain, print_r($domain, TRUE));
165 * Test civicrm_domain_create.
167 public function testCreate() {
168 $result = $this->callAPIAndDocument('domain', 'create', $this->params
, __FUNCTION__
, __FILE__
);
169 $this->assertEquals($result['count'], 1);
170 $this->assertNotNull($result['id']);
171 $this->assertEquals($result['values'][$result['id']]['name'], $this->params
['name']);
172 $this->assertEquals($result['values'][$result['id']]['version'], $this->params
['domain_version']);
176 * Test civicrm_domain_create with empty params.
179 public function testCreateWithEmptyParams() {
180 $result = $this->callAPIFailure('domain', 'create', array());