CRM-13072 upgrade Paritipant Payment test classes to pass
[civicrm-core.git] / tests / phpunit / api / v3 / DomainTest.php
1 <?php
2
3 /*
4 +--------------------------------------------------------------------+
5 | CiviCRM version 4.3 |
6 +--------------------------------------------------------------------+
7 | Copyright CiviCRM LLC (c) 2004-2013 |
8 +--------------------------------------------------------------------+
9 | This file is a part of CiviCRM. |
10 | |
11 | CiviCRM is free software; you can copy, modify, and distribute it |
12 | under the terms of the GNU Affero General Public License |
13 | Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
14 | |
15 | CiviCRM is distributed in the hope that it will be useful, but |
16 | WITHOUT ANY WARRANTY; without even the implied warranty of |
17 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
18 | See the GNU Affero General Public License for more details. |
19 | |
20 | You should have received a copy of the GNU Affero General Public |
21 | License and the CiviCRM Licensing Exception along |
22 | with this program; if not, contact CiviCRM LLC |
23 | at info[AT]civicrm[DOT]org. If you have questions about the |
24 | GNU Affero General Public License or the licensing of CiviCRM, |
25 | see the CiviCRM license FAQ at http://civicrm.org/licensing |
26 +--------------------------------------------------------------------+
27 */
28
29 require_once 'CiviTest/CiviUnitTestCase.php';
30
31 /**
32 * Test class for Domain API - civicrm_domain_*
33 *
34 * @package CiviCRM_APIv3
35 * @subpackage API_Domain
36 */
37 class api_v3_DomainTest extends CiviUnitTestCase {
38
39 /* This test case doesn't require DB reset - apart from
40 where cleanDB() is called. */
41
42
43
44 public $DBResetRequired = FALSE;
45
46 protected $_apiversion = 3;
47 protected $params;
48 public $_eNoticeCompliant = TRUE;
49
50 /**
51 * Constructor
52 *
53 * Initialize configuration
54 */ function __construct() {
55 parent::__construct();
56 }
57
58 /**
59 * Sets up the fixture, for example, opens a network connection.
60 * This method is called before a test is executed.
61 *
62 * @access protected
63 */
64 protected function setUp() {
65 parent::setUp();
66
67 // taken from form code - couldn't find good method to use
68 $params['entity_id'] = 1;
69 $params['entity_table'] = CRM_Core_BAO_Domain::getTableName();
70 $domain = 1;
71 $defaultLocationType = CRM_Core_BAO_LocationType::getDefault();
72 $location = array();
73 $domContact = civicrm_api('contact', 'create', array(
74 'version' => $this->_apiversion,
75 'contact_type' => 'Organization',
76 'organization_name' => 'new org',
77 'api.phone.create' => array(
78 'location_type_id' => $defaultLocationType->id,
79 'phone_type_id' => 1,
80 'phone' => '456-456',
81 ),
82 'api.address.create' => array(
83 'location_type_id' => $defaultLocationType->id,
84 'street_address' => '45 Penny Lane',
85 ),
86 'api.email.create' => array(
87 'location_type_id' => $defaultLocationType->id,
88 'email' => 'my@email.com',
89 )
90 )
91 );
92
93 civicrm_api('domain','create',array(
94 'id' => 1,
95 'contact_id' => $domContact['id'],
96 'version' => $this->_apiversion
97 )
98 );
99 $this->_apiversion = 3;
100 $this->params = array(
101 'name' => 'A-team domain',
102 'description' => 'domain of chaos',
103 'version' => $this->_apiversion,
104 'domain_version' => '4.2',
105 'contact_id' => $domContact['id'],
106 );
107 }
108
109 /**
110 * Tears down the fixture, for example, closes a network connection.
111 * This method is called after a test is executed.
112 *
113 * @access protected
114 */
115 protected function tearDown() {
116
117 }
118
119 ///////////////// civicrm_domain_get methods
120
121 /**
122 * Test civicrm_domain_get. Takes no params.
123 * Testing mainly for format.
124 */
125 public function testGet() {
126
127
128 $params = array('version' => 3, 'sequential' => 1,);
129 $result = civicrm_api('domain', 'get', $params);
130 $this->documentMe($params, $result, __FUNCTION__, __FILE__);
131
132 $this->assertType('array', $result, 'In line' . __LINE__);
133
134 $domain = $result['values'][0];
135 $this->assertEquals("info@EXAMPLE.ORG", $domain['from_email'], 'In line ' . __LINE__);
136 $this->assertEquals("FIXME", $domain['from_name'], 'In line' . __LINE__);
137 // checking other important parts of domain information
138 // test will fail if backward incompatible changes happen
139 $this->assertArrayHasKey('id', $domain, 'In line' . __LINE__);
140 $this->assertArrayHasKey('name', $domain, 'In line' . __LINE__);
141 $this->assertArrayHasKey('domain_email', $domain, 'In line' . __LINE__);
142 $this->assertArrayHasKey('domain_phone', $domain, 'In line' . __LINE__);
143 $this->assertArrayHasKey('domain_address', $domain, 'In line' . __LINE__);
144 }
145
146 public function testGetCurrentDomain() {
147 $params = array('version' => 3, 'current_domain' => 1);
148 $result = civicrm_api('domain', 'get', $params);
149
150 $this->assertType('array', $result, 'In line' . __LINE__);
151
152 foreach ($result['values'] as $key => $domain) {
153 if ($key == 'version') {
154 continue;
155 }
156
157 $this->assertEquals("info@EXAMPLE.ORG", $domain['from_email'], 'In line ' . __LINE__);
158 $this->assertEquals("FIXME", $domain['from_name'], 'In line' . __LINE__);
159
160 // checking other important parts of domain information
161 // test will fail if backward incompatible changes happen
162 $this->assertArrayHasKey('id', $domain, 'In line' . __LINE__);
163 $this->assertArrayHasKey('name', $domain, 'In line' . __LINE__);
164 $this->assertArrayHasKey('domain_email', $domain, 'In line' . __LINE__);
165 $this->assertArrayHasKey('domain_phone', $domain, 'In line' . __LINE__);
166 $this->assertArrayHasKey('domain_address', $domain, 'In line' . __LINE__);
167 $this->assertEquals("my@email.com",$domain['domain_email']);
168 $this->assertEquals("456-456",$domain['domain_phone']['phone']);
169 $this->assertEquals("45 Penny Lane",$domain['domain_address']['street_address']);
170 }
171 }
172
173 ///////////////// civicrm_domain_create methods
174 /*
175 * This test checks for a memory leak observed when doing 2 gets on current domain
176 */
177
178
179
180 public function testGetCurrentDomainTwice() {
181 $domain = civicrm_api('domain', 'getvalue', array(
182 'version' => 3,
183 'current_domain' => 1,
184 'return' => 'name',
185 ));
186 $this->assertEquals('Default Domain Name', $domain, print_r($domain, TRUE) . 'in line ' . __LINE__);
187 $domain = civicrm_api('domain', 'getvalue', array(
188 'version' => 3,
189 'current_domain' => 1,
190 'return' => 'name',
191 ));
192 $this->assertEquals('Default Domain Name', $domain, print_r($domain, TRUE) . 'in line ' . __LINE__);
193 }
194
195 /**
196 * Test civicrm_domain_create.
197 */
198 public function testCreate() {
199 $result = civicrm_api('domain', 'create', $this->params);
200 $this->documentMe($this->params, $result, __FUNCTION__, __FILE__);
201 $this->assertAPISuccess($result);
202 $this->assertEquals($result['count'], 1);
203 $this->assertNotNull($result['id']);
204 $this->assertEquals($result['values'][$result['id']]['name'], $this->params['name']);
205 $this->assertEquals($result['values'][$result['id']]['version'], $this->params['domain_version']);
206 }
207
208 /**
209 * Test civicrm_domain_create with empty params.
210 * Error expected.
211 */
212 public function testCreateWithEmptyParams() {
213 $params = array('version' => $this->_apiversion);
214 $result = civicrm_api('domain', 'create', $params);
215 $this->assertAPIFailure($result,
216 "In line " . __LINE__
217 );
218 }
219
220 /**
221 * Test civicrm_domain_create with wrong parameter type.
222 */
223 public function testCreateWithWrongParams() {
224 $params = 1;
225 $result = civicrm_api('domain', 'create', $params);
226 $this->assertAPIFailure($result,
227 "In line " . __LINE__
228 );
229 }
230 }
231