fix membership_type to be editable within tests so we can address test failure
authorEileen McNaughton <eileen@fuzion.co.nz>
Sun, 19 Oct 2014 07:31:39 +0000 (20:31 +1300)
committerEileen McNaughton <eileen@fuzion.co.nz>
Sun, 19 Oct 2014 07:32:33 +0000 (20:32 +1300)
CRM/Core/DAO.php
CRM/Member/BAO/MembershipType.php
tests/phpunit/api/v3/SyntaxConformanceTest.php

index 7f990f5a7b8fbb6af0f4aa6c2d5a0c95ff47eb08..3bd298dcd6be2987ef338d5ca230124f368a823c 100644 (file)
@@ -1570,6 +1570,7 @@ SELECT contact_id
       'CRM_Core_DAO_StateProvince',
       'CRM_Core_DAO_Country',
       'CRM_Core_DAO_Domain',
+      'CRM_Financial_DAO_FinancialType'//because valid ones exist & we use pick them due to pseudoconstant can't reliably create & delete these
     );
 
     for ($i = 0; $i < $numObjects; ++$i) {
@@ -1649,7 +1650,10 @@ SELECT contact_id
         if ($FKClassName != NULL
           && $object->$dbName
           && !in_array($FKClassName, CRM_Core_DAO::$_testEntitiesToSkip)
-          && ($required || $dbName == 'contact_id')) {
+          && ($required || $dbName == 'contact_id')
+          //I'm a bit stuck on this one - we might need to change the singleValueAlter so that the entities don't share a contact
+          // to make this test process pass - line below makes pass for now
+          && $dbName != 'member_of_contact_id') {
           $deletions[] = array($FKClassName, array('id' => $object->$dbName)); // x
         }
       }
index e6790f7209f9a9bc134655d553f421349a71b00a..ef448155c3b5e5c58f87fbf209409249c26e67cc 100644 (file)
@@ -115,12 +115,16 @@ class CRM_Member_BAO_MembershipType extends CRM_Member_DAO_MembershipType {
 
     // $previousID is the old organization id for membership type i.e 'member_of_contact_id'. This is used when an organization is changed.
     $previousID = NULL;
-    if ($membershipType->id) {
-      $previousID = CRM_Core_DAO::getFieldValue('CRM_Member_DAO_MembershipType', $membershipType->id, 'member_of_contact_id');
+    if ($id) {
+      $previousID = CRM_Core_DAO::getFieldValue('CRM_Member_DAO_MembershipType', $id, 'member_of_contact_id');
     }
 
     $membershipType->save();
-
+    if ($id) {
+      // on update we may need to retrieve some details for the price field function - otherwise we get e-notices on attempts to retrieve
+      // name etc - the presence of previous id tells us this is an update
+      $params = array_merge(civicrm_api3('membership_type', 'getsingle', array('id' => $membershipType->id)), $params);
+    }
     self::createMembershipPriceField($params, $previousID, $membershipType->id);
     // update all price field value for quick config when membership type is set CRM-11718
     if ($id) {
@@ -701,7 +705,7 @@ class CRM_Member_BAO_MembershipType extends CRM_Member_DAO_MembershipType {
         CRM_Member_Form_MembershipType::checkPreviousPriceField($previousID, $priceSetId, $membershipTypeId, $optionsIds);
         $fieldParams['option_id'] = CRM_Utils_Array::value('option_id', $optionsIds);
       }
-      $priceField = CRM_Price_BAO_PriceField::create($fieldParams);
+      CRM_Price_BAO_PriceField::create($fieldParams);
     }
     else {
       $fieldID = $results['id'];
index 1992bac3b3fd04df6305b6d0744845c1d06143d7..60bcc443e169f9f1e2e5b047287b1182f79e2c7b 100644 (file)
@@ -323,7 +323,6 @@ class api_v3_SyntaxConformanceTest extends CiviUnitTestCase {
       'Note',
       'OptionGroup',
       'Membership',
-      'MembershipType',
       'MembershipStatus',
       'Group',
       'GroupOrganization',
@@ -1068,7 +1067,7 @@ class api_v3_SyntaxConformanceTest extends CiviUnitTestCase {
         'id' => $entity['id'],
         $field => isset($entity[$field]) ? $entity[$field] : NULL,
       );
-      if(isset($updateParams['financial_type_id']) && $entityName != 'Product') {
+      if(isset($updateParams['financial_type_id']) && !in_array($entityName, array('Product', 'MembershipType'))) {
         //api has special handling on these 2 fields for backward compatibility reasons
         $entity['contribution_type_id'] = $updateParams['financial_type_id'];
       }