Cleanup on test class.
authoreileen <emcnaughton@wikimedia.org>
Thu, 10 May 2018 02:20:01 +0000 (14:20 +1200)
committereileen <emcnaughton@wikimedia.org>
Tue, 15 May 2018 07:17:38 +0000 (19:17 +1200)
Remove some functions that were not testing what they said they were & clarify others. Improve
formatting & declaration of unused vars

api/v3/Activity.php
tests/phpunit/api/v3/ActivityTest.php

index 576b8771905d2c775c45a8277a523a1cadaeb7ed..67b01d965f609c24abd17c1a731238d353b00f89 100644 (file)
@@ -635,7 +635,7 @@ function civicrm_api3_activity_delete($params) {
     return civicrm_api3_create_success(1, $params, 'Activity', 'delete');
   }
   else {
-    throw new API_Exception('Could not delete Activity');
+    throw new API_Exception('Could not delete Activity: ' . (int) $params['id']);
   }
 }
 
index b2b0f5523c64ee1ae864ce316bb2fb0c70d3bd73..cffae8f77860d05c02a7c88f017ab99a67ed64d8 100644 (file)
@@ -47,6 +47,12 @@ class api_v3_ActivityTest extends CiviUnitTestCase {
   protected $_apiversion = 3;
   protected $test_activity_type_value;
   protected $_contactID;
+  /**
+   * Activity type id created for use in this test class.
+   *
+   * @var int
+   */
+  protected $test_activity_type_id;
 
   /**
    * Test setup for every test.
@@ -232,7 +238,7 @@ class api_v3_ActivityTest extends CiviUnitTestCase {
    * Check with incorrect required fields.
    */
   public function testActivityCreateWithUnknownActivityTypeId() {
-    $params = array(
+    $this->callAPIFailure('activity', 'create', [
       'source_contact_id' => $this->_contactID,
       'subject' => 'Make-it-Happen Meeting',
       'activity_date_time' => date('Ymd'),
@@ -241,9 +247,7 @@ class api_v3_ActivityTest extends CiviUnitTestCase {
       'details' => 'a test activity',
       'status_id' => 1,
       'activity_type_id' => 699,
-    );
-
-    $result = $this->callAPIFailure('activity', 'create', $params);
+    ]);
   }
 
   public function testActivityCreateWithInvalidPriority() {
@@ -920,43 +924,18 @@ class api_v3_ActivityTest extends CiviUnitTestCase {
     $this->assertEquals($result['values'][0]['id'], $result['id']);
   }
 
-  /**
-   * Check activity deletion with empty params.
-   */
-  public function testDeleteActivityForEmptyParams() {
-    $params = array('version' => $this->_apiversion);
-    $this->callAPIFailure('activity', 'delete', $params);
-  }
-
   /**
    * Check activity deletion without activity id.
    */
   public function testDeleteActivityWithoutId() {
-    $params = array(
-      'activity_name' => 'Meeting',
-      'version' => $this->_apiversion,
-    );
-    $result = $this->callAPIFailure('activity', 'delete', $params);
+    $this->callAPIFailure('activity', 'delete', ['activity_name' => 'Meeting'], 'Mandatory key(s) missing from params array: id');
   }
 
   /**
    * Check activity deletion without activity type.
    */
-  public function testDeleteActivityWithoutActivityType() {
-    $params = array('id' => 1);
-    $result = $this->callAPIFailure('activity', 'delete', $params);
-  }
-
-  /**
-   * Check activity deletion with incorrect data.
-   */
-  public function testDeleteActivityWithIncorrectActivityType() {
-    $params = array(
-      'id' => 1,
-      'activity_name' => 'Test Activity',
-    );
-
-    $result = $this->callAPIFailure('activity', 'delete', $params);
+  public function testDeleteActivityWithInvalidID() {
+    $this->callAPIFailure('activity', 'delete', ['id' => 1], 'Could not delete Activity: 1');
   }
 
   /**
@@ -964,11 +943,7 @@ class api_v3_ActivityTest extends CiviUnitTestCase {
    */
   public function testDeleteActivity() {
     $result = $this->callAPISuccess('activity', 'create', $this->_params);
-    $params = array(
-      'id' => $result['id'],
-      'version' => $this->_apiversion,
-    );
-
+    $params = ['id' => $result['id']];
     $this->callAPIAndDocument('activity', 'delete', $params, __FUNCTION__, __FILE__);
   }
 
@@ -976,12 +951,10 @@ class api_v3_ActivityTest extends CiviUnitTestCase {
    * Check if required fields are not passed.
    */
   public function testActivityUpdateWithoutRequired() {
-    $params = array(
+    $this->callAPIFailure('activity', 'create', [
       'subject' => 'this case should fail',
       'scheduled_date_time' => date('Ymd'),
-    );
-
-    $result = $this->callAPIFailure('activity', 'create', $params);
+    ]);
   }
 
   /**