From 842c077aa1e9f89dd9a4af1bf099ba5e5d7f7b4d Mon Sep 17 00:00:00 2001 From: Seamus Lee Date: Sun, 18 Aug 2019 13:17:09 +1000 Subject: [PATCH] Add in unit test of searching when price field value label has changed --- CRM/Price/BAO/PriceFieldValue.php | 3 + tests/phpunit/CRM/Event/Form/SearchTest.php | 65 ++++++++++++++------- 2 files changed, 47 insertions(+), 21 deletions(-) diff --git a/CRM/Price/BAO/PriceFieldValue.php b/CRM/Price/BAO/PriceFieldValue.php index b8c304499e..57a78fc071 100644 --- a/CRM/Price/BAO/PriceFieldValue.php +++ b/CRM/Price/BAO/PriceFieldValue.php @@ -56,6 +56,9 @@ class CRM_Price_BAO_PriceFieldValue extends CRM_Price_DAO_PriceFieldValue { // CRM-16189 $priceFieldID = CRM_Utils_Array::value('price_field_id', $params); + + $id = CRM_Utils_Array::value('id', $ids, CRM_Utils_Array::value('id', $params)); + if (!$priceFieldID) { $priceFieldID = CRM_Core_DAO::getFieldValue('CRM_Price_BAO_PriceFieldValue', $id, 'price_field_id'); } diff --git a/tests/phpunit/CRM/Event/Form/SearchTest.php b/tests/phpunit/CRM/Event/Form/SearchTest.php index 76f885e958..16b6a39dfd 100644 --- a/tests/phpunit/CRM/Event/Form/SearchTest.php +++ b/tests/phpunit/CRM/Event/Form/SearchTest.php @@ -8,48 +8,71 @@ class CRM_Event_Form_SearchTest extends CiviUnitTestCase { public function setUp() { parent::setUp(); $this->individualID = $this->individualCreate(); - } - - /** - * Test that search form returns correct number of rows for complex regex filters. - */ - public function testSearch() { - $priceFieldValues = $this->createPriceSet('event', NULL, [ + $this->event = $this->eventCreate(); + $this->priceFieldValues = $this->createPriceSet('event', $this->event, [ 'html_type' => 'Radio', 'option_label' => ['1' => 'Radio Label A (inc. GST)', '2' => 'Radio Label B (inc. GST)'], 'option_name' => ['1' => 'Radio Label A', '2' => 'Radio Label B'], ]); - $priceFieldValues = $priceFieldValues['values']; - $participantPrice = NULL; - foreach ($priceFieldValues as $priceFieldValue) { - $participantPrice = $priceFieldValue; + $this->priceFieldValues = $this->priceFieldValues['values']; + $this->participantPrice = NULL; + foreach ($this->priceFieldValues as $priceFieldValue) { + $this->participantPrice = $priceFieldValue; break; } - $event = $this->eventCreate(); - $individualID = $this->individualCreate(); $today = new DateTime(); - $this->participantCreate([ - 'event_id' => $event['id'], - 'contact_id' => $individualID, - 'status_id' => 1, - 'fee_level' => $participantPrice['label'], - 'fee_amount' => $participantPrice['amount'], - 'fee_currency' => 'USD', + $this->participant = $this->participantCreate([ + 'event_id' => $this->event['id'], + 'contact_id' => $this->individualID, + 'status_id' => 1, + 'fee_level' => $this->participantPrice['label'], + 'fee_amount' => $this->participantPrice['amount'], + 'fee_currency' => 'USD', 'register_date' => $today->format('YmdHis'), ]); + } + public function tearDown() { + $this->quickCleanUpFinancialEntities(); + parent::tearDown(); + } + + /** + * Test that search form returns correct number of rows for complex regex filters. + */ + public function testSearch() { + $form = new CRM_Event_Form_Search(); + $form->controller = new CRM_Event_Controller_Search(); + $form->preProcess(); + $form->testSubmit([ + 'participant_test' => 0, + 'participant_fee_id' => [ + $this->participantPrice['id'], + ], + 'radio_ts' => 'ts_all', + ]); + $rows = $form->controller->get('rows'); + $this->assertEquals(1, count($rows), 'Exactly one row should be returned for given price field value.'); + } + + public function testSearchWithPricelabelChange() { + $this->callAPISuccess('PriceFieldValue', 'create', [ + 'label' => 'Radio Label C', + 'id' => $this->participantPrice['id'], + ]); $form = new CRM_Event_Form_Search(); $form->controller = new CRM_Event_Controller_Search(); $form->preProcess(); $form->testSubmit([ 'participant_test' => 0, 'participant_fee_id' => [ - $participantPrice['id'], + $this->participantPrice['id'], ], 'radio_ts' => 'ts_all', ]); + // Confirm that even tho we have changed the label for the price field value the query still works $rows = $form->controller->get('rows'); $this->assertEquals(1, count($rows), 'Exactly one row should be returned for given price field value.'); } -- 2.25.1