Skip to content

Instantly share code, notes, and snippets.

@MegaphoneJon
Created November 14, 2019 17:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save MegaphoneJon/eaf4b446a3eda0d9bcd0825713a99df9 to your computer and use it in GitHub Desktop.
Save MegaphoneJon/eaf4b446a3eda0d9bcd0825713a99df9 to your computer and use it in GitHub Desktop.
I tried and failed to write a CiviCRM ReportTemplate test that relied on custom fields.
+ /**
+ * Ensure that a LEFT JOIN to a 1-to-many table doesn't multiply the statistics (reporting#21).
+ */
+ public function testContributionDetailStatisticsMultiRecordCustomField() {
+ $customGroup = $this->CustomGroupMultipleCreateWithFields();
+ $contactID = $this->individualCreate();
+ $params = [
+ 'entity_id' => $contactID,
+ 'custom_' . $customGroup['custom_field_id'][0] => 'value 1',
+ ];
+ $this->callAPISuccess('CustomValue', 'create', $params);
+ $params = [
+ 'entity_id' => $contactID,
+ 'custom_' . $customGroup['custom_field_id'][0] => 'value 2',
+ ];
+ $this->callAPISuccess('CustomValue', 'create', $params);
+ $this->contributionCreate(['contact_id' => $contactID]);
+ $params = [
+ 'report_id' => 'contribute/detail',
+ 'fields' => [
+ 'custom_' . $customGroup['custom_field_id'][0] => '1',
+ 'id' => '1',
+ ],
+ ];
+ $result = $this->callAPISuccess('report_template', 'getstatistics', $params);
+ print_r($result);
+ }
+
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment