Fix handling of location type in Reports
authorSeamus Lee <seamuslee001@gmail.com>
Thu, 1 Aug 2019 06:03:03 +0000 (16:03 +1000)
committerSeamus Lee <seamuslee001@gmail.com>
Thu, 1 Aug 2019 06:07:20 +0000 (16:07 +1000)
CRM/Report/Form.php
tests/phpunit/CRM/Report/Form/ContactSummaryTest.php

index 73c4f561f16accf267a27759e4551474878891c7..5affd4b5a804088c5646ce713d76912626679fc0 100644 (file)
@@ -5777,7 +5777,7 @@ LEFT JOIN civicrm_contact {$field['alias']} ON {$field['alias']}.id = {$this->_a
         'options' => CRM_Core_PseudoConstant::country(),
       ],
       $options['prefix'] . 'location_type_id' => [
-        'name' => 'is_primary',
+        'name' => 'location_type_id',
         'title' => $options['prefix_label'] . ts('Location Type'),
         'type' => CRM_Utils_Type::T_INT,
         'is_fields' => TRUE,
index b173d4d462db7e73d0330eb1bf31d91ff066048a..dbfb3ed6cb927156cc12f9d6faa40550290620a6 100644 (file)
@@ -196,4 +196,36 @@ class CRM_Report_Form_ContactSummaryTest extends CiviReportTestCase {
     }
   }
 
+  /**
+   * Test that Loation Type prints out a sensible piece of data
+   */
+  public function testLocationTypeIdHandling() {
+    $customLocationType = $this->callAPISuccess('LocationType', 'create', [
+      'name' => 'Custom Location Type',
+      'display_name' => 'CiviTest Custom Location Type',
+      'is_active' => 1,
+    ]);
+    $this->individualCreate([
+      'api.Address.create' => [
+        'location_type_id' => $customLocationType['id'],
+        'is_primary' => 1,
+        'street_number' => 3,
+      ],
+    ]);
+    $input = [
+      'fields' => [
+        'address_street_number',
+        'address_odd_street_number',
+        'address_location_type_id',
+      ],
+    ];
+    $obj = $this->getReportObject('CRM_Report_Form_Contact_Summary', $input);
+    $obj->setParams($obj->getParams());
+    $sql = $obj->buildQuery(TRUE);
+    $rows = [];
+    $obj->buildRows($sql, $rows);
+    $obj->formatDisplay($rows);
+    $this->assertEquals('CiviTest Custom Location Type', $rows[0]['civicrm_address_address_location_type_id']);
+  }
+
 }