Merge pull request #20284 from civicrm/5.38
[civicrm-core.git] / tests / phpunit / api / v3 / EntityBatchTest.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 * Test APIv3 civicrm_entity_batch_* functions
13 *
14 * @package CiviCRM_APIv3
15 * @group headless
16 */
17 class 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 /**
27 * @throws \CRM_Core_Exception
28 * @throws \CiviCRM_API3_Exception
29 */
30 public function setUp(): void {
31 parent::setUp();
32 $this->useTransaction();
33
34 $entityParams = ['contact_id' => $this->individualCreate()];
35
36 $this->_entity = 'EntityBatch';
37 $this->_entityID = $this->contributionCreate($entityParams);
38 $this->_batchID = $this->batchCreate();
39 $this->params = [
40 'entity_id' => $this->_entityID,
41 'batch_id' => $this->_batchID,
42 'entity_table' => 'civicrm_financial_trxn',
43 ];
44 }
45
46 public function testCreateEntityBatch() {
47 $result = $this->callAPIAndDocument($this->_entity, 'create', $this->params, __FUNCTION__, __FILE__);
48 $this->assertEquals(1, $result['count']);
49 $this->getAndCheck($this->params, $result['id'], $this->_entity);
50 $this->assertNotNull($result['values'][$result['id']]['id']);
51 }
52
53 public function testGetEntityBatch() {
54 $result = $this->callAPISuccess($this->_entity, 'create', $this->params);
55 $result = $this->callAPIAndDocument($this->_entity, 'get', $this->params, __FUNCTION__, __FILE__);
56 $this->assertEquals(1, $result['count']);
57 $this->assertNotNull($result['values'][$result['id']]['id']);
58 $this->callAPISuccess($this->_entity, 'delete', ['id' => $result['id']]);
59 }
60
61 public function testDeleteEntityBatch() {
62 $result = $this->callAPISuccess($this->_entity, 'create', $this->params);
63 $deleteParams = ['id' => $result['id']];
64 $result = $this->callAPIAndDocument($this->_entity, 'delete', $deleteParams, __FUNCTION__, __FILE__);
65 $checkDeleted = $this->callAPISuccess($this->_entity, 'get', []);
66 $this->assertEquals(0, $checkDeleted['count']);
67 }
68
69 }