3 +--------------------------------------------------------------------+
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2020 |
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 * Test APIv3 civicrm_country* functions
31 * @package CiviCRM_APIv3
32 * @subpackage API_Contact
35 class api_v3_CountryTest
extends CiviUnitTestCase
{
36 protected $_apiversion;
39 public function setUp() {
40 $this->_apiversion
= 3;
42 $this->useTransaction(TRUE);
44 'name' => 'Made Up Land',
50 public function testCreateCountry() {
52 $result = $this->callAPIAndDocument('country', 'create', $this->_params
, __FUNCTION__
, __FILE__
);
53 $this->assertEquals(1, $result['count']);
54 $this->assertNotNull($result['values'][$result['id']]['id']);
56 $this->callAPISuccess('country', 'delete', ['id' => $result['id']]);
59 public function testDeleteCountry() {
61 $create = $this->callAPISuccess('country', 'create', $this->_params
);
63 $result = $this->callAPIAndDocument('country', 'delete', ['id' => $create['id']], __FUNCTION__
, __FILE__
);
64 $this->assertEquals(1, $result['count']);
65 $get = $this->callAPISuccess('country', 'get', [
66 'id' => $create['id'],
68 $this->assertEquals(0, $get['count'], 'Country not successfully deleted');
72 * Test civicrm_phone_get with empty params.
74 public function testGetEmptyParams() {
75 $result = $this->callAPISuccess('Country', 'Get', []);
79 * Test civicrm_phone_get with wrong params.
81 public function testGetWrongParams() {
82 $this->callAPIFailure('Country', 'Get', ['id' => 'abc']);
86 * Test civicrm_phone_get - success expected.
88 public function testGet() {
89 $country = $this->callAPISuccess('Country', 'create', $this->_params
);
91 'iso_code' => $this->_params
['iso_code'],
93 $result = $this->callAPIAndDocument('Country', 'Get', $params, __FUNCTION__
, __FILE__
);
94 $this->assertEquals($country['values'][$country['id']]['name'], $result['values'][$country['id']]['name']);
95 $this->assertEquals($country['values'][$country['id']]['iso_code'], $result['values'][$country['id']]['iso_code']);
98 ///////////////// civicrm_country_create methods
101 * If a new country is created and it is created again it should not create a second one.
102 * We check on the iso code (there should be only one iso code
104 public function testCreateDuplicateFail() {
105 $params = $this->_params
;
106 unset($params['id']);
107 $this->callAPISuccess('country', 'create', $params);
108 $this->callAPIFailure('country', 'create', $params);
109 $check = $this->callAPISuccess('country', 'getcount', [
110 'iso_code' => $params['iso_code'],
112 $this->assertEquals(1, $check);