Merge pull request #16469 from civicrm/5.22
[civicrm-core.git] / tests / phpunit / api / v3 / BatchTest.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 class for Batch API - civicrm_batch_*
14 *
15 * @package CiviCRM_APIv3
16 * @group headless
17 */
18 class api_v3_BatchTest extends CiviUnitTestCase {
19
20 protected $_params = [];
21 protected $_entity = 'batch';
22
23 /**
24 * Sets up the fixture, for example, opens a network connection.
25 *
26 * This method is called before a test is executed.
27 */
28 protected function setUp() {
29 parent::setUp();
30 $this->useTransaction(TRUE);
31 }
32
33 /**
34 * Test civicrm_batch_get - success expected.
35 */
36 public function testGet() {
37 $params = [
38 'id' => $this->batchCreate(),
39 ];
40 $result = $this->callAPIAndDocument('batch', 'get', $params, __FUNCTION__, __FILE__);
41 $this->assertEquals($params['id'], $result['id']);
42 }
43
44 /**
45 * Test civicrm_batch_create - success expected.
46 */
47 public function testCreate() {
48 $params = [
49 'name' => 'New_Batch_03',
50 'title' => 'New Batch 03',
51 'description' => 'This is description for New Batch 03',
52 'total' => '300.33',
53 'item_count' => 3,
54 'status_id' => 1,
55 ];
56
57 $result = $this->callAPIAndDocument('batch', 'create', $params, __FUNCTION__, __FILE__);
58 $this->assertNotNull($result['id']);
59 $this->getAndCheck($params, $result['id'], $this->_entity);
60 }
61
62 /**
63 * Test civicrm_batch_create with id.
64 */
65 public function testUpdate() {
66 $params = [
67 'name' => 'New_Batch_04',
68 'title' => 'New Batch 04',
69 'description' => 'This is description for New Batch 04',
70 'total' => '400.44',
71 'item_count' => 4,
72 'id' => $this->batchCreate(),
73 ];
74
75 $result = $this->callAPIAndDocument('batch', 'create', $params, __FUNCTION__, __FILE__);
76 $this->assertNotNull($result['id']);
77 $this->getAndCheck($params, $result['id'], $this->_entity);
78 }
79
80 /**
81 * Test civicrm_batch_delete using the old $params['batch_id'] syntax.
82 */
83 public function testBatchDeleteOldSyntax() {
84 $batchID = $this->batchCreate();
85 $params = [
86 'batch_id' => $batchID,
87 ];
88 $result = $this->callAPISuccess('batch', 'delete', $params);
89 }
90
91 /**
92 * Test civicrm_batch_delete using the new $params['id'] syntax.
93 */
94 public function testBatchDeleteCorrectSyntax() {
95 $batchID = $this->batchCreate();
96 $params = [
97 'id' => $batchID,
98 ];
99 $result = $this->callAPIAndDocument('batch', 'delete', $params, __FUNCTION__, __FILE__);
100 }
101
102 }