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
{
22 public function setUp() {
24 $this->useTransaction(TRUE);
27 'abbreviation' => 'WEX',
33 * @dataProvider versionThreeAndFour
35 public function testCreateStateProvince() {
36 $result = $this->callAPIAndDocument('StateProvince', 'create', $this->_params
, __FUNCTION__
, __FILE__
);
37 $this->assertEquals(1, $result['count']);
38 $this->assertNotNull($result['values'][$result['id']]['id']);
39 $this->callAPISuccess('StateProvince', 'delete', ['id' => $result['id']]);
43 * @dataProvider versionThreeAndFour
45 public function testDeleteStateProvince() {
47 $create = $this->callAPISuccess('StateProvince', 'create', $this->_params
);
50 $result = $this->callAPIAndDocument('StateProvince', 'delete', ['id' => $create['id']], __FUNCTION__
, __FILE__
);
51 $this->assertEquals(1, $result['count']);
52 $get = $this->callAPISuccess('StateProvince', 'get', [
53 'id' => $create['id'],
55 $this->assertEquals(0, $get['count'], 'State/province not successfully deleted');
59 * Test with empty params
60 * @dataProvider versionThreeAndFour
62 public function testGetEmptyParams() {
63 $result = $this->callAPISuccess('StateProvince', 'Get', []);
67 * Test with wrong params
68 * @dataProvider versionThreeAndFour
70 public function testGetWrongParams() {
71 $this->callAPIFailure('StateProvince', 'Get', ['id' => 'abc']);
76 * @dataProvider versionThreeAndFour
78 public function testGet() {
79 $province = $this->callAPISuccess('StateProvince', 'create', $this->_params
);
81 'name' => $this->_params
['name'],
83 $result = $this->callAPIAndDocument('StateProvince', 'Get', $params, __FUNCTION__
, __FILE__
);
84 $this->assertEquals($province['values'][$province['id']]['name'], $result['values'][$province['id']]['name']);
85 $this->assertEquals($province['values'][$province['id']]['abbreviation'], $result['values'][$province['id']]['abbreviation']);
89 * There cannot be two state/provinces with the same name in the same country.
90 * @dataProvider versionThreeAndFour
92 public function testCreateDuplicateFail() {
93 $params = $this->_params
;
95 $this->callAPISuccess('StateProvince', 'create', $params);
96 $this->callAPIFailure('StateProvince', 'create', $params);
97 $check = $this->callAPISuccess('StateProvince', 'getcount', [
98 'name' => $params['name'],
100 $this->assertEquals(1, $check);