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