Merge pull request #16469 from civicrm/5.22
[civicrm-core.git] / tests / phpunit / api / v3 / EntityBatchTest.php
CommitLineData
a646bdd2
SB
1<?php
2/*
7d61e75f
TO
3 +--------------------------------------------------------------------+
4 | Copyright CiviCRM LLC. All rights reserved. |
a646bdd2 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 |
9 +--------------------------------------------------------------------+ */
a646bdd2 10
a646bdd2
SB
11/**
12 * Test APIv3 civicrm_entity_batch_* functions
13 *
14 * @package CiviCRM_APIv3
acb109b7 15 * @group headless
a646bdd2
SB
16 */
17class api_v3_EntityBatchTest extends CiviUnitTestCase {
18
19 protected $_apiversion = 3;
20 protected $params;
21 protected $id;
22 protected $_entity;
23
24 public $DBResetRequired = FALSE;
25
26 public function setUp() {
27 parent::setUp();
28 $this->useTransaction(TRUE);
29
9099cab3 30 $entityParams = ['contact_id' => 1];
a646bdd2
SB
31
32 $this->_entity = 'EntityBatch';
33 $this->_entityID = $this->contributionCreate($entityParams);
34 $this->_batchID = $this->batchCreate();
9099cab3 35 $this->params = [
a646bdd2
SB
36 'entity_id' => $this->_entityID,
37 'batch_id' => $this->_batchID,
38 'entity_table' => 'civicrm_financial_trxn',
9099cab3 39 ];
a646bdd2
SB
40 }
41
42 public function testCreateEntityBatch() {
43 $result = $this->callAPIAndDocument($this->_entity, 'create', $this->params, __FUNCTION__, __FILE__);
44 $this->assertEquals(1, $result['count']);
45 $this->getAndCheck($this->params, $result['id'], $this->_entity);
46 $this->assertNotNull($result['values'][$result['id']]['id']);
47 }
48
49 public function testGetEntityBatch() {
50 $result = $this->callAPISuccess($this->_entity, 'create', $this->params);
51 $result = $this->callAPIAndDocument($this->_entity, 'get', $this->params, __FUNCTION__, __FILE__);
52 $this->assertEquals(1, $result['count']);
53 $this->assertNotNull($result['values'][$result['id']]['id']);
9099cab3 54 $this->callAPISuccess($this->_entity, 'delete', ['id' => $result['id']]);
a646bdd2
SB
55 }
56
57 public function testDeleteEntityBatch() {
58 $result = $this->callAPISuccess($this->_entity, 'create', $this->params);
9099cab3 59 $deleteParams = ['id' => $result['id']];
a646bdd2 60 $result = $this->callAPIAndDocument($this->_entity, 'delete', $deleteParams, __FUNCTION__, __FILE__);
9099cab3 61 $checkDeleted = $this->callAPISuccess($this->_entity, 'get', []);
a646bdd2
SB
62 $this->assertEquals(0, $checkDeleted['count']);
63 }
64
65}