dev/core#2102 Fix hang on event edit
authoreileen <emcnaughton@wikimedia.org>
Thu, 8 Oct 2020 20:57:45 +0000 (09:57 +1300)
committereileen <emcnaughton@wikimedia.org>
Fri, 9 Oct 2020 00:15:30 +0000 (13:15 +1300)
Per https://lab.civicrm.org/dev/core/-/issues/2102

CRM/Event/Form/ManageEvent/Location.php
tests/phpunit/CRM/Event/Form/ManageEvent/LocationTest.php

index 3314d035eb0fbf43869d91b9308394b9ae820939..b0d045da488255d82dbf36c20dc3f13485cec007 100644 (file)
@@ -231,7 +231,7 @@ class CRM_Event_Form_ManageEvent_Location extends CRM_Event_Form_ManageEvent {
       CRM_Event_BAO_Event::deleteEventLocBlock($this->_oldLocBlockId, $this->_id);
     }
 
-    $isUpdateToExistingLocationBlock = !empty($params['loc_event_id']) && (int) $params['loc_event_id'] === $this->locationBlock['loc_block_id'];
+    $isUpdateToExistingLocationBlock = !$deleteOldBlock && !empty($params['loc_event_id']) && (int) $params['loc_event_id'] === $this->locationBlock['loc_block_id'];
     // It should be impossible for there to be no default location type. Consider removing this handling
     $defaultLocationTypeID = CRM_Core_BAO_LocationType::getDefault()->id ?? 1;
 
index 8ff04280db66cdd97e3779d353cab5c7623b9532..58bcb441f42630c743c70f1a8a4634302a64eb3b 100644 (file)
@@ -110,6 +110,76 @@ class CRM_Event_Form_ManageEvent_LocationTest extends CiviUnitTestCase {
     $this->eventDelete($eventID);
   }
 
+  /**
+   * Test updating a location block.
+   *
+   * @throws \API_Exception
+   * @throws \CRM_Core_Exception
+   * @throws \Civi\API\Exception\UnauthorizedException
+   */
+  public function testUpdateLocationBlock() {
+    $eventID = (int) $this->eventCreate()['id'];
+    $this->submitForm([
+      'address' => [
+        '1' => [
+          'street_address' => 'Old address',
+          'supplemental_address_1' => 'Hallmark Ct',
+          'supplemental_address_2' => 'Jersey Village',
+          'supplemental_address_3' => 'My Town',
+          'city' => 'Newark',
+          'postal_code' => '01903',
+          'country_id' => 1228,
+          'state_province_id' => 1029,
+          'geo_code_1' => '18.219023',
+          'geo_code_2' => '-105.00973',
+          'is_primary' => 1,
+          'location_type_id' => 1,
+        ],
+      ],
+    ], $eventID);
+
+    $this->submitForm([
+      'location_option' => 1,
+      'loc_event_id' => Event::get()->addWhere('id', '=', $eventID)->addSelect('loc_block_id')->execute()->first()['loc_block_id'],
+      'address' => [
+        '1' => [
+          'street_address' => 'New address',
+          'supplemental_address_1' => 'Hallmark Ct',
+          'supplemental_address_2' => 'Jersey Village',
+          'supplemental_address_3' => 'My Town',
+          'city' => 'Newark',
+          'postal_code' => '01903',
+          'country_id' => 1228,
+          'state_province_id' => 1029,
+          'geo_code_1' => '18.219023',
+          'geo_code_2' => '-105.00973',
+        ],
+      ],
+      'email' => [
+        '1' => [
+          'email' => '',
+        ],
+        '2' => [
+          'email' => '',
+        ],
+      ],
+      'phone' => [
+        '1' => [
+          'phone_type_id' => 1,
+          'phone' => '',
+          'phone_ext' => '',
+        ],
+        '2' => [
+          'phone_type_id' => 1,
+          'phone' => '',
+          'phone_ext' => '',
+        ],
+      ],
+    ], $eventID);
+    // Cleanup.
+    $this->eventDelete($eventID);
+  }
+
   /**
    * Get the values to submit for the form.
    *