From: Eileen McNaughton Date: Sun, 3 May 2015 11:50:06 +0000 (+1200) Subject: CRM-16367 (Backoffice Contribution Form) centralisation & testing of setting premium... X-Git-Url: https://vcs.fsf.org/?a=commitdiff_plain;h=945f423dcc24c233767fc77be9f9bb2d3e4b7a8d;p=civicrm-core.git CRM-16367 (Backoffice Contribution Form) centralisation & testing of setting premium & note --- diff --git a/CRM/Contribute/Form/AdditionalInfo.php b/CRM/Contribute/Form/AdditionalInfo.php index 448f05bc4d..74f53f0c3e 100644 --- a/CRM/Contribute/Form/AdditionalInfo.php +++ b/CRM/Contribute/Form/AdditionalInfo.php @@ -263,7 +263,7 @@ class CRM_Contribute_Form_AdditionalInfo { * * @return void */ - public static function processNote(&$params, $contactID, $contributionID, $contributionNoteID = NULL) { + public static function processNote($params, $contactID, $contributionID, $contributionNoteID = NULL) { //process note $noteParams = array( 'entity_table' => 'civicrm_contribution', diff --git a/CRM/Contribute/Form/Contribution.php b/CRM/Contribute/Form/Contribution.php index 0352c12d02..5c27b2671e 100644 --- a/CRM/Contribute/Form/Contribution.php +++ b/CRM/Contribute/Form/Contribution.php @@ -1294,11 +1294,6 @@ class CRM_Contribute_Form_Contribution extends CRM_Contribute_Form_AbstractEditP $sendReceipt = CRM_Contribute_Form_AdditionalInfo::emailReceipt($this, $this->_params, TRUE); } - //process the note - if ($contribution->id && isset($params['note'])) { - CRM_Contribute_Form_AdditionalInfo::processNote($params, $contactID, $contribution->id, NULL); - } - if ($contribution->id) { array_unshift($this->statusMessage, ts('The contribution record has been processed.')); if (!empty($this->_params['is_email_receipt']) && $sendReceipt) { @@ -1772,17 +1767,6 @@ class CRM_Contribute_Form_Contribution extends CRM_Contribute_Form_AbstractEditP ); } - //process note - if ($contribution->id && isset($formValues['note'])) { - CRM_Contribute_Form_AdditionalInfo::processNote($formValues, $this->_contactID, $contribution->id, $this->_noteID); - } - - //process premium - if ($contribution->id && isset($formValues['product_name'][0])) { - CRM_Contribute_Form_AdditionalInfo::processPremium($formValues, $contribution->id, - $this->_premiumID, $this->_options - ); - } array_unshift($this->statusMessage, ts('The contribution record has been saved.')); $this->invoicingPostProcessHook($submittedValues, $action, $lineItem); @@ -1805,6 +1789,16 @@ class CRM_Contribute_Form_Contribution extends CRM_Contribute_Form_AbstractEditP } + if ($contribution->id && isset($formValues['product_name'][0])) { + CRM_Contribute_Form_AdditionalInfo::processPremium($formValues, $contribution->id, + $this->_premiumID, $this->_options + ); + } + + if ($contribution->id && isset($submittedValues['note'])) { + CRM_Contribute_Form_AdditionalInfo::processNote($submittedValues, $this->_contactID, $contribution->id, $this->_noteID); + } + CRM_Core_Session::setStatus(implode(' ', $this->statusMessage), $this->statusMessageTitle, 'success'); CRM_Contribute_BAO_Contribution::updateRelatedPledge( diff --git a/CRM/Core/BAO/Note.php b/CRM/Core/BAO/Note.php index 94b973708d..038dbf7744 100644 --- a/CRM/Core/BAO/Note.php +++ b/CRM/Core/BAO/Note.php @@ -139,7 +139,7 @@ class CRM_Core_BAO_Note extends CRM_Core_DAO_Note { * @return object * $note CRM_Core_BAO_Note object */ - public static function &add(&$params, $ids = array()) { + public static function add(&$params, $ids = array()) { $dataExists = self::dataExists($params); if (!$dataExists) { return CRM_Core_DAO::$_nullObject; diff --git a/tests/phpunit/CRM/Contribute/Form/ContributionTest.php b/tests/phpunit/CRM/Contribute/Form/ContributionTest.php index 0208520707..ef4cfc26b7 100644 --- a/tests/phpunit/CRM/Contribute/Form/ContributionTest.php +++ b/tests/phpunit/CRM/Contribute/Form/ContributionTest.php @@ -144,6 +144,7 @@ class CRM_Contribute_Form_ContributionTest extends CiviUnitTestCase { */ public function tearDown() { $this->quickCleanUpFinancialEntities(); + $this->quickCleanup(array('civicrm_note')); } /** @@ -308,4 +309,61 @@ class CRM_Contribute_Form_ContributionTest extends CiviUnitTestCase { $mut->stop(); } + /** + * Test the submit function on the contribution page. + */ + public function testSubmitWithNote() { + $form = new CRM_Contribute_Form_Contribution(); + $form->testSubmit(array( + 'total_amount' => 50, + 'financial_type_id' => 1, + 'receive_date' => '04/21/2015', + 'receive_date_time' => '11:27PM', + 'contact_id' => $this->_individualId, + 'payment_instrument_id' => array_search('Check', $this->paymentInstruments), + 'contribution_status_id' => 1, + 'note' => 'Super cool and interesting stuff', + ), + CRM_Core_Action::ADD); + $this->callAPISuccessGetCount('Contribution', array('contact_id' => $this->_individualId), 1); + $note = $this->callAPISuccessGetSingle('note', array('entity_table' => 'civicrm_contribution')); + $this->assertEquals($note['note'], 'Super cool and interesting stuff'); + } + + /** + * Test the submit function on the contribution page. + */ + public function testSubmitWithNoteCreditCard() { + $form = new CRM_Contribute_Form_Contribution(); + + $form->testSubmit(array( + 'total_amount' => 50, + 'financial_type_id' => 1, + 'receive_date' => '04/21/2015', + 'receive_date_time' => '11:27PM', + 'contact_id' => $this->_individualId, + 'payment_instrument_id' => array_search('Check', $this->paymentInstruments), + 'contribution_status_id' => 1, + 'note' => 'Super cool and interesting stuff', + ) + $this->getCreditCardParams (), + CRM_Core_Action::ADD); + $this->callAPISuccessGetCount('Contribution', array('contact_id' => $this->_individualId), 1); + $note = $this->callAPISuccessGetSingle('note', array('entity_table' => 'civicrm_contribution')); + $this->assertEquals($note['note'], 'Super cool and interesting stuff'); + } + + /** + * Get parameters for credit card submit calls. + * + * @return array + * Credit card specific parameters. + */ + function getCreditCardParams() { + return array( + 'payment_processor_id' => $this->paymentProcessor->id, + 'credit_card_exp_date' => array('M' => 5, 'Y' => 2012), + 'credit_card_number' => '411111111111111', + ); + } } + diff --git a/tests/phpunit/CiviTest/CiviUnitTestCase.php b/tests/phpunit/CiviTest/CiviUnitTestCase.php index 10388ebc58..b9ebdd5738 100755 --- a/tests/phpunit/CiviTest/CiviUnitTestCase.php +++ b/tests/phpunit/CiviTest/CiviUnitTestCase.php @@ -2515,6 +2515,7 @@ AND ( TABLE_NAME LIKE 'civicrm_value_%' ) $tablesToTruncate = array( 'civicrm_contribution', 'civicrm_contribution_soft', + 'civicrm_contribution_product', 'civicrm_financial_trxn', 'civicrm_financial_item', 'civicrm_contribution_recur',