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);
108 * Test that the list of states is in the correct format when chaining
109 * and using sequential.
111 public function testCountryStateChainSequential() {
112 // first without specifying
113 $result = $this->callAPISuccess('Country', 'getsingle', [
115 'api.Address.getoptions' => [
116 'field' => 'state_province_id',
117 'country_id' => '$value.id',
120 $this->assertSame(['key' => 1000, 'value' => 'Alabama'], $result['api.Address.getoptions']['values'][0]);
121 $this->assertSame(['key' => 1001, 'value' => 'Alaska'], $result['api.Address.getoptions']['values'][1]);
122 $this->assertSame(['key' => 1049, 'value' => 'Wyoming'], $result['api.Address.getoptions']['values'][59]);
124 // now specifying sequential
125 $result = $this->callAPISuccess('Country', 'getsingle', [
127 'api.Address.getoptions' => [
128 'field' => 'state_province_id',
129 'country_id' => '$value.id',
133 $this->assertSame(['key' => 1000, 'value' => 'Alabama'], $result['api.Address.getoptions']['values'][0]);
134 $this->assertSame(['key' => 1001, 'value' => 'Alaska'], $result['api.Address.getoptions']['values'][1]);
135 $this->assertSame(['key' => 1049, 'value' => 'Wyoming'], $result['api.Address.getoptions']['values'][59]);
137 // now specifying keyed
138 $result = $this->callAPISuccess('Country', 'getsingle', [
140 'api.Address.getoptions' => [
141 'field' => 'state_province_id',
142 'country_id' => '$value.id',
146 $this->assertSame('Alabama', $result['api.Address.getoptions']['values'][1000]);
147 $this->assertSame('Alaska', $result['api.Address.getoptions']['values'][1001]);
148 $this->assertSame('Wyoming', $result['api.Address.getoptions']['values'][1049]);