3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.6 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2014 |
7 +--------------------------------------------------------------------+
8 | This file is a part of CiviCRM. |
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. |
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. |
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 +--------------------------------------------------------------------+
29 require_once 'CiviTest/CiviUnitTestCase.php';
33 * Test APIv3 civicrm_country* functions
35 * @package CiviCRM_APIv3
36 * @subpackage API_Contact
38 class api_v3_CountryTest
extends CiviUnitTestCase
{
39 protected $_apiversion;
44 $this->_apiversion
= 3;
46 $this->useTransaction(TRUE);
47 $this->_params
= array(
48 'name' => 'Made Up Land',
54 public function testCreateCountry() {
56 $result = $this->callAPIAndDocument('country', 'create', $this->_params
, __FUNCTION__
, __FILE__
);
57 $this->assertEquals(1, $result['count']);
58 $this->assertNotNull($result['values'][$result['id']]['id']);
60 $this->callAPISuccess('country', 'delete', array('id' => $result['id']));
63 public function testDeleteCountry() {
65 $create = $this->callAPISuccess('country', 'create', $this->_params
);
67 $result = $this->callAPIAndDocument('country', 'delete', array('id' => $create['id'],), __FUNCTION__
, __FILE__
);
68 $this->assertEquals(1, $result['count']);
69 $get = $this->callAPISuccess('country', 'get', array(
70 'id' => $create['id'],
72 $this->assertEquals(0, $get['count'], 'Country not successfully deleted');
76 * Test civicrm_phone_get with empty params.
78 public function testGetEmptyParams() {
79 $result = $this->callAPISuccess('Country', 'Get', array());
83 * Test civicrm_phone_get with wrong params.
85 public function testGetWrongParams() {
86 $this->callAPIFailure('Country', 'Get', array('id' => 'abc'));
90 * Test civicrm_phone_get - success expected.
92 public function testGet() {
93 $country = $this->callAPISuccess('Country', 'create', $this->_params
);
95 'iso_code' => $this->_params
['iso_code'],
97 $result = $this->callAPIAndDocument('Country', 'Get', $params, __FUNCTION__
, __FILE__
);
98 $this->assertEquals($country['values'][$country['id']]['name'], $result['values'][$country['id']]['name']);
99 $this->assertEquals($country['values'][$country['id']]['iso_code'], $result['values'][$country['id']]['iso_code']);
102 ///////////////// civicrm_country_create methods
105 * If a new country is created and it is created again it should not create a second one.
106 * We check on the iso code (there should be only one iso code
109 public function testCreateDuplicateFail() {
110 $params = $this->_params
;
111 unset($params['id']);
112 $this->callAPISuccess('country', 'create', $params);
113 $this->callAPIFailure('country', 'create', $params);
114 $check = $this->callAPISuccess('country', 'getcount', array(
115 'iso_code' => $params['iso_code'],
117 $this->assertEquals(1, $check);