Merge pull request #11965 from colemanw/CRM-21855
[civicrm-core.git] / tests / phpunit / api / v3 / CountryTest.php
CommitLineData
fe14170b
JJ
1<?php
2/*
3 +--------------------------------------------------------------------+
81621fee 4 | CiviCRM version 4.7 |
fe14170b 5 +--------------------------------------------------------------------+
8c9251b3 6 | Copyright CiviCRM LLC (c) 2004-2018 |
fe14170b
JJ
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
fe14170b
JJ
28/**
29 * Test APIv3 civicrm_country* functions
30 *
6c6e6187
TO
31 * @package CiviCRM_APIv3
32 * @subpackage API_Contact
acb109b7 33 * @group headless
fe14170b
JJ
34 */
35class api_v3_CountryTest extends CiviUnitTestCase {
36 protected $_apiversion;
37 protected $_params;
38
39
00be9182 40 public function setUp() {
fe14170b
JJ
41 $this->_apiversion = 3;
42 parent::setUp();
a6e1ef97 43 $this->useTransaction(TRUE);
fe14170b 44 $this->_params = array(
78abe068 45 'name' => 'Made Up Land',
a6e1ef97 46 'iso_code' => 'ZZ',
78abe068 47 'region_id' => 1,
fe14170b
JJ
48 );
49 }
50
51 public function testCreateCountry() {
52
53 $result = $this->callAPIAndDocument('country', 'create', $this->_params, __FUNCTION__, __FILE__);
78abe068
C
54 $this->assertEquals(1, $result['count']);
55 $this->assertNotNull($result['values'][$result['id']]['id']);
fe14170b
JJ
56
57 $this->callAPISuccess('country', 'delete', array('id' => $result['id']));
58 }
59
60 public function testDeleteCountry() {
61 //create one
62 $create = $this->callAPISuccess('country', 'create', $this->_params);
63
6c6e6187 64 $result = $this->callAPIAndDocument('country', 'delete', array('id' => $create['id']), __FUNCTION__, __FILE__);
78abe068 65 $this->assertEquals(1, $result['count']);
fe14170b
JJ
66 $get = $this->callAPISuccess('country', 'get', array(
67 'id' => $create['id'],
68 ));
78abe068 69 $this->assertEquals(0, $get['count'], 'Country not successfully deleted');
fe14170b
JJ
70 }
71
72 /**
73 * Test civicrm_phone_get with empty params.
74 */
75 public function testGetEmptyParams() {
76 $result = $this->callAPISuccess('Country', 'Get', array());
77 }
78
79 /**
80 * Test civicrm_phone_get with wrong params.
81 */
82 public function testGetWrongParams() {
83 $this->callAPIFailure('Country', 'Get', array('id' => 'abc'));
84 }
85
86 /**
87 * Test civicrm_phone_get - success expected.
88 */
89 public function testGet() {
90 $country = $this->callAPISuccess('Country', 'create', $this->_params);
91 $params = array(
6c6e6187 92 'iso_code' => $this->_params['iso_code'],
fe14170b
JJ
93 );
94 $result = $this->callAPIAndDocument('Country', 'Get', $params, __FUNCTION__, __FILE__);
78abe068
C
95 $this->assertEquals($country['values'][$country['id']]['name'], $result['values'][$country['id']]['name']);
96 $this->assertEquals($country['values'][$country['id']]['iso_code'], $result['values'][$country['id']]['iso_code']);
fe14170b
JJ
97 }
98
99 ///////////////// civicrm_country_create methods
100
101 /**
102 * If a new country is created and it is created again it should not create a second one.
103 * We check on the iso code (there should be only one iso code
fe14170b 104 */
78abe068 105 public function testCreateDuplicateFail() {
fe14170b
JJ
106 $params = $this->_params;
107 unset($params['id']);
78abe068
C
108 $this->callAPISuccess('country', 'create', $params);
109 $this->callAPIFailure('country', 'create', $params);
fe14170b
JJ
110 $check = $this->callAPISuccess('country', 'getcount', array(
111 'iso_code' => $params['iso_code'],
112 ));
113 $this->assertEquals(1, $check);
114 }
96025800 115
fe14170b 116}