From: Eileen McNaughton Date: Thu, 8 Jan 2015 11:19:27 +0000 (+1300) Subject: minor tidyups X-Git-Url: https://vcs.fsf.org/?a=commitdiff_plain;h=edc9b94e65a9ab6b8cb05cba85d1ea420c37d443;p=civicrm-core.git minor tidyups --- diff --git a/CRM/Member/BAO/MembershipType.php b/CRM/Member/BAO/MembershipType.php index 59bfb5bdeb..84df6f4eb3 100644 --- a/CRM/Member/BAO/MembershipType.php +++ b/CRM/Member/BAO/MembershipType.php @@ -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; } diff --git a/tests/phpunit/api/v3/MembershipTypeTest.php b/tests/phpunit/api/v3/MembershipTypeTest.php index 5ee2dd1b5f..e6603dd196 100644 --- a/tests/phpunit/api/v3/MembershipTypeTest.php +++ b/tests/phpunit/api/v3/MembershipTypeTest.php @@ -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__); } }