minor tidyups
authorEileen McNaughton <eileen@fuzion.co.nz>
Thu, 8 Jan 2015 11:19:27 +0000 (00:19 +1300)
committerEileen McNaughton <eileen@fuzion.co.nz>
Mon, 26 Jan 2015 23:02:42 +0000 (12:02 +1300)
CRM/Member/BAO/MembershipType.php
tests/phpunit/api/v3/MembershipTypeTest.php

index 59bfb5bdeb819edabff24068503ee23a3c8960c8..84df6f4eb388f8da7d4167928aec74b4dddac4da 100644 (file)
@@ -154,12 +154,12 @@ class CRM_Member_BAO_MembershipType extends CRM_Member_DAO_MembershipType {
     //check dependencies
     $check = FALSE;
     $status = array();
-    $dependancy = array(
+    $dependency = array(
       'Membership' => 'membership_type_id',
       'MembershipBlock' => 'membership_type_default',
     );
 
-    foreach ($dependancy as $name => $field) {
+    foreach ($dependency as $name => $field) {
       $baoString = 'CRM_Member_BAO_' . $name;
       $dao = new $baoString();
       $dao->$field = $membershipTypeId;
@@ -462,16 +462,11 @@ class CRM_Member_BAO_MembershipType extends CRM_Member_DAO_MembershipType {
       }
     }
 
-    $membershipDates = array();
-
-    $dates = array(
-      'start_date' => 'startDate',
-      'end_date' => 'endDate',
-      'join_date' => 'joinDate',
+    $membershipDates = array(
+      'start_date' =>  CRM_Utils_Date::customFormat($startDate, '%Y%m%d'),
+      'end_date' => CRM_Utils_Date::customFormat($endDate, '%Y%m%d'),
+      'join_date' => CRM_Utils_Date::customFormat($joinDate, '%Y%m%d'),
     );
-    foreach ($dates as $varName => $valName) {
-      $membershipDates[$varName] = CRM_Utils_Date::customFormat($$valName, '%Y%m%d');
-    }
 
     return $membershipDates;
   }
index 5ee2dd1b5ff4c558a400436cb6c52fd6b66468d7..e6603dd1960d05d2985c219c427f7a7629e24c70 100644 (file)
@@ -203,20 +203,22 @@ class api_v3_MembershipTypeTest extends CiviUnitTestCase {
       'visibility' => 'public',
     );
 
-    $membershiptype = $this->callAPIAndDocument('membership_type', 'create', $params, __FUNCTION__, __FILE__);
-    $this->assertNotNull($membershiptype['values']);
-    $this->membershipTypeDelete(array('id' => $membershiptype['id']));
+    $membershipType = $this->callAPIAndDocument('membership_type', 'create', $params, __FUNCTION__, __FILE__);
+    $this->assertNotNull($membershipType['values']);
+    $this->membershipTypeDelete(array('id' => $membershipType['id']));
   }
 
 
+  /**
+   * Test mandatory parameter check.
+   */
   public function testUpdateWithEmptyParams() {
-    $params = array();
-    $membershiptype = $this->callAPIFailure('membership_type', 'create', $params);
-    $this->assertEquals($membershiptype['error_message'],
-      'Mandatory key(s) missing from params array: domain_id, member_of_contact_id, financial_type_id, duration_unit, duration_interval, name'
-                       );
+    $this->callAPIFailure('membership_type', 'create', array());
   }
 
+  /**
+   * Test update fails with no ID.
+   */
   public function testUpdateWithoutId() {
     $params = array(
       'name' => '60+ Membership',
@@ -230,8 +232,8 @@ class api_v3_MembershipTypeTest extends CiviUnitTestCase {
       'visibility' => 'public',
     );
 
-    $membershiptype = $this->callAPIFailure('membership_type', 'create', $params);
-    $this->assertEquals($membershiptype['error_message'], 'Mandatory key(s) missing from params array: domain_id');
+    $membershipType = $this->callAPIFailure('membership_type', 'create', $params);
+    $this->assertEquals($membershipType['error_message'], 'Mandatory key(s) missing from params array: domain_id');
   }
 
   public function testUpdate() {
@@ -260,13 +262,16 @@ class api_v3_MembershipTypeTest extends CiviUnitTestCase {
     $this->getAndCheck($params, $id, $this->_entity);
   }
 
+  /**
+   * Test for failure when id is not valid.
+   */
   public function testDeleteNotExists() {
     $params = array(
       'id' => 'doesNotExist',
     );
-    $membershiptype = $this->callAPIFailure('membership_type', 'delete', $params,
-                      'Error while deleting membership type. id : ' . $params['id']
-                                           );
+    $this->callAPIFailure('membership_type', 'delete', $params,
+      'Error while deleting membership type. id : ' . $params['id']
+    );
   }
 
   public function testDelete() {
@@ -276,7 +281,7 @@ class api_v3_MembershipTypeTest extends CiviUnitTestCase {
       'id' => $membershipTypeID,
     );
 
-    $result = $this->callAPIAndDocument('membership_type', 'delete', $params, __FUNCTION__, __FILE__);
+    $this->callAPIAndDocument('membership_type', 'delete', $params, __FUNCTION__, __FILE__);
   }
 
 }