Merge pull request #17440 from eileenmcnaughton/log_summ
[civicrm-core.git] / tests / phpunit / CiviTest / CiviUnitTestCase.php
index 742a59273decd43f4e781bc59798655f61c974f2..83fff3e4185cae226db4a55ae446b90a74260078 100644 (file)
@@ -495,14 +495,14 @@ class CiviUnitTestCase extends PHPUnit\Framework\TestCase {
    * Create a batch of external API calls which can
    * be executed concurrently.
    *
-   * @code
+   * ```
    * $calls = $this->createExternalAPI()
    *    ->addCall('Contact', 'get', ...)
    *    ->addCall('Contact', 'get', ...)
    *    ...
    *    ->run()
    *    ->getResults();
-   * @endcode
+   * ```
    *
    * @return \Civi\API\ExternalBatch
    * @throws PHPUnit_Framework_SkippedTestError
@@ -929,6 +929,8 @@ class CiviUnitTestCase extends PHPUnit\Framework\TestCase {
    *
    * @return int
    *   id of created pledge
+   *
+   * @throws \CRM_Core_Exception
    */
   public function pledgeCreate($params) {
     $params = array_merge([
@@ -954,6 +956,8 @@ class CiviUnitTestCase extends PHPUnit\Framework\TestCase {
    * Delete contribution.
    *
    * @param int $pledgeId
+   *
+   * @throws \CRM_Core_Exception
    */
   public function pledgeDelete($pledgeId) {
     $params = [
@@ -3558,4 +3562,35 @@ VALUES
     }
   }
 
+  /**
+   * Generic create test.
+   *
+   * @param int $version
+   *
+   * @throws \CRM_Core_Exception
+   */
+  protected function basicCreateTest(int $version) {
+    $this->_apiversion = $version;
+    $result = $this->callAPIAndDocument($this->_entity, 'create', $this->params, __FUNCTION__, __FILE__);
+    $this->assertEquals(1, $result['count']);
+    $this->assertNotNull($result['values'][$result['id']]['id']);
+    $this->getAndCheck($this->params, $result['id'], $this->_entity);
+  }
+
+  /**
+   * Generic delete test.
+   *
+   * @param int $version
+   *
+   * @throws \CRM_Core_Exception
+   */
+  protected function basicDeleteTest($version) {
+    $this->_apiversion = $version;
+    $result = $this->callAPISuccess($this->_entity, 'create', $this->params);
+    $deleteParams = ['id' => $result['id']];
+    $this->callAPIAndDocument($this->_entity, 'delete', $deleteParams, __FUNCTION__, __FILE__);
+    $checkDeleted = $this->callAPISuccess($this->_entity, 'get', []);
+    $this->assertEquals(0, $checkDeleted['count']);
+  }
+
 }