Merge pull request #10946 from mattwire/CRM-21037_activity_sendsms_unittests
[civicrm-core.git] / tests / phpunit / api / v3 / CountryTest.php
1 <?php
2 /*
3 +--------------------------------------------------------------------+
4 | CiviCRM version 5 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2018 |
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
40 public function setUp() {
41 $this->_apiversion = 3;
42 parent::setUp();
43 $this->useTransaction(TRUE);
44 $this->_params = array(
45 'name' => 'Made Up Land',
46 'iso_code' => 'ZZ',
47 'region_id' => 1,
48 );
49 }
50
51 public function testCreateCountry() {
52
53 $result = $this->callAPIAndDocument('country', 'create', $this->_params, __FUNCTION__, __FILE__);
54 $this->assertEquals(1, $result['count']);
55 $this->assertNotNull($result['values'][$result['id']]['id']);
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
64 $result = $this->callAPIAndDocument('country', 'delete', array('id' => $create['id']), __FUNCTION__, __FILE__);
65 $this->assertEquals(1, $result['count']);
66 $get = $this->callAPISuccess('country', 'get', array(
67 'id' => $create['id'],
68 ));
69 $this->assertEquals(0, $get['count'], 'Country not successfully deleted');
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(
92 'iso_code' => $this->_params['iso_code'],
93 );
94 $result = $this->callAPIAndDocument('Country', 'Get', $params, __FUNCTION__, __FILE__);
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']);
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
104 */
105 public function testCreateDuplicateFail() {
106 $params = $this->_params;
107 unset($params['id']);
108 $this->callAPISuccess('country', 'create', $params);
109 $this->callAPIFailure('country', 'create', $params);
110 $check = $this->callAPISuccess('country', 'getcount', array(
111 'iso_code' => $params['iso_code'],
112 ));
113 $this->assertEquals(1, $check);
114 }
115
116 }