APIv4 - Use non-deprecated join syntax internally
[civicrm-core.git] / tests / phpunit / CRM / Event / Form / ManageEvent / LocationTest.php
index 8ff04280db66cdd97e3779d353cab5c7623b9532..eece2165b5856aa932fa32d1f4089bf578ed2833 100644 (file)
@@ -78,10 +78,10 @@ class CRM_Event_Form_ManageEvent_LocationTest extends CiviUnitTestCase {
 
     $locationBlock = Event::get()
       ->addWhere('id', '=', $eventID)
-      ->setSelect(['loc_block.*', 'loc_block_id'])
+      ->setSelect(['loc_block_id.*', 'loc_block_id'])
       ->execute()->first();
 
-    $address = $this->callAPISuccessGetSingle('Address', ['id' => $locationBlock['loc_block.address_id']]);
+    $address = $this->callAPISuccessGetSingle('Address', ['id' => $locationBlock['loc_block_id.address_id']]);
 
     $this->assertEquals([
       'id' => $address['id'],
@@ -101,15 +101,85 @@ class CRM_Event_Form_ManageEvent_LocationTest extends CiviUnitTestCase {
       'manual_geo_code' => '0',
     ], $address);
 
-    $this->callAPISuccessGetSingle('Email', ['id' => $locationBlock['loc_block.email_id'], 'email' => 'john.smith@example.org']);
-    $this->callAPISuccessGetSingle('Phone', ['id' => $locationBlock['loc_block.phone_id'], 'phone' => '303443689']);
-    $this->callAPISuccessGetSingle('Phone', ['id' => $locationBlock['loc_block.phone_2_id'], 'phone' => '9833910234']);
+    $this->callAPISuccessGetSingle('Email', ['id' => $locationBlock['loc_block_id.email_id'], 'email' => 'john.smith@example.org']);
+    $this->callAPISuccessGetSingle('Phone', ['id' => $locationBlock['loc_block_id.phone_id'], 'phone' => '303443689']);
+    $this->callAPISuccessGetSingle('Phone', ['id' => $locationBlock['loc_block_id.phone_2_id'], 'phone' => '9833910234']);
 
     // Cleanup.
     CRM_Core_BAO_Location::deleteLocBlock($locationBlock['loc_block_id']);
     $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.
    *
@@ -185,12 +255,12 @@ class CRM_Event_Form_ManageEvent_LocationTest extends CiviUnitTestCase {
     $firstEmail = $emails->first();
     $locationBlock = Event::get()
       ->addWhere('id', '=', $eventID)
-      ->setSelect(['loc_block.*', 'loc_block_id'])
+      ->setSelect(['loc_block_id.*', 'loc_block_id'])
       ->execute()->first();
     $this->ids['LocBlock'][0] = $locationBlock['loc_block_id'];
-    $this->assertEquals($firstEmail['id'], $locationBlock['loc_block.email_id']);
+    $this->assertEquals($firstEmail['id'], $locationBlock['loc_block_id.email_id']);
     $secondEmail = $emails->last();
-    $this->assertEquals($secondEmail['id'], $locationBlock['loc_block.email_2_id']);
+    $this->assertEquals($secondEmail['id'], $locationBlock['loc_block_id.email_2_id']);
     return $emails;
   }