Skip to content

Commit

Permalink
Add v4 batch api
Browse files Browse the repository at this point in the history
  • Loading branch information
eileenmcnaughton committed Mar 29, 2021
1 parent 027ef84 commit 37607fe
Show file tree
Hide file tree
Showing 2 changed files with 66 additions and 11 deletions.
30 changes: 30 additions & 0 deletions Civi/Api4/Batch.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?php

/*
+--------------------------------------------------------------------+
| Copyright CiviCRM LLC. All rights reserved. |
| |
| This work is published under the GNU AGPLv3 license with some |
| permitted exceptions and without any warranty. For full license |
| and copyright information, see https://civicrm.org/licensing |
+--------------------------------------------------------------------+
*/

/**
*
* @package CRM
* @copyright CiviCRM LLC https://civicrm.org/licensing
*/


namespace Civi\Api4;

/**
* Batch entity.
*
* @see https://docs.civicrm.org/user/en/latest/pledges/everyday-tasks/#batch-entry-of-pledges
* @package Civi\Api4
*/
class Batch extends Generic\DAOEntity {

}
47 changes: 36 additions & 11 deletions tests/phpunit/api/v3/BatchTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
*/
class api_v3_BatchTest extends CiviUnitTestCase {

protected $_params = [];
protected $_entity = 'batch';

/**
Expand All @@ -27,24 +26,36 @@ class api_v3_BatchTest extends CiviUnitTestCase {
*/
protected function setUp(): void {
parent::setUp();
$this->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',
Expand All @@ -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',
Expand All @@ -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__);
}

}

0 comments on commit 37607fe

Please sign in to comment.