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