From: Eileen McNaughton Date: Sun, 19 Oct 2014 07:31:39 +0000 (+1300) Subject: fix membership_type to be editable within tests so we can address test failure X-Git-Url: https://vcs.fsf.org/?a=commitdiff_plain;h=806e9b716755a1291261bbd159785e7e38f6c0a1;p=civicrm-core.git fix membership_type to be editable within tests so we can address test failure --- diff --git a/CRM/Core/DAO.php b/CRM/Core/DAO.php index 7f990f5a7b..3bd298dcd6 100644 --- a/CRM/Core/DAO.php +++ b/CRM/Core/DAO.php @@ -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 } } diff --git a/CRM/Member/BAO/MembershipType.php b/CRM/Member/BAO/MembershipType.php index e6790f7209..ef448155c3 100644 --- a/CRM/Member/BAO/MembershipType.php +++ b/CRM/Member/BAO/MembershipType.php @@ -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']; diff --git a/tests/phpunit/api/v3/SyntaxConformanceTest.php b/tests/phpunit/api/v3/SyntaxConformanceTest.php index 1992bac3b3..60bcc443e1 100644 --- a/tests/phpunit/api/v3/SyntaxConformanceTest.php +++ b/tests/phpunit/api/v3/SyntaxConformanceTest.php @@ -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']; }