Swap out some additional assigns for tokens, improve tests
[civicrm-core.git] / tests / phpunit / CRM / Event / Form / SearchTest.php
1 <?php
2
3 /**
4 * @group headless
5 */
6 class CRM_Event_Form_SearchTest extends CiviUnitTestCase {
7
8 public function setUp(): void {
9 parent::setUp();
10 $this->individualID = $this->individualCreate();
11 $this->event = $this->eventCreate();
12 $this->priceFieldValues = $this->createPriceSet('event', $this->event, [
13 'html_type' => 'Radio',
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 ]);
17
18 $this->priceFieldValues = $this->priceFieldValues['values'];
19 $this->participantPrice = NULL;
20 foreach ($this->priceFieldValues as $priceFieldValue) {
21 $this->participantPrice = $priceFieldValue;
22 break;
23 }
24
25 $today = new DateTime();
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',
33 'register_date' => $today->format('YmdHis'),
34 ]);
35 }
36
37 public function tearDown(): void {
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 ]);
65 $form = new CRM_Event_Form_Search();
66 $form->controller = new CRM_Event_Controller_Search();
67 $form->preProcess();
68 $form->testSubmit([
69 'participant_test' => 0,
70 'participant_fee_id' => [
71 $this->participantPrice['id'],
72 ],
73 'radio_ts' => 'ts_all',
74 ]);
75 // Confirm that even tho we have changed the label for the price field value the query still works
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 }