Commit | Line | Data |
---|---|---|
6a488035 TO |
1 | <?php |
2 | /* | |
3 | +--------------------------------------------------------------------+ | |
7d61e75f | 4 | | Copyright CiviCRM LLC. All rights reserved. | |
6a488035 | 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 | | |
6a488035 | 9 | +--------------------------------------------------------------------+ |
d25dd0ee | 10 | */ |
6a488035 | 11 | |
6a488035 TO |
12 | /** |
13 | * Test class for Batch API - civicrm_batch_* | |
14 | * | |
6c6e6187 | 15 | * @package CiviCRM_APIv3 |
acb109b7 | 16 | * @group headless |
6a488035 TO |
17 | */ |
18 | class api_v3_BatchTest extends CiviUnitTestCase { | |
b7c9bc4c | 19 | |
9099cab3 | 20 | protected $_params = []; |
23c385a2 | 21 | protected $_entity = 'batch'; |
22 | ||
6a488035 TO |
23 | /** |
24 | * Sets up the fixture, for example, opens a network connection. | |
fe482240 | 25 | * |
6a488035 | 26 | * This method is called before a test is executed. |
6a488035 TO |
27 | */ |
28 | protected function setUp() { | |
6a488035 | 29 | parent::setUp(); |
7d27f8fe | 30 | $this->useTransaction(TRUE); |
23c385a2 | 31 | } |
6a488035 | 32 | |
6a488035 TO |
33 | /** |
34 | * Test civicrm_batch_get - success expected. | |
35 | */ | |
36 | public function testGet() { | |
9099cab3 | 37 | $params = [ |
6a488035 | 38 | 'id' => $this->batchCreate(), |
9099cab3 | 39 | ]; |
23c385a2 | 40 | $result = $this->callAPIAndDocument('batch', 'get', $params, __FUNCTION__, __FILE__); |
ba4a1892 | 41 | $this->assertEquals($params['id'], $result['id']); |
6a488035 TO |
42 | } |
43 | ||
6a488035 TO |
44 | /** |
45 | * Test civicrm_batch_create - success expected. | |
46 | */ | |
00be9182 | 47 | public function testCreate() { |
9099cab3 | 48 | $params = [ |
6a488035 TO |
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, | |
9099cab3 | 55 | ]; |
6a488035 | 56 | |
23c385a2 | 57 | $result = $this->callAPIAndDocument('batch', 'create', $params, __FUNCTION__, __FILE__); |
ba4a1892 | 58 | $this->assertNotNull($result['id']); |
23c385a2 | 59 | $this->getAndCheck($params, $result['id'], $this->_entity); |
6a488035 TO |
60 | } |
61 | ||
62 | /** | |
63 | * Test civicrm_batch_create with id. | |
64 | */ | |
00be9182 | 65 | public function testUpdate() { |
9099cab3 | 66 | $params = [ |
6a488035 TO |
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, | |
6a488035 | 72 | 'id' => $this->batchCreate(), |
9099cab3 | 73 | ]; |
6a488035 | 74 | |
23c385a2 | 75 | $result = $this->callAPIAndDocument('batch', 'create', $params, __FUNCTION__, __FILE__); |
ba4a1892 | 76 | $this->assertNotNull($result['id']); |
23c385a2 | 77 | $this->getAndCheck($params, $result['id'], $this->_entity); |
6a488035 TO |
78 | } |
79 | ||
80 | /** | |
81 | * Test civicrm_batch_delete using the old $params['batch_id'] syntax. | |
82 | */ | |
00be9182 | 83 | public function testBatchDeleteOldSyntax() { |
6a488035 | 84 | $batchID = $this->batchCreate(); |
9099cab3 | 85 | $params = [ |
6a488035 | 86 | 'batch_id' => $batchID, |
9099cab3 | 87 | ]; |
23c385a2 | 88 | $result = $this->callAPISuccess('batch', 'delete', $params); |
6a488035 TO |
89 | } |
90 | ||
91 | /** | |
d177a2a6 | 92 | * Test civicrm_batch_delete using the new $params['id'] syntax. |
6a488035 | 93 | */ |
00be9182 | 94 | public function testBatchDeleteCorrectSyntax() { |
6a488035 | 95 | $batchID = $this->batchCreate(); |
9099cab3 | 96 | $params = [ |
6a488035 | 97 | 'id' => $batchID, |
9099cab3 | 98 | ]; |
23c385a2 | 99 | $result = $this->callAPIAndDocument('batch', 'delete', $params, __FUNCTION__, __FILE__); |
6a488035 TO |
100 | } |
101 | ||
102 | } |