From a646bdd257802b5685dc038439fee73e8de78e6c Mon Sep 17 00:00:00 2001 From: Saurabh Batra Date: Sun, 18 Oct 2015 21:41:40 +0530 Subject: [PATCH] CRM-16842 add EntityBatch API fixed. ---------------------------------------- * CRM-16842: https://issues.civicrm.org/jira/browse/CRM-16842 --- CRM/Batch/BAO/EntityBatch.php | 35 +++++++++ api/v3/EntityBatch.php | 81 ++++++++++++++++++++ tests/phpunit/CiviTest/CiviUnitTestCase.php | 11 +++ tests/phpunit/api/v3/BatchTest.php | 11 --- tests/phpunit/api/v3/EntityBatchTest.php | 84 +++++++++++++++++++++ xml/schema/Batch/EntityBatch.xml | 4 + 6 files changed, 215 insertions(+), 11 deletions(-) create mode 100644 CRM/Batch/BAO/EntityBatch.php create mode 100644 api/v3/EntityBatch.php create mode 100644 tests/phpunit/api/v3/EntityBatchTest.php diff --git a/CRM/Batch/BAO/EntityBatch.php b/CRM/Batch/BAO/EntityBatch.php new file mode 100644 index 0000000000..1895eaa91a --- /dev/null +++ b/CRM/Batch/BAO/EntityBatch.php @@ -0,0 +1,35 @@ +_params; + $params['name'] = $params['title'] = 'Batch_433397'; + $params['status_id'] = 1; + $result = $this->callAPISuccess('batch', 'create', $params); + return $result['id']; + } + /** * Create Tag. * diff --git a/tests/phpunit/api/v3/BatchTest.php b/tests/phpunit/api/v3/BatchTest.php index cd87ae8dd5..bf6bac07cc 100644 --- a/tests/phpunit/api/v3/BatchTest.php +++ b/tests/phpunit/api/v3/BatchTest.php @@ -47,17 +47,6 @@ class api_v3_BatchTest extends CiviUnitTestCase { $this->useTransaction(TRUE); } - /** - * Create a sample batch. - */ - public function batchCreate() { - $params = $this->_params; - $params['name'] = $params['title'] = 'Batch_433397'; - $params['status_id'] = 1; - $result = $this->callAPISuccess('batch', 'create', $params); - return $result['id']; - } - /** * Test civicrm_batch_get - success expected. */ diff --git a/tests/phpunit/api/v3/EntityBatchTest.php b/tests/phpunit/api/v3/EntityBatchTest.php new file mode 100644 index 0000000000..e429c0ee45 --- /dev/null +++ b/tests/phpunit/api/v3/EntityBatchTest.php @@ -0,0 +1,84 @@ +useTransaction(TRUE); + + $entityParams = array('contact_id' => 1); + + $this->_entity = 'EntityBatch'; + $this->_entityID = $this->contributionCreate($entityParams); + $this->_batchID = $this->batchCreate(); + $this->params = array( + 'entity_id' => $this->_entityID, + 'batch_id' => $this->_batchID, + 'entity_table' => 'civicrm_financial_trxn', + ); + } + + public function testCreateEntityBatch() { + $result = $this->callAPIAndDocument($this->_entity, 'create', $this->params, __FUNCTION__, __FILE__); + $this->assertEquals(1, $result['count']); + $this->getAndCheck($this->params, $result['id'], $this->_entity); + $this->assertNotNull($result['values'][$result['id']]['id']); + } + + public function testGetEntityBatch() { + $result = $this->callAPISuccess($this->_entity, 'create', $this->params); + $result = $this->callAPIAndDocument($this->_entity, 'get', $this->params, __FUNCTION__, __FILE__); + $this->assertEquals(1, $result['count']); + $this->assertNotNull($result['values'][$result['id']]['id']); + $this->callAPISuccess($this->_entity, 'delete', array('id' => $result['id'])); + } + + public function testDeleteEntityBatch() { + $result = $this->callAPISuccess($this->_entity, 'create', $this->params); + $deleteParams = array('id' => $result['id']); + $result = $this->callAPIAndDocument($this->_entity, 'delete', $deleteParams, __FUNCTION__, __FILE__); + $checkDeleted = $this->callAPISuccess($this->_entity, 'get', array()); + $this->assertEquals(0, $checkDeleted['count']); + } + +} diff --git a/xml/schema/Batch/EntityBatch.xml b/xml/schema/Batch/EntityBatch.xml index 1ab00dd36e..2f4ebec5e3 100644 --- a/xml/schema/Batch/EntityBatch.xml +++ b/xml/schema/Batch/EntityBatch.xml @@ -7,6 +7,7 @@ Batch entities (Contributions, Participants, Contacts) to a batch. id + EntityBatch ID int unsigned true primary key @@ -18,6 +19,7 @@ entity_table + EntityBatch Table varchar 64 physical tablename for entity being joined to file, e.g. civicrm_contact @@ -25,6 +27,7 @@ entity_id + Entity ID int unsigned true FK to entity table specified in entity_table column. @@ -43,6 +46,7 @@ batch_id + Batch ID int unsigned true FK to civicrm_batch -- 2.25.1