Merge pull request #16469 from civicrm/5.22
[civicrm-core.git] / tests / phpunit / api / v3 / MappingTest.php
1 <?php
2 /*
3 +--------------------------------------------------------------------+
4 | Copyright CiviCRM LLC. All rights reserved. |
5 | |
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 +--------------------------------------------------------------------+
10 */
11
12 /**
13 * Test APIv3 civicrm_mapping_* functions
14 *
15 * @package CiviCRM_APIv3
16 * @subpackage API_Contact
17 * @group headless
18 */
19 class api_v3_MappingTest 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';
33 $this->params = [
34 'name' => 'Mapping name',
35 'description' => 'Mapping description',
36 // 'Export Contact' mapping.
37 'mapping_type_id' => 7,
38 ];
39 }
40
41 public function testCreateMapping() {
42 $result = $this->callAPIAndDocument($this->_entity, 'create', $this->params, __FUNCTION__, __FILE__);
43 $this->assertEquals(1, $result['count']);
44 $this->getAndCheck($this->params, $result['id'], $this->_entity);
45 $this->assertNotNull($result['values'][$result['id']]['id']);
46 }
47
48 public function testGetMapping() {
49 $result = $this->callAPISuccess($this->_entity, 'create', $this->params);
50 $result = $this->callAPIAndDocument($this->_entity, 'get', $this->params, __FUNCTION__, __FILE__);
51 $this->assertEquals(1, $result['count']);
52 $this->assertNotNull($result['values'][$result['id']]['id']);
53 $this->callAPISuccess($this->_entity, 'delete', ['id' => $result['id']]);
54 }
55
56 public function testDeleteMapping() {
57 $result = $this->callAPISuccess($this->_entity, 'create', $this->params);
58 $deleteParams = ['id' => $result['id']];
59 $result = $this->callAPIAndDocument($this->_entity, 'delete', $deleteParams, __FUNCTION__, __FILE__);
60 $checkDeleted = $this->callAPISuccess($this->_entity, 'get', []);
61 $this->assertEquals(0, $checkDeleted['count']);
62 }
63
64 public function testDeleteMappingInvalid() {
65 $result = $this->callAPISuccess($this->_entity, 'create', $this->params);
66 $deleteParams = ['id' => 600];
67 $result = $this->callAPIFailure($this->_entity, 'delete', $deleteParams);
68 $checkDeleted = $this->callAPISuccess($this->_entity, 'get', []);
69 $this->assertEquals(1, $checkDeleted['count']);
70 }
71
72 }