From 55d2c6f131a13abad62d120cd9159b1c0e17fd44 Mon Sep 17 00:00:00 2001 From: Eileen McNaughton Date: Thu, 15 Jan 2015 15:31:14 +1300 Subject: [PATCH] fix clean up --- CRM/Contact/BAO/Contact.php | 21 +++++----- CRM/Report/Form/Membership/Summary.php | 36 ++++++++++++------ tests/phpunit/CRM/Contact/BAO/ContactTest.php | 38 +++++-------------- tests/phpunit/api/v3/ContributionTest.php | 19 +++++----- 4 files changed, 53 insertions(+), 61 deletions(-) diff --git a/CRM/Contact/BAO/Contact.php b/CRM/Contact/BAO/Contact.php index 10fd7477bd..506c958f96 100644 --- a/CRM/Contact/BAO/Contact.php +++ b/CRM/Contact/BAO/Contact.php @@ -524,10 +524,10 @@ WHERE civicrm_contact.id = " . CRM_Utils_Type::escape($id, 'Integer'); * Create last viewed link to recently updated contact. * * @param array $crudLinkSpec - * With keys:. - * - action: int, CRM_Core_Action::UPDATE or CRM_Core_Action::VIEW [default: VIEW] - * - entity_table: string, eg "civicrm_contact" - * - entity_id: int + * - action: int, CRM_Core_Action::UPDATE or CRM_Core_Action::VIEW [default: VIEW] + * - entity_table: string, eg "civicrm_contact" + * - entity_id: int + * * @return array|NULL * NULL if unavailable, or * [path: string, query: string, title: string] @@ -759,7 +759,7 @@ WHERE civicrm_contact.id = " . CRM_Utils_Type::escape($id, 'Integer'); } /** - * Delete a contact and all its associated records + * Delete a contact and all its associated records. * * @param int $id * Id of the contact to delete. @@ -768,8 +768,8 @@ WHERE civicrm_contact.id = " . CRM_Utils_Type::escape($id, 'Integer'); * @param bool $skipUndelete * Whether to force contact delete or not. * - * @return boolean - * true if contact deleted, false otherwise + * @return bool + * Was contact deleted? */ public static function deleteContact($id, $restore = FALSE, $skipUndelete = FALSE) { @@ -819,7 +819,6 @@ WHERE civicrm_contact.id = " . CRM_Utils_Type::escape($id, 'Integer'); return TRUE; } - // currently we only clear employer cache. // we are not deleting inherited membership if any. if ($contact->contact_type == 'Organization') { @@ -896,13 +895,13 @@ WHERE civicrm_contact.id = " . CRM_Utils_Type::escape($id, 'Integer'); } /** - * Delete the image of a contact + * Delete the image of a contact. * * @param int $id * Id of the contact. * - * @return boolean - * true if contact image is deleted + * @return bool + * Was contact image deleted? */ public static function deleteContactImage($id) { if (!$id) { diff --git a/CRM/Report/Form/Membership/Summary.php b/CRM/Report/Form/Membership/Summary.php index 4e8746bdd5..387abf4566 100644 --- a/CRM/Report/Form/Membership/Summary.php +++ b/CRM/Report/Form/Membership/Summary.php @@ -30,7 +30,6 @@ * @package CRM * @copyright CiviCRM LLC (c) 2004-2014 * $Id$ - * */ class CRM_Report_Form_Membership_Summary extends CRM_Report_Form { @@ -43,12 +42,11 @@ class CRM_Report_Form_Membership_Summary extends CRM_Report_Form { ); /** - */ - /** + * Constructor function. */ public function __construct() { // UI for selecting columns to appear in the report list - // array conatining the columns, group_bys and filters build and provided to Form + // array containing the columns, group_bys and filters build and provided to Form $this->_columns = array( 'civicrm_contact' => array( 'dao' => 'CRM_Contact_DAO_Contact', @@ -139,18 +137,27 @@ class CRM_Report_Form_Membership_Summary extends CRM_Report_Form { parent::__construct(); } + /** + * Pre-process function. + */ public function preProcess() { $this->assign('reportTitle', ts('Membership Summary Report')); parent::preProcess(); } /** + * Set default values. + * * @return array + * Default values. */ public function setDefaultValues() { return parent::setDefaultValues(); } + /** + * Generate select clause. + */ public function select() { $select = array(); $this->_columnHeaders = array(); @@ -179,6 +186,8 @@ class CRM_Report_Form_Membership_Summary extends CRM_Report_Form { } /** + * Set form rules. + * * @param $fields * @param $files * @param $self @@ -205,12 +214,12 @@ LEFT JOIN civicrm_membership_type {$this->_aliases['civicrm_membership_type']} LEFT JOIN civicrm_contribution {$this->_aliases['civicrm_contribution']} ON {$this->_aliases['civicrm_membership']}.contact_id = {$this->_aliases['civicrm_contribution']}.contact_id "; - // include address field if address column is to be included + // Include address table if address column is to be included. if ($this->_addressField) { $this->_from .= "LEFT JOIN civicrm_address {$this->_aliases['civicrm_address']} ON {$this->_aliases['civicrm_contact']}.id = {$this->_aliases['civicrm_address']}.contact_id AND {$this->_aliases['civicrm_address']}.is_primary = 1\n"; } - // include email field if email column is to be included + // Include email table if email column is to be included. if ($this->_emailField) { $this->_from .= "LEFT JOIN civicrm_email {$this->_aliases['civicrm_email']} ON {$this->_aliases['civicrm_contact']}.id = {$this->_aliases['civicrm_email']}.contact_id AND {$this->_aliases['civicrm_email']}.is_primary = 1\n"; } @@ -259,7 +268,9 @@ LEFT JOIN civicrm_contribution {$this->_aliases['civicrm_contribution']} } /** - * @param $rows + * Generate statistics (bottom section of the report). + * + * @param array $rows * * @return array */ @@ -363,7 +374,9 @@ LEFT JOIN civicrm_contribution {$this->_aliases['civicrm_contribution']} } /** - * @param $rows + * Make changes to how data is displayed. + * + * @param array $rows */ public function alterDisplay(&$rows) { // custom code to alter rows @@ -418,12 +431,13 @@ LEFT JOIN civicrm_contribution {$this->_aliases['civicrm_contribution']} if (array_key_exists('civicrm_contact_sort_name', $row) && array_key_exists('civicrm_contact_id', $row) ) { - $url = CRM_Utils_System::url('civicrm/report/member/detail', + $url = CRM_Utils_System::url( + 'civicrm/report/member/detail', 'reset=1&force=1&id_op=eq&id_value=' . $row['civicrm_contact_id'], $this->_absoluteUrl ); - $rows[$rowNum]['civicrm_contact_sort_name'] = - "" . $row["civicrm_contact_sort_name"] . ''; + $rows[$rowNum]['civicrm_contact_sort_name'] + = "" . $row["civicrm_contact_sort_name"] . ''; $entryFound = TRUE; } diff --git a/tests/phpunit/CRM/Contact/BAO/ContactTest.php b/tests/phpunit/CRM/Contact/BAO/ContactTest.php index 19b46231f1..77be6e2d69 100644 --- a/tests/phpunit/CRM/Contact/BAO/ContactTest.php +++ b/tests/phpunit/CRM/Contact/BAO/ContactTest.php @@ -715,9 +715,7 @@ class CRM_Contact_BAO_ContactTest extends CiviUnitTestCase { } /** - * Test case for createProfileContac( ) - * test with all params. - * ( create and update modes ) + * Test case for createProfileContact. */ public function testCreateProfileContact() { $fields = CRM_Contact_BAO_Contact::exportableFields('Individual'); @@ -1108,7 +1106,7 @@ class CRM_Contact_BAO_ContactTest extends CiviUnitTestCase { } /** - * Test case for getContactDetails( ) + * Test case for getContactDetails( ). */ public function testGetContactDetails() { //get the contact params @@ -1134,8 +1132,7 @@ class CRM_Contact_BAO_ContactTest extends CiviUnitTestCase { } /** - * Test case for - * importableFields( ) and exportableFields( ) + * Test case for importableFields( ) and exportableFields( ). */ public function testFields() { $allImpFileds = CRM_Contact_BAO_Contact::importableFields('All'); @@ -1302,23 +1299,6 @@ class CRM_Contact_BAO_ContactTest extends CiviUnitTestCase { Contact::delete($contactId); } - // /** - // * test logged in user has permissions for - // * various operation types - // */ - // function testPermissionedContact() - // { - // $contactId = Contact::createIndividual(); - // require_once 'CRM/Contact/BAO/Contact/Permission.php'; - // $userViewPermission = CRM_Contact_BAO_Contact_Permission::allow($contactId); - // $this->assertEquals( $userViewPermission, true, 'Check user for view contact permission.' ); - // - // $userEditPermission = CRM_Contact_BAO_Contact_Permission::allow($contactId, CRM_Core_Permission::EDIT); - // $this->assertEquals( $userEditPermission, true, 'Check user for edit contact permission.' ); - // - // Contact::delete($contactId); - // } - /** * Build common params */ @@ -1418,9 +1398,9 @@ class CRM_Contact_BAO_ContactTest extends CiviUnitTestCase { } /** - * Ensure that created_date and modified_date are set + * Ensure that created_date and modified_date are set. */ - public function testTimestamps_contact() { + public function testTimestampContact() { $test = $this; $this->_testTimestamps(array( 'UPDATE' => function ($contactId) use ($test) { @@ -1429,16 +1409,16 @@ class CRM_Contact_BAO_ContactTest extends CiviUnitTestCase { 'contact_type' => 'Individual', 'contact_id' => $contactId, ); - $contact = CRM_Contact_BAO_Contact::add($params); - $test->assertInstanceOf('CRM_Contact_DAO_Contact', $contact, 'Check for created object'); + $contact = CRM_Contact_BAO_Contact::add($params); + $test->assertInstanceOf('CRM_Contact_DAO_Contact', $contact, 'Check for created object'); }, )); } /** - * Ensure that civicrm_contact.modified_date is updated when manipulating a phone record + * Ensure that civicrm_contact.modified_date is updated when manipulating a phone record. */ - public function testTimestamps_email() { + public function testTimestampsEmail() { $test = $this; $this->_testTimestamps(array( 'INSERT' => function ($contactId) use ($test) { diff --git a/tests/phpunit/api/v3/ContributionTest.php b/tests/phpunit/api/v3/ContributionTest.php index 46e55e16d3..d81c7a952c 100644 --- a/tests/phpunit/api/v3/ContributionTest.php +++ b/tests/phpunit/api/v3/ContributionTest.php @@ -543,9 +543,9 @@ class api_v3_ContributionTest extends CiviUnitTestCase { } /** - * Create test with unique field name on source + * Create test with unique field name on source. */ - public function testCreateContributionSourceInvalidContac() { + public function testCreateContributionSourceInvalidContact() { $params = array( 'contact_id' => 999, @@ -645,29 +645,28 @@ class api_v3_ContributionTest extends CiviUnitTestCase { } /** - * This is the test for creating soft credits - however a 'get' is not yet possible via API - * as the current BAO functions are contact-centric (from what I can find) + * This is the test for creating soft credits. */ - public function testCreateContributionWithSoftCredt() { + public function testCreateContributionWithSoftCredit() { $description = "Demonstrates creating contribution with SoftCredit"; $subfile = "ContributionCreateWithSoftCredit"; $contact2 = $this->callAPISuccess('Contact', 'create', array( 'display_name' => 'superman', 'contact_type' => 'Individual', )); - $softparams = array( + $softParams = array( 'contact_id' => $contact2['id'], 'amount' => 50, 'soft_credit_type_id' => 3, ); - $params = $this->_params + array('soft_credit' => array(1 => $softparams)); + $params = $this->_params + array('soft_credit' => array(1 => $softParams)); $contribution = $this->callAPIAndDocument('contribution', 'create', $params, __FUNCTION__, __FILE__, $description, $subfile); $result = $this->callAPISuccess('contribution', 'get', array('return' => 'soft_credit', 'sequential' => 1)); - $this->assertEquals($softparams['contact_id'], $result['values'][0]['soft_credit'][1]['contact_id']); - $this->assertEquals($softparams['amount'], $result['values'][0]['soft_credit'][1]['amount']); - $this->assertEquals($softparams['soft_credit_type_id'], $result['values'][0]['soft_credit'][1]['soft_credit_type']); + $this->assertEquals($softParams['contact_id'], $result['values'][0]['soft_credit'][1]['contact_id']); + $this->assertEquals($softParams['amount'], $result['values'][0]['soft_credit'][1]['amount']); + $this->assertEquals($softParams['soft_credit_type_id'], $result['values'][0]['soft_credit'][1]['soft_credit_type']); $this->callAPISuccess('contribution', 'delete', array('id' => $contribution['id'])); $this->callAPISuccess('contact', 'delete', array('id' => $contact2['id'])); -- 2.25.1