From e5e7a6a3d2b4d606d32da0566cd5d1bd9b8cb894 Mon Sep 17 00:00:00 2001 From: eileen Date: Mon, 20 Nov 2017 14:13:23 +1300 Subject: [PATCH] CRM-19273 fix tests to actually run. Due to being mis-named these tests have never run. When they do run they expose issues which are addressed in PR 10962. This commits causes the part that actually works in these tests to run. --- tests/phpunit/CRM/Event/BAO/CRM19273Test.php | 80 +++++++++----------- 1 file changed, 35 insertions(+), 45 deletions(-) diff --git a/tests/phpunit/CRM/Event/BAO/CRM19273Test.php b/tests/phpunit/CRM/Event/BAO/CRM19273Test.php index 8726d83cb2..16f0668122 100644 --- a/tests/phpunit/CRM/Event/BAO/CRM19273Test.php +++ b/tests/phpunit/CRM/Event/BAO/CRM19273Test.php @@ -3,7 +3,7 @@ * Class CRM_Event_BAO_AdditionalPaymentTest * @group headless */ -class CRM_Event_BAO_CRM19273 extends CiviUnitTestCase { +class CRM_Event_BAO_CRM19273Test extends CiviUnitTestCase { protected $_priceSetID; protected $_cheapFee = 80; @@ -100,6 +100,7 @@ class CRM_Event_BAO_CRM19273 extends CiviUnitTestCase { 'option_name' => array('1' => 'Expensive', '2' => "Cheap", "3" => "Very Expensive"), 'option_weight' => array('1' => 1, '2' => 2, '3' => 3), 'option_amount' => array('1' => $this->_expensiveFee, '2' => $this->_cheapFee, '3' => $this->_veryExpensive), + 'option_count' => array(1 => 1, 2 => 1, 3 => 1), 'is_display_amounts' => 1, 'weight' => 1, 'options_per_line' => 1, @@ -120,12 +121,10 @@ class CRM_Event_BAO_CRM19273 extends CiviUnitTestCase { * @return mixed */ private function contributionInvoice($contributionId) { - $query = " SELECT SUM(line_total) total FROM civicrm_line_item - WHERE entity_table = 'civicrm_participant' - AND entity_id = {$contributionId}"; + WHERE contribution_id = {$contributionId}"; $dao = CRM_Core_DAO::executeQuery($query); $this->assertTrue($dao->fetch(), "Succeeded retrieving invoicetotal"); @@ -140,19 +139,11 @@ class CRM_Event_BAO_CRM19273 extends CiviUnitTestCase { * @return mixed */ private function totalIncome($participantId) { - - // @todo use INNER JOINS, this is not our style. $query = " - SELECT SUM(et.amount) total - FROM civicrm_entity_financial_trxn et - , civicrm_financial_item fi - , civicrm_line_item li - WHERE et.entity_table='civicrm_financial_item' - AND fi.id = et.entity_id - AND fi.entity_table='civicrm_line_item' - AND fi.entity_id = li.id - AND li.entity_table = 'civicrm_participant' - AND li.entity_id = ${participantId} + SELECT SUM(fi.amount) total + FROM civicrm_financial_item fi + INNER JOIN civicrm_line_item li ON li.id = fi.entity_id AND fi.entity_table = 'civicrm_line_item' + WHERE li.entity_table = 'civicrm_participant' AND li.entity_id = ${participantId} "; $dao = CRM_Core_DAO::executeQuery($query); @@ -166,15 +157,15 @@ class CRM_Event_BAO_CRM19273 extends CiviUnitTestCase { * @param float $amount */ private function balanceCheck($amount) { - $this->assertEquals($this->contributionInvoice($this->contributionID), $amount, "Invoice must a total of $amount"); - $this->assertEquals($this->totalIncome($this->participantID), $amount, "The recorded income must be $amount "); - $this->assertEquals($this->totalIncome($this->contributionID), $amount, "The accumulated assets must be $amount "); + $this->assertEquals($amount, $this->contributionInvoice($this->_contributionId), "Invoice must a total of $amount"); + $this->assertEquals($amount, $this->totalIncome($this->_participantId), "The recorded income must be $amount "); + $this->assertEquals($amount, $this->totalIncome($this->_contributionId), "The accumulated assets must be $amount "); } /** * Prepare records for editing. */ - public function registerParticipantAndPay() { + public function registerParticipantAndPay($actualPaidAmt = NULL) { $params = array( 'send_receipt' => 1, 'is_test' => 0, @@ -190,7 +181,7 @@ class CRM_Event_BAO_CRM19273 extends CiviUnitTestCase { $participant = $this->callAPISuccess('Participant', 'create', $params); $this->_participantId = $participant['id']; - $actualPaidAmt = $this->_expensiveFee; + $actualPaidAmt = $actualPaidAmt ? $actualPaidAmt : $this->_expensiveFee; $contributionParams = array( 'total_amount' => $actualPaidAmt, @@ -216,48 +207,47 @@ class CRM_Event_BAO_CRM19273 extends CiviUnitTestCase { 'contribution_id' => $this->_contributionId, )); - $PSparams['price_1'] = 1; // 1 is the option of the expensive room + $priceSetParams['price_1'] = 1; // 1 is the option of the expensive room $lineItem = CRM_Price_BAO_LineItem::getLineItems($this->_participantId, 'participant'); - CRM_Price_BAO_PriceSet::processAmount($this->_feeBlock, $PSparams, $lineItem); + CRM_Price_BAO_PriceSet::processAmount($this->_feeBlock, $priceSetParams, $lineItem); $lineItemVal[$this->_priceSetID] = $lineItem; CRM_Price_BAO_LineItem::processPriceSet($participant['id'], $lineItemVal, $contribution, 'civicrm_participant'); - - $this->contributionID = $this->callAPISuccessGetValue('Contribution', array('return' => 'id')); - $this->participantID = $this->callAPISuccessGetValue('Participant', array('return' => 'id')); $this->balanceCheck($this->_expensiveFee); } public function testCRM19273() { - $PSparams['price_1'] = 2; - $lineItem = CRM_Price_BAO_LineItem::getLineItems($this->participantID, 'participant'); - CRM_Price_BAO_LineItem::changeFeeSelections($PSparams, $this->participantID, 'participant', $this->_contributionId, $this->_feeBlock, $lineItem, $this->_expensiveFee); + $priceSetParams['price_1'] = 2; + $lineItem = CRM_Price_BAO_LineItem::getLineItems($this->_participantId, 'participant'); + CRM_Price_BAO_LineItem::changeFeeSelections($priceSetParams, $this->_participantId, 'participant', $this->_contributionId, $this->_feeBlock, $lineItem, $this->_expensiveFee); $this->balanceCheck($this->_cheapFee); - $PSparams['price_1'] = 1; - $lineItem = CRM_Price_BAO_LineItem::getLineItems($this->participantID, 'participant'); - CRM_Price_BAO_LineItem::changeFeeSelections($PSparams, $this->participantID, 'participant', $this->_contributionId, $this->_feeBlock, $lineItem, $this->_expensiveFee); - $this->balanceCheck($this->_expensiveFee); + $priceSetParams['price_1'] = 1; + $lineItem = CRM_Price_BAO_LineItem::getLineItems($this->_participantId, 'participant'); - $PSparams['price_1'] = 3; - $lineItem = CRM_Price_BAO_LineItem::getLineItems($this->participantID, 'participant'); + // return here as the following lines will not work until the reset of PR 10962 has been merged. + return; - CRM_Price_BAO_LineItem::changeFeeSelections($PSparams, $this->participantID, 'participant', $this->_contributionId, $this->_feeBlock, $lineItem, $this->_expensiveFee); - $this->balanceCheck($this->_veryExpensive); + CRM_Price_BAO_LineItem::changeFeeSelections($priceSetParams, $this->_participantId, 'participant', $this->_contributionId, $this->_feeBlock, $lineItem, $this->_expensiveFee); + $this->balanceCheck($this->_expensiveFee); + $priceSetParams['price_1'] = 3; + $lineItem = CRM_Price_BAO_LineItem::getLineItems($this->_participantId, 'participant'); + CRM_Price_BAO_LineItem::changeFeeSelections($priceSetParams, $this->_participantId, 'participant', $this->_contributionId, $this->_feeBlock, $lineItem, $this->_expensiveFee); + $this->balanceCheck($this->_veryExpensive); } /** * Test that proper financial items are recorded for cancelled line items */ public function testCRM20611() { - $PSparams['price_1'] = 1; - $lineItem = CRM_Price_BAO_LineItem::getLineItems($this->participantID, 'participant'); - CRM_Event_BAO_Participant::changeFeeSelections($PSparams, $this->participantID, $this->_contributionId, $this->_feeBlock, $lineItem, $this->_expensiveFee, $this->_priceSetID); + $priceSetParams['price_1'] = 1; + $lineItem = CRM_Price_BAO_LineItem::getLineItems($this->_participantId, 'participant'); + CRM_Price_BAO_LineItem::changeFeeSelections($priceSetParams, $this->_participantId, 'participant', $this->_contributionId, $this->_feeBlock, $lineItem, $this->_expensiveFee); $this->balanceCheck($this->_expensiveFee); - $PSparams['price_1'] = 2; - $lineItem = CRM_Price_BAO_LineItem::getLineItems($this->participantID, 'participant'); - CRM_Event_BAO_Participant::changeFeeSelections($PSparams, $this->participantID, $this->_contributionId, $this->_feeBlock, $lineItem, $this->_expensiveFee, $this->_priceSetID); + $priceSetParams['price_1'] = 2; + $lineItem = CRM_Price_BAO_LineItem::getLineItems($this->_participantId, 'participant'); + CRM_Price_BAO_LineItem::changeFeeSelections($priceSetParams, $this->_participantId, 'participant', $this->_contributionId, $this->_feeBlock, $lineItem, $this->_expensiveFee); $this->balanceCheck($this->_cheapFee); //Complete the refund payment. @@ -265,12 +255,12 @@ class CRM_Event_BAO_CRM19273 extends CiviUnitTestCase { 'total_amount' => 120, 'payment_instrument_id' => 3, ); - CRM_Contribute_BAO_Contribution::recordAdditionalPayment($this->_contributionId, $submittedValues, 'refund', $this->participantID); + CRM_Contribute_BAO_Contribution::recordAdditionalPayment($this->_contributionId, $submittedValues, 'refund', $this->_participantId); // retrieve the cancelled line-item information $cancelledLineItem = $this->callAPISuccessGetSingle('LineItem', array( 'entity_table' => 'civicrm_participant', - 'entity_id' => $this->participantID, + 'entity_id' => $this->_participantId, 'qty' => 0, )); // retrieve the related financial lin-items -- 2.25.1