CRM-15855 - Allow mailings to be saved (but not sent) without name+subject.
[civicrm-core.git] / tests / phpunit / CiviTest / CiviUnitTestCase.php
index 596bf3b53ff057051138e2d3f1021b6354060c5e..0fdbf562baf07545b4b72555143f13d2a47d3d85 100755 (executable)
@@ -189,11 +189,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();
@@ -555,6 +563,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)) {
@@ -667,7 +680,7 @@ class CiviUnitTestCase extends PHPUnit_Extensions_Database_TestCase {
    * @param $expectedValue
    * @param $message
    */
-  function assertDBCompareValue(
+  public function assertDBCompareValue(
     $daoName, $searchValue, $returnColumn, $searchColumn,
     $expectedValue, $message
   ) {
@@ -698,6 +711,10 @@ 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")));
+   * @param $expected
+   * @param $query
+   * @param array $params
+   * @param string $message
    */
   public function assertDBQuery($expected, $query, $params = array(), $message = '') {
     if ($message) {
@@ -843,6 +860,8 @@ class CiviUnitTestCase extends PHPUnit_Extensions_Database_TestCase {
 
   /**
    * 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);
@@ -1006,7 +1025,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)) {
@@ -1158,7 +1177,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(
@@ -1196,7 +1215,7 @@ class CiviUnitTestCase extends PHPUnit_Extensions_Database_TestCase {
    *   Contact ID to delete
    */
   public function contactDelete($contactID) {
-    $domain = new CRM_Core_BAO_Domain;
+    $domain = new CRM_Core_BAO_Domain();
     $domain->contact_id = $contactID;
     if (!$domain->find(TRUE)) {
       $this->callAPISuccess('contact', 'delete', array(
@@ -1212,7 +1231,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');
@@ -1287,7 +1305,6 @@ class CiviUnitTestCase extends PHPUnit_Extensions_Database_TestCase {
   public function membershipDelete($membershipID) {
     $deleteParams = array('id' => $membershipID);
     $result = $this->callAPISuccess('Membership', 'Delete', $deleteParams);
-    return;
   }
 
   /**
@@ -1315,7 +1332,6 @@ class CiviUnitTestCase extends PHPUnit_Extensions_Database_TestCase {
       return;
     }
     $result = $this->callAPISuccess('MembershipStatus', 'Delete', array('id' => $membershipStatusID));
-    return;
   }
 
   /**
@@ -1794,7 +1810,7 @@ class CiviUnitTestCase extends PHPUnit_Extensions_Database_TestCase {
   /**
    * Delete a Location Type
    *
-   * @param int location type id
+   * @param int $locationTypeId
    */
   public function locationTypeDelete($locationTypeId) {
     $locationType = new CRM_Core_DAO_LocationType();
@@ -1833,9 +1849,10 @@ class CiviUnitTestCase extends PHPUnit_Extensions_Database_TestCase {
    *
    * @params array to add group
    *
-   * @param array $params
+   * @param int $groupID
+   * @param int $totalCount
    * @return int
-   *   groupId of created group
+   *    groupId of created group
    */
   public function groupContactCreate($groupID, $totalCount = 10) {
     $params = array('group_id' => $groupID);
@@ -1911,7 +1928,8 @@ class CiviUnitTestCase extends PHPUnit_Extensions_Database_TestCase {
   /**
    * 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) {
@@ -2003,10 +2021,10 @@ class CiviUnitTestCase extends PHPUnit_Extensions_Database_TestCase {
    *
    * @param array $params
    *   Parameters.
+   * @return array
    */
   public function activityTypeCreate($params) {
-    $result = $this->callAPISuccess('ActivityType', 'create', $params);
-    return $result;
+    return $this->callAPISuccess('ActivityType', 'create', $params);
   }
 
   /**
@@ -2014,11 +2032,11 @@ class CiviUnitTestCase extends PHPUnit_Extensions_Database_TestCase {
    *
    * @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);
   }
 
   /**
@@ -2054,6 +2072,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(
@@ -2069,6 +2089,8 @@ class CiviUnitTestCase extends PHPUnit_Extensions_Database_TestCase {
 
   /**
    * Create custom group with multi fields
+   * @param array $params
+   * @return array|int
    */
   public function CustomGroupMultipleCreateByParams($params = array()) {
     $defaults = array(
@@ -2081,6 +2103,8 @@ class CiviUnitTestCase extends PHPUnit_Extensions_Database_TestCase {
 
   /**
    * 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
@@ -2481,6 +2505,7 @@ class CiviUnitTestCase extends PHPUnit_Extensions_Database_TestCase {
         return TRUE;
       }
     }
+    return FALSE;
   }
 
   /**
@@ -2745,6 +2770,7 @@ AND    ( TABLE_NAME LIKE 'civicrm_value_%' )
 
   /**
    * 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) {
@@ -3073,6 +3099,8 @@ AND    ( TABLE_NAME LIKE 'civicrm_value_%' )
    * 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(
@@ -3241,4 +3269,5 @@ AND    ( TABLE_NAME LIKE 'civicrm_value_%' )
       ob_end_clean();
     }
   }
+
 }