From 37607fee5677b50d493547f1cb257e58691bec66 Mon Sep 17 00:00:00 2001 From: eileen Date: Mon, 29 Mar 2021 12:42:43 +1300 Subject: [PATCH] Add v4 batch api --- Civi/Api4/Batch.php | 30 +++++++++++++++++++ tests/phpunit/api/v3/BatchTest.php | 47 +++++++++++++++++++++++------- 2 files changed, 66 insertions(+), 11 deletions(-) create mode 100644 Civi/Api4/Batch.php diff --git a/Civi/Api4/Batch.php b/Civi/Api4/Batch.php new file mode 100644 index 000000000000..8a75875070d7 --- /dev/null +++ b/Civi/Api4/Batch.php @@ -0,0 +1,30 @@ +useTransaction(TRUE); + $this->useTransaction(); } /** * Test civicrm_batch_get - success expected. + * + * @dataProvider versionThreeAndFour + * + * @param int $version */ - public function testGet() { + public function testGet(int $version): void { + $this->_apiversion = $version; $params = [ 'id' => $this->batchCreate(), ]; - $result = $this->callAPIAndDocument('batch', 'get', $params, __FUNCTION__, __FILE__); + $result = $this->callAPIAndDocument('Batch', 'get', $params, __FUNCTION__, __FILE__); $this->assertEquals($params['id'], $result['id']); } /** * Test civicrm_batch_create - success expected. + * + * @dataProvider versionThreeAndFour + * + * @param int $version + * + * @throws \CRM_Core_Exception */ - public function testCreate() { + public function testCreate(int $version): void { + $this->_apiversion = $version; $params = [ 'name' => 'New_Batch_03', 'title' => 'New Batch 03', @@ -56,13 +67,20 @@ public function testCreate() { $result = $this->callAPIAndDocument('batch', 'create', $params, __FUNCTION__, __FILE__); $this->assertNotNull($result['id']); - $this->getAndCheck($params, $result['id'], $this->_entity); + $this->getAndCheck($params, $result['id'], 'Batch'); } /** * Test civicrm_batch_create with id. + * + * @dataProvider versionThreeAndFour + * + * @param int $version + * + * @throws \CRM_Core_Exception */ - public function testUpdate() { + public function testUpdate(int $version): void { + $this->_apiversion = $version; $params = [ 'name' => 'New_Batch_04', 'title' => 'New Batch 04', @@ -79,24 +97,31 @@ public function testUpdate() { /** * Test civicrm_batch_delete using the old $params['batch_id'] syntax. + * + * @throws \CRM_Core_Exception */ - public function testBatchDeleteOldSyntax() { + public function testBatchDeleteOldSyntax(): void { $batchID = $this->batchCreate(); $params = [ 'batch_id' => $batchID, ]; - $result = $this->callAPISuccess('batch', 'delete', $params); + $this->callAPISuccess('Batch', 'delete', $params); } /** * Test civicrm_batch_delete using the new $params['id'] syntax. + * + * @dataProvider versionThreeAndFour + * + * @param int $version */ - public function testBatchDeleteCorrectSyntax() { + public function testBatchDeleteCorrectSyntax(int $version): void { + $this->_apiversion = $version; $batchID = $this->batchCreate(); $params = [ 'id' => $batchID, ]; - $result = $this->callAPIAndDocument('batch', 'delete', $params, __FUNCTION__, __FILE__); + $this->callAPIAndDocument('Batch', 'delete', $params, __FUNCTION__, __FILE__); } }