CRM-16842 add EntityBatch API fixed.
authorSaurabh Batra <saurabh.batra96@gmail.com>
Sun, 18 Oct 2015 16:11:40 +0000 (21:41 +0530)
committerSaurabh Batra <saurabh.batra96@gmail.com>
Sun, 18 Oct 2015 16:11:40 +0000 (21:41 +0530)
----------------------------------------
* CRM-16842:
  https://issues.civicrm.org/jira/browse/CRM-16842

CRM/Batch/BAO/EntityBatch.php [new file with mode: 0644]
api/v3/EntityBatch.php [new file with mode: 0644]
tests/phpunit/CiviTest/CiviUnitTestCase.php
tests/phpunit/api/v3/BatchTest.php
tests/phpunit/api/v3/EntityBatchTest.php [new file with mode: 0644]
xml/schema/Batch/EntityBatch.xml

diff --git a/CRM/Batch/BAO/EntityBatch.php b/CRM/Batch/BAO/EntityBatch.php
new file mode 100644 (file)
index 0000000..1895eaa
--- /dev/null
@@ -0,0 +1,35 @@
+<?php
+/*
+ +--------------------------------------------------------------------+
+ | CiviCRM version 4.6                                                |
+ +--------------------------------------------------------------------+
+ | Copyright CiviCRM LLC (c) 2004-2015                                |
+ +--------------------------------------------------------------------+
+ | This file is a part of CiviCRM.                                    |
+ |                                                                    |
+ | CiviCRM is free software; you can copy, modify, and distribute it  |
+ | under the terms of the GNU Affero General Public License           |
+ | Version 3, 19 November 2007 and the CiviCRM Licensing Exception.   |
+ |                                                                    |
+ | CiviCRM is distributed in the hope that it will be useful, but     |
+ | WITHOUT ANY WARRANTY; without even the implied warranty of         |
+ | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.               |
+ | See the GNU Affero General Public License for more details.        |
+ |                                                                    |
+ | You should have received a copy of the GNU Affero General Public   |
+ | License and the CiviCRM Licensing Exception along                  |
+ | with this program; if not, contact CiviCRM LLC                     |
+ | at info[AT]civicrm[DOT]org. If you have questions about the        |
+ | GNU Affero General Public License or the licensing of CiviCRM,     |
+ | see the CiviCRM license FAQ at http://civicrm.org/licensing        |
+ +--------------------------------------------------------------------+
+ */
+
+/**
+ *
+ * @package CRM
+ * @copyright CiviCRM LLC (c) 2004-2015
+ */
+class CRM_Batch_BAO_EntityBatch extends CRM_Batch_DAO_EntityBatch {
+
+}
diff --git a/api/v3/EntityBatch.php b/api/v3/EntityBatch.php
new file mode 100644 (file)
index 0000000..bcac0bb
--- /dev/null
@@ -0,0 +1,81 @@
+<?php
+/*
+ --------------------------------------------------------------------
+ | CiviCRM version 4.6                                                |
+ --------------------------------------------------------------------
+ | Copyright CiviCRM LLC (c) 2004-2015                                |
+ --------------------------------------------------------------------
+ | This file is a part of CiviCRM.                                    |
+ |                                                                    |
+ | CiviCRM is free software; you can copy, modify, and distribute it  |
+ | under the terms of the GNU Affero General Public License           |
+ | Version 3, 19 November 2007 and the CiviCRM Licensing Exception.   |
+ |                                                                    |
+ | CiviCRM is distributed in the hope that it will be useful, but     |
+ | WITHOUT ANY WARRANTY; without even the implied warranty of         |
+ | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.               |
+ | See the GNU Affero General Public License for more details.        |
+ |                                                                    |
+ | You should have received a copy of the GNU Affero General Public   |
+ | License and the CiviCRM Licensing Exception along                  |
+ | with this program; if not, contact CiviCRM LLC                     |
+ | at info[AT]civicrm[DOT]org. If you have questions about the        |
+ | GNU Affero General Public License or the licensing of CiviCRM,     |
+ | see the CiviCRM license FAQ at http://civicrm.org/licensing        |
+ --------------------------------------------------------------------
+ */
+
+/**
+ * This api exposes CiviCRM EntityBatch records.
+ *
+ * Use this api to add/remove entities from a batch.
+ * To create/update/delete the batches themselves, use the Batch api.
+ *
+ * @package CiviCRM_APIv3
+ */
+
+/**
+ * Get entity batches.
+ *
+ * @param array $params
+ *
+ * @return array
+ */
+function civicrm_api3_entity_batch_get($params) {
+  return _civicrm_api3_basic_get(_civicrm_api3_get_BAO(__FUNCTION__), $params);
+}
+
+/**
+ * Adjust Metadata for Create action.
+ *
+ * The metadata is used for setting defaults, documentation & validation.
+ *
+ * @param array $params
+ *   Array of parameters determined by getfields.
+ */
+function _civicrm_api3_entity_batch_create_spec(&$params) {
+  $params['entity_id']['api.required'] = 1;
+  $params['batch_id']['api.required'] = 1;
+}
+
+/**
+ * Create an entity batch.
+ *
+ * @param array $params
+ *
+ * @return array
+ */
+function civicrm_api3_entity_batch_create($params) {
+  return _civicrm_api3_basic_create(_civicrm_api3_get_BAO(__FUNCTION__), $params);
+}
+
+/**
+ * Mark entity batch as removed.
+ *
+ * @param array $params
+ *
+ * @return array
+ */
+function civicrm_api3_entity_batch_delete($params) {
+  return _civicrm_api3_basic_delete(_civicrm_api3_get_BAO(__FUNCTION__), $params);
+}
index 4e9605dbb89b8317709c8445bc9df4adbc61a073..092147c8eb77e0fbc0c3103b3b6adda4f5c80783 100755 (executable)
@@ -1543,6 +1543,17 @@ class CiviUnitTestCase extends PHPUnit_Extensions_Database_TestCase {
     return $contributionPage;
   }
 
+  /**
+   * 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'];
+  }
+
   /**
    * Create Tag.
    *
index cd87ae8dd5763384ba44b439b6bcb858ac6ef8e3..bf6bac07ccd55141c3ff95fa884a2f2029c939f3 100644 (file)
@@ -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 (file)
index 0000000..e429c0e
--- /dev/null
@@ -0,0 +1,84 @@
+<?php
+/*
+ --------------------------------------------------------------------
+ | CiviCRM version 4.6                                                |
+ --------------------------------------------------------------------
+ | Copyright CiviCRM LLC (c) 2004-2015                                |
+ --------------------------------------------------------------------
+ | This file is a part of CiviCRM.                                    |
+ |                                                                    |
+ | CiviCRM is free software; you can copy, modify, and distribute it  |
+ | under the terms of the GNU Affero General Public License           |
+ | Version 3, 19 November 2007 and the CiviCRM Licensing Exception.   |
+ |                                                                    |
+ | CiviCRM is distributed in the hope that it will be useful, but     |
+ | WITHOUT ANY WARRANTY; without even the implied warranty of         |
+ | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.               |
+ | See the GNU Affero General Public License for more details.        |
+ |                                                                    |
+ | You should have received a copy of the GNU Affero General Public   |
+ | License and the CiviCRM Licensing Exception along                  |
+ | with this program; if not, contact CiviCRM LLC                     |
+ | at info[AT]civicrm[DOT]org. If you have questions about the        |
+ | GNU Affero General Public License or the licensing of CiviCRM,     |
+ | see the CiviCRM license FAQ at http://civicrm.org/licensing        |
+ --------------------------------------------------------------------
+ */
+
+require_once 'CiviTest/CiviUnitTestCase.php';
+
+
+/**
+ *  Test APIv3 civicrm_entity_batch_* functions
+ *
+ * @package CiviCRM_APIv3
+ */
+class api_v3_EntityBatchTest extends CiviUnitTestCase {
+
+  protected $_apiversion = 3;
+  protected $params;
+  protected $id;
+  protected $_entity;
+
+  public $DBResetRequired = FALSE;
+
+  public function setUp() {
+    parent::setUp();
+    $this->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']);
+  }
+
+}
index 1ab00dd36e740ae9c63136313d8e6917367944f3..2f4ebec5e350d9d56dad019b04e043fcc3932bab 100644 (file)
@@ -7,6 +7,7 @@
   <comment>Batch entities (Contributions, Participants, Contacts) to a batch.</comment>
   <field>
     <name>id</name>
+    <title>EntityBatch ID</title>
     <type>int unsigned</type>
     <required>true</required>
     <comment>primary key</comment>
@@ -18,6 +19,7 @@
   </primaryKey>
   <field>
     <name>entity_table</name>
+    <title>EntityBatch Table</title>
     <type>varchar</type>
     <length>64</length>
     <comment>physical tablename for entity being joined to file, e.g. civicrm_contact</comment>
@@ -25,6 +27,7 @@
   </field>
   <field>
     <name>entity_id</name>
+    <title>Entity ID</title>
     <type>int unsigned</type>
     <required>true</required>
     <comment>FK to entity table specified in entity_table column.</comment>
@@ -43,6 +46,7 @@
   </index>
   <field>
     <name>batch_id</name>
+    <title>Batch ID</title>
     <type>int unsigned</type>
     <required>true</required>
     <comment>FK to civicrm_batch</comment>