From 12cda498263f0a258db31865173b5df967dc6669 Mon Sep 17 00:00:00 2001 From: Alok Patel Date: Mon, 1 Apr 2019 17:50:18 +0530 Subject: [PATCH] CIVICRM-990: Unit test to make sure regular expression in Participant search works. --- CRM/Event/Form/Search.php | 75 +++++++++++++-------- tests/phpunit/CRM/Event/Form/SearchTest.php | 57 ++++++++++++++++ 2 files changed, 104 insertions(+), 28 deletions(-) create mode 100644 tests/phpunit/CRM/Event/Form/SearchTest.php diff --git a/CRM/Event/Form/Search.php b/CRM/Event/Form/Search.php index a1421cbe3a..78232e7ee4 100644 --- a/CRM/Event/Form/Search.php +++ b/CRM/Event/Form/Search.php @@ -295,36 +295,19 @@ class CRM_Event_Form_Search extends CRM_Core_Form_Search { } /** - * The post processing of the form gets done here. - * - * Key things done during post processing are - * - check for reset or next request. if present, skip post procesing. - * - now check if user requested running a saved search, if so, then - * the form values associated with the saved search are used for searching. - * - if user has done a submit with new values the regular post submissing is - * done. - * The processing consists of using a Selector / Controller framework for getting the - * search results. - * - * @param - * - * @return void + * Test submit the form. + * @param $formValues */ - public function postProcess() { - if ($this->_done) { - return; - } - - $this->_done = TRUE; - - if (!empty($_POST)) { - $this->_formValues = $this->controller->exportValues($this->_name); - CRM_Contact_BAO_Query::processSpecialFormValue($this->_formValues, array('participant_status_id')); - } + public function testSubmit($formValues) { + $this->submit($formValues); + } - if (empty($this->_formValues)) { - $this->_formValues = $this->controller->exportValues($this->_name); - } + /** + * Submit the search form with given values. + * @param $formValues + */ + private function submit($formValues) { + $this->_formValues = $formValues; $this->fixFormValues(); @@ -400,6 +383,42 @@ class CRM_Event_Form_Search extends CRM_Core_Form_Search { $controller->run(); } + /** + * The post processing of the form gets done here. + * + * Key things done during post processing are + * - check for reset or next request. if present, skip post procesing. + * - now check if user requested running a saved search, if so, then + * the form values associated with the saved search are used for searching. + * - if user has done a submit with new values the regular post submissing is + * done. + * The processing consists of using a Selector / Controller framework for getting the + * search results. + * + * @param + * + * @return void + */ + public function postProcess() { + if ($this->_done) { + return; + } + + $this->_done = TRUE; + $formValues = array(); + + if (!empty($_POST)) { + $formValues = $this->controller->exportValues($this->_name); + CRM_Contact_BAO_Query::processSpecialFormValue($this->_formValues, array('participant_status_id')); + } + + if (empty($this->_formValues)) { + $formValues = $this->controller->exportValues($this->_name); + } + + $this->submit($formValues); + } + /** * add the rules (mainly global rules) for form. * All local rules are added near the element diff --git a/tests/phpunit/CRM/Event/Form/SearchTest.php b/tests/phpunit/CRM/Event/Form/SearchTest.php new file mode 100644 index 0000000000..d6b22fd439 --- /dev/null +++ b/tests/phpunit/CRM/Event/Form/SearchTest.php @@ -0,0 +1,57 @@ +individualID = $this->individualCreate(); + } + + /** + * Test that search form returns correct number of rows for complex regex filters. + */ + public function testSearch() { + $priceFieldValues = $this->createPriceSet('event', NULL, array( + 'html_type' => 'Radio', + 'option_label' => array('1' => 'Radio Label A (inc. GST)', '2' => 'Radio Label B (inc. GST)'), + 'option_name' => array('1' => 'Radio Label A', '2' => 'Radio Label B'), + )); + + $priceFieldValues = $priceFieldValues['values']; + $participantPrice = NULL; + foreach ($priceFieldValues as $priceFieldValue) { + $participantPrice = $priceFieldValue; + break; + } + + $event = $this->eventCreate(); + $individualID = $this->individualCreate(); + $today = new DateTime(); + $this->participantCreate(array( + 'event_id' => $event['id'], + 'contact_id' => $individualID, + 'status_id' => 1, + 'fee_level' => $participantPrice['label'], + 'fee_amount' => $participantPrice['amount'], + 'fee_currency' => 'USD', + 'register_date' => $today->format('YmdHis'), + )); + + $form = new CRM_Event_Form_Search(); + $form->controller = new CRM_Event_Controller_Search(); + $form->preProcess(); + $form->testSubmit(array( + 'participant_test' => 0, + 'participant_fee_id' => array( + $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.'); + } + +} -- 2.25.1