Merge pull request #5192 from colemanw/CRM-15988
[civicrm-core.git] / tests / phpunit / CiviTest / CiviUnitTestCase.php
index 895153016a6b3b35e374a4aa5b327cc40a9849aa..6f761fbbeabcf725def9d673b0a749e6718ddd2e 100755 (executable)
@@ -26,6 +26,8 @@
  *   <http://www.gnu.org/licenses/>.
  */
 
+use Civi\Payment\System;
+
 /**
  *  Include configuration
  */
@@ -68,28 +70,28 @@ class CiviUnitTestCase extends PHPUnit_Extensions_Database_TestCase {
    */
   protected $_apiversion = API_LATEST_VERSION;
   /**
-   *  Database has been initialized
+   *  Database has been initialized.
    *
    * @var boolean
    */
   private static $dbInit = FALSE;
 
   /**
-   *  Database connection
+   *  Database connection.
    *
    * @var PHPUnit_Extensions_Database_DB_IDatabaseConnection
    */
   protected $_dbconn;
 
   /**
-   * The database name
+   * The database name.
    *
    * @var string
    */
   static protected $_dbName;
 
   /**
-   * Track tables we have modified during a test
+   * Track tables we have modified during a test.
    */
   protected $_tablesToTruncate = array();
 
@@ -153,7 +155,7 @@ class CiviUnitTestCase extends PHPUnit_Extensions_Database_TestCase {
   protected $origExtensionSystem;
 
   /**
-   *  Constructor
+   *  Constructor.
    *
    *  Because we are overriding the parent class constructor, we
    *  need to show the same arguments as exist in the constructor of
@@ -189,11 +191,19 @@ class CiviUnitTestCase extends PHPUnit_Extensions_Database_TestCase {
     // also load the class loader
     require_once 'CRM/Core/ClassLoader.php';
     CRM_Core_ClassLoader::singleton()->register();
-    if (function_exists('_civix_phpunit_setUp')) { // FIXME: loosen coupling
+    if (function_exists('_civix_phpunit_setUp')) {
+      // FIXME: loosen coupling
       _civix_phpunit_setUp();
     }
   }
 
+  /**
+   * Override to run the test and assert its state.
+   * @return mixed
+   * @throws \Exception
+   * @throws \PHPUnit_Framework_IncompleteTest
+   * @throws \PHPUnit_Framework_SkippedTest
+   */
   protected function runTest() {
     try {
       return parent::runTest();
@@ -220,7 +230,7 @@ class CiviUnitTestCase extends PHPUnit_Extensions_Database_TestCase {
   }
 
   /**
-   *  Create database connection for this instance
+   *  Create database connection for this instance.
    *
    *  Initialize the test database if it hasn't been initialized
    *
@@ -242,7 +252,7 @@ class CiviUnitTestCase extends PHPUnit_Extensions_Database_TestCase {
   }
 
   /**
-   *  Required implementation of abstract method
+   *  Required implementation of abstract method.
    */
   protected function getDataSet() {
   }
@@ -250,7 +260,8 @@ class CiviUnitTestCase extends PHPUnit_Extensions_Database_TestCase {
   /**
    * @param bool $perClass
    * @param null $object
-   * @return bool TRUE if the populate logic runs; FALSE if it is skipped
+   * @return bool
+   *   TRUE if the populate logic runs; FALSE if it is skipped
    */
   protected static function _populateDB($perClass = FALSE, &$object = NULL) {
 
@@ -370,7 +381,7 @@ class CiviUnitTestCase extends PHPUnit_Extensions_Database_TestCase {
   }
 
   /**
-   *  Common setup functions for all unit tests
+   *  Common setup functions for all unit tests.
    */
   protected function setUp() {
     $session = CRM_Core_Session::singleton();
@@ -430,7 +441,7 @@ class CiviUnitTestCase extends PHPUnit_Extensions_Database_TestCase {
   }
 
   /**
-   * Read everything from the datasets directory and insert into the db
+   * Read everything from the datasets directory and insert into the db.
    */
   public function loadAllFixtures() {
     $fixturesDir = __DIR__ . '/../../fixtures';
@@ -457,7 +468,7 @@ class CiviUnitTestCase extends PHPUnit_Extensions_Database_TestCase {
   }
 
   /**
-   * Emulate a logged in user since certain functions use that
+   * Emulate a logged in user since certain functions use that.
    * value to store a record in the DB (like activity)
    * CRM-8180
    */
@@ -483,7 +494,7 @@ class CiviUnitTestCase extends PHPUnit_Extensions_Database_TestCase {
   }
 
   /**
-   * Create default domain contacts for the two domains added during test class
+   * Create default domain contacts for the two domains added during test class.
    * database population.
    */
   public function createDomainContacts() {
@@ -492,7 +503,7 @@ class CiviUnitTestCase extends PHPUnit_Extensions_Database_TestCase {
   }
 
   /**
-   *  Common teardown functions for all unit tests
+   *  Common teardown functions for all unit tests.
    */
   protected function tearDown() {
     error_reporting(E_ALL & ~E_NOTICE);
@@ -546,7 +557,7 @@ class CiviUnitTestCase extends PHPUnit_Extensions_Database_TestCase {
   }
 
   /**
-   * Generic function to compare expected values after an api call to retrieved
+   * Generic function to compare expected values after an api call to retrieved.
    * DB values.
    *
    * @daoName  string   DAO Name of object we're evaluating.
@@ -554,6 +565,11 @@ class CiviUnitTestCase extends PHPUnit_Extensions_Database_TestCase {
    * @match    array    Associative array of field name => expected value. Empty if asserting
    *                      that a DELETE occurred
    * @delete   boolean  True if we're checking that a DELETE action occurred.
+   * @param $daoName
+   * @param $id
+   * @param $match
+   * @param bool $delete
+   * @throws \PHPUnit_Framework_AssertionFailedError
    */
   public function assertDBState($daoName, $id, $match, $delete = FALSE) {
     if (empty($id)) {
@@ -599,8 +615,8 @@ class CiviUnitTestCase extends PHPUnit_Extensions_Database_TestCase {
     }
   }
 
-  // Request a record from the DB by seachColumn+searchValue. Success if a record is found.
   /**
+   * Request a record from the DB by seachColumn+searchValue. Success if a record is found.
    * @param string $daoName
    * @param $searchValue
    * @param $returnColumn
@@ -620,8 +636,8 @@ class CiviUnitTestCase extends PHPUnit_Extensions_Database_TestCase {
     return $value;
   }
 
-  // Request a record from the DB by seachColumn+searchValue. Success if returnColumn value is NULL.
   /**
+   * Request a record from the DB by seachColumn+searchValue. Success if returnColumn value is NULL.
    * @param string $daoName
    * @param $searchValue
    * @param $returnColumn
@@ -633,8 +649,8 @@ class CiviUnitTestCase extends PHPUnit_Extensions_Database_TestCase {
     $this->assertNull($value, $message);
   }
 
-  // Request a record from the DB by id. Success if row not found.
   /**
+   * Request a record from the DB by id. Success if row not found.
    * @param string $daoName
    * @param int $id
    * @param null $message
@@ -645,8 +661,8 @@ class CiviUnitTestCase extends PHPUnit_Extensions_Database_TestCase {
     $this->assertNull($value, $message);
   }
 
-  // Request a record from the DB by id. Success if row not found.
   /**
+   * Request a record from the DB by id. Success if row not found.
    * @param string $daoName
    * @param int $id
    * @param null $message
@@ -657,8 +673,8 @@ class CiviUnitTestCase extends PHPUnit_Extensions_Database_TestCase {
     $this->assertEquals($id, $value, $message);
   }
 
-  // Compare a single column value in a retrieved DB record to an expected value
   /**
+   * Compare a single column value in a retrieved DB record to an expected value.
    * @param string $daoName
    * @param $searchValue
    * @param $returnColumn
@@ -666,7 +682,7 @@ class CiviUnitTestCase extends PHPUnit_Extensions_Database_TestCase {
    * @param $expectedValue
    * @param $message
    */
-  function assertDBCompareValue(
+  public function assertDBCompareValue(
     $daoName, $searchValue, $returnColumn, $searchColumn,
     $expectedValue, $message
   ) {
@@ -674,8 +690,8 @@ class CiviUnitTestCase extends PHPUnit_Extensions_Database_TestCase {
     $this->assertEquals($value, $expectedValue, $message);
   }
 
-  // Compare all values in a single retrieved DB record to an array of expected values
   /**
+   * Compare all values in a single retrieved DB record to an array of expected values.
    * @param string $daoName
    * @param array $searchParams
    * @param $expectedValues
@@ -690,13 +706,17 @@ class CiviUnitTestCase extends PHPUnit_Extensions_Database_TestCase {
   }
 
   /**
-   * Assert that a SQL query returns a given value
+   * Assert that a SQL query returns a given value.
    *
    * The first argument is an expected value. The remaining arguments are passed
    * to CRM_Core_DAO::singleValueQuery
    *
    * Example: $this->assertSql(2, 'select count(*) from foo where foo.bar like "%1"',
    * array(1 => array("Whiz", "String")));
+   * @param $expected
+   * @param $query
+   * @param array $params
+   * @param string $message
    */
   public function assertDBQuery($expected, $query, $params = array(), $message = '') {
     if ($message) {
@@ -729,7 +749,7 @@ class CiviUnitTestCase extends PHPUnit_Extensions_Database_TestCase {
   }
 
   /**
-   * Assert that two numbers are approximately equal
+   * Assert that two numbers are approximately equal.
    *
    * @param int|float $expected
    * @param int|float $actual
@@ -744,9 +764,11 @@ class CiviUnitTestCase extends PHPUnit_Extensions_Database_TestCase {
   }
 
   /**
+   * Assert attributes are equal.
+   *
    * @param $expectedValues
    * @param $actualValues
-   * @param null $message
+   * @param string $message
    *
    * @throws PHPUnit_Framework_AssertionFailedError
    */
@@ -788,8 +810,8 @@ class CiviUnitTestCase extends PHPUnit_Extensions_Database_TestCase {
   }
 
   /**
-   * Check that api returned 'is_error' => 0
-   * else provide full message
+   * Check that api returned 'is_error' => 0.
+   *
    * @param array $apiResult
    *   Api result.
    * @param string $prefix
@@ -811,8 +833,7 @@ class CiviUnitTestCase extends PHPUnit_Extensions_Database_TestCase {
   }
 
   /**
-   * Check that api returned 'is_error' => 1
-   * else provide full message
+   * Check that api returned 'is_error' => 1.
    *
    * @param array $apiResult
    *   Api result.
@@ -841,7 +862,10 @@ class CiviUnitTestCase extends PHPUnit_Extensions_Database_TestCase {
   }
 
   /**
-   * Check that a deleted item has been deleted
+   * Check that a deleted item has been deleted.
+   *
+   * @param $entity
+   * @param $id
    */
   public function assertAPIDeleted($entity, $id) {
     $this->callAPISuccess($entity, 'getcount', array('id' => $id), 0);
@@ -883,7 +907,7 @@ class CiviUnitTestCase extends PHPUnit_Extensions_Database_TestCase {
   }
 
   /**
-   * This function exists to wrap api functions
+   * wrap api functions.
    * so we can ensure they succeed & throw exceptions without litterering the test with checks
    *
    * @param string $entity
@@ -928,12 +952,12 @@ class CiviUnitTestCase extends PHPUnit_Extensions_Database_TestCase {
    * @param array $params
    * @param string $type
    *   Per http://php.net/manual/en/function.gettype.php possible types.
-   * - boolean
-   * - integer
-   * - double
-   * - string
-   * - array
-   * - object
+   *   - boolean
+   *   - integer
+   *   - double
+   *   - string
+   *   - array
+   *   - object
    *
    * @return array|int
    */
@@ -963,12 +987,12 @@ class CiviUnitTestCase extends PHPUnit_Extensions_Database_TestCase {
    * @param array $params
    * @param array $checkAgainst
    *   Array to compare result against.
-   * - boolean
-   * - integer
-   * - double
-   * - string
-   * - array
-   * - object
+   *   - boolean
+   *   - integer
+   *   - double
+   *   - string
+   *   - array
+   *   - object
    *
    * @throws Exception
    * @return array|int
@@ -1005,7 +1029,7 @@ class CiviUnitTestCase extends PHPUnit_Extensions_Database_TestCase {
       'debug' => 1,
     );
     $result = $this->civicrm_api($entity, 'getcount', $params);
-    if (!is_integer($result) || !empty($result['is_error']) || isset($result['values'])) {
+    if (!is_int($result) || !empty($result['is_error']) || isset($result['values'])) {
       throw new Exception('Invalid getcount result : ' . print_r($result, TRUE) . " type :" . gettype($result));
     }
     if (is_int($count)) {
@@ -1015,7 +1039,7 @@ class CiviUnitTestCase extends PHPUnit_Extensions_Database_TestCase {
   }
 
   /**
-   * This function exists to wrap api functions
+   * This function exists to wrap api functions.
    * so we can ensure they succeed, generate and example & throw exceptions without litterering the test with checks
    *
    * @param string $entity
@@ -1026,19 +1050,19 @@ class CiviUnitTestCase extends PHPUnit_Extensions_Database_TestCase {
    * @param string $file
    *   Pass this in to create a generated example.
    * @param string $description
-   * @param string|null $subfile
-   * @param string|null $actionName
+   * @param string|null $exampleName
+   *
    * @return array|int
    */
-  public function callAPIAndDocument($entity, $action, $params, $function, $file, $description = "", $subfile = NULL, $actionName = NULL) {
+  public function callAPIAndDocument($entity, $action, $params, $function, $file, $description = "", $exampleName = NULL) {
     $params['version'] = $this->_apiversion;
     $result = $this->callAPISuccess($entity, $action, $params);
-    $this->documentMe($params, $result, $function, $file, $description, $subfile, $actionName);
+    $this->documentMe($entity, $action, $params, $result, $function, $file, $description, $exampleName);
     return $result;
   }
 
   /**
-   * This function exists to wrap api functions
+   * This function exists to wrap api functions.
    * so we can ensure they fail where expected & throw exceptions without litterering the test with checks
    * @param string $entity
    * @param string $action
@@ -1065,7 +1089,8 @@ class CiviUnitTestCase extends PHPUnit_Extensions_Database_TestCase {
    * so the distinction between set
    * up & tested functions is clearer
    *
-   * @return array api Result
+   * @return array
+   *   api Result
    */
   public function createTestEntity() {
     return $entity = $this->callAPISuccess($this->entity, 'create', $this->params);
@@ -1074,10 +1099,13 @@ class CiviUnitTestCase extends PHPUnit_Extensions_Database_TestCase {
   /**
    * Generic function to create Organisation, to be used in test cases
    *
-   * @param array parameters for civicrm_contact_add api function call
-   * @param int sequence number if creating multiple organizations
+   * @param array $params
+   *   parameters for civicrm_contact_add api function call
+   * @param int $seq
+   *   sequence number if creating multiple organizations
    *
-   * @return int    id of Organisation created
+   * @return int
+   *   id of Organisation created
    */
   public function organizationCreate($params = array(), $seq = 0) {
     if (!$params) {
@@ -1090,10 +1118,13 @@ class CiviUnitTestCase extends PHPUnit_Extensions_Database_TestCase {
   /**
    * Generic function to create Individual, to be used in test cases
    *
-   * @param array parameters for civicrm_contact_add api function call
-   * @param int sequence number if creating multiple individuals
+   * @param array $params
+   *   parameters for civicrm_contact_add api function call
+   * @param int $seq
+   *   sequence number if creating multiple individuals
    *
-   * @return int    id of Individual created
+   * @return int
+   *   id of Individual created
    */
   public function individualCreate($params = array(), $seq = 0) {
     $params = array_merge($this->sampleContact('Individual', $seq), $params);
@@ -1103,10 +1134,13 @@ class CiviUnitTestCase extends PHPUnit_Extensions_Database_TestCase {
   /**
    * Generic function to create Household, to be used in test cases
    *
-   * @param array parameters for civicrm_contact_add api function call
-   * @param int sequence number if creating multiple households
+   * @param array $params
+   *   parameters for civicrm_contact_add api function call
+   * @param int $seq
+   *   sequence number if creating multiple households
    *
-   * @return int    id of Household created
+   * @return int
+   *   id of Household created
    */
   public function householdCreate($params = array(), $seq = 0) {
     $params = array_merge($this->sampleContact('Household', $seq), $params);
@@ -1114,12 +1148,15 @@ class CiviUnitTestCase extends PHPUnit_Extensions_Database_TestCase {
   }
 
   /**
-   * Helper function for getting sample contact properties
+   * Helper function for getting sample contact properties.
    *
-   * @param enum contact type: Individual, Organization
-   * @param int sequence number for the values of this type
+   * @param string $contact_type
+   *   enum contact type: Individual, Organization
+   * @param int $seq
+   *   sequence number for the values of this type
    *
-   * @return array   properties of sample contact (ie. $params for API call)
+   * @return array
+   *   properties of sample contact (ie. $params for API call)
    */
   public function sampleContact($contact_type, $seq = 0) {
     $samples = array(
@@ -1144,7 +1181,7 @@ class CiviUnitTestCase extends PHPUnit_Extensions_Database_TestCase {
     );
     $params = array('contact_type' => $contact_type);
     foreach ($samples[$contact_type] as $key => $values) {
-      $params[$key] = $values[$seq % sizeof($values)];
+      $params[$key] = $values[$seq % count($values)];
     }
     if ($contact_type == 'Individual') {
       $params['email'] = strtolower(
@@ -1157,14 +1194,15 @@ class CiviUnitTestCase extends PHPUnit_Extensions_Database_TestCase {
   }
 
   /**
-   * Private helper function for calling civicrm_contact_add
+   * Private helper function for calling civicrm_contact_add.
    *
    * @param array $params
    *   For civicrm_contact_add api function call.
    *
    * @throws Exception
    *
-   * @return int    id of Household created
+   * @return int
+   *   id of Household created
    */
   private function _contactCreate($params) {
     $result = $this->callAPISuccess('contact', 'create', $params);
@@ -1175,25 +1213,20 @@ class CiviUnitTestCase extends PHPUnit_Extensions_Database_TestCase {
   }
 
   /**
-   * @param int $contactID
+   * Delete contact, ensuring it is not the domain contact
    *
-   * @return array|int
+   * @param int $contactID
+   *   Contact ID to delete
    */
   public function contactDelete($contactID) {
-    $params = array(
-      'id' => $contactID,
-      'skip_undelete' => 1,
-      'debug' => 1,
-    );
-    $domain = new CRM_Core_BAO_Domain;
+    $domain = new CRM_Core_BAO_Domain();
     $domain->contact_id = $contactID;
-    if ($domain->find(TRUE)) {
-      // we are finding tests trying to delete the domain contact in cleanup
-      //since this is mainly for cleanup lets put a safeguard here
-      return;
+    if (!$domain->find(TRUE)) {
+      $this->callAPISuccess('contact', 'delete', array(
+        'id' => $contactID,
+        'skip_undelete' => 1,
+      ));
     }
-    $result = $this->callAPISuccess('contact', 'delete', $params);
-    return $result;
   }
 
   /**
@@ -1202,7 +1235,6 @@ class CiviUnitTestCase extends PHPUnit_Extensions_Database_TestCase {
    * @throws Exception
    */
   public function contactTypeDelete($contactTypeId) {
-    require_once 'CRM/Contact/BAO/ContactType.php';
     $result = CRM_Contact_BAO_ContactType::del($contactTypeId);
     if (!$result) {
       throw new Exception('Could not delete contact type');
@@ -1263,7 +1295,7 @@ class CiviUnitTestCase extends PHPUnit_Extensions_Database_TestCase {
   }
 
   /**
-   * Delete Membership Type
+   * Delete Membership Type.
    *
    * @param array $params
    */
@@ -1277,7 +1309,6 @@ class CiviUnitTestCase extends PHPUnit_Extensions_Database_TestCase {
   public function membershipDelete($membershipID) {
     $deleteParams = array('id' => $membershipID);
     $result = $this->callAPISuccess('Membership', 'Delete', $deleteParams);
-    return;
   }
 
   /**
@@ -1305,7 +1336,6 @@ class CiviUnitTestCase extends PHPUnit_Extensions_Database_TestCase {
       return;
     }
     $result = $this->callAPISuccess('MembershipStatus', 'Delete', array('id' => $membershipStatusID));
-    return;
   }
 
   /**
@@ -1332,7 +1362,7 @@ class CiviUnitTestCase extends PHPUnit_Extensions_Database_TestCase {
   }
 
   /**
-   * Delete Relatinship Type
+   * Delete Relatinship Type.
    *
    * @param int $relationshipTypeID
    */
@@ -1366,12 +1396,13 @@ class CiviUnitTestCase extends PHPUnit_Extensions_Database_TestCase {
   }
 
   /**
-   * Create Participant
+   * Create Participant.
    *
    * @param array $params
    *   Array of contact id and event id values.
    *
-   * @return int $id of participant created
+   * @return int
+   *   $id of participant created
    */
   public function participantCreate($params) {
     if (empty($params['contact_id'])) {
@@ -1396,9 +1427,10 @@ class CiviUnitTestCase extends PHPUnit_Extensions_Database_TestCase {
   }
 
   /**
-   * Create Payment Processor
+   * Create Payment Processor.
    *
-   * @return object of Payment Processsor
+   * @return CRM_Financial_DAO_PaymentProcessor
+   *   instance of Payment Processsor
    */
   public function processorCreate() {
     $processorParams = array(
@@ -1417,10 +1449,11 @@ class CiviUnitTestCase extends PHPUnit_Extensions_Database_TestCase {
   }
 
   /**
-   * Create contribution page
+   * Create contribution page.
    *
    * @param array $params
-   * @return object of contribution page
+   * @return array
+   *   Array of contribution page
    */
   public function contributionPageCreate($params) {
     $this->_pageParams = array(
@@ -1439,10 +1472,11 @@ class CiviUnitTestCase extends PHPUnit_Extensions_Database_TestCase {
   }
 
   /**
-   * Create Tag
+   * Create Tag.
    *
    * @param array $params
-   * @return array result of created tag
+   * @return array
+   *   result of created tag
    */
   public function tagCreate($params = array()) {
     $defaults = array(
@@ -1456,10 +1490,12 @@ class CiviUnitTestCase extends PHPUnit_Extensions_Database_TestCase {
   }
 
   /**
-   * Delete Tag
+   * Delete Tag.
    *
    * @param int $tagId
    *   Id of the tag to be deleted.
+   *
+   * @return int
    */
   public function tagDelete($tagId) {
     require_once 'api/api.php';
@@ -1483,12 +1519,13 @@ class CiviUnitTestCase extends PHPUnit_Extensions_Database_TestCase {
   }
 
   /**
-   * Create contribution
+   * Create contribution.
    *
    * @param int $cID
    *   Contact_id.
    *
-   * @return int id of created contribution
+   * @return int
+   *   id of created contribution
    */
   public function pledgeCreate($cID) {
     $params = array(
@@ -1511,7 +1548,7 @@ class CiviUnitTestCase extends PHPUnit_Extensions_Database_TestCase {
   }
 
   /**
-   * Delete contribution
+   * Delete contribution.
    *
    * @param int $pledgeId
    */
@@ -1523,18 +1560,19 @@ class CiviUnitTestCase extends PHPUnit_Extensions_Database_TestCase {
   }
 
   /**
-   * Create contribution
+   * Create contribution.
    *
    * @param int $cID
    *   Contact_id.
    * @param int $cTypeID
    *   Id of financial type.
-   *
    * @param int $invoiceID
    * @param int $trxnID
    * @param int $paymentInstrumentID
    * @param bool $isFee
-   * @return int id of created contribution
+   *
+   * @return int
+   *   id of created contribution
    */
   public function contributionCreate($cID, $cTypeID = 1, $invoiceID = 67890, $trxnID = 12345, $paymentInstrumentID = 1, $isFee = TRUE) {
     $params = array(
@@ -1562,15 +1600,16 @@ class CiviUnitTestCase extends PHPUnit_Extensions_Database_TestCase {
   }
 
   /**
-   * Create online contribution
+   * Create online contribution.
    *
    * @param array $params
    * @param int $financialType
    *   Id of financial type.
-   *
    * @param int $invoiceID
    * @param int $trxnID
-   * @return int id of created contribution
+   *
+   * @return int
+   *   id of created contribution
    */
   public function onlineContributionCreate($params, $financialType, $invoiceID = 67890, $trxnID = 12345) {
     $contribParams = array(
@@ -1590,7 +1629,7 @@ class CiviUnitTestCase extends PHPUnit_Extensions_Database_TestCase {
   }
 
   /**
-   * Delete contribution
+   * Delete contribution.
    *
    * @param int $contributionId
    *
@@ -1605,12 +1644,12 @@ class CiviUnitTestCase extends PHPUnit_Extensions_Database_TestCase {
   }
 
   /**
-   * Create an Event
+   * Create an Event.
    *
    * @param array $params
    *   Name-value pair for an event.
    *
-   * @return array $event
+   * @return array
    */
   public function eventCreate($params = array()) {
     // if no contact was passed, make up a dummy event creator
@@ -1645,7 +1684,7 @@ class CiviUnitTestCase extends PHPUnit_Extensions_Database_TestCase {
   }
 
   /**
-   * Delete event
+   * Delete event.
    *
    * @param int $id
    *   ID of the event.
@@ -1660,7 +1699,7 @@ class CiviUnitTestCase extends PHPUnit_Extensions_Database_TestCase {
   }
 
   /**
-   * Delete participant
+   * Delete participant.
    *
    * @param int $participantID
    *
@@ -1674,11 +1713,12 @@ class CiviUnitTestCase extends PHPUnit_Extensions_Database_TestCase {
   }
 
   /**
-   * Create participant payment
+   * Create participant payment.
    *
    * @param int $participantID
    * @param int $contributionID
-   * @return int $id of created payment
+   * @return int
+   *   $id of created payment
    */
   public function participantPaymentCreate($participantID, $contributionID = NULL) {
     //Create Participant Payment record With Values
@@ -1692,7 +1732,7 @@ class CiviUnitTestCase extends PHPUnit_Extensions_Database_TestCase {
   }
 
   /**
-   * Delete participant payment
+   * Delete participant payment.
    *
    * @param int $paymentID
    */
@@ -1704,10 +1744,11 @@ class CiviUnitTestCase extends PHPUnit_Extensions_Database_TestCase {
   }
 
   /**
-   * Add a Location
+   * Add a Location.
    *
    * @param int $contactID
-   * @return int location id of created location
+   * @return int
+   *   location id of created location
    */
   public function locationAdd($contactID) {
     $address = array(
@@ -1735,7 +1776,7 @@ class CiviUnitTestCase extends PHPUnit_Extensions_Database_TestCase {
   }
 
   /**
-   * Delete Locations of contact
+   * Delete Locations of contact.
    *
    * @param array $params
    *   Parameters.
@@ -1745,10 +1786,11 @@ class CiviUnitTestCase extends PHPUnit_Extensions_Database_TestCase {
   }
 
   /**
-   * Add a Location Type
+   * Add a Location Type.
    *
    * @param array $params
-   * @return CRM_Core_DAO_LocationType location id of created location
+   * @return CRM_Core_DAO_LocationType
+   *   location id of created location
    */
   public function locationTypeCreate($params = NULL) {
     if ($params === NULL) {
@@ -1770,9 +1812,9 @@ class CiviUnitTestCase extends PHPUnit_Extensions_Database_TestCase {
   }
 
   /**
-   * Delete a Location Type
+   * Delete a Location Type.
    *
-   * @param int location type id
+   * @param int $locationTypeId
    */
   public function locationTypeDelete($locationTypeId) {
     $locationType = new CRM_Core_DAO_LocationType();
@@ -1781,10 +1823,11 @@ class CiviUnitTestCase extends PHPUnit_Extensions_Database_TestCase {
   }
 
   /**
-   * Add a Group
+   * Add a Group.
    *
    * @param array $params
-   * @return int groupId of created group
+   * @return int
+   *   groupId of created group
    */
   public function groupCreate($params = array()) {
     $params = array_merge(array(
@@ -1806,12 +1849,14 @@ class CiviUnitTestCase extends PHPUnit_Extensions_Database_TestCase {
 
 
   /**
-   * Function to add a Group
+   * Function to add a Group.
    *
    * @params array to add group
    *
-   * @param array $params
-   * @return int groupId of created group
+   * @param int $groupID
+   * @param int $totalCount
+   * @return int
+   *    groupId of created group
    */
   public function groupContactCreate($groupID, $totalCount = 10) {
     $params = array('group_id' => $groupID);
@@ -1830,7 +1875,7 @@ class CiviUnitTestCase extends PHPUnit_Extensions_Database_TestCase {
   }
 
   /**
-   * Delete a Group
+   * Delete a Group.
    *
    * @param int $gid
    */
@@ -1844,7 +1889,7 @@ class CiviUnitTestCase extends PHPUnit_Extensions_Database_TestCase {
   }
 
   /**
-   * Create a UFField
+   * Create a UFField.
    * @param array $params
    */
   public function uFFieldCreate($params = array()) {
@@ -1863,10 +1908,11 @@ class CiviUnitTestCase extends PHPUnit_Extensions_Database_TestCase {
   }
 
   /**
-   * Add a UF Join Entry
+   * Add a UF Join Entry.
    *
    * @param array $params
-   * @return int $id of created UF Join
+   * @return int
+   *   $id of created UF Join
    */
   public function ufjoinCreate($params = NULL) {
     if ($params === NULL) {
@@ -1884,9 +1930,10 @@ class CiviUnitTestCase extends PHPUnit_Extensions_Database_TestCase {
   }
 
   /**
-   * Delete a UF Join Entry
+   * Delete a UF Join Entry.
    *
-   * @param array with missing uf_group_id
+   * @param array $params
+   *   with missing uf_group_id
    */
   public function ufjoinDelete($params = NULL) {
     if ($params === NULL) {
@@ -1904,7 +1951,7 @@ class CiviUnitTestCase extends PHPUnit_Extensions_Database_TestCase {
   }
 
   /**
-   * Create Group for a contact
+   * Create Group for a contact.
    *
    * @param int $contactId
    */
@@ -1918,7 +1965,7 @@ class CiviUnitTestCase extends PHPUnit_Extensions_Database_TestCase {
   }
 
   /**
-   * Delete Group for a contact
+   * Delete Group for a contact.
    *
    * @param int $contactId
    */
@@ -1931,7 +1978,7 @@ class CiviUnitTestCase extends PHPUnit_Extensions_Database_TestCase {
   }
 
   /**
-   * Create Activity
+   * Create Activity.
    *
    * @param array $params
    * @return array|int
@@ -1974,30 +2021,30 @@ class CiviUnitTestCase extends PHPUnit_Extensions_Database_TestCase {
   }
 
   /**
-   * Create an activity type
+   * Create an activity type.
    *
    * @param array $params
    *   Parameters.
+   * @return array
    */
   public function activityTypeCreate($params) {
-    $result = $this->callAPISuccess('ActivityType', 'create', $params);
-    return $result;
+    return $this->callAPISuccess('ActivityType', 'create', $params);
   }
 
   /**
-   * Delete activity type
+   * Delete activity type.
    *
    * @param int $activityTypeId
    *   Id of the activity type.
+   * @return array
    */
   public function activityTypeDelete($activityTypeId) {
     $params['activity_type_id'] = $activityTypeId;
-    $result = $this->callAPISuccess('ActivityType', 'delete', $params);
-    return $result;
+    return $this->callAPISuccess('ActivityType', 'delete', $params);
   }
 
   /**
-   * Create custom group
+   * Create custom group.
    *
    * @param array $params
    * @return array|int
@@ -2019,9 +2066,9 @@ class CiviUnitTestCase extends PHPUnit_Extensions_Database_TestCase {
 
     //have a crack @ deleting it first in the hope this will prevent derailing our tests
     $this->callAPISuccess('custom_group', 'get', array(
-        'title' => $params['title'],
-        array('api.custom_group.delete' => 1),
-      ));
+      'title' => $params['title'],
+      array('api.custom_group.delete' => 1),
+    ));
 
     return $this->callAPISuccess('custom_group', 'create', $params);
   }
@@ -2029,6 +2076,8 @@ 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
+   * @param array $params
+   * @return array|int
    */
   public function CustomGroupCreateByParams($params = array()) {
     $defaults = array(
@@ -2043,7 +2092,9 @@ class CiviUnitTestCase extends PHPUnit_Extensions_Database_TestCase {
   }
 
   /**
-   * Create custom group with multi fields
+   * Create custom group with multi fields.
+   * @param array $params
+   * @return array|int
    */
   public function CustomGroupMultipleCreateByParams($params = array()) {
     $defaults = array(
@@ -2055,7 +2106,9 @@ class CiviUnitTestCase extends PHPUnit_Extensions_Database_TestCase {
   }
 
   /**
-   * Create custom group with multi fields
+   * Create custom group with multi fields.
+   * @param array $params
+   * @return array
    */
   public function CustomGroupMultipleCreateWithFields($params = array()) {
     // also need to pass on $params['custom_field'] if not set but not in place yet
@@ -2064,24 +2117,24 @@ class CiviUnitTestCase extends PHPUnit_Extensions_Database_TestCase {
     $ids['custom_group_id'] = $customGroup['id'];
 
     $customField = $this->customFieldCreate(array(
-        'custom_group_id' => $ids['custom_group_id'],
-        'label' => 'field_1' . $ids['custom_group_id'],
-      ));
+      'custom_group_id' => $ids['custom_group_id'],
+      'label' => 'field_1' . $ids['custom_group_id'],
+    ));
 
     $ids['custom_field_id'][] = $customField['id'];
 
     $customField = $this->customFieldCreate(array(
-        'custom_group_id' => $ids['custom_group_id'],
-        'default_value' => '',
-        'label' => 'field_2' . $ids['custom_group_id'],
-      ));
+      'custom_group_id' => $ids['custom_group_id'],
+      'default_value' => '',
+      'label' => 'field_2' . $ids['custom_group_id'],
+    ));
     $ids['custom_field_id'][] = $customField['id'];
 
     $customField = $this->customFieldCreate(array(
-        'custom_group_id' => $ids['custom_group_id'],
-        'default_value' => '',
-        'label' => 'field_3' . $ids['custom_group_id'],
-      ));
+      'custom_group_id' => $ids['custom_group_id'],
+      'default_value' => '',
+      'label' => 'field_3' . $ids['custom_group_id'],
+    ));
     $ids['custom_field_id'][] = $customField['id'];
 
     return $ids;
@@ -2093,10 +2146,11 @@ class CiviUnitTestCase extends PHPUnit_Extensions_Database_TestCase {
    *
    * @param string $function
    *   __FUNCTION__.
-   * @param $filename
-   *   String $file __FILE__.
+   * @param string $filename
+   *   $file __FILE__.
    *
-   * @return array $ids ids of created objects
+   * @return array
+   *   ids of created objects
    */
   public function entityCustomGroupWithSingleFieldCreate($function, $filename) {
     $params = array('title' => $function);
@@ -2110,7 +2164,7 @@ class CiviUnitTestCase extends PHPUnit_Extensions_Database_TestCase {
   }
 
   /**
-   * Delete custom group
+   * Delete custom group.
    *
    * @param int $customGroupID
    *
@@ -2122,11 +2176,11 @@ class CiviUnitTestCase extends PHPUnit_Extensions_Database_TestCase {
   }
 
   /**
-   * Create custom field
+   * Create custom field.
    *
    * @param array $params
    *   (custom_group_id) is required.
-   * @return array|int
+   * @return array
    */
   public function customFieldCreate($params) {
     $params = array_merge(array(
@@ -2139,17 +2193,14 @@ class CiviUnitTestCase extends PHPUnit_Extensions_Database_TestCase {
     ), $params);
 
     $result = $this->callAPISuccess('custom_field', 'create', $params);
-
-    if ($result['is_error'] == 0 && isset($result['id'])) {
-      CRM_Core_BAO_CustomField::getTableColumnGroup($result['id'], 1);
-      // force reset of enabled components to help grab custom fields
-      CRM_Core_Component::getEnabledComponents(1);
-      return $result;
-    }
+    // these 2 functions are called with force to flush static caches
+    CRM_Core_BAO_CustomField::getTableColumnGroup($result['id'], 1);
+    CRM_Core_Component::getEnabledComponents(1);
+    return $result;
   }
 
   /**
-   * Delete custom field
+   * Delete custom field.
    *
    * @param int $customFieldID
    *
@@ -2162,10 +2213,10 @@ class CiviUnitTestCase extends PHPUnit_Extensions_Database_TestCase {
   }
 
   /**
-   * Create note
+   * Create note.
    *
    * @param int $cId
-   * @return array $note
+   * @return array
    */
   public function noteCreate($cId) {
     $params = array(
@@ -2181,7 +2232,7 @@ class CiviUnitTestCase extends PHPUnit_Extensions_Database_TestCase {
   }
 
   /**
-   * Enable CiviCampaign Component
+   * Enable CiviCampaign Component.
    */
   public function enableCiviCampaign() {
     CRM_Core_BAO_ConfigSetting::enableComponent('CiviCampaign');
@@ -2193,123 +2244,77 @@ class CiviUnitTestCase extends PHPUnit_Extensions_Database_TestCase {
 
   /**
    * Create test generated example in api/v3/examples.
+   *
    * To turn this off (e.g. on the server) set
    * define(DONT_DOCUMENT_TEST_CONFIG ,1);
    * in your settings file
+   *
+   * @param string $entity
+   * @param string $action
    * @param array $params
    *   Array as passed to civicrm_api function.
    * @param array $result
    *   Array as received from the civicrm_api function.
-   * @param string $function
+   * @param string $testFunction
    *   Calling function - generally __FUNCTION__.
-   * @param string $filename
+   * @param string $testFile
    *   Called from file - generally __FILE__.
    * @param string $description
    *   Descriptive text for the example file.
-   * @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.
+   * @param string $exampleName
+   *   Name for this example file (CamelCase) - if ommitted the action name will be substituted.
    */
-  public function documentMe($params, $result, $function, $filename, $description = "", $subfile = NULL, $action = NULL) {
+  private function documentMe($entity, $action, $params, $result, $testFunction, $testFile, $description = "", $exampleName = NULL) {
     if (defined('DONT_DOCUMENT_TEST_CONFIG') && DONT_DOCUMENT_TEST_CONFIG) {
       return;
     }
-    $entity = substr(basename($filename), 0, strlen(basename($filename)) - 8);
-    //todo - this is a bit cludgey
-    if (empty($action)) {
-      if (strstr($function, 'Create')) {
-        $action = empty($action) ? 'create' : $action;
-        $entityAction = 'Create';
-      }
-      elseif (strstr($function, 'GetSingle')) {
-        $action = empty($action) ? 'getsingle' : $action;
-        $entityAction = 'GetSingle';
-      }
-      elseif (strstr($function, 'GetValue')) {
-        $action = empty($action) ? 'getvalue' : $action;
-        $entityAction = 'GetValue';
-      }
-      elseif (strstr($function, 'GetCount')) {
-        $action = empty($action) ? 'getcount' : $action;
-        $entityAction = 'GetCount';
-      }
-      elseif (strstr($function, 'GetFields')) {
-        $action = empty($action) ? 'getfields' : $action;
-        $entityAction = 'GetFields';
-      }
-      elseif (strstr($function, 'GetList')) {
-        $action = empty($action) ? 'getlist' : $action;
-        $entityAction = 'GetList';
-      }
-      elseif (strstr($function, 'GetActions')) {
-        $action = empty($action) ? 'getactions' : $action;
-        $entityAction = 'GetActions';
-      }
-      elseif (strstr($function, 'Get')) {
-        $action = empty($action) ? 'get' : $action;
-        $entityAction = 'Get';
-      }
-      elseif (strstr($function, 'Delete')) {
-        $action = empty($action) ? 'delete' : $action;
-        $entityAction = 'Delete';
-      }
-      elseif (strstr($function, 'Update')) {
-        $action = empty($action) ? 'update' : $action;
-        $entityAction = 'Update';
-      }
-      elseif (strstr($function, 'Subscribe')) {
-        $action = empty($action) ? 'subscribe' : $action;
-        $entityAction = 'Subscribe';
-      }
-      elseif (strstr($function, 'Submit')) {
-        $action = empty($action) ? 'submit' : $action;
-        $entityAction = 'Submit';
-      }
-      elseif (strstr($function, 'Apply')) {
-        $action = empty($action) ? 'apply' : $action;
-        $entityAction = 'Apply';
-      }
-      elseif (strstr($function, 'Replace')) {
-        $action = empty($action) ? 'replace' : $action;
-        $entityAction = 'Replace';
+    $entity = _civicrm_api_get_camel_name($entity);
+    $action = strtolower($action);
+
+    if (empty($exampleName)) {
+      // Attempt to convert lowercase action name to CamelCase.
+      // This is clunky/imperfect due to the convention of all lowercase actions.
+      $exampleName = CRM_Utils_String::convertStringToCamel($action);
+      $knownPrefixes = array(
+        'Get',
+        'Set',
+        'Create',
+        'Update',
+        'Send',
+      );
+      foreach ($knownPrefixes as $prefix) {
+        if (strpos($exampleName, $prefix) === 0 && $prefix != $exampleName) {
+          $exampleName[strlen($prefix)] = strtoupper($exampleName[strlen($prefix)]);
+        }
       }
     }
-    else {
-      $entityAction = ucwords($action);
-    }
 
     $this->tidyExampleResult($result);
     if (isset($params['version'])) {
       unset($params['version']);
     }
-    // a cleverer person than me would do it in a single regex
-    if (strstr($entity, 'UF')) {
-      $fnPrefix = strtolower(preg_replace('/(?<! )(?<!^)(?<=UF)[A-Z]/', '_$0', $entity));
-    }
-    else {
-      $fnPrefix = strtolower(preg_replace('/(?<! )(?<!^)[A-Z]/', '_$0', $entity));
+    // Format multiline description as array
+    $desc = array();
+    if (is_string($description) && strlen($description)) {
+      foreach (explode("\n", $description) as $line) {
+        $desc[] = trim($line);
+      }
     }
     $smarty = CRM_Core_Smarty::singleton();
-    $smarty->assign('testfunction', $function);
-    $function = $fnPrefix . "_" . strtolower($action);
-    $smarty->assign('function', $function);
-    $smarty->assign('fnPrefix', $fnPrefix);
+    $smarty->assign('testFunction', $testFunction);
+    $smarty->assign('function', _civicrm_api_get_entity_name_from_camel($entity) . "_$action");
     $smarty->assign('params', $params);
     $smarty->assign('entity', $entity);
-    $smarty->assign('filename', basename($filename));
-    $smarty->assign('description', $description);
+    $smarty->assign('testFile', basename($testFile));
+    $smarty->assign('description', $desc);
     $smarty->assign('result', $result);
-
     $smarty->assign('action', $action);
-    if (empty($subfile)) {
-      $subfile = $entityAction;
-    }
+
     if (file_exists('../tests/templates/documentFunction.tpl')) {
       if (!is_dir("../api/v3/examples/$entity")) {
         mkdir("../api/v3/examples/$entity");
       }
-      $f = fopen("../api/v3/examples/$entity/$subfile.php", "w+b");
+      $f = fopen("../api/v3/examples/$entity/$exampleName.php", "w+b");
       fwrite($f, $smarty->fetch('../tests/templates/documentFunction.tpl'));
       fclose($f);
     }
@@ -2320,7 +2325,6 @@ class CiviUnitTestCase extends PHPUnit_Extensions_Database_TestCase {
    * and debug related fields are unset
    *
    * @param array $result
-   *
    */
   public function tidyExampleResult(&$result) {
     if (!is_array($result)) {
@@ -2394,7 +2398,7 @@ class CiviUnitTestCase extends PHPUnit_Extensions_Database_TestCase {
   }
 
   /**
-   * Delete note
+   * Delete note.
    *
    * @param array $params
    *
@@ -2405,7 +2409,7 @@ class CiviUnitTestCase extends PHPUnit_Extensions_Database_TestCase {
   }
 
   /**
-   * Create custom field with Option Values
+   * Create custom field with Option Values.
    *
    * @param array $customGroup
    * @param string $name
@@ -2459,11 +2463,13 @@ class CiviUnitTestCase extends PHPUnit_Extensions_Database_TestCase {
         return TRUE;
       }
     }
+    return FALSE;
   }
 
   /**
    * @param $tablesToTruncate
    * @param bool $dropCustomValueTables
+   * @throws \Exception
    */
   public function quickCleanup($tablesToTruncate, $dropCustomValueTables = FALSE) {
     if ($this->tx) {
@@ -2532,6 +2538,7 @@ AND    ( TABLE_NAME LIKE 'civicrm_value_%' )
     $this->restoreDefaultPriceSetConfig();
     $var = TRUE;
     CRM_Member_BAO_Membership::createRelatedMemberships($var, $var, TRUE);
+    Civi\Payment\System::singleton()->flushProcessors();
   }
 
   public function restoreDefaultPriceSetConfig() {
@@ -2551,7 +2558,6 @@ AND    ( TABLE_NAME LIKE 'civicrm_value_%' )
    *   Should the entity be deleted as part of this check.
    * @param string $errorText
    *   Text to print on error.
-   *
    */
   /**
    * @param array $params
@@ -2624,12 +2630,11 @@ AND    ( TABLE_NAME LIKE 'civicrm_value_%' )
   }
 
   /**
-   * Get formatted values in  the actual and expected result
+   * Get formatted values in  the actual and expected result.
    * @param array $actual
    *   Actual calculated values.
    * @param array $expected
    *   Expected values.
-   *
    */
   public function checkArrayEquals(&$actual, &$expected) {
     self::unsetId($actual);
@@ -2641,7 +2646,6 @@ AND    ( TABLE_NAME LIKE 'civicrm_value_%' )
    * Unset the key 'id' from the array
    * @param array $unformattedArray
    *   The array from which the 'id' has to be unset.
-   *
    */
   public static function unsetId(&$unformattedArray) {
     $formattedArray = array();
@@ -2700,10 +2704,10 @@ AND    ( TABLE_NAME LIKE 'civicrm_value_%' )
   }
 
   /**
-   * Generate a temporary folder
+   * Generate a temporary folder.
    *
    * @param string $prefix
-   * @return string $string
+   * @return string
    */
   public function createTempDir($prefix = 'test-') {
     $tempDir = CRM_Utils_File::tempdir($prefix);
@@ -2724,7 +2728,8 @@ AND    ( TABLE_NAME LIKE 'civicrm_value_%' )
   }
 
   /**
-   * Temporarily replace the singleton extension with a different one
+   * Temporarily replace the singleton extension with a different one.
+   * @param \CRM_Extension_System $system
    */
   public function setExtensionSystem(CRM_Extension_System $system) {
     if ($this->origExtensionSystem == NULL) {
@@ -2959,7 +2964,6 @@ AND    ( TABLE_NAME LIKE 'civicrm_value_%' )
    *  $this->createLoggedInUser();
    *   $this->_permissionedDisabledGroup = $this->groupCreate(array('title' => 'pick-me-disabled', 'is_active' => 0, 'name' => 'pick-me-disabled'));
    *   $this->_permissionedGroup = $this->groupCreate(array('title' => 'pick-me-active', 'is_active' => 1, 'name' => 'pick-me-active'));
-   *
    */
   public function setupACL() {
     global $_REQUEST;
@@ -3022,24 +3026,24 @@ AND    ( TABLE_NAME LIKE 'civicrm_value_%' )
     $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',
-      ));
+      'id' => $contributionPriceSet['id'],
+      'is_active' => 0,
+      'name' => 'old',
+    ));
     unset($contributionPriceSet['id']);
     $newPriceSet = $this->callAPISuccess('price_set', 'create', $contributionPriceSet);
     $priceField = $this->callAPISuccess('price_field', 'getsingle', array(
-        'price_set_id' => $firstID,
-        'options' => array('limit' => 1),
-      ));
+      'price_set_id' => $firstID,
+      'options' => array('limit' => 1),
+    ));
     unset($priceField['id']);
     $priceField['price_set_id'] = $newPriceSet['id'];
     $newPriceField = $this->callAPISuccess('price_field', 'create', $priceField);
     $priceFieldValue = $this->callAPISuccess('price_field_value', 'getsingle', array(
-        'price_set_id' => $firstID,
-        'sequential' => 1,
-        'options' => array('limit' => 1),
-      ));
+      'price_set_id' => $firstID,
+      'sequential' => 1,
+      'options' => array('limit' => 1),
+    ));
 
     unset($priceFieldValue['id']);
     //create some padding to use up ids
@@ -3049,11 +3053,13 @@ AND    ( TABLE_NAME LIKE 'civicrm_value_%' )
   }
 
   /**
-   * Create an instance of the paypal processor
+   * 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
+   * @param array $params
+   * @return int $result['id'] payment processor id
    */
   public function paymentProcessorCreate($params = array()) {
     $params = array_merge(array(
@@ -3087,7 +3093,7 @@ AND    ( TABLE_NAME LIKE 'civicrm_value_%' )
   }
 
   /**
-   * Set up initial recurring payment allowing subsequent IPN payments
+   * Set up initial recurring payment allowing subsequent IPN payments.
    */
   public function setupRecurringPaymentProcessorTransaction() {
     $contributionRecur = $this->callAPISuccess('contribution_recur', 'create', array(
@@ -3142,18 +3148,18 @@ AND    ( TABLE_NAME LIKE 'civicrm_value_%' )
       'line_total' => 200,
       'financial_type_id' => 1,
       'price_field_id' => $this->callAPISuccess('price_field', 'getvalue', array(
-          'return' => 'id',
-          'label' => 'Membership Amount',
-        )),
+        'return' => 'id',
+        'label' => 'Membership Amount',
+      )),
       'price_field_value_id' => $this->callAPISuccess('price_field_value', 'getvalue', array(
-          'return' => 'id',
-          'label' => 'General',
-        )),
+        'return' => 'id',
+        'label' => 'General',
+      )),
     ));
     $this->callAPISuccess('membership_payment', 'create', array(
-        'contribution_id' => $this->_contributionID,
-        'membership_id' => $this->ids['membership'],
-      ));
+      'contribution_id' => $this->_contributionID,
+      'membership_id' => $this->ids['membership'],
+    ));
   }
 
   /**
@@ -3166,16 +3172,15 @@ AND    ( TABLE_NAME LIKE 'civicrm_value_%' )
   }
 
   /**
-   * Helper function to create new mailing
+   * Helper function to create new mailing.
    * @return mixed
    */
   public function createMailing() {
     $params = array(
       'subject' => 'maild' . rand(),
-      'body_text' => 'bdkfhdskfhduew',
+      'body_text' => 'bdkfhdskfhduew{domain.address}{action.optOutUrl}',
       'name' => 'mailing name' . rand(),
       'created_id' => 1,
-      'api.mailing_job.create' => 0,
     );
 
     $result = $this->callAPISuccess('Mailing', 'create', $params);
@@ -3183,7 +3188,7 @@ AND    ( TABLE_NAME LIKE 'civicrm_value_%' )
   }
 
   /**
-   * Helper function to delete mailing
+   * Helper function to delete mailing.
    * @param $id
    */
   public function deleteMailing($id) {
@@ -3195,7 +3200,7 @@ AND    ( TABLE_NAME LIKE 'civicrm_value_%' )
   }
 
   /**
-   * Wrap the entire test case in a transaction
+   * 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
@@ -3222,4 +3227,21 @@ AND    ( TABLE_NAME LIKE 'civicrm_value_%' )
       ob_end_clean();
     }
   }
+
+  /**
+   * @param $exists
+   * @param array $apiResult
+   */
+  protected function assertAttachmentExistence($exists, $apiResult) {
+    $fileId = $apiResult['id'];
+    $this->assertTrue(is_numeric($fileId));
+    $this->assertEquals($exists, file_exists($apiResult['values'][$fileId]['path']));
+    $this->assertDBQuery($exists ? 1 : 0, 'SELECT count(*) FROM civicrm_file WHERE id = %1', array(
+      1 => array($fileId, 'Int'),
+    ));
+    $this->assertDBQuery($exists ? 1 : 0, 'SELECT count(*) FROM civicrm_entity_file WHERE id = %1', array(
+      1 => array($fileId, 'Int'),
+    ));
+  }
+
 }