Commit | Line | Data |
---|---|---|
6a488035 | 1 | <?php |
6a488035 TO |
2 | /* |
3 | +--------------------------------------------------------------------+ | |
39de6fd5 | 4 | | CiviCRM version 4.6 | |
6a488035 | 5 | +--------------------------------------------------------------------+ |
e7112fa7 | 6 | | Copyright CiviCRM LLC (c) 2004-2015 | |
6a488035 TO |
7 | +--------------------------------------------------------------------+ |
8 | | This file is a part of CiviCRM. | | |
9 | | | | |
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. | | |
13 | | | | |
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. | | |
18 | | | | |
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 | +--------------------------------------------------------------------+ | |
d25dd0ee | 26 | */ |
6a488035 TO |
27 | |
28 | require_once 'CiviTest/CiviUnitTestCase.php'; | |
29 | ||
30 | /** | |
31 | * Test class for Domain API - civicrm_domain_* | |
32 | * | |
6c6e6187 TO |
33 | * @package CiviCRM_APIv3 |
34 | * @subpackage API_Domain | |
6a488035 TO |
35 | */ |
36 | class api_v3_DomainTest extends CiviUnitTestCase { | |
37 | ||
38 | /* This test case doesn't require DB reset - apart from | |
e70a7fc0 | 39 | where cleanDB() is called. */ |
6a488035 TO |
40 | |
41 | ||
6a488035 TO |
42 | public $DBResetRequired = FALSE; |
43 | ||
44 | protected $_apiversion = 3; | |
45 | protected $params; | |
b7c9bc4c | 46 | |
6a488035 TO |
47 | /** |
48 | * Sets up the fixture, for example, opens a network connection. | |
fe482240 | 49 | * |
6a488035 | 50 | * This method is called before a test is executed. |
6a488035 TO |
51 | */ |
52 | protected function setUp() { | |
53 | parent::setUp(); | |
66c8c250 | 54 | $this->useTransaction(TRUE); |
6a488035 TO |
55 | |
56 | // taken from form code - couldn't find good method to use | |
57 | $params['entity_id'] = 1; | |
58 | $params['entity_table'] = CRM_Core_BAO_Domain::getTableName(); | |
59 | $domain = 1; | |
60 | $defaultLocationType = CRM_Core_BAO_LocationType::getDefault(); | |
61 | $location = array(); | |
fc928539 | 62 | $domContact = $this->callAPISuccess('contact', 'create', array( |
5896d037 TO |
63 | 'contact_type' => 'Organization', |
64 | 'organization_name' => 'new org', | |
65 | 'api.phone.create' => array( | |
66 | 'location_type_id' => $defaultLocationType->id, | |
67 | 'phone_type_id' => 1, | |
68 | 'phone' => '456-456', | |
6a488035 | 69 | ), |
5896d037 TO |
70 | 'api.address.create' => array( |
71 | 'location_type_id' => $defaultLocationType->id, | |
72 | 'street_address' => '45 Penny Lane', | |
73 | ), | |
74 | 'api.email.create' => array( | |
75 | 'location_type_id' => $defaultLocationType->id, | |
76 | 'email' => 'my@email.com', | |
21dfd5f5 | 77 | ), |
6a488035 TO |
78 | ) |
79 | ); | |
80 | ||
6c6e6187 | 81 | $this->callAPISuccess('domain', 'create', array( |
5896d037 TO |
82 | 'id' => 1, |
83 | 'contact_id' => $domContact['id'], | |
6a488035 TO |
84 | ) |
85 | ); | |
6a488035 TO |
86 | $this->params = array( |
87 | 'name' => 'A-team domain', | |
88 | 'description' => 'domain of chaos', | |
6a488035 TO |
89 | 'domain_version' => '4.2', |
90 | 'contact_id' => $domContact['id'], | |
91 | ); | |
92 | } | |
93 | ||
6a488035 | 94 | /** |
fe482240 EM |
95 | * Test civicrm_domain_get. |
96 | * | |
97 | * Takes no params. | |
6a488035 TO |
98 | * Testing mainly for format. |
99 | */ | |
100 | public function testGet() { | |
101 | ||
6c6e6187 | 102 | $params = array('sequential' => 1); |
fc928539 | 103 | $result = $this->callAPIAndDocument('domain', 'get', $params, __FUNCTION__, __FILE__); |
6a488035 | 104 | |
38af8710 | 105 | $this->assertType('array', $result); |
6a488035 TO |
106 | |
107 | $domain = $result['values'][0]; | |
ba4a1892 | 108 | $this->assertEquals("info@EXAMPLE.ORG", $domain['from_email']); |
38af8710 | 109 | $this->assertEquals("FIXME", $domain['from_name']); |
6a488035 TO |
110 | // checking other important parts of domain information |
111 | // test will fail if backward incompatible changes happen | |
38af8710 EM |
112 | $this->assertArrayHasKey('id', $domain); |
113 | $this->assertArrayHasKey('name', $domain); | |
114 | $this->assertArrayHasKey('domain_email', $domain); | |
115 | $this->assertArrayHasKey('domain_phone', $domain); | |
116 | $this->assertArrayHasKey('domain_address', $domain); | |
6a488035 TO |
117 | } |
118 | ||
119 | public function testGetCurrentDomain() { | |
fc928539 | 120 | $params = array('current_domain' => 1); |
121 | $result = $this->callAPISuccess('domain', 'get', $params); | |
6a488035 | 122 | |
38af8710 | 123 | $this->assertType('array', $result); |
6a488035 TO |
124 | |
125 | foreach ($result['values'] as $key => $domain) { | |
126 | if ($key == 'version') { | |
127 | continue; | |
128 | } | |
129 | ||
ba4a1892 | 130 | $this->assertEquals("info@EXAMPLE.ORG", $domain['from_email']); |
38af8710 | 131 | $this->assertEquals("FIXME", $domain['from_name']); |
6a488035 TO |
132 | |
133 | // checking other important parts of domain information | |
134 | // test will fail if backward incompatible changes happen | |
38af8710 EM |
135 | $this->assertArrayHasKey('id', $domain); |
136 | $this->assertArrayHasKey('name', $domain); | |
137 | $this->assertArrayHasKey('domain_email', $domain); | |
138 | $this->assertArrayHasKey('domain_phone', $domain); | |
139 | $this->assertArrayHasKey('domain_address', $domain); | |
6c6e6187 TO |
140 | $this->assertEquals("my@email.com", $domain['domain_email']); |
141 | $this->assertEquals("456-456", $domain['domain_phone']['phone']); | |
142 | $this->assertEquals("45 Penny Lane", $domain['domain_address']['street_address']); | |
6a488035 TO |
143 | } |
144 | } | |
145 | ||
146 | ///////////////// civicrm_domain_create methods | |
a1a2a83d TO |
147 | |
148 | /** | |
e70a7fc0 TO |
149 | * This test checks for a memory leak observed when doing 2 gets on current domain |
150 | */ | |
6a488035 | 151 | public function testGetCurrentDomainTwice() { |
fc928539 | 152 | $domain = $this->callAPISuccess('domain', 'getvalue', array( |
5896d037 TO |
153 | 'current_domain' => 1, |
154 | 'return' => 'name', | |
155 | )); | |
38af8710 | 156 | $this->assertEquals('Default Domain Name', $domain, print_r($domain, TRUE)); |
fc928539 | 157 | $domain = $this->callAPISuccess('domain', 'getvalue', array( |
5896d037 TO |
158 | 'current_domain' => 1, |
159 | 'return' => 'name', | |
160 | )); | |
38af8710 | 161 | $this->assertEquals('Default Domain Name', $domain, print_r($domain, TRUE)); |
6a488035 TO |
162 | } |
163 | ||
164 | /** | |
165 | * Test civicrm_domain_create. | |
166 | */ | |
167 | public function testCreate() { | |
fc928539 | 168 | $result = $this->callAPIAndDocument('domain', 'create', $this->params, __FUNCTION__, __FILE__); |
6a488035 TO |
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']); | |
173 | } | |
174 | ||
175 | /** | |
176 | * Test civicrm_domain_create with empty params. | |
fe482240 | 177 | * |
6a488035 TO |
178 | * Error expected. |
179 | */ | |
180 | public function testCreateWithEmptyParams() { | |
fe482240 | 181 | $this->callAPIFailure('domain', 'create', array()); |
6a488035 | 182 | } |
96025800 | 183 | |
6a488035 | 184 | } |