3 +--------------------------------------------------------------------+
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2019 |
7 +--------------------------------------------------------------------+
8 | This file is a part of CiviCRM. |
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. |
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. |
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 +--------------------------------------------------------------------+
29 * Test APIv3 civicrm_state_province* functions
31 * @package CiviCRM_APIv3
32 * @subpackage API_Contact
35 class api_v3_StateProvinceTest
extends CiviUnitTestCase
{
36 protected $_apiversion;
39 public function setUp() {
40 $this->_apiversion
= 3;
42 $this->useTransaction(TRUE);
45 'abbreviation' => 'WEX',
50 public function testCreateStateProvince() {
51 $result = $this->callAPIAndDocument('StateProvince', 'create', $this->_params
, __FUNCTION__
, __FILE__
);
52 $this->assertEquals(1, $result['count']);
53 $this->assertNotNull($result['values'][$result['id']]['id']);
54 $this->callAPISuccess('StateProvince', 'delete', ['id' => $result['id']]);
57 public function testDeleteStateProvince() {
59 $create = $this->callAPISuccess('StateProvince', 'create', $this->_params
);
62 $result = $this->callAPIAndDocument('StateProvince', 'delete', ['id' => $create['id']], __FUNCTION__
, __FILE__
);
63 $this->assertEquals(1, $result['count']);
64 $get = $this->callAPISuccess('StateProvince', 'get', [
65 'id' => $create['id'],
67 $this->assertEquals(0, $get['count'], 'State/province not successfully deleted');
71 * Test with empty params
73 public function testGetEmptyParams() {
74 $result = $this->callAPISuccess('StateProvince', 'Get', []);
78 * Test with wrong params
80 public function testGetWrongParams() {
81 $this->callAPIFailure('StateProvince', 'Get', ['id' => 'abc']);
87 public function testGet() {
88 $province = $this->callAPISuccess('StateProvince', 'create', $this->_params
);
90 'name' => $this->_params
['name'],
92 $result = $this->callAPIAndDocument('StateProvince', 'Get', $params, __FUNCTION__
, __FILE__
);
93 $this->assertEquals($province['values'][$province['id']]['name'], $result['values'][$province['id']]['name']);
94 $this->assertEquals($province['values'][$province['id']]['abbreviation'], $result['values'][$province['id']]['abbreviation']);
98 * There cannot be two state/provinces with the same name in the same country.
100 public function testCreateDuplicateFail() {
101 $params = $this->_params
;
102 unset($params['id']);
103 $this->callAPISuccess('StateProvince', 'create', $params);
104 $this->callAPIFailure('StateProvince', 'create', $params);
105 $check = $this->callAPISuccess('StateProvince', 'getcount', [
106 'name' => $params['name'],
108 $this->assertEquals(1, $check);