}
/**
- * 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();
$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
--- /dev/null
+<?php
+
+/**
+ * @group headless
+ */
+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, 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.');
+ }
+
+}