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