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