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