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
{
22 public function setUp(): void
{
24 $this->useTransaction(TRUE);
26 'name' => 'Made Up Land',
33 * @dataProvider versionThreeAndFour
35 public function testCreateCountry() {
37 $result = $this->callAPIAndDocument('country', 'create', $this->_params
, __FUNCTION__
, __FILE__
);
38 $this->assertEquals(1, $result['count']);
39 $this->assertNotNull($result['values'][$result['id']]['id']);
41 $this->callAPISuccess('country', 'delete', ['id' => $result['id']]);
45 * @dataProvider versionThreeAndFour
47 public function testDeleteCountry() {
49 $create = $this->callAPISuccess('country', 'create', $this->_params
);
51 $result = $this->callAPIAndDocument('country', 'delete', ['id' => $create['id']], __FUNCTION__
, __FILE__
);
52 $this->assertEquals(1, $result['count']);
53 $get = $this->callAPISuccess('country', 'get', [
54 'id' => $create['id'],
56 $this->assertEquals(0, $get['count'], 'Country not successfully deleted');
60 * Test civicrm_phone_get with empty params.
61 * @dataProvider versionThreeAndFour
63 public function testGetEmptyParams() {
64 $result = $this->callAPISuccess('Country', 'Get', []);
68 * Test civicrm_phone_get with wrong params.
69 * @dataProvider versionThreeAndFour
71 public function testGetWrongParams() {
72 $this->callAPIFailure('Country', 'Get', ['id' => 'abc']);
76 * Test civicrm_phone_get - success expected.
77 * @dataProvider versionThreeAndFour
79 public function testGet() {
80 $country = $this->callAPISuccess('Country', 'create', $this->_params
);
82 'iso_code' => $this->_params
['iso_code'],
84 $result = $this->callAPIAndDocument('Country', 'Get', $params, __FUNCTION__
, __FILE__
);
85 $this->assertEquals($country['values'][$country['id']]['name'], $result['values'][$country['id']]['name']);
86 $this->assertEquals($country['values'][$country['id']]['iso_code'], $result['values'][$country['id']]['iso_code']);
89 ///////////////// civicrm_country_create methods
92 * If a new country is created and it is created again it should not create a second one.
93 * We check on the iso code (there should be only one iso code
94 * @dataProvider versionThreeAndFour
96 public function testCreateDuplicateFail() {
97 $params = $this->_params
;
99 $this->callAPISuccess('country', 'create', $params);
100 $this->callAPIFailure('country', 'create', $params);
101 $check = $this->callAPISuccess('country', 'getcount', [
102 'iso_code' => $params['iso_code'],
104 $this->assertEquals(1, $check);