CRM-15680 fix custom data on survey & campaign
[civicrm-core.git] / tests / phpunit / CiviTest / CiviUnitTestCase.php
old mode 100644 (file)
new mode 100755 (executable)
index ca8620d..5bb07b4
@@ -47,6 +47,17 @@ define('API_LATEST_VERSION', 3);
 /**
  *  Base class for CiviCRM unit tests
  *
+ * This class supports two (mutually-exclusive) techniques for cleaning up test data. Subclasses
+ * may opt for one or neither:
+ *
+ * 1. quickCleanup() is a helper which truncates a series of tables. Call quickCleanup()
+ *    as part of setUp() and/or tearDown(). quickCleanup() is thorough - but it can
+ *    be cumbersome to use (b/c you must identify the tables to cleanup) and slow to execute.
+ * 2. useTransaction() executes the test inside a transaction. It's easier to use
+ *    (because you don't need to identify specific tables), but it doesn't work for tests
+ *    which manipulate schema or truncate data -- and could behave inconsistently
+ *    for tests which specifically examine DB transactions.
+ *
  *  Common functions for unit tests
  * @package CiviCRM
  */
@@ -119,6 +130,11 @@ class CiviUnitTestCase extends PHPUnit_Extensions_Database_TestCase {
    */
   public $DBResetRequired = TRUE;
 
+  /**
+   * @var CRM_Core_Transaction|NULL
+   */
+  private $tx = NULL;
+
   /**
    *  Constructor
    *
@@ -133,7 +149,7 @@ class CiviUnitTestCase extends PHPUnit_Extensions_Database_TestCase {
    * @param  array  $data
    * @param  string $dataName
    */
-  function __construct($name = NULL, array$data = array(), $dataName = '') {
+  public function __construct($name = NULL, array$data = array(), $dataName = '') {
     parent::__construct($name, $data, $dataName);
 
     // we need full error reporting
@@ -173,14 +189,14 @@ class CiviUnitTestCase extends PHPUnit_Extensions_Database_TestCase {
   /**
    * @return bool
    */
-  function requireDBReset() {
+  public function requireDBReset() {
     return $this->DBResetRequired;
   }
 
   /**
    * @return string
    */
-  static function getDBName() {
+  public static function getDBName() {
     $dbName = !empty($GLOBALS['mysql_db']) ? $GLOBALS['mysql_db'] : 'civicrm_tests_dev';
     return $dbName;
   }
@@ -382,6 +398,7 @@ class CiviUnitTestCase extends PHPUnit_Extensions_Database_TestCase {
     //flush component settings
     CRM_Core_Component::getEnabledComponents(TRUE);
 
+
     if ($this->_eNoticeCompliant) {
       error_reporting(E_ALL);
     }
@@ -460,19 +477,31 @@ class CiviUnitTestCase extends PHPUnit_Extensions_Database_TestCase {
     error_reporting(E_ALL & ~E_NOTICE);
     $session = CRM_Core_Session::singleton();
     $session->set('userID', NULL);
-    $tablesToTruncate = array('civicrm_contact');
-    $this->quickCleanup($tablesToTruncate);
-    $this->createDomainContacts();
+
+    if ($this->tx) {
+      $this->tx->rollback()->commit();
+      $this->tx = NULL;
+
+      CRM_Core_Transaction::forceRollbackIfEnabled();
+      \Civi\Core\Transaction\Manager::singleton(TRUE);
+    } else {
+      CRM_Core_Transaction::forceRollbackIfEnabled();
+      \Civi\Core\Transaction\Manager::singleton(TRUE);
+
+      $tablesToTruncate = array('civicrm_contact');
+      $this->quickCleanup($tablesToTruncate);
+      $this->createDomainContacts();
+    }
+
     $this->cleanTempDirs();
     $this->unsetExtensionSystem();
-    CRM_Core_Transaction::forceRollbackIfEnabled();
-    \Civi\Core\Transaction\Manager::singleton(TRUE);
+    $this->clearOutputBuffer();
   }
 
   /**
    *  FIXME: Maybe a better way to do it
    */
-  function foreignKeyChecksOff() {
+  public function foreignKeyChecksOff() {
     self::$utils = new Utils($GLOBALS['mysql_host'],
       $GLOBALS['mysql_port'],
       $GLOBALS['mysql_user'],
@@ -488,7 +517,7 @@ class CiviUnitTestCase extends PHPUnit_Extensions_Database_TestCase {
     return TRUE;
   }
 
-  function foreignKeyChecksOn() {
+  public function foreignKeyChecksOn() {
     // FIXME: might not be needed if previous fixme implemented
   }
 
@@ -502,7 +531,7 @@ class CiviUnitTestCase extends PHPUnit_Extensions_Database_TestCase {
    *                      that a DELETE occurred
    * @delete   boolean  True if we're checking that a DELETE action occurred.
    */
-  function assertDBState($daoName, $id, $match, $delete = FALSE) {
+  public function assertDBState($daoName, $id, $match, $delete = FALSE) {
     if (empty($id)) {
       // adding this here since developers forget to check for an id
       // and hence we get the first value in the db
@@ -557,7 +586,7 @@ class CiviUnitTestCase extends PHPUnit_Extensions_Database_TestCase {
    * @return null|string
    * @throws PHPUnit_Framework_AssertionFailedError
    */
-  function assertDBNotNull($daoName, $searchValue, $returnColumn, $searchColumn, $message) {
+  public function assertDBNotNull($daoName, $searchValue, $returnColumn, $searchColumn, $message) {
     if (empty($searchValue)) {
       $this->fail("empty value passed to assertDBNotNull");
     }
@@ -575,7 +604,7 @@ class CiviUnitTestCase extends PHPUnit_Extensions_Database_TestCase {
    * @param $searchColumn
    * @param $message
    */
-  function assertDBNull($daoName, $searchValue, $returnColumn, $searchColumn, $message) {
+  public function assertDBNull($daoName, $searchValue, $returnColumn, $searchColumn, $message) {
     $value = CRM_Core_DAO::getFieldValue($daoName, $searchValue, $returnColumn, $searchColumn, TRUE);
     $this->assertNull($value, $message);
   }
@@ -586,7 +615,7 @@ class CiviUnitTestCase extends PHPUnit_Extensions_Database_TestCase {
    * @param int $id
    * @param null $message
    */
-  function assertDBRowNotExist($daoName, $id, $message = NULL) {
+  public function assertDBRowNotExist($daoName, $id, $message = NULL) {
     $message = $message ? $message : "$daoName (#$id) should not exist";
     $value = CRM_Core_DAO::getFieldValue($daoName, $id, 'id', 'id', TRUE);
     $this->assertNull($value, $message);
@@ -598,7 +627,7 @@ class CiviUnitTestCase extends PHPUnit_Extensions_Database_TestCase {
    * @param int $id
    * @param null $message
    */
-  function assertDBRowExist($daoName, $id, $message = NULL) {
+  public function assertDBRowExist($daoName, $id, $message = NULL) {
     $message = $message ? $message : "$daoName (#$id) should exist";
     $value = CRM_Core_DAO::getFieldValue($daoName, $id, 'id', 'id', TRUE);
     $this->assertEquals($id, $value, $message);
@@ -626,7 +655,7 @@ class CiviUnitTestCase extends PHPUnit_Extensions_Database_TestCase {
    * @param array $searchParams
    * @param $expectedValues
    */
-  function assertDBCompareValues($daoName, $searchParams, $expectedValues) {
+  public function assertDBCompareValues($daoName, $searchParams, $expectedValues) {
     //get the values from db
     $dbValues = array();
     CRM_Core_DAO::commonRetrieve($daoName, $searchParams, $dbValues);
@@ -644,7 +673,7 @@ class CiviUnitTestCase extends PHPUnit_Extensions_Database_TestCase {
    * Example: $this->assertSql(2, 'select count(*) from foo where foo.bar like "%1"',
    * array(1 => array("Whiz", "String")));
    */
-  function assertDBQuery($expected, $query, $params = array(), $message = '') {
+  public function assertDBQuery($expected, $query, $params = array(), $message = '') {
     if ($message) $message .= ': ';
     $actual = CRM_Core_DAO::singleValueQuery($query, $params);
     $this->assertEquals($expected, $actual,
@@ -661,7 +690,7 @@ class CiviUnitTestCase extends PHPUnit_Extensions_Database_TestCase {
    * @param array $expected
    * @param array $actual
    */
-  function assertTreeEquals($expected, $actual) {
+  public function assertTreeEquals($expected, $actual) {
     $e = array();
     $a = array();
     CRM_Utils_Array::flatten($expected, $e, '', ':::');
@@ -680,7 +709,7 @@ class CiviUnitTestCase extends PHPUnit_Extensions_Database_TestCase {
    * @param int|float $tolerance
    * @param string $message
    */
-  function assertApproxEquals($expected, $actual, $tolerance, $message = NULL) {
+  public function assertApproxEquals($expected, $actual, $tolerance, $message = NULL) {
     if ($message === NULL) {
       $message = sprintf("approx-equals: expected=[%.3f] actual=[%.3f] tolerance=[%.3f]", $expected, $actual, $tolerance);
     }
@@ -694,7 +723,7 @@ class CiviUnitTestCase extends PHPUnit_Extensions_Database_TestCase {
    *
    * @throws PHPUnit_Framework_AssertionFailedError
    */
-  function assertAttributesEquals($expectedValues, $actualValues, $message = NULL) {
+  public function assertAttributesEquals($expectedValues, $actualValues, $message = NULL) {
     foreach ($expectedValues as $paramName => $paramValue) {
       if (isset($actualValues[$paramName])) {
         $this->assertEquals($paramValue, $actualValues[$paramName], "Value Mismatch On $paramName - value 1 is " . print_r($paramValue, TRUE) . "  value 2 is " . print_r($actualValues[$paramName], TRUE) );
@@ -709,7 +738,7 @@ class CiviUnitTestCase extends PHPUnit_Extensions_Database_TestCase {
    * @param $key
    * @param $list
    */
-  function assertArrayKeyExists($key, &$list) {
+  public function assertArrayKeyExists($key, &$list) {
     $result = isset($list[$key]) ? TRUE : FALSE;
     $this->assertTrue($result, ts("%1 element exists?",
       array(1 => $key)
@@ -720,7 +749,7 @@ class CiviUnitTestCase extends PHPUnit_Extensions_Database_TestCase {
    * @param $key
    * @param $list
    */
-  function assertArrayValueNotNull($key, &$list) {
+  public function assertArrayValueNotNull($key, &$list) {
     $this->assertArrayKeyExists($key, $list);
 
     $value = isset($list[$key]) ? $list[$key] : NULL;
@@ -737,7 +766,7 @@ class CiviUnitTestCase extends PHPUnit_Extensions_Database_TestCase {
    * @param array $apiResult api result
    * @param string $prefix extra test to add to message
    */
-  function assertAPISuccess($apiResult, $prefix = '') {
+  public function assertAPISuccess($apiResult, $prefix = '') {
     if (!empty($prefix)) {
       $prefix .= ': ';
     }
@@ -760,7 +789,7 @@ class CiviUnitTestCase extends PHPUnit_Extensions_Database_TestCase {
    * @param string $prefix extra test to add to message
    * @param null $expectedError
    */
-  function assertAPIFailure($apiResult, $prefix = '', $expectedError = NULL) {
+  public function assertAPIFailure($apiResult, $prefix = '', $expectedError = NULL) {
     if (!empty($prefix)) {
       $prefix .= ': ';
     }
@@ -776,14 +805,14 @@ class CiviUnitTestCase extends PHPUnit_Extensions_Database_TestCase {
    * @param $actual
    * @param string $message
    */
-  function assertType($expected, $actual, $message = '') {
+  public function assertType($expected, $actual, $message = '') {
     return $this->assertInternalType($expected, $actual, $message);
   }
 
   /**
    * Check that a deleted item has been deleted
    */
-  function assertAPIDeleted($entity, $id) {
+  public function assertAPIDeleted($entity, $id) {
     $this->callAPISuccess($entity, 'getcount', array('id' => $id), 0);
   }
 
@@ -796,7 +825,7 @@ class CiviUnitTestCase extends PHPUnit_Extensions_Database_TestCase {
    * @param array $valuesToExclude
    * @param string $prefix extra test to add to message
    */
-  function assertAPIArrayComparison($result, $expected, $valuesToExclude = array(), $prefix = '') {
+  public function assertAPIArrayComparison($result, $expected, $valuesToExclude = array(), $prefix = '') {
     $valuesToExclude = array_merge($valuesToExclude, array('debug', 'xdebug', 'sequential'));
     foreach ($valuesToExclude as $value) {
       if(isset($result[$value])) {
@@ -817,7 +846,7 @@ class CiviUnitTestCase extends PHPUnit_Extensions_Database_TestCase {
    * @param array $params
    * @return array|int
    */
-  function civicrm_api($entity, $action, $params) {
+  public function civicrm_api($entity, $action, $params) {
     return civicrm_api($entity, $action, $params);
   }
 
@@ -835,7 +864,7 @@ class CiviUnitTestCase extends PHPUnit_Extensions_Database_TestCase {
    *
    * @return array|int
    */
-  function callAPISuccess($entity, $action, $params, $checkAgainst = NULL) {
+  public function callAPISuccess($entity, $action, $params, $checkAgainst = NULL) {
     $params = array_merge(array(
         'version' => $this->_apiversion,
         'debug' => 1,
@@ -872,7 +901,7 @@ class CiviUnitTestCase extends PHPUnit_Extensions_Database_TestCase {
    *
    * @return array|int
    */
-  function callAPISuccessGetValue($entity, $params, $type = NULL) {
+  public function callAPISuccessGetValue($entity, $params, $type = NULL) {
     $params += array(
       'version' => $this->_apiversion,
       'debug' => 1,
@@ -907,7 +936,7 @@ class CiviUnitTestCase extends PHPUnit_Extensions_Database_TestCase {
    * @throws Exception
    * @return array|int
    */
-  function callAPISuccessGetSingle($entity, $params, $checkAgainst = NULL) {
+  public function callAPISuccessGetSingle($entity, $params, $checkAgainst = NULL) {
     $params += array(
       'version' => $this->_apiversion,
       'debug' => 1,
@@ -940,7 +969,7 @@ class CiviUnitTestCase extends PHPUnit_Extensions_Database_TestCase {
    * - array
    * - object
    */
-  function callAPISuccessGetCount($entity, $params, $count = NULL) {
+  public function callAPISuccessGetCount($entity, $params, $count = NULL) {
     $params += array(
       'version' => $this->_apiversion,
       'debug' => 1,
@@ -950,7 +979,7 @@ class CiviUnitTestCase extends PHPUnit_Extensions_Database_TestCase {
       throw new Exception('Invalid getcount result : ' . print_r($result, TRUE) . " type :" . gettype($result));
     }
     if(is_int($count)){
-      $this->assertEquals($count, $result, "incorect count returned from $entity getcount");
+      $this->assertEquals($count, $result, "incorrect count returned from $entity getcount");
     }
     return $result;
   }
@@ -969,7 +998,7 @@ class CiviUnitTestCase extends PHPUnit_Extensions_Database_TestCase {
    * @param string|null $actionName
    * @return array|int
    */
-  function callAPIAndDocument($entity, $action, $params, $function, $file, $description = "", $subfile = NULL, $actionName = NULL){
+  public function callAPIAndDocument($entity, $action, $params, $function, $file, $description = "", $subfile = NULL, $actionName = NULL){
     $params['version'] = $this->_apiversion;
     $result = $this->callAPISuccess($entity, $action, $params);
     $this->documentMe($params, $result, $function, $file, $description, $subfile, $actionName);
@@ -986,7 +1015,7 @@ class CiviUnitTestCase extends PHPUnit_Extensions_Database_TestCase {
    * @param null $extraOutput
    * @return array|int
    */
-  function callAPIFailure($entity, $action, $params, $expectedErrorMessage = NULL, $extraOutput = NULL) {
+  public function callAPIFailure($entity, $action, $params, $expectedErrorMessage = NULL, $extraOutput = NULL) {
     if (is_array($params)) {
       $params += array(
         'version' => $this->_apiversion,
@@ -1017,7 +1046,7 @@ class CiviUnitTestCase extends PHPUnit_Extensions_Database_TestCase {
    *
    * @return int    id of Organisation created
    */
-  function organizationCreate($params = array(), $seq = 0) {
+  public function organizationCreate($params = array(), $seq = 0) {
     if (!$params) {
       $params = array();
     }
@@ -1033,7 +1062,7 @@ class CiviUnitTestCase extends PHPUnit_Extensions_Database_TestCase {
    *
    * @return int    id of Individual created
    */
-  function individualCreate($params = array(), $seq = 0) {
+  public function individualCreate($params = array(), $seq = 0) {
     $params = array_merge($this->sampleContact('Individual', $seq), $params);
     return $this->_contactCreate($params);
   }
@@ -1046,7 +1075,7 @@ class CiviUnitTestCase extends PHPUnit_Extensions_Database_TestCase {
    *
    * @return int    id of Household created
    */
-  function householdCreate($params = array(), $seq = 0) {
+  public function householdCreate($params = array(), $seq = 0) {
     $params = array_merge($this->sampleContact('Household', $seq), $params);
     return $this->_contactCreate($params);
   }
@@ -1059,7 +1088,7 @@ class CiviUnitTestCase extends PHPUnit_Extensions_Database_TestCase {
    *
    * @return array   properties of sample contact (ie. $params for API call)
    */
-  function sampleContact($contact_type, $seq = 0) {
+  public function sampleContact($contact_type, $seq = 0) {
     $samples = array(
       'Individual' => array(
         // The number of values in each list need to be coprime numbers to not have duplicates
@@ -1110,7 +1139,7 @@ class CiviUnitTestCase extends PHPUnit_Extensions_Database_TestCase {
    *
    * @return array|int
    */
-  function contactDelete($contactID) {
+  public function contactDelete($contactID) {
     $params = array(
       'id' => $contactID,
       'skip_undelete' => 1,
@@ -1132,7 +1161,7 @@ class CiviUnitTestCase extends PHPUnit_Extensions_Database_TestCase {
    *
    * @throws Exception
    */
-  function contactTypeDelete($contactTypeId) {
+  public function contactTypeDelete($contactTypeId) {
     require_once 'CRM/Contact/BAO/ContactType.php';
     $result = CRM_Contact_BAO_ContactType::del($contactTypeId);
     if (!$result) {
@@ -1145,7 +1174,7 @@ class CiviUnitTestCase extends PHPUnit_Extensions_Database_TestCase {
    *
    * @return mixed
    */
-  function membershipTypeCreate($params = array()) {
+  public function membershipTypeCreate($params = array()) {
     CRM_Member_PseudoConstant::flush('membershipType');
     CRM_Core_Config::clearDBCache();
     $memberOfOrganization = $this->organizationCreate();
@@ -1175,7 +1204,7 @@ class CiviUnitTestCase extends PHPUnit_Extensions_Database_TestCase {
    *
    * @return mixed
    */
-  function contactMembershipCreate($params) {
+  public function contactMembershipCreate($params) {
     $pre = array(
       'join_date' => '2007-01-21',
       'start_date' => '2007-01-21',
@@ -1198,14 +1227,14 @@ class CiviUnitTestCase extends PHPUnit_Extensions_Database_TestCase {
    *
    * @param array $params
    */
-  function membershipTypeDelete($params) {
+  public function membershipTypeDelete($params) {
     $this->callAPISuccess('MembershipType', 'Delete', $params);
   }
 
   /**
    * @param int $membershipID
    */
-  function membershipDelete($membershipID) {
+  public function membershipDelete($membershipID) {
     $deleteParams = array('id' => $membershipID);
     $result = $this->callAPISuccess('Membership', 'Delete', $deleteParams);
     return;
@@ -1216,7 +1245,7 @@ class CiviUnitTestCase extends PHPUnit_Extensions_Database_TestCase {
    *
    * @return mixed
    */
-  function membershipStatusCreate($name = 'test member status') {
+  public function membershipStatusCreate($name = 'test member status') {
     $params['name'] = $name;
     $params['start_event'] = 'start_date';
     $params['end_event'] = 'end_date';
@@ -1231,7 +1260,7 @@ class CiviUnitTestCase extends PHPUnit_Extensions_Database_TestCase {
   /**
    * @param int $membershipStatusID
    */
-  function membershipStatusDelete($membershipStatusID) {
+  public function membershipStatusDelete($membershipStatusID) {
     if (!$membershipStatusID) {
       return;
     }
@@ -1244,7 +1273,7 @@ class CiviUnitTestCase extends PHPUnit_Extensions_Database_TestCase {
    *
    * @return mixed
    */
-  function relationshipTypeCreate($params = array()) {
+  public function relationshipTypeCreate($params = array()) {
     $params = array_merge(array(
         'name_a_b' => 'Relation 1 for relationship type create',
         'name_b_a' => 'Relation 2 for relationship type create',
@@ -1267,7 +1296,7 @@ class CiviUnitTestCase extends PHPUnit_Extensions_Database_TestCase {
    *
    * @param int $relationshipTypeID
    */
-  function relationshipTypeDelete($relationshipTypeID) {
+  public function relationshipTypeDelete($relationshipTypeID) {
     $params['id'] = $relationshipTypeID;
     $this->callAPISuccess('relationship_type', 'delete', $params);
   }
@@ -1277,7 +1306,7 @@ class CiviUnitTestCase extends PHPUnit_Extensions_Database_TestCase {
    *
    * @return mixed
    */
-  function paymentProcessorTypeCreate($params = NULL) {
+  public function paymentProcessorTypeCreate($params = NULL) {
     if (is_null($params)) {
       $params = array(
         'name' => 'API_Test_PP',
@@ -1303,7 +1332,7 @@ class CiviUnitTestCase extends PHPUnit_Extensions_Database_TestCase {
    *
    * @return int $id of participant created
    */
-  function participantCreate($params) {
+  public function participantCreate($params) {
     if(empty($params['contact_id'])){
       $params['contact_id'] = $this->individualCreate();
     }
@@ -1330,7 +1359,7 @@ class CiviUnitTestCase extends PHPUnit_Extensions_Database_TestCase {
    *
    * @return object of Payment Processsor
    */
-  function processorCreate() {
+  public function processorCreate() {
     $processorParams = array(
       'domain_id' => 1,
       'name' => 'Dummy',
@@ -1352,7 +1381,7 @@ class CiviUnitTestCase extends PHPUnit_Extensions_Database_TestCase {
    * @param array $params
    * @return object of contribution page
    */
-  function contributionPageCreate($params) {
+  public function contributionPageCreate($params) {
     $this->_pageParams = array(
       'title' => 'Test Contribution Page',
       'financial_type_id' => 1,
@@ -1374,7 +1403,7 @@ class CiviUnitTestCase extends PHPUnit_Extensions_Database_TestCase {
    * @param array $params
    * @return array result of created tag
    */
-  function tagCreate($params = array()) {
+  public function tagCreate($params = array()) {
     $defaults = array(
       'name' => 'New Tag3',
       'description' => 'This is description for Our New Tag ',
@@ -1390,7 +1419,7 @@ class CiviUnitTestCase extends PHPUnit_Extensions_Database_TestCase {
    *
    * @param  int $tagId   id of the tag to be deleted
    */
-  function tagDelete($tagId) {
+  public function tagDelete($tagId) {
     require_once 'api/api.php';
     $params = array(
       'tag_id' => $tagId,
@@ -1406,7 +1435,7 @@ class CiviUnitTestCase extends PHPUnit_Extensions_Database_TestCase {
    *
    * @return bool
    */
-  function entityTagAdd($params) {
+  public function entityTagAdd($params) {
     $result = $this->callAPISuccess('entity_tag', 'create', $params);
     return TRUE;
   }
@@ -1418,7 +1447,7 @@ class CiviUnitTestCase extends PHPUnit_Extensions_Database_TestCase {
    *
    * @return int id of created contribution
    */
-  function pledgeCreate($cID) {
+  public function pledgeCreate($cID) {
     $params = array(
       'contact_id' => $cID,
       'pledge_create_date' => date('Ymd'),
@@ -1443,7 +1472,7 @@ class CiviUnitTestCase extends PHPUnit_Extensions_Database_TestCase {
    *
    * @param int $pledgeId
    */
-  function pledgeDelete($pledgeId) {
+  public function pledgeDelete($pledgeId) {
     $params = array(
       'pledge_id' => $pledgeId,
     );
@@ -1462,7 +1491,7 @@ class CiviUnitTestCase extends PHPUnit_Extensions_Database_TestCase {
    * @param bool $isFee
    * @return int id of created contribution
    */
-  function contributionCreate($cID, $cTypeID = 1, $invoiceID = 67890, $trxnID = 12345, $paymentInstrumentID = 1, $isFee = TRUE) {
+  public function contributionCreate($cID, $cTypeID = 1, $invoiceID = 67890, $trxnID = 12345, $paymentInstrumentID = 1, $isFee = TRUE) {
     $params = array(
       'domain_id' => 1,
       'contact_id' => $cID,
@@ -1497,7 +1526,7 @@ class CiviUnitTestCase extends PHPUnit_Extensions_Database_TestCase {
    * @param int $trxnID
    * @return int id of created contribution
    */
-  function onlineContributionCreate($params, $financialType, $invoiceID = 67890, $trxnID = 12345) {
+  public function onlineContributionCreate($params, $financialType, $invoiceID = 67890, $trxnID = 12345) {
     $contribParams = array(
       'contact_id' => $params['contact_id'],
       'receive_date' => date('Ymd'),
@@ -1521,7 +1550,7 @@ class CiviUnitTestCase extends PHPUnit_Extensions_Database_TestCase {
    *
    * @return array|int
    */
-  function contributionDelete($contributionId) {
+  public function contributionDelete($contributionId) {
     $params = array(
       'contribution_id' => $contributionId,
     );
@@ -1536,7 +1565,7 @@ class CiviUnitTestCase extends PHPUnit_Extensions_Database_TestCase {
    *
    * @return array $event
    */
-  function eventCreate($params = array()) {
+  public function eventCreate($params = array()) {
     // if no contact was passed, make up a dummy event creator
     if (!isset($params['contact_id'])) {
       $params['contact_id'] = $this->_contactCreate(array(
@@ -1575,7 +1604,7 @@ class CiviUnitTestCase extends PHPUnit_Extensions_Database_TestCase {
    *
    * @return array|int
    */
-  function eventDelete($id) {
+  public function eventDelete($id) {
     $params = array(
       'event_id' => $id,
     );
@@ -1589,7 +1618,7 @@ class CiviUnitTestCase extends PHPUnit_Extensions_Database_TestCase {
    *
    * @return array|int
    */
-  function participantDelete($participantID) {
+  public function participantDelete($participantID) {
     $params = array(
       'id' => $participantID,
     );
@@ -1603,7 +1632,7 @@ class CiviUnitTestCase extends PHPUnit_Extensions_Database_TestCase {
    * @param int $contributionID
    * @return int $id of created payment
    */
-  function participantPaymentCreate($participantID, $contributionID = NULL) {
+  public function participantPaymentCreate($participantID, $contributionID = NULL) {
     //Create Participant Payment record With Values
     $params = array(
       'participant_id' => $participantID,
@@ -1619,7 +1648,7 @@ class CiviUnitTestCase extends PHPUnit_Extensions_Database_TestCase {
    *
    * @param int $paymentID
    */
-  function participantPaymentDelete($paymentID) {
+  public function participantPaymentDelete($paymentID) {
     $params = array(
       'id' => $paymentID,
     );
@@ -1632,7 +1661,7 @@ class CiviUnitTestCase extends PHPUnit_Extensions_Database_TestCase {
    * @param int $contactID
    * @return int location id of created location
    */
-  function locationAdd($contactID) {
+  public function locationAdd($contactID) {
     $address = array(
       1 => array(
         'location_type' => 'New Location Type',
@@ -1662,7 +1691,7 @@ class CiviUnitTestCase extends PHPUnit_Extensions_Database_TestCase {
    *
    * @param array $params parameters
    */
-  function locationDelete($params) {
+  public function locationDelete($params) {
     $this->callAPISuccess('Location', 'delete', $params);
   }
 
@@ -1672,7 +1701,7 @@ class CiviUnitTestCase extends PHPUnit_Extensions_Database_TestCase {
    * @param array $params
    * @return int location id of created location
    */
-  function locationTypeCreate($params = NULL) {
+  public function locationTypeCreate($params = NULL) {
     if ($params === NULL) {
       $params = array(
         'name' => 'New Location Type',
@@ -1696,7 +1725,7 @@ class CiviUnitTestCase extends PHPUnit_Extensions_Database_TestCase {
    *
    * @param int location type id
    */
-  function locationTypeDelete($locationTypeId) {
+  public function locationTypeDelete($locationTypeId) {
     $locationType = new CRM_Core_DAO_LocationType();
     $locationType->id = $locationTypeId;
     $locationType->delete();
@@ -1708,7 +1737,7 @@ class CiviUnitTestCase extends PHPUnit_Extensions_Database_TestCase {
    * @param array $params
    * @return int groupId of created group
    */
-  function groupCreate($params = array()) {
+  public function groupCreate($params = array()) {
     $params = array_merge(array(
         'name' => 'Test Group 1',
         'domain_id' => 1,
@@ -1726,12 +1755,37 @@ class CiviUnitTestCase extends PHPUnit_Extensions_Database_TestCase {
     return $result['id'];
   }
 
+
+ /**
+   * Function to add a Group
+   *
+   * @params array to add group
+   *
+   * @param array $params
+   * @return int groupId of created group
+   */
+  public function groupContactCreate($groupID, $totalCount = 10) {
+    $params = array('group_id' => $groupID);
+    for ($i=1; $i <= $totalCount; $i++) {
+      $contactID = $this->individualCreate();
+      if ($i == 1) {
+        $params += array('contact_id' => $contactID);
+      }
+      else {
+        $params += array("contact_id.$i" => $contactID);
+      }
+    }
+    $result = $this->callAPISuccess('GroupContact', 'create', $params);
+
+    return $result;
+  }
+
   /**
    * Delete a Group
    *
    * @param int $gid
    */
-  function groupDelete($gid) {
+  public function groupDelete($gid) {
 
     $params = array(
       'id' => $gid,
@@ -1744,7 +1798,7 @@ class CiviUnitTestCase extends PHPUnit_Extensions_Database_TestCase {
    * Create a UFField
    * @param array $params
    */
-  function uFFieldCreate($params = array()) {
+  public function uFFieldCreate($params = array()) {
     $params = array_merge(array(
       'uf_group_id' => 1,
       'field_name' => 'first_name',
@@ -1765,7 +1819,7 @@ class CiviUnitTestCase extends PHPUnit_Extensions_Database_TestCase {
    * @param array $params
    * @return int $id of created UF Join
    */
-  function ufjoinCreate($params = NULL) {
+  public function ufjoinCreate($params = NULL) {
     if ($params === NULL) {
       $params = array(
         'is_active' => 1,
@@ -1785,7 +1839,7 @@ class CiviUnitTestCase extends PHPUnit_Extensions_Database_TestCase {
    *
    * @param array with missing uf_group_id
    */
-  function ufjoinDelete($params = NULL) {
+  public function ufjoinDelete($params = NULL) {
     if ($params === NULL) {
       $params = array(
         'is_active' => 1,
@@ -1805,7 +1859,7 @@ class CiviUnitTestCase extends PHPUnit_Extensions_Database_TestCase {
    *
    * @param int $contactId
    */
-  function contactGroupCreate($contactId) {
+  public function contactGroupCreate($contactId) {
     $params = array(
       'contact_id.1' => $contactId,
       'group_id' => 1,
@@ -1819,7 +1873,7 @@ class CiviUnitTestCase extends PHPUnit_Extensions_Database_TestCase {
    *
    * @param int $contactId
    */
-  function contactGroupDelete($contactId) {
+  public function contactGroupDelete($contactId) {
     $params = array(
       'contact_id.1' => $contactId,
       'group_id' => 1,
@@ -1833,7 +1887,7 @@ class CiviUnitTestCase extends PHPUnit_Extensions_Database_TestCase {
    * @param array $params
    * @return array|int
    */
-  function activityCreate($params = NULL) {
+  public function activityCreate($params = NULL) {
 
     if ($params === NULL) {
       $individualSourceID = $this->individualCreate();
@@ -1875,7 +1929,7 @@ class CiviUnitTestCase extends PHPUnit_Extensions_Database_TestCase {
    *
    * @param array $params parameters
    */
-  function activityTypeCreate($params) {
+  public function activityTypeCreate($params) {
     $result = $this->callAPISuccess('ActivityType', 'create', $params);
     return $result;
   }
@@ -1885,7 +1939,7 @@ class CiviUnitTestCase extends PHPUnit_Extensions_Database_TestCase {
    *
    * @param int $activityTypeId id of the activity type
    */
-  function activityTypeDelete($activityTypeId) {
+  public function activityTypeDelete($activityTypeId) {
     $params['activity_type_id'] = $activityTypeId;
     $result = $this->callAPISuccess('ActivityType', 'delete', $params);
     return $result;
@@ -1897,7 +1951,7 @@ class CiviUnitTestCase extends PHPUnit_Extensions_Database_TestCase {
    * @param array $params
    * @return array|int
    */
-  function customGroupCreate($params = array()) {
+  public function customGroupCreate($params = array()) {
     $defaults = array(
       'title' => 'new custom group',
       'extends' => 'Contact',
@@ -1922,7 +1976,7 @@ class CiviUnitTestCase extends PHPUnit_Extensions_Database_TestCase {
    * Existing function doesn't allow params to be over-ridden so need a new one
    * this one allows you to only pass in the params you want to change
    */
-  function CustomGroupCreateByParams($params = array()) {
+  public function CustomGroupCreateByParams($params = array()) {
     $defaults = array(
       'title' => "API Custom Group",
       'extends' => 'Contact',
@@ -1937,7 +1991,7 @@ class CiviUnitTestCase extends PHPUnit_Extensions_Database_TestCase {
   /**
    * Create custom group with multi fields
    */
-  function CustomGroupMultipleCreateByParams($params = array()) {
+  public function CustomGroupMultipleCreateByParams($params = array()) {
     $defaults = array(
       'style' => 'Tab',
       'is_multiple' => 1,
@@ -1949,7 +2003,7 @@ class CiviUnitTestCase extends PHPUnit_Extensions_Database_TestCase {
   /**
    * Create custom group with multi fields
    */
-  function CustomGroupMultipleCreateWithFields($params = array()) {
+  public function CustomGroupMultipleCreateWithFields($params = array()) {
     // also need to pass on $params['custom_field'] if not set but not in place yet
     $ids = array();
     $customGroup = $this->CustomGroupMultipleCreateByParams($params);
@@ -1977,7 +2031,7 @@ class CiviUnitTestCase extends PHPUnit_Extensions_Database_TestCase {
    *
    * @return array $ids ids of created objects
    */
-  function entityCustomGroupWithSingleFieldCreate($function, $filename) {
+  public function entityCustomGroupWithSingleFieldCreate($function, $filename) {
     $params = array('title' => $function);
     $entity = substr(basename($filename), 0, strlen(basename($filename)) - 8);
     $params['extends'] =  $entity ? $entity : 'Contact';
@@ -1995,7 +2049,7 @@ class CiviUnitTestCase extends PHPUnit_Extensions_Database_TestCase {
    *
    * @return array|int
    */
-  function customGroupDelete($customGroupID) {
+  public function customGroupDelete($customGroupID) {
     $params['id'] = $customGroupID;
     return $this->callAPISuccess('custom_group', 'delete', $params);
   }
@@ -2006,7 +2060,7 @@ class CiviUnitTestCase extends PHPUnit_Extensions_Database_TestCase {
    * @param array $params (custom_group_id) is required
    * @return array|int
    */
-  function customFieldCreate($params) {
+  public function customFieldCreate($params) {
     $params = array_merge(array(
       'label' => 'Custom Field',
       'data_type' => 'String',
@@ -2033,7 +2087,7 @@ class CiviUnitTestCase extends PHPUnit_Extensions_Database_TestCase {
    *
    * @return array|int
    */
-  function customFieldDelete($customFieldID) {
+  public function customFieldDelete($customFieldID) {
 
     $params['id'] = $customFieldID;
     return $this->callAPISuccess('custom_field', 'delete', $params);
@@ -2045,7 +2099,7 @@ class CiviUnitTestCase extends PHPUnit_Extensions_Database_TestCase {
    * @param int $cId
    * @return array $note
    */
-  function noteCreate($cId) {
+  public function noteCreate($cId) {
     $params = array(
       'entity_table' => 'civicrm_contact',
       'entity_id' => $cId,
@@ -2061,7 +2115,7 @@ class CiviUnitTestCase extends PHPUnit_Extensions_Database_TestCase {
   /**
    * Enable CiviCampaign Component
    */
-  function enableCiviCampaign() {
+  public function enableCiviCampaign() {
     CRM_Core_BAO_ConfigSetting::enableComponent('CiviCampaign');
     // force reload of config object
     $config = CRM_Core_Config::singleton(TRUE, TRUE);
@@ -2082,7 +2136,7 @@ class CiviUnitTestCase extends PHPUnit_Extensions_Database_TestCase {
    * @param string $subfile name for subfile - if this is completed the example will be put in a subfolder (named by the entity)
    * @param string $action - optional action - otherwise taken from function name
    */
-  function documentMe($params, $result, $function, $filename, $description = "", $subfile = NULL, $action = NULL) {
+  public function documentMe($params, $result, $function, $filename, $description = "", $subfile = NULL, $action = NULL) {
     if (defined('DONT_DOCUMENT_TEST_CONFIG') && DONT_DOCUMENT_TEST_CONFIG) {
       return;
     }
@@ -2193,7 +2247,7 @@ class CiviUnitTestCase extends PHPUnit_Extensions_Database_TestCase {
    * @param array $result
    *
    */
-  function tidyExampleResult(&$result){
+  public function tidyExampleResult(&$result){
     if(!is_array($result)) {
       return;
     }
@@ -2271,7 +2325,7 @@ class CiviUnitTestCase extends PHPUnit_Extensions_Database_TestCase {
    *
    * @return array|int
    */
-  function noteDelete($params) {
+  public function noteDelete($params) {
     return $this->callAPISuccess('Note', 'delete', $params);
   }
 
@@ -2283,7 +2337,7 @@ class CiviUnitTestCase extends PHPUnit_Extensions_Database_TestCase {
    *
    * @return array|int
    */
-  function customFieldOptionValueCreate($customGroup, $name) {
+  public function customFieldOptionValueCreate($customGroup, $name) {
     $fieldParams = array(
       'custom_group_id' => $customGroup['id'],
       'name' => 'test_custom_group',
@@ -2320,7 +2374,7 @@ class CiviUnitTestCase extends PHPUnit_Extensions_Database_TestCase {
    *
    * @return bool
    */
-  function confirmEntitiesDeleted($entities) {
+  public function confirmEntitiesDeleted($entities) {
     foreach ($entities as $entity) {
 
       $result = $this->callAPISuccess($entity, 'Get', array());
@@ -2335,7 +2389,10 @@ class CiviUnitTestCase extends PHPUnit_Extensions_Database_TestCase {
    * @param $tablesToTruncate
    * @param bool $dropCustomValueTables
    */
-  function quickCleanup($tablesToTruncate, $dropCustomValueTables = FALSE) {
+  public function quickCleanup($tablesToTruncate, $dropCustomValueTables = FALSE) {
+    if ($this->tx) {
+      throw new Exception("CiviUnitTestCase: quickCleanup() is not compatible with useTransaction()");
+    }
     if ($dropCustomValueTables) {
       $tablesToTruncate[] = 'civicrm_custom_group';
       $tablesToTruncate[] = 'civicrm_custom_field';
@@ -2370,7 +2427,7 @@ AND    ( TABLE_NAME LIKE 'civicrm_value_%' )
   /**
    * Clean up financial entities after financial tests (so we remember to get all the tables :-))
    */
-  function quickCleanUpFinancialEntities() {
+  public function quickCleanUpFinancialEntities() {
     $tablesToTruncate = array(
       'civicrm_contribution',
       'civicrm_contribution_soft',
@@ -2401,7 +2458,7 @@ AND    ( TABLE_NAME LIKE 'civicrm_value_%' )
     CRM_Member_BAO_Membership::createRelatedMemberships($var, $var, TRUE);
   }
 
-  function restoreDefaultPriceSetConfig() {
+  public function restoreDefaultPriceSetConfig() {
     CRM_Core_DAO::executeQuery("INSERT INTO `civicrm_price_field` (`id`, `price_set_id`, `name`, `label`, `html_type`, `is_enter_qty`, `help_pre`, `help_post`, `weight`, `is_display_amounts`, `options_per_line`, `is_active`, `is_required`, `active_on`, `expire_on`, `javascript`, `visibility_id`) VALUES (1, 1, 'contribution_amount', 'Contribution Amount', 'Text', 0, NULL, NULL, 1, 1, 1, 1, 1, NULL, NULL, NULL, 1)");
     CRM_Core_DAO::executeQuery("INSERT INTO `civicrm_price_field_value` (`id`, `price_field_id`, `name`, `label`, `description`, `amount`, `count`, `max_value`, `weight`, `membership_type_id`, `membership_num_terms`, `is_default`, `is_active`, `financial_type_id`, `deductible_amount`) VALUES (1, 1, 'contribution_amount', 'Contribution Amount', NULL, '1', NULL, NULL, 1, NULL, NULL, 0, 1, 1, 0.00)");
   }
@@ -2424,7 +2481,7 @@ AND    ( TABLE_NAME LIKE 'civicrm_value_%' )
    *
    * @throws Exception
    */
-  function getAndCheck($params, $id, $entity, $delete = 1, $errorText = '') {
+  public function getAndCheck($params, $id, $entity, $delete = 1, $errorText = '') {
 
     $result = $this->callAPISuccessGetSingle($entity, array(
       'id' => $id,
@@ -2491,7 +2548,7 @@ AND    ( TABLE_NAME LIKE 'civicrm_value_%' )
    * @param array $expected expected values
    *
    */
-  function checkArrayEquals(&$actual, &$expected) {
+  public function checkArrayEquals(&$actual, &$expected) {
     self::unsetId($actual);
     self::unsetId($expected);
     $this->assertEquals($actual, $expected);
@@ -2502,7 +2559,7 @@ AND    ( TABLE_NAME LIKE 'civicrm_value_%' )
    * @param array $unformattedArray The array from which the 'id' has to be unset
    *
    */
-  static function unsetId(&$unformattedArray) {
+  public static function unsetId(&$unformattedArray) {
     $formattedArray = array();
     if (array_key_exists('id', $unformattedArray)) {
       unset($unformattedArray['id']);
@@ -2532,7 +2589,7 @@ AND    ( TABLE_NAME LIKE 'civicrm_value_%' )
    *   'php_path' Set to TRUE to use the default, FALSE or "" to disable support, or a string path to use another path
    *   'template_path' Set to TRUE to use the default, FALSE or "" to disable support, or a string path to use another path
    */
-  function customDirectories($customDirs) {
+  public function customDirectories($customDirs) {
     require_once 'CRM/Core/Config.php';
     $config = CRM_Core_Config::singleton();
 
@@ -2563,13 +2620,13 @@ AND    ( TABLE_NAME LIKE 'civicrm_value_%' )
    * @param string $prefix
    * @return string $string
    */
-  function createTempDir($prefix = 'test-') {
+  public function createTempDir($prefix = 'test-') {
     $tempDir = CRM_Utils_File::tempdir($prefix);
     $this->tempDirs[] = $tempDir;
     return $tempDir;
   }
 
-  function cleanTempDirs() {
+  public function cleanTempDirs() {
     if (!is_array($this->tempDirs)) {
       // fix test errors where this is not set
       return;
@@ -2584,14 +2641,14 @@ AND    ( TABLE_NAME LIKE 'civicrm_value_%' )
   /**
    * Temporarily replace the singleton extension with a different one
    */
-  function setExtensionSystem(CRM_Extension_System $system) {
+  public function setExtensionSystem(CRM_Extension_System $system) {
     if ($this->origExtensionSystem == NULL) {
       $this->origExtensionSystem = CRM_Extension_System::singleton();
     }
     CRM_Extension_System::setSingleton($this->origExtensionSystem);
   }
 
-  function unsetExtensionSystem() {
+  public function unsetExtensionSystem() {
     if ($this->origExtensionSystem !== NULL) {
       CRM_Extension_System::setSingleton($this->origExtensionSystem);
       $this->origExtensionSystem = NULL;
@@ -2606,7 +2663,7 @@ AND    ( TABLE_NAME LIKE 'civicrm_value_%' )
    * @param $extras
    * @return void
    */
-  function setMockSettingsMetaData($extras) {
+  public function setMockSettingsMetaData($extras) {
     CRM_Core_BAO_Setting::$_cache = array();
     $this->callAPISuccess('system','flush', array());
     CRM_Core_BAO_Setting::$_cache = array();
@@ -2625,7 +2682,7 @@ AND    ( TABLE_NAME LIKE 'civicrm_value_%' )
   /**
    * @param string $name
    */
-  function financialAccountDelete($name) {
+  public function financialAccountDelete($name) {
     $financialAccount = new CRM_Financial_DAO_FinancialAccount();
     $financialAccount->name = $name;
     if($financialAccount->find(TRUE)) {
@@ -2636,22 +2693,11 @@ AND    ( TABLE_NAME LIKE 'civicrm_value_%' )
     }
   }
 
-  /**
-   * Use $ids as an instruction to do test cleanup
-   */
-  function deleteFromIDSArray() {
-    foreach ($this->ids as $entity => $ids) {
-      foreach ($ids as $id) {
-        $this->callAPISuccess($entity, 'delete', array('id' => $id));
-      }
-    }
-  }
-
   /**
    * FIXME: something NULLs $GLOBALS['_HTML_QuickForm_registered_rules'] when the tests are ran all together
    * (NB unclear if this is still required)
    */
-  function _sethtmlGlobals() {
+  public function _sethtmlGlobals() {
     $GLOBALS['_HTML_QuickForm_registered_rules'] = array(
       'required' => array(
         'html_quickform_rule_required',
@@ -2829,7 +2875,7 @@ AND    ( TABLE_NAME LIKE 'civicrm_value_%' )
    *   $this->_permissionedGroup = $this->groupCreate(array('title' => 'pick-me-active', 'is_active' => 1, 'name' => 'pick-me-active'));
    *
    */
-  function setupACL() {
+  public function setupACL() {
     global $_REQUEST;
     $_REQUEST = $this->_params;
 
@@ -2887,7 +2933,7 @@ AND    ( TABLE_NAME LIKE 'civicrm_value_%' )
   /**
    * Alter default price set so that the field numbers are not all 1 (hiding errors)
    */
-  function offsetDefaultPriceSet() {
+  public function offsetDefaultPriceSet() {
     $contributionPriceSet = $this->callAPISuccess('price_set', 'getsingle', array('name' => 'default_contribution_amount'));
     $firstID = $contributionPriceSet['id'];
     $this->callAPISuccess('price_set', 'create', array('id' => $contributionPriceSet['id'], 'is_active' => 0, 'name' => 'old'));
@@ -2906,48 +2952,48 @@ AND    ( TABLE_NAME LIKE 'civicrm_value_%' )
     $this->callAPISuccess('price_field_value', 'create', array_merge($priceFieldValue, array('price_field_id' => $newPriceField['id'])));
   }
 
-/**
- * Create an instance of the paypal processor
- * @todo this isn't a great place to put it - but really it belongs on a class that extends
- * this parent class & we don't have a structure for that yet
- * There is another function to this effect on the PaypalPro test but it appears to be silently failing
- * & the best protection agains that is the functions this class affords
- */
- function paymentProcessorCreate($params = array()) {
-   $params = array_merge(array(
-     'name' => 'demo',
-     'domain_id' => CRM_Core_Config::domainID(),
-     'payment_processor_type_id' => 'PayPal',
-     'is_active' => 1,
-     'is_default' => 0,
-     'is_test' => 1,
-     'user_name' => 'sunil._1183377782_biz_api1.webaccess.co.in',
-     'password' => '1183377788',
-     'signature' => 'APixCoQ-Zsaj-u3IH7mD5Do-7HUqA9loGnLSzsZga9Zr-aNmaJa3WGPH',
-     'url_site' => 'https://www.sandbox.paypal.com/',
-     'url_api' => 'https://api-3t.sandbox.paypal.com/',
-     'url_button' => 'https://www.paypal.com/en_US/i/btn/btn_xpressCheckout.gif',
-     'class_name' => 'Payment_PayPalImpl',
-     'billing_mode' => 3,
-     'financial_type_id' => 1,
-     ),
-   $params);
-   if(!is_numeric($params['payment_processor_type_id'])) {
-     // really the api should handle this through getoptions but it's not exactly api call so lets just sort it
-     //here
-     $params['payment_processor_type_id'] = $this->callAPISuccess('payment_processor_type', 'getvalue', array(
-       'name' => $params['payment_processor_type_id'],
-       'return' => 'id',
-       ), 'integer');
-   }
-   $result = $this->callAPISuccess('payment_processor', 'create', $params);
-   return $result['id'];
- }
+  /**
  * Create an instance of the paypal processor
  * @todo this isn't a great place to put it - but really it belongs on a class that extends
  * this parent class & we don't have a structure for that yet
  * There is another function to this effect on the PaypalPro test but it appears to be silently failing
  * & the best protection agains that is the functions this class affords
  */
 public function paymentProcessorCreate($params = array()) {
+    $params = array_merge(array(
+      'name' => 'demo',
+      'domain_id' => CRM_Core_Config::domainID(),
+      'payment_processor_type_id' => 'PayPal',
+      'is_active' => 1,
+      'is_default' => 0,
+      'is_test' => 1,
+      'user_name' => 'sunil._1183377782_biz_api1.webaccess.co.in',
+      'password' => '1183377788',
+      'signature' => 'APixCoQ-Zsaj-u3IH7mD5Do-7HUqA9loGnLSzsZga9Zr-aNmaJa3WGPH',
+      'url_site' => 'https://www.sandbox.paypal.com/',
+      'url_api' => 'https://api-3t.sandbox.paypal.com/',
+      'url_button' => 'https://www.paypal.com/en_US/i/btn/btn_xpressCheckout.gif',
+      'class_name' => 'Payment_PayPalImpl',
+      'billing_mode' => 3,
+      'financial_type_id' => 1,
+    ),
+    $params);
+    if(!is_numeric($params['payment_processor_type_id'])) {
+      // really the api should handle this through getoptions but it's not exactly api call so lets just sort it
+      //here
+      $params['payment_processor_type_id'] = $this->callAPISuccess('payment_processor_type', 'getvalue', array(
+        'name' => $params['payment_processor_type_id'],
+        'return' => 'id',
+      ), 'integer');
+    }
+    $result = $this->callAPISuccess('payment_processor', 'create', $params);
+    return $result['id'];
 }
 
   /**
    * Set up initial recurring payment allowing subsequent IPN payments
    */
-  function setupRecurringPaymentProcessorTransaction() {
+  public function setupRecurringPaymentProcessorTransaction() {
     $contributionRecur = $this->callAPISuccess('contribution_recur', 'create', array(
       'contact_id' => $this->_contactID,
       'amount' => 1000,
@@ -2975,7 +3021,7 @@ AND    ( TABLE_NAME LIKE 'civicrm_value_%' )
   /**
    * We don't have a good way to set up a recurring contribution with a membership so let's just do one then alter it
    */
-  function setupMembershipRecurringPaymentProcessorTransaction() {
+  public function setupMembershipRecurringPaymentProcessorTransaction() {
     $this->ids['membership_type'] = $this->membershipTypeCreate();
     //create a contribution so our membership & contribution don't both have id = 1
     $this->contributionCreate($this->_contactID, 1, 'abcd', '345j');
@@ -3010,7 +3056,64 @@ AND    ( TABLE_NAME LIKE 'civicrm_value_%' )
    *
    * @throws Exception
    */
-  function CiviUnitTestCase_fatalErrorHandler($message) {
+  public function CiviUnitTestCase_fatalErrorHandler($message) {
     throw new Exception("{$message['message']}: {$message['code']}");
   }
+
+  /**
+   * Helper function to create new mailing
+   * @return mixed
+   */
+  public function createMailing() {
+    $params = array(
+      'subject' => 'maild' . rand(),
+      'body_text' => 'bdkfhdskfhduew',
+      'name' => 'mailing name' . rand(),
+      'created_id' => 1,
+      'api.mailing_job.create' => 0,
+    );
+
+    $result = $this->callAPISuccess('Mailing', 'create', $params);
+    return $result['id'];
+  }
+
+  /**
+   * Helper function to delete mailing
+   * @param $id
+   */
+  public function deleteMailing($id) {
+    $params = array(
+      'id' => $id,
+    );
+
+    $this->callAPISuccess('Mailing', 'delete', $params);
+  }
+
+  /**
+   * Wrap the entire test case in a transaction
+   *
+   * Only subsequent DB statements will be wrapped in TX -- this cannot
+   * retroactively wrap old DB statements. Therefore, it makes sense to
+   * call this at the beginning of setUp().
+   *
+   * Note: Recall that TRUNCATE and ALTER will force-commit transactions, so
+   * this option does not work with, e.g., custom-data.
+   *
+   * WISHLIST: Monitor SQL queries in unit-tests and generate an exception
+   * if TRUNCATE or ALTER is called while using a transaction.
+   *
+   * @param bool $nest whether to use nesting or reference-counting
+   */
+  public function useTransaction($nest = TRUE) {
+    if (!$this->tx) {
+      $this->tx = new CRM_Core_Transaction($nest);
+      $this->tx->rollback();
+    }
+  }
+
+  public function clearOutputBuffer() {
+    while (ob_get_level() > 0) {
+      ob_end_clean();
+    }
+  }
 }