Commit | Line | Data |
---|---|---|
12cda498 AP |
1 | <?php |
2 | ||
3 | /** | |
4 | * @group headless | |
5 | */ | |
6 | class CRM_Event_Form_SearchTest extends CiviUnitTestCase { | |
7 | ||
faba1457 | 8 | public function setUp(): void { |
12cda498 AP |
9 | parent::setUp(); |
10 | $this->individualID = $this->individualCreate(); | |
842c077a SL |
11 | $this->event = $this->eventCreate(); |
12 | $this->priceFieldValues = $this->createPriceSet('event', $this->event, [ | |
12cda498 | 13 | 'html_type' => 'Radio', |
9099cab3 CW |
14 | 'option_label' => ['1' => 'Radio Label A (inc. GST)', '2' => 'Radio Label B (inc. GST)'], |
15 | 'option_name' => ['1' => 'Radio Label A', '2' => 'Radio Label B'], | |
16 | ]); | |
12cda498 | 17 | |
842c077a SL |
18 | $this->priceFieldValues = $this->priceFieldValues['values']; |
19 | $this->participantPrice = NULL; | |
20 | foreach ($this->priceFieldValues as $priceFieldValue) { | |
21 | $this->participantPrice = $priceFieldValue; | |
12cda498 AP |
22 | break; |
23 | } | |
24 | ||
12cda498 | 25 | $today = new DateTime(); |
842c077a SL |
26 | $this->participant = $this->participantCreate([ |
27 | 'event_id' => $this->event['id'], | |
28 | 'contact_id' => $this->individualID, | |
29 | 'status_id' => 1, | |
30 | 'fee_level' => $this->participantPrice['label'], | |
31 | 'fee_amount' => $this->participantPrice['amount'], | |
32 | 'fee_currency' => 'USD', | |
12cda498 | 33 | 'register_date' => $today->format('YmdHis'), |
9099cab3 | 34 | ]); |
842c077a | 35 | } |
12cda498 | 36 | |
594a9328 | 37 | public function tearDown(): void { |
842c077a SL |
38 | $this->quickCleanUpFinancialEntities(); |
39 | parent::tearDown(); | |
40 | } | |
41 | ||
42 | /** | |
43 | * Test that search form returns correct number of rows for complex regex filters. | |
44 | */ | |
45 | public function testSearch() { | |
46 | $form = new CRM_Event_Form_Search(); | |
47 | $form->controller = new CRM_Event_Controller_Search(); | |
48 | $form->preProcess(); | |
49 | $form->testSubmit([ | |
50 | 'participant_test' => 0, | |
51 | 'participant_fee_id' => [ | |
52 | $this->participantPrice['id'], | |
53 | ], | |
54 | 'radio_ts' => 'ts_all', | |
55 | ]); | |
56 | $rows = $form->controller->get('rows'); | |
57 | $this->assertEquals(1, count($rows), 'Exactly one row should be returned for given price field value.'); | |
58 | } | |
59 | ||
60 | public function testSearchWithPricelabelChange() { | |
61 | $this->callAPISuccess('PriceFieldValue', 'create', [ | |
62 | 'label' => 'Radio Label C', | |
63 | 'id' => $this->participantPrice['id'], | |
64 | ]); | |
12cda498 AP |
65 | $form = new CRM_Event_Form_Search(); |
66 | $form->controller = new CRM_Event_Controller_Search(); | |
67 | $form->preProcess(); | |
9099cab3 | 68 | $form->testSubmit([ |
12cda498 | 69 | 'participant_test' => 0, |
9099cab3 | 70 | 'participant_fee_id' => [ |
842c077a | 71 | $this->participantPrice['id'], |
9099cab3 | 72 | ], |
12cda498 | 73 | 'radio_ts' => 'ts_all', |
9099cab3 | 74 | ]); |
842c077a | 75 | // Confirm that even tho we have changed the label for the price field value the query still works |
12cda498 AP |
76 | $rows = $form->controller->get('rows'); |
77 | $this->assertEquals(1, count($rows), 'Exactly one row should be returned for given price field value.'); | |
78 | } | |
79 | ||
80 | } |