7 * Test CRM_Event_Form_Registration functions.
12 class CRM_Event_Form_ManageEvent_LocationTest
extends CiviUnitTestCase
{
15 * Test the right emails exist after submitting the location form twice.
17 * @throws \API_Exception
18 * @throws \CRM_Core_Exception
19 * @throws \Civi\API\Exception\UnauthorizedException
21 public function testSubmit() {
22 $eventID = (int) $this->eventCreate()['id'];
23 $form = $this->getFormObject('CRM_Event_Form_ManageEvent_Location', $this->getFormValues());
24 $form->set('id', $eventID);
26 $form->buildQuickForm();
28 $this->assertCorrectEmails($eventID);
30 // Now do it again to see if it gets messed with.
31 $form = $this->getFormObject('CRM_Event_Form_ManageEvent_Location', array_merge($this->getFormValues(), ['loc_event_id' => $this->ids
['LocBlock'][0]]));
32 $form->set('id', $eventID);
34 $form->buildQuickForm();
36 $this->assertCorrectEmails($eventID);
40 * Get the values to submit for the form.
44 protected function getFormValues() {
51 'street_address' => '581O Lincoln Dr SW',
52 'supplemental_address_1' => '',
53 'supplemental_address_2' => '',
54 'supplemental_address_3' => '',
56 'postal_code' => '87594',
57 'country_id' => '1228',
58 'state_province_id' => '1030',
60 'geo_code_1' => '35.5212',
61 'geo_code_2' => '-105.982',
68 'email' => 'celebration@example.org',
72 'email' => 'bigger_party@example.org',
79 'phone_type_id' => '1',
80 'phone' => '303 323-1000',
85 'phone_type_id' => '1',
90 'location_option' => '2',
91 'loc_event_id' => '3',
92 'is_show_location' => '1',
100 * @return \Civi\Api4\Generic\Result
101 * @throws \API_Exception
102 * @throws \Civi\API\Exception\UnauthorizedException
104 protected function assertCorrectEmails($eventID) {
105 $emails = Email
::get()
106 ->addWhere('email', 'IN', ['bigger_party@example.org', 'celebration@example.org'])
107 ->addOrderBy('email', 'DESC')
110 $this->assertCount(2, $emails);
111 $firstEmail = $emails->first();
112 $locationBlock = Event
::get()
113 ->addWhere('id', '=', $eventID)
114 ->setSelect(['loc_block.*', 'loc_block_id'])
115 ->execute()->first();
116 $this->ids
['LocBlock'][0] = $locationBlock['loc_block_id'];
117 $this->assertEquals($firstEmail['id'], $locationBlock['loc_block.email_id']);
118 $secondEmail = $emails->last();
119 $this->assertEquals($secondEmail['id'], $locationBlock['loc_block.email_2_id']);