Merge pull request #13689 from eileenmcnaughton/no_record_payment
[civicrm-core.git] / tests / phpunit / api / v3 / CountryTest.php
1 <?php
2 /*
3 +--------------------------------------------------------------------+
4 | CiviCRM version 5 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2019 |
7 +--------------------------------------------------------------------+
8 | This file is a part of CiviCRM. |
9 | |
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. |
13 | |
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. |
18 | |
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 +--------------------------------------------------------------------+
26 */
27
28 /**
29 * Test APIv3 civicrm_country* functions
30 *
31 * @package CiviCRM_APIv3
32 * @subpackage API_Contact
33 * @group headless
34 */
35 class api_v3_CountryTest extends CiviUnitTestCase {
36 protected $_apiversion;
37 protected $_params;
38
39 public function setUp() {
40 $this->_apiversion = 3;
41 parent::setUp();
42 $this->useTransaction(TRUE);
43 $this->_params = array(
44 'name' => 'Made Up Land',
45 'iso_code' => 'ZZ',
46 'region_id' => 1,
47 );
48 }
49
50 public function testCreateCountry() {
51
52 $result = $this->callAPIAndDocument('country', 'create', $this->_params, __FUNCTION__, __FILE__);
53 $this->assertEquals(1, $result['count']);
54 $this->assertNotNull($result['values'][$result['id']]['id']);
55
56 $this->callAPISuccess('country', 'delete', array('id' => $result['id']));
57 }
58
59 public function testDeleteCountry() {
60 //create one
61 $create = $this->callAPISuccess('country', 'create', $this->_params);
62
63 $result = $this->callAPIAndDocument('country', 'delete', array('id' => $create['id']), __FUNCTION__, __FILE__);
64 $this->assertEquals(1, $result['count']);
65 $get = $this->callAPISuccess('country', 'get', array(
66 'id' => $create['id'],
67 ));
68 $this->assertEquals(0, $get['count'], 'Country not successfully deleted');
69 }
70
71 /**
72 * Test civicrm_phone_get with empty params.
73 */
74 public function testGetEmptyParams() {
75 $result = $this->callAPISuccess('Country', 'Get', array());
76 }
77
78 /**
79 * Test civicrm_phone_get with wrong params.
80 */
81 public function testGetWrongParams() {
82 $this->callAPIFailure('Country', 'Get', array('id' => 'abc'));
83 }
84
85 /**
86 * Test civicrm_phone_get - success expected.
87 */
88 public function testGet() {
89 $country = $this->callAPISuccess('Country', 'create', $this->_params);
90 $params = array(
91 'iso_code' => $this->_params['iso_code'],
92 );
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']);
96 }
97
98 ///////////////// civicrm_country_create methods
99
100 /**
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
103 */
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', array(
110 'iso_code' => $params['iso_code'],
111 ));
112 $this->assertEquals(1, $check);
113 }
114
115 }