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 $this->submitForm([], $eventID);
24 $this->assertCorrectEmails($eventID);
26 // Now do it again to see if it gets messed with.
27 $this->submitForm(['loc_event_id' => $this->ids
['LocBlock'][0]], $eventID);
28 $this->assertCorrectEmails($eventID);
33 * create various elements of location block
34 * with civicrm_loc_block
36 public function testCreateWithLocBlock() {
37 $eventID = (int) $this->eventCreate()['id'];
41 'street_address' => 'Saint Helier St',
42 'supplemental_address_1' => 'Hallmark Ct',
43 'supplemental_address_2' => 'Jersey Village',
44 'supplemental_address_3' => 'My Town',
46 'postal_code' => '01903',
48 'state_province_id' => 1029,
49 'geo_code_1' => '18.219023',
50 'geo_code_2' => '-105.00973',
52 'location_type_id' => 1,
57 'email' => 'john.smith@example.org',
59 'location_type_id' => 1,
65 'phone' => '303443689',
67 'location_type_id' => 1,
71 'phone' => '9833910234',
72 'location_type_id' => 1,
77 //Now check DB for location block
79 $locationBlock = Event
::get()
80 ->addWhere('id', '=', $eventID)
81 ->setSelect(['loc_block.*', 'loc_block_id'])
84 $address = $this->callAPISuccessGetSingle('Address', ['id' => $locationBlock['loc_block.address_id']]);
87 'id' => $address['id'],
88 'location_type_id' => '1',
91 'street_address' => 'Saint Helier St',
92 'supplemental_address_1' => 'Hallmark Ct',
93 'supplemental_address_2' => 'Jersey Village',
94 'supplemental_address_3' => 'My Town',
96 'postal_code' => '01903',
98 'state_province_id' => 1029,
99 'geo_code_1' => '18.219023',
100 'geo_code_2' => '-105.00973',
101 'manual_geo_code' => '0',
104 $this->callAPISuccessGetSingle('Email', ['id' => $locationBlock['loc_block.email_id'], 'email' => 'john.smith@example.org']);
105 $this->callAPISuccessGetSingle('Phone', ['id' => $locationBlock['loc_block.phone_id'], 'phone' => '303443689']);
106 $this->callAPISuccessGetSingle('Phone', ['id' => $locationBlock['loc_block.phone_2_id'], 'phone' => '9833910234']);
109 CRM_Core_BAO_Location
::deleteLocBlock($locationBlock['loc_block_id']);
110 $this->eventDelete($eventID);
114 * Test updating a location block.
116 * @throws \API_Exception
117 * @throws \CRM_Core_Exception
118 * @throws \Civi\API\Exception\UnauthorizedException
120 public function testUpdateLocationBlock() {
121 $eventID = (int) $this->eventCreate()['id'];
125 'street_address' => 'Old address',
126 'supplemental_address_1' => 'Hallmark Ct',
127 'supplemental_address_2' => 'Jersey Village',
128 'supplemental_address_3' => 'My Town',
130 'postal_code' => '01903',
131 'country_id' => 1228,
132 'state_province_id' => 1029,
133 'geo_code_1' => '18.219023',
134 'geo_code_2' => '-105.00973',
136 'location_type_id' => 1,
142 'location_option' => 1,
143 'loc_event_id' => Event
::get()->addWhere('id', '=', $eventID)->addSelect('loc_block_id')->execute()->first()['loc_block_id'],
146 'street_address' => 'New address',
147 'supplemental_address_1' => 'Hallmark Ct',
148 'supplemental_address_2' => 'Jersey Village',
149 'supplemental_address_3' => 'My Town',
151 'postal_code' => '01903',
152 'country_id' => 1228,
153 'state_province_id' => 1029,
154 'geo_code_1' => '18.219023',
155 'geo_code_2' => '-105.00973',
168 'phone_type_id' => 1,
173 'phone_type_id' => 1,
180 $this->eventDelete($eventID);
184 * Get the values to submit for the form.
188 protected function getFormValues() {
195 'street_address' => '581O Lincoln Dr SW',
196 'supplemental_address_1' => '',
197 'supplemental_address_2' => '',
198 'supplemental_address_3' => '',
199 'city' => 'Santa Fe',
200 'postal_code' => '87594',
201 'country_id' => '1228',
202 'state_province_id' => '1030',
204 'geo_code_1' => '35.5212',
205 'geo_code_2' => '-105.982',
212 'email' => 'celebration@example.org',
216 'email' => 'bigger_party@example.org',
223 'phone_type_id' => '1',
224 'phone' => '303 323-1000',
229 'phone_type_id' => '1',
234 'location_option' => '2',
235 'loc_event_id' => '3',
236 'is_show_location' => '1',
237 'is_template' => '0',
242 * @param int $eventID
244 * @return \Civi\Api4\Generic\Result
245 * @throws \API_Exception
246 * @throws \Civi\API\Exception\UnauthorizedException
248 protected function assertCorrectEmails($eventID) {
249 $emails = Email
::get()
250 ->addWhere('email', 'IN', ['bigger_party@example.org', 'celebration@example.org'])
251 ->addOrderBy('email', 'DESC')
254 $this->assertCount(2, $emails);
255 $firstEmail = $emails->first();
256 $locationBlock = Event
::get()
257 ->addWhere('id', '=', $eventID)
258 ->setSelect(['loc_block.*', 'loc_block_id'])
259 ->execute()->first();
260 $this->ids
['LocBlock'][0] = $locationBlock['loc_block_id'];
261 $this->assertEquals($firstEmail['id'], $locationBlock['loc_block.email_id']);
262 $secondEmail = $emails->last();
263 $this->assertEquals($secondEmail['id'], $locationBlock['loc_block.email_2_id']);
268 * @param array $formValues
269 * @param int $eventID
271 * @throws \CRM_Core_Exception
273 protected function submitForm(array $formValues, int $eventID): void
{
274 $form = $this->getFormObject('CRM_Event_Form_ManageEvent_Location', array_merge($this->getFormValues(), $formValues));
275 $form->set('id', $eventID);
277 $form->buildQuickForm();
278 $form->postProcess();