From: kurund Date: Wed, 25 Sep 2013 00:01:34 +0000 (+0200) Subject: Merge remote-tracking branch 'upstream/4.3' into 4.3-master-2013-09-25-01-46-57 X-Git-Url: https://vcs.fsf.org/?a=commitdiff_plain;h=03a8c3dcf5d8c3fe76a0551cbdfea259fc40e101;p=civicrm-core.git Merge remote-tracking branch 'upstream/4.3' into 4.3-master-2013-09-25-01-46-57 Conflicts: CRM/Contribute/BAO/Contribution.php CRM/Contribute/Form/Contribution.php CRM/Upgrade/Incremental/sql/4.3.4.mysql.tpl templates/CRM/Financial/Form/FinancialTypeAccount.tpl tests/phpunit/WebTest/Contribute/OnlineContributionTest.php tests/phpunit/WebTest/Profile/MultiRecordProfileAddTest.php --- 03a8c3dcf5d8c3fe76a0551cbdfea259fc40e101 diff --cc CRM/Contribute/BAO/Contribution.php index 72773a80c8,fc21c4bff5..6c1ab28259 --- a/CRM/Contribute/BAO/Contribution.php +++ b/CRM/Contribute/BAO/Contribution.php @@@ -2868,31 -3018,23 +2868,54 @@@ WHERE contribution_id = %1 " self::deleteContribution($contribution->id); } } + + /** + * Get options for a given contribution field. + * @see CRM_Core_DAO::buildOptions + * + * @param String $fieldName + * @param String $context: @see CRM_Core_DAO::buildOptionsContext - * @param Array $props: whatever is known about this dao object ++ * @param Array $props: whatever is known about this dao object + */ + public static function buildOptions($fieldName, $context = NULL, $props = array()) { + $className = __CLASS__; + $params = array(); + switch ($fieldName) { + // This field is not part of this object but the api supports it + case 'payment_processor': + $className = 'CRM_Contribute_BAO_ContributionPage'; + // Filter results by contribution page + if (!empty($props['contribution_page_id'])) { - $page = civicrm_api('contribution_page', 'getsingle', array('version' => 3, 'id' => ($props['contribution_page_id']))); ++ $page = civicrm_api('contribution_page', 'getsingle', array( ++ 'version' => 3, ++ 'id' => ($props['contribution_page_id']) ++ )); + $types = (array) CRM_Utils_Array::value('payment_processor', $page, 0); + $params['condition'] = 'id IN (' . implode(',', $types) . ')'; + } + } + return CRM_Core_PseudoConstant::get($className, $fieldName, $params, $context); + } ++ + /** + * Function to validate financial type + * + * CRM-13231 + * - * @param integer $financialTypeId Financial Type id ++ * @param integer $financialTypeId Financial Type id + * + * @access public + * @static + */ + static function validateFinancialType($financialTypeId, $relationName = 'Expense Account is') { + $expenseTypeId = key(CRM_Core_PseudoConstant::accountOptionValues('account_relationship', NULL, " AND v.name LIKE '{$relationName}' ")); + $financialAccount = CRM_Contribute_PseudoConstant::financialAccountType($financialTypeId, $expenseTypeId); + + if (!$financialAccount) { + return CRM_Contribute_PseudoConstant::financialType($financialTypeId); + } + return FALSE; + } } + + diff --cc CRM/Contribute/Form/Contribution.php index 7d567f7159,fe7fb48905..fc31ea359b --- a/CRM/Contribute/Form/Contribution.php +++ b/CRM/Contribute/Form/Contribution.php @@@ -930,20 -976,10 +930,12 @@@ class CRM_Contribute_Form_Contribution } //FIXME FOR NEW DATA FLOW http://wiki.civicrm.org/confluence/display/CRM/CiviAccounts+4.3+Data+Flow - if (CRM_Utils_Array::value('fee_amount', $fields)) { - $financialAccount = array(); - CRM_Core_PseudoConstant::populate($financialAccount, - 'CRM_Financial_DAO_EntityFinancialAccount', - $all = TRUE, - $retrieve = 'financial_account_id', - $filter = NULL, - " account_relationship = 5 AND entity_id = {$fields['financial_type_id']} "); - if (!current($financialAccount)) { - $errors['financial_type_id'] = ts("Financial Account of account relationship of 'Expense Account is' is not configured for this Financial Type"); - } + if (CRM_Utils_Array::value('fee_amount', $fields) + && $financialType = CRM_Contribute_BAO_Contribution::validateFinancialType($fields['financial_type_id'])) { + $errors['financial_type_id'] = ts("Financial Account of account relationship of 'Expense Account is' is not configured for Financial Type : ") . $financialType; } + + $errors = array_merge($errors, $softErrors); return $errors; } diff --cc CRM/Financial/BAO/FinancialTypeAccount.php index ec7024699d,cc636ef153..9fa29dc750 --- a/CRM/Financial/BAO/FinancialTypeAccount.php +++ b/CRM/Financial/BAO/FinancialTypeAccount.php @@@ -152,16 -152,18 +152,18 @@@ class CRM_Financial_BAO_FinancialTypeAc //delete from financial Type table $financialType = new CRM_Financial_DAO_EntityFinancialAccount( ); $financialType->id = $financialTypeAccountId; + $financialType->find(TRUE); $financialType->delete(); + CRM_Core_Session::setStatus(ts('Unbalanced transactions may be created if you delete %1 account.', array(1 => $relationValues[$financialType->account_relationship]))); } - + /** - * Function to get Financial Account Name - * + * Function to get Financial Account Name + * * @param int $entityId - * - * @param string $entityTable - * + * + * @param string $entityTable + * * @param string $columnName Column to fetch * @static */ diff --cc CRM/Upgrade/Incremental/sql/4.3.4.mysql.tpl index 1c5b9352b6,dbca1af7d1..20464bc508 --- a/CRM/Upgrade/Incremental/sql/4.3.4.mysql.tpl +++ b/CRM/Upgrade/Incremental/sql/4.3.4.mysql.tpl @@@ -91,5 -105,5 +105,5 @@@ INSERT INTO civicrm_entity_financial_ac SELECT 'civicrm_financial_type', cft.id, @option_value_rel_id_exp, @financialAccountId FROM civicrm_financial_type cft LEFT JOIN civicrm_entity_financial_account ceft - ON ceft.entity_id = cft.id AND ceft.account_relationship = 5 AND ceft.entity_table = 'civicrm_financial_type' -ON ceft.entity_id = cft.id AND ceft.account_relationship = @option_value_rel_id_exp AND ceft.entity_table = 'civicrm_financial_type' ++ON ceft.entity_id = cft.id AND ceft.account_relationship = @option_value_rel_id_exp AND ceft.entity_table = 'civicrm_financial_type' WHERE ceft.entity_id IS NULL; diff --cc tests/phpunit/WebTest/Profile/MultiRecordProfileAddTest.php index bae57f0f5b,480625b932..85d6ee0387 --- a/tests/phpunit/WebTest/Profile/MultiRecordProfileAddTest.php +++ b/tests/phpunit/WebTest/Profile/MultiRecordProfileAddTest.php @@@ -205,13 -204,12 +205,12 @@@ class WebTest_Profile_MultiRecordProfil } $this->openCiviPage('profile/edit', "reset=1&id=$id&gid=$gid", NULL); if (!$checkMultiRecord) { - $this->assertElementContainsText('crm-container', 'No multi-record entries found'); + $this->assertElementContainsText('crm-container', 'No records'); return array($gid, $profileTitle); } - $this->waitForElementPresent("//div[@id='crm-profile-block']/../a"); - $this->click("//div[@id='crm-profile-block']/../a"); - sleep(1); - $record1 = $this->_addRecords('Edit', FALSE, "//div[@class='crm-container-snippet']/form/div[2]/"); + $this->waitForElementPresent("//a/span[contains(text(), 'Add New Record')]"); + $this->click("//a/span[contains(text(), 'Add New Record')]"); + $record1 = $this->_addRecords(); $this->waitForPageToLoad($this->getTimeoutMsec()); $this->verifyText("//div[@id='browseValues']/div/div/table/thead/tr/th[1]", preg_quote($params['textFieldLabel'])); $this->verifyText("//div[@id='browseValues']/div/div/table/tbody/tr[2]/td[1]", preg_quote($record1['text'])); @@@ -353,12 -350,10 +351,12 @@@ return $params; } - function _addRecords($context = 'Edit') { - $this->waitForPageToLoad($this->getTimeoutMsec()); + function _addRecords($context = 'Edit', $waitAtStart = TRUE, $parentElement = '//') { + if ($waitAtStart) { + $this->waitForPageToLoad($this->getTimeoutMsec()); + } $params['text'] = 'text' . substr(sha1(rand()), 0, 3); - $this->type("{$parentElement}div[@id='crm-profile-block']/div/div[2]/input[@type='text']", $params['text']); + $this->type("//div[@id='crm-profile-block']/div/div[2]/input[@type='text']", $params['text']); if ($context == 'Create') { $params['firstname'] = 'John' . substr(sha1(rand()), 0, 3); $this->type('first_name', $params['firstname']);