Merge pull request #20400 from MegaphoneJon/check-signature
[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 protected $params;
19 protected $id;
20 protected $_entity;
21
22 public $DBResetRequired = FALSE;
23
24 /**
25 * @throws \CRM_Core_Exception
26 * @throws \CiviCRM_API3_Exception
27 */
28 public function setUp(): void {
29 parent::setUp();
30 $this->useTransaction();
31
32 $entityParams = ['contact_id' => $this->individualCreate()];
33
34 $this->_entity = 'EntityBatch';
35 $this->params = [
36 'entity_id' => $this->contributionCreate($entityParams),
37 'batch_id' => $this->batchCreate(),
38 'entity_table' => 'civicrm_financial_trxn',
39 ];
40 }
41
42 /**
43 * @throws \CRM_Core_Exception
44 */
45 public function testCreateEntityBatch(): void {
46 $result = $this->callAPIAndDocument($this->_entity, 'create', $this->params, __FUNCTION__, __FILE__);
47 $this->assertEquals(1, $result['count']);
48 $this->getAndCheck($this->params, $result['id'], $this->_entity);
49 $this->assertNotNull($result['values'][$result['id']]['id']);
50 }
51
52 /**
53 * @throws \CRM_Core_Exception
54 */
55 public function testGetEntityBatch(): void {
56 $this->callAPISuccess($this->_entity, 'create', $this->params);
57 $result = $this->callAPIAndDocument($this->_entity, 'get', $this->params, __FUNCTION__, __FILE__);
58 $this->assertEquals(1, $result['count']);
59 $this->assertNotNull($result['values'][$result['id']]['id']);
60 $this->callAPISuccess($this->_entity, 'delete', ['id' => $result['id']]);
61 }
62
63 /**
64 * @throws \CRM_Core_Exception
65 */
66 public function testDeleteEntityBatch(): void {
67 $result = $this->callAPISuccess($this->_entity, 'create', $this->params);
68 $deleteParams = ['id' => $result['id']];
69 $this->callAPIAndDocument($this->_entity, 'delete', $deleteParams, __FUNCTION__, __FILE__);
70 $checkDeleted = $this->callAPISuccess($this->_entity, 'get', []);
71 $this->assertEquals(0, $checkDeleted['count']);
72 }
73
74 }