3 +--------------------------------------------------------------------+
4 | Copyright CiviCRM LLC. All rights reserved. |
6 | This work is published under the GNU AGPLv3 license with some |
7 | permitted exceptions and without any warranty. For full license |
8 | and copyright information, see https://civicrm.org/licensing |
9 +--------------------------------------------------------------------+
13 * Test APIv3 civicrm_country* functions
15 * @package CiviCRM_APIv3
16 * @subpackage API_Contact
19 class api_v3_CountryTest
extends CiviUnitTestCase
{
20 protected $_apiversion;
23 public function setUp() {
24 $this->_apiversion
= 3;
26 $this->useTransaction(TRUE);
28 'name' => 'Made Up Land',
34 public function testCreateCountry() {
36 $result = $this->callAPIAndDocument('country', 'create', $this->_params
, __FUNCTION__
, __FILE__
);
37 $this->assertEquals(1, $result['count']);
38 $this->assertNotNull($result['values'][$result['id']]['id']);
40 $this->callAPISuccess('country', 'delete', ['id' => $result['id']]);
43 public function testDeleteCountry() {
45 $create = $this->callAPISuccess('country', 'create', $this->_params
);
47 $result = $this->callAPIAndDocument('country', 'delete', ['id' => $create['id']], __FUNCTION__
, __FILE__
);
48 $this->assertEquals(1, $result['count']);
49 $get = $this->callAPISuccess('country', 'get', [
50 'id' => $create['id'],
52 $this->assertEquals(0, $get['count'], 'Country not successfully deleted');
56 * Test civicrm_phone_get with empty params.
58 public function testGetEmptyParams() {
59 $result = $this->callAPISuccess('Country', 'Get', []);
63 * Test civicrm_phone_get with wrong params.
65 public function testGetWrongParams() {
66 $this->callAPIFailure('Country', 'Get', ['id' => 'abc']);
70 * Test civicrm_phone_get - success expected.
72 public function testGet() {
73 $country = $this->callAPISuccess('Country', 'create', $this->_params
);
75 'iso_code' => $this->_params
['iso_code'],
77 $result = $this->callAPIAndDocument('Country', 'Get', $params, __FUNCTION__
, __FILE__
);
78 $this->assertEquals($country['values'][$country['id']]['name'], $result['values'][$country['id']]['name']);
79 $this->assertEquals($country['values'][$country['id']]['iso_code'], $result['values'][$country['id']]['iso_code']);
82 ///////////////// civicrm_country_create methods
85 * If a new country is created and it is created again it should not create a second one.
86 * We check on the iso code (there should be only one iso code
88 public function testCreateDuplicateFail() {
89 $params = $this->_params
;
91 $this->callAPISuccess('country', 'create', $params);
92 $this->callAPIFailure('country', 'create', $params);
93 $check = $this->callAPISuccess('country', 'getcount', [
94 'iso_code' => $params['iso_code'],
96 $this->assertEquals(1, $check);