Commit | Line | Data |
---|---|---|
927f93e2 TM |
1 | <?php |
2 | /* | |
3 | +--------------------------------------------------------------------+ | |
7d61e75f | 4 | | Copyright CiviCRM LLC. All rights reserved. | |
927f93e2 | 5 | | | |
7d61e75f TO |
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 | | |
927f93e2 TM |
9 | +--------------------------------------------------------------------+ |
10 | */ | |
11 | ||
927f93e2 TM |
12 | /** |
13 | * Test APIv3 civicrm_mapping_field_* functions | |
14 | * | |
15 | * @package CiviCRM_APIv3 | |
16 | * @subpackage API_Contact | |
acb109b7 | 17 | * @group headless |
927f93e2 TM |
18 | */ |
19 | class api_v3_MappingFieldTest extends CiviUnitTestCase { | |
20 | ||
21 | protected $_apiversion = 3; | |
22 | protected $params; | |
23 | protected $id; | |
24 | protected $_entity; | |
25 | ||
26 | public $DBResetRequired = FALSE; | |
27 | ||
28 | public function setUp() { | |
29 | parent::setUp(); | |
30 | $this->useTransaction(TRUE); | |
31 | ||
32 | $this->_entity = 'mapping_field'; | |
ddfe3ced | 33 | $mappingID = $this->mappingCreate(); |
9099cab3 | 34 | $this->params = [ |
ddfe3ced | 35 | 'mapping_id' => $mappingID->id, |
927f93e2 TM |
36 | 'name' => 'last_name', |
37 | 'contact_type' => 'Individual', | |
38 | 'column_number' => 2, | |
39 | 'grouping' => 1, | |
9099cab3 | 40 | ]; |
927f93e2 TM |
41 | } |
42 | ||
43 | public function testCreateMappingField() { | |
44 | $result = $this->callAPIAndDocument($this->_entity, 'create', $this->params, __FUNCTION__, __FILE__); | |
45 | $this->assertEquals(1, $result['count']); | |
46 | $this->getAndCheck($this->params, $result['id'], $this->_entity); | |
47 | $this->assertNotNull($result['values'][$result['id']]['id']); | |
48 | } | |
49 | ||
50 | public function testGetMappingField() { | |
51 | $result = $this->callAPISuccess($this->_entity, 'create', $this->params); | |
52 | $result = $this->callAPIAndDocument($this->_entity, 'get', $this->params, __FUNCTION__, __FILE__); | |
53 | $this->assertEquals(1, $result['count']); | |
54 | $this->assertNotNull($result['values'][$result['id']]['id']); | |
9099cab3 | 55 | $this->callAPISuccess($this->_entity, 'delete', ['id' => $result['id']]); |
927f93e2 TM |
56 | } |
57 | ||
58 | public function testDeleteMappingField() { | |
59 | $result = $this->callAPISuccess($this->_entity, 'create', $this->params); | |
9099cab3 | 60 | $deleteParams = ['id' => $result['id']]; |
927f93e2 | 61 | $result = $this->callAPIAndDocument($this->_entity, 'delete', $deleteParams, __FUNCTION__, __FILE__); |
9099cab3 | 62 | $checkDeleted = $this->callAPISuccess($this->_entity, 'get', []); |
927f93e2 TM |
63 | $this->assertEquals(0, $checkDeleted['count']); |
64 | } | |
65 | ||
66 | public function testDeleteMappingFieldInvalid() { | |
67 | $result = $this->callAPISuccess($this->_entity, 'create', $this->params); | |
9099cab3 | 68 | $deleteParams = ['id' => 600]; |
927f93e2 | 69 | $result = $this->callAPIFailure($this->_entity, 'delete', $deleteParams); |
9099cab3 | 70 | $checkDeleted = $this->callAPISuccess($this->_entity, 'get', []); |
927f93e2 TM |
71 | $this->assertEquals(1, $checkDeleted['count']); |
72 | } | |
73 | ||
74 | } |