Commit | Line | Data |
---|---|---|
4d4819b0 J |
1 | <?php |
2 | /* | |
3 | +--------------------------------------------------------------------+ | |
2fe49090 | 4 | | CiviCRM version 5 | |
4d4819b0 | 5 | +--------------------------------------------------------------------+ |
6b83d5bd | 6 | | Copyright CiviCRM LLC (c) 2004-2019 | |
4d4819b0 J |
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_state_province* functions | |
30 | * | |
31 | * @package CiviCRM_APIv3 | |
32 | * @subpackage API_Contact | |
33 | * @group headless | |
34 | */ | |
35 | class api_v3_StateProvinceTest extends CiviUnitTestCase { | |
36 | protected $_apiversion; | |
37 | protected $_params; | |
38 | ||
39 | public function setUp() { | |
40 | $this->_apiversion = 3; | |
41 | parent::setUp(); | |
42 | $this->useTransaction(TRUE); | |
9099cab3 | 43 | $this->_params = [ |
4d4819b0 J |
44 | 'name' => 'Wessex', |
45 | 'abbreviation' => 'WEX', | |
46 | 'country_id' => 1226, | |
9099cab3 | 47 | ]; |
4d4819b0 J |
48 | } |
49 | ||
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']); | |
9099cab3 | 54 | $this->callAPISuccess('StateProvince', 'delete', ['id' => $result['id']]); |
4d4819b0 J |
55 | } |
56 | ||
57 | public function testDeleteStateProvince() { | |
58 | // Create | |
59 | $create = $this->callAPISuccess('StateProvince', 'create', $this->_params); | |
60 | ||
61 | // Delete | |
9099cab3 | 62 | $result = $this->callAPIAndDocument('StateProvince', 'delete', ['id' => $create['id']], __FUNCTION__, __FILE__); |
4d4819b0 | 63 | $this->assertEquals(1, $result['count']); |
9099cab3 | 64 | $get = $this->callAPISuccess('StateProvince', 'get', [ |
4d4819b0 | 65 | 'id' => $create['id'], |
9099cab3 | 66 | ]); |
4d4819b0 J |
67 | $this->assertEquals(0, $get['count'], 'State/province not successfully deleted'); |
68 | } | |
69 | ||
70 | /** | |
71 | * Test with empty params | |
72 | */ | |
73 | public function testGetEmptyParams() { | |
9099cab3 | 74 | $result = $this->callAPISuccess('StateProvince', 'Get', []); |
4d4819b0 J |
75 | } |
76 | ||
77 | /** | |
78 | * Test with wrong params | |
79 | */ | |
80 | public function testGetWrongParams() { | |
9099cab3 | 81 | $this->callAPIFailure('StateProvince', 'Get', ['id' => 'abc']); |
4d4819b0 J |
82 | } |
83 | ||
84 | /** | |
85 | * Test get | |
86 | */ | |
87 | public function testGet() { | |
88 | $province = $this->callAPISuccess('StateProvince', 'create', $this->_params); | |
9099cab3 | 89 | $params = [ |
4d4819b0 | 90 | 'name' => $this->_params['name'], |
9099cab3 | 91 | ]; |
4d4819b0 J |
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']); | |
95 | } | |
96 | ||
97 | /** | |
98 | * There cannot be two state/provinces with the same name in the same country. | |
99 | */ | |
100 | public function testCreateDuplicateFail() { | |
101 | $params = $this->_params; | |
102 | unset($params['id']); | |
103 | $this->callAPISuccess('StateProvince', 'create', $params); | |
104 | $this->callAPIFailure('StateProvince', 'create', $params); | |
9099cab3 | 105 | $check = $this->callAPISuccess('StateProvince', 'getcount', [ |
4d4819b0 | 106 | 'name' => $params['name'], |
9099cab3 | 107 | ]); |
4d4819b0 J |
108 | $this->assertEquals(1, $check); |
109 | } | |
110 | ||
111 | } |