3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.7 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2016 |
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 +--------------------------------------------------------------------+
29 * Test class for Domain API - civicrm_domain_*
31 * @package CiviCRM_APIv3
32 * @subpackage API_Domain
35 class api_v3_DomainTest
extends CiviUnitTestCase
{
37 /* This test case doesn't require DB reset - apart from
38 where cleanDB() is called. */
40 public $DBResetRequired = FALSE;
42 protected $_apiversion = 3;
46 * Sets up the fixture, for example, opens a network connection.
48 * This method is called before a test is executed.
50 protected function setUp() {
52 $this->useTransaction(TRUE);
54 // taken from form code - couldn't find good method to use
55 $params['entity_id'] = 1;
56 $params['entity_table'] = CRM_Core_BAO_Domain
::getTableName();
57 $defaultLocationType = CRM_Core_BAO_LocationType
::getDefault();
58 $domContact = $this->callAPISuccess('contact', 'create', array(
59 'contact_type' => 'Organization',
60 'organization_name' => 'new org',
61 'api.phone.create' => array(
62 'location_type_id' => $defaultLocationType->id
,
66 'api.address.create' => array(
67 'location_type_id' => $defaultLocationType->id
,
68 'street_address' => '45 Penny Lane',
70 'api.email.create' => array(
71 'location_type_id' => $defaultLocationType->id
,
72 'email' => 'my@email.com',
77 $this->callAPISuccess('domain', 'create', array(
79 'contact_id' => $domContact['id'],
82 $this->params
= array(
83 'name' => 'A-team domain',
84 'description' => 'domain of chaos',
85 'domain_version' => '4.2',
86 'contact_id' => $domContact['id'],
91 * Test civicrm_domain_get.
94 * Testing mainly for format.
96 public function testGet() {
98 $params = array('sequential' => 1);
99 $result = $this->callAPIAndDocument('domain', 'get', $params, __FUNCTION__
, __FILE__
);
101 $this->assertType('array', $result);
103 $domain = $result['values'][0];
104 $this->assertEquals("info@EXAMPLE.ORG", $domain['from_email']);
105 $this->assertEquals("FIXME", $domain['from_name']);
106 // checking other important parts of domain information
107 // test will fail if backward incompatible changes happen
108 $this->assertArrayHasKey('id', $domain);
109 $this->assertArrayHasKey('name', $domain);
110 $this->assertArrayHasKey('domain_email', $domain);
111 $this->assertEquals(array(
112 'phone_type' => 'Phone',
113 'phone' => '456-456',
114 ), $domain['domain_phone']);
115 $this->assertArrayHasKey('domain_address', $domain);
119 * Test get function with current domain.
121 public function testGetCurrentDomain() {
122 $params = array('current_domain' => 1);
123 $result = $this->callAPISuccess('domain', 'get', $params);
125 $this->assertType('array', $result);
127 foreach ($result['values'] as $key => $domain) {
128 if ($key == 'version') {
132 $this->assertEquals("info@EXAMPLE.ORG", $domain['from_email']);
133 $this->assertEquals("FIXME", $domain['from_name']);
135 // checking other important parts of domain information
136 // test will fail if backward incompatible changes happen
137 $this->assertArrayHasKey('id', $domain);
138 $this->assertArrayHasKey('name', $domain);
139 $this->assertArrayHasKey('domain_email', $domain);
140 $this->assertArrayHasKey('domain_phone', $domain);
141 $this->assertArrayHasKey('domain_address', $domain);
142 $this->assertEquals("my@email.com", $domain['domain_email']);
143 $this->assertEquals("456-456", $domain['domain_phone']['phone']);
144 $this->assertEquals("45 Penny Lane", $domain['domain_address']['street_address']);
149 * This test checks for a memory leak.
151 * The leak was observed when doing 2 gets on current domain.
153 public function testGetCurrentDomainTwice() {
154 $domain = $this->callAPISuccess('domain', 'getvalue', array(
155 'current_domain' => 1,
158 $this->assertEquals('Default Domain Name', $domain, print_r($domain, TRUE));
159 $domain = $this->callAPISuccess('domain', 'getvalue', array(
160 'current_domain' => 1,
163 $this->assertEquals('Default Domain Name', $domain, print_r($domain, TRUE));
167 * Test civicrm_domain_create.
169 public function testCreate() {
170 $result = $this->callAPIAndDocument('domain', 'create', $this->params
, __FUNCTION__
, __FILE__
);
171 $this->assertEquals($result['count'], 1);
172 $this->assertNotNull($result['id']);
173 $this->assertEquals($result['values'][$result['id']]['name'], $this->params
['name']);
174 $this->assertEquals($result['values'][$result['id']]['domain_version'], $this->params
['domain_version']);
178 * Test if Domain.create does not touch the version of the domain.
182 public function testUpdateDomainName() {
183 // First create a domain.
184 $domain_result = $this->callAPISuccess('domain', 'create', $this->params
);
185 $domain_before = $this->callAPISuccess('Domain', 'getsingle', array('id' => $domain_result['id']));
187 // Change domain name.
188 $this->callAPISuccess('Domain', 'create', array(
189 'id' => $domain_result['id'],
190 'name' => 'B-Team domain',
194 $domain_after = $this->callAPISuccess('Domain', 'getsingle', array('id' => $domain_result['id']));
196 // Version should still be the same.
197 $this->assertEquals($domain_before['version'], $domain_after['version']);
201 * Test whether Domain.create returns a correct value for domain_version.
205 public function testCreateDomainResult() {
206 // First create a domain.
207 $domain_result = $this->callAPISuccess('Domain', 'create', $this->params
);
208 $result_value = CRM_Utils_Array
::first($domain_result['values']);
210 // Check for domain_version in create result.
211 $this->assertEquals($this->params
['domain_version'], $result_value['domain_version']);
215 * Test civicrm_domain_create with empty params.
219 public function testCreateWithEmptyParams() {
220 $this->callAPIFailure('domain', 'create', array());