Merge pull request #22921 from totten/5.48-yml
[civicrm-core.git] / tests / phpunit / CRM / Event / Form / ManageEvent / RegistrationTest.php
CommitLineData
b39946ff
FW
1<?php
2
3use Civi\Api4\Event;
4
5class CRM_Event_Form_ManageEvent_RegistrationTest extends CiviUnitTestCase {
6
7 public function preventCiviExit($event) {
8 if (is_a($event->form, 'CRM_Event_Form_ManageEvent_Registration')) {
9 // EventInfo form redirects to the location form if the action is ADD
10 $event->form->setAction(CRM_Core_Action::NONE);
11 }
12 }
13
14 public function testTimeZone() {
15 $event_id = $this->eventCreate([
16 'event_tz' => 'Australia/Sydney',
17 'start_date' => '2022-06-22 12:00:00',
18 'end_date' => '2022-06-22 20:00:00',
19 ])['id'];
20
21 $formValues = [
22 'registration_start_date' => '2022-05-23 09:00:00',
23 'registration_end_date' => '2022-06-20 17:00:00',
24 ];
25
26 Civi::dispatcher()->addListener('hook_civicrm_postProcess', [$this, 'preventCiviExit']);
27
28 $this->submitForm($formValues, $event_id);
29
30 $this->assertIsInt($event_id, 'Event creation success');
31
32 Civi::dispatcher()->removeListener('hook_civicrm_postProcess', [$this, 'preventCiviExit']);
33
34 $event = Event::get(FALSE)
35 ->addWhere('id', '=', $event_id)
36 ->addSelect('id', 'registration_start_date', 'registration_end_date', 'event_tz')
37 ->execute()[0];
38
39 $this->assertEquals('2022-05-22 23:00:00', $event['registration_start_date'], 'Registration start date resolved by timezone.');
40 $this->assertEquals('2022-06-20 07:00:00', $event['registration_end_date'], 'Registration end date resolved by timezone.');
41
42 }
43
44 public function submitForm(array $formValues, int $eventID): int {
45 $form = $this->getFormObject(CRM_Event_Form_ManageEvent_Registration::class, $formValues);
46 if ($eventID) {
47 $form->set('id', $eventID);
48 }
49
50 $form->preProcess();
51 $form->buildQuickForm();
52 $form->postProcess();
53 return $form->get('id');
54 }
55
56}