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_state_province* functions
15 * @package CiviCRM_APIv3
16 * @subpackage API_Contact
19 class api_v3_StateProvinceTest
extends CiviUnitTestCase
{
20 protected $_apiversion;
23 public function setUp() {
24 $this->_apiversion
= 3;
26 $this->useTransaction(TRUE);
29 'abbreviation' => 'WEX',
34 public function testCreateStateProvince() {
35 $result = $this->callAPIAndDocument('StateProvince', 'create', $this->_params
, __FUNCTION__
, __FILE__
);
36 $this->assertEquals(1, $result['count']);
37 $this->assertNotNull($result['values'][$result['id']]['id']);
38 $this->callAPISuccess('StateProvince', 'delete', ['id' => $result['id']]);
41 public function testDeleteStateProvince() {
43 $create = $this->callAPISuccess('StateProvince', 'create', $this->_params
);
46 $result = $this->callAPIAndDocument('StateProvince', 'delete', ['id' => $create['id']], __FUNCTION__
, __FILE__
);
47 $this->assertEquals(1, $result['count']);
48 $get = $this->callAPISuccess('StateProvince', 'get', [
49 'id' => $create['id'],
51 $this->assertEquals(0, $get['count'], 'State/province not successfully deleted');
55 * Test with empty params
57 public function testGetEmptyParams() {
58 $result = $this->callAPISuccess('StateProvince', 'Get', []);
62 * Test with wrong params
64 public function testGetWrongParams() {
65 $this->callAPIFailure('StateProvince', 'Get', ['id' => 'abc']);
71 public function testGet() {
72 $province = $this->callAPISuccess('StateProvince', 'create', $this->_params
);
74 'name' => $this->_params
['name'],
76 $result = $this->callAPIAndDocument('StateProvince', 'Get', $params, __FUNCTION__
, __FILE__
);
77 $this->assertEquals($province['values'][$province['id']]['name'], $result['values'][$province['id']]['name']);
78 $this->assertEquals($province['values'][$province['id']]['abbreviation'], $result['values'][$province['id']]['abbreviation']);
82 * There cannot be two state/provinces with the same name in the same country.
84 public function testCreateDuplicateFail() {
85 $params = $this->_params
;
87 $this->callAPISuccess('StateProvince', 'create', $params);
88 $this->callAPIFailure('StateProvince', 'create', $params);
89 $check = $this->callAPISuccess('StateProvince', 'getcount', [
90 'name' => $params['name'],
92 $this->assertEquals(1, $check);