Enotice fix
authorEileen McNaughton <emcnaughton@wikimedia.org>
Mon, 15 Nov 2021 01:50:33 +0000 (14:50 +1300)
committerEileen McNaughton <emcnaughton@wikimedia.org>
Mon, 22 Nov 2021 05:06:13 +0000 (18:06 +1300)
12 files changed:
CRM/Report/Form.php
CRM/Report/Utils/Report.php
templates/CRM/Report/Form.tpl
templates/CRM/Report/Form/Contact/Detail.tpl
templates/CRM/Report/Form/Contribute/DeferredRevenue.tpl
templates/CRM/Report/Form/Event/Income.tpl
templates/CRM/Report/Form/Layout/Graph.tpl
templates/CRM/Report/Form/Layout/Table.tpl
templates/CRM/Report/Form/Statistics.tpl
tests/phpunit/CRM/Report/Form/Contribute/DetailTest.php
tests/phpunit/CRM/Report/Utils/ReportTest.php
tests/phpunit/api/v3/ReportTemplateTest.php

index 2d015a178e991bfb62ea23ef266b17b56bcadacd..92425afbf05f1b24ae207098e9f1d0d9cef2ae2a 100644 (file)
  * Class CRM_Report_Form
  */
 class CRM_Report_Form extends CRM_Core_Form {
+  /**
+   * Variables smarty expects to have set.
+   *
+   * We ensure these are assigned (value = NULL) when Smarty is instantiated in
+   * order to avoid e-notices / having to use empty or isset in the template layer.
+   *
+   * @var string[]
+   */
+  public $expectedSmartyVariables = ['pager', 'skip', 'sections', 'grandStat'];
+
   /**
    * Deprecated constant, Reports should be updated to use the getRowCount function.
    */
@@ -2471,11 +2481,11 @@ WHERE cg.extends IN ('" . implode("','", $this->_customGroupExtends) . "') AND
     if ($pager) {
       $this->setPager();
     }
-
+    $chartEnabled = !empty($this->_params['charts']) && !empty($rows);
+    $this->assign('chartEnabled', $chartEnabled);
     // allow building charts if any
-    if (!empty($this->_params['charts']) && !empty($rows)) {
+    if ($chartEnabled) {
       $this->buildChart($rows);
-      $this->assign('chartEnabled', TRUE);
       $this->_chartId = "{$this->_params['charts']}_" .
         ($this->_id ? $this->_id : substr(get_class($this), 16)) . '_' .
         CRM_Core_Config::singleton()->userSystem->getSessionId();
@@ -2487,6 +2497,12 @@ WHERE cg.extends IN ('" . implode("','", $this->_customGroupExtends) . "') AND
       if (!empty($value['no_display'])) {
         unset($this->_columnHeaders[$key]);
       }
+      foreach (['colspan', 'type'] as $expectedKey) {
+        if (!isset($this->_columnHeaders[$key][$expectedKey])) {
+          // Ensure it is set to prevent smarty notices.
+          $this->_columnHeaders[$key][$expectedKey] = FALSE;
+        }
+      }
     }
 
     // unset columns not to be displayed.
@@ -2494,6 +2510,12 @@ WHERE cg.extends IN ('" . implode("','", $this->_customGroupExtends) . "') AND
       foreach ($this->_noDisplay as $noDisplayField) {
         foreach ($rows as $rowNum => $row) {
           unset($this->_columnHeaders[$noDisplayField]);
+          $expectedKeys = ['class'];
+          foreach ($expectedKeys as $expectedKey) {
+            if (!array_key_exists($expectedKey, $row)) {
+              $rows[$rowNum][$expectedKey] = NULL;
+            }
+          }
         }
       }
     }
@@ -3300,7 +3322,7 @@ WHERE cg.extends IN ('" . implode("','", $this->_customGroupExtends) . "') AND
    * @param array $rows
    */
   public function doTemplateAssignment(&$rows) {
-    $this->assign_by_ref('columnHeaders', $this->_columnHeaders);
+    $this->assign('columnHeaders', $this->_columnHeaders);
     $this->assign_by_ref('rows', $rows);
     $this->assign('statistics', $this->statistics($rows));
   }
@@ -3344,12 +3366,14 @@ WHERE cg.extends IN ('" . implode("','", $this->_customGroupExtends) . "') AND
     $statistics['counts']['rowCount'] = [
       'title' => ts('Row(s) Listed'),
       'value' => $count,
+      'type' => CRM_Utils_Type::T_INT,
     ];
 
     if ($this->_rowsFound && ($this->_rowsFound > $count)) {
       $statistics['counts']['rowsFound'] = [
         'title' => ts('Total Row(s)'),
         'value' => $this->_rowsFound,
+        'type' => CRM_Utils_Type::T_INT,
       ];
     }
   }
@@ -3378,6 +3402,10 @@ WHERE cg.extends IN ('" . implode("','", $this->_customGroupExtends) . "') AND
         'value' => implode(' & ', $combinations),
       ];
     }
+    else {
+      // prevents an e-notice in statistics.tpl.
+      $statistics['groups'] = [];
+    }
   }
 
   /**
@@ -3485,6 +3513,10 @@ WHERE cg.extends IN ('" . implode("','", $this->_customGroupExtends) . "') AND
           }
         }
       }
+      else {
+        // Prevents an e-notice in statistics.tpl.
+        $statistics['filters'] = [];
+      }
     }
   }
 
index b3fd9556fa74b4c2e18444ff6ed1523f95775f21..7e05025016f94675df46ea36ec42c67fd7f3b2bc 100644 (file)
@@ -394,7 +394,7 @@ WHERE  inst.report_id = %1";
     $_REQUEST['reset'] = CRM_Utils_Array::value('reset', $params, 1);
 
     $optionVal = self::getValueFromUrl($instanceId);
-    $messages = ["Report Mail Triggered..."];
+    $messages = ['Report Mail Triggered...'];
 
     $templateInfo = CRM_Core_OptionGroup::getRowValues('report_template', $optionVal, 'value');
     $obj = new CRM_Report_Page_Instance();
index db27dbab83acb3aec2a1deb08b53809f55f9d0fa..5f34d26e1f85d097e01f8454bb3e969db4348913 100644 (file)
@@ -16,7 +16,7 @@
 {elseif $section eq 2}
   <div class="crm-block crm-content-block crm-report-layoutTable-form-block">
     {*include the table layout*}
-    {if empty($chartEnabled) || empty($chartSupported)}
+    {if !$chartEnabled || empty($chartSupported)}
       {include file="CRM/Report/Form/Layout/Table.tpl"}
     {/if}
   </div>
     {include file="CRM/Report/Form/Actions.tpl"}
 
     {*Statistics at the Top of the page*}
-    {include file="CRM/Report/Form/Statistics.tpl" top=true}
+    {include file="CRM/Report/Form/Statistics.tpl" top=true bottom=false}
 
     {*include the graph*}
     {include file="CRM/Report/Form/Layout/Graph.tpl"}
 
     {*include the table layout*}
 
-    {if empty($chartEnabled) || empty($chartSupported)}
+    {if !$chartEnabled || empty($chartSupported)}
       {include file="CRM/Report/Form/Layout/Table.tpl"}
     {/if}
     <br />
     {*Statistics at the bottom of the page*}
-    {include file="CRM/Report/Form/Statistics.tpl" bottom=true}
+    {include file="CRM/Report/Form/Statistics.tpl" top="false" bottom=true}
 
     {include file="CRM/Report/Form/ErrorMessage.tpl"}
   </div>
index 7dfdeb2eb797fee69ef0c8e93e2353bd6f7fa382..80ec862f577dfbc63f98406265cd830125e5de78 100644 (file)
@@ -17,7 +17,7 @@
 <div class="crm-block crm-content-block crm-report-form-block">
 {include file="CRM/Report/Form/Actions.tpl"}
 {if !$section }
-{include file="CRM/Report/Form/Statistics.tpl" top=true}
+{include file="CRM/Report/Form/Statistics.tpl" top=true bottom=false}
 {/if}
     {if $rows}
         <div class="report-pager">
 
         {if !$section }
             {*Statistics at the bottom of the page*}
-            {include file="CRM/Report/Form/Statistics.tpl" bottom=true}
+            {include file="CRM/Report/Form/Statistics.tpl" top="false" bottom=true}
         {/if}
     {/if}
     {include file="CRM/Report/Form/ErrorMessage.tpl"}
index 6707b4020032444fa78920f6d43435bc16155dc8..e519abfd460c3cdc409cf6a9965dc27a7cb63804 100644 (file)
   {include file="CRM/Report/Form/Actions.tpl"}
 
   {*Statistics at the Top of the page*}
-  {include file="CRM/Report/Form/Statistics.tpl" top=true}
-  
+  {include file="CRM/Report/Form/Statistics.tpl" top=true bottom=false}
+
 <table class="report-layout display">
    {foreach from=$rows item=row}
      <thead><th colspan=16><font color="black" size="3">{$row.label}</font></th></thead>
-   
+
      <thead class="sticky">
      <tr>
        {foreach from=$columnHeaders item=label key=header}
@@ -43,7 +43,7 @@
 
   <br />
   {*Statistics at the bottom of the page*}
-  {include file="CRM/Report/Form/Statistics.tpl" bottom=true}
+  {include file="CRM/Report/Form/Statistics.tpl" top="false" bottom=true}
 
   {include file="CRM/Report/Form/ErrorMessage.tpl"}
 </div>
index 0030909b90478da4acd119fdc63be1115baa7892..2ce5a713c6af91943922dc890f2785c139886902 100644 (file)
@@ -18,7 +18,7 @@
 {include file="CRM/Report/Form/Actions.tpl"}
 {*Statistics at the Top of the page*}
     {if !$section }
-        {include file="CRM/Report/Form/Statistics.tpl" top=true}
+        {include file="CRM/Report/Form/Statistics.tpl" top=true bottom=false}
     {/if}
 
     {if $events}
@@ -70,7 +70,7 @@
         </div>
         {if !$section }
             {*Statistics at the bottom of the page*}
-            {include file="CRM/Report/Form/Statistics.tpl" bottom=true}
+            {include file="CRM/Report/Form/Statistics.tpl" top="false" bottom=true}
         {/if}
     {/if}
     {include file="CRM/Report/Form/ErrorMessage.tpl"}
index 137753d1bdc81ac03fca5f2820ed8bba550e443f..176c36ad7c01e59ee59375fe9ffe12580e011509 100644 (file)
@@ -9,7 +9,7 @@
 *}
 {assign var=uploadURL value=$config->imageUploadURL|replace:'/persist/contribute/':'/persist/'}
 {* Display weekly,Quarterly,monthly and yearly contributions using pChart (Bar and Pie) *}
-{if !empty($chartEnabled) and !empty($chartSupported)}
+{if $chartEnabled and !empty($chartSupported)}
   <div class='crm-chart'>
     {if $outputMode eq 'print' OR $outputMode eq 'pdf'}
       <img src="{$uploadURL|cat:$chartId}.png" />
index 1d567a6fb6af054f324f6c51bf844f48116a1cb8..0f3e6ef22a2594aefa3b538ef91e18ea92caa6ab 100644 (file)
@@ -7,10 +7,10 @@
  | and copyright information, see https://civicrm.org/licensing       |
  +--------------------------------------------------------------------+
 *}
-{if empty($rows)}
+{if !$rows}
   <p>{ts}None found.{/ts}</p>
 {else}
-    {if !empty($pager) and $pager->_response and $pager->_response.numPages > 1}
+    {if $pager and $pager->_response and $pager->_response.numPages > 1}
         <div class="report-pager">
             {include file="CRM/common/pager.tpl" location="top"}
         </div>
@@ -24,8 +24,8 @@
                 {else}
                     {assign var=class value="class='reports-header'"}
                 {/if}
-                {if empty($skip)}
-                   {if !empty($header.colspan)}
+                {if !$skip}
+                   {if $header.colspan}
                        <th colspan={$header.colspan}>{$header.title|escape}</th>
                       {assign var=skip value=true}
                       {assign var=skipCount value=`$header.colspan`}
@@ -41,7 +41,7 @@
             {/foreach}
         {/capture}
 
-        {if empty($sections)} {* section headers and sticky headers aren't playing nice yet *}
+        {if !$sections} {* section headers and sticky headers aren't playing nice yet *}
             <thead class="sticky">
             <tr>
                 {$tableHeader}
 
         {foreach from=$rows item=row key=rowid}
            {eval var=$sectionHeaderTemplate}
-            <tr  class="{cycle values="odd-row,even-row"} {if !empty($row.class)}{$row.class}{/if} crm-report" id="crm-report_{$rowid}">
+            <tr  class="{cycle values="odd-row,even-row"} {if $row.class}{$row.class}{/if} crm-report" id="crm-report_{$rowid}">
                 {foreach from=$columnHeaders item=header key=field}
                     {assign var=fieldLink value=$field|cat:"_link"}
                     {assign var=fieldHover value=$field|cat:"_hover"}
                     {assign var=fieldClass value=$field|cat:"_class"}
                     <td class="crm-report-{$field}{if $header.type eq 1024 OR $header.type eq 1 OR $header.type eq 512} report-contents-right{elseif $row.$field eq 'Subtotal'} report-label{/if}">
                         {if !empty($row.$fieldLink)}
-                            <a title="{$row.$fieldHover|escape}" href="{$row.$fieldLink}"  {if !empty($row.$fieldClass)} class="{$row.$fieldClass}"{/if}>
+                            <a title="{$row.$fieldHover|escape}" href="{$row.$fieldLink}"  {if array_key_exists($fieldClass, $row)} class="{$row.$fieldClass}"{/if}>
                         {/if}
 
                         {if is_array($row.$field)}
             </tr>
         {/foreach}
 
-        {if !empty($grandStat)}
+        {if $grandStat}
             {* foreach from=$grandStat item=row*}
             <tr class="total-row">
                 {foreach from=$columnHeaders item=header key=field}
             {* /foreach*}
         {/if}
     </table>
-    {if !empty($pager) and $pager->_response and $pager->_response.numPages > 1}
+    {if $pager and $pager->_response and $pager->_response.numPages > 1}
         <div class="report-pager">
             {include file="CRM/common/pager.tpl" location="bottom"}
         </div>
index f94e32db417d38e09dd1741536b94941121bf45d..104f95466aeb4a0c82068a031015f4553aef9ca2 100644 (file)
@@ -7,43 +7,39 @@
  | and copyright information, see https://civicrm.org/licensing       |
  +--------------------------------------------------------------------+
 *}
-{if !empty($top)}
+{if $top}
   {if !empty($printOnly)}
     <h1>{$reportTitle}</h1>
     <div id="report-date">{if !empty($reportDate)}{$reportDate}{/if}</div>
   {/if}
   {if !empty($statistics)}
     <table class="report-layout statistics-table">
-      {if !empty($statistics.groups)}
-        {foreach from=$statistics.groups item=row}
-          <tr>
-            <th class="statistics" scope="row">{$row.title}</th>
-            <td>{$row.value|escape}</td>
-          </tr>
-        {/foreach}
-      {/if}
-      {if !empty($statistics.filters)}
-        {foreach from=$statistics.filters item=row}
-          <tr>
-            <th class="statistics" scope="row">{$row.title}</th>
-            <td>{$row.value|escape}</td>
-          </tr>
-        {/foreach}
-      {/if}
+      {foreach from=$statistics.groups item=row}
+        <tr>
+          <th class="statistics" scope="row">{$row.title}</th>
+          <td>{$row.value|escape}</td>
+        </tr>
+      {/foreach}
+      {foreach from=$statistics.filters item=row}
+        <tr>
+          <th class="statistics" scope="row">{$row.title}</th>
+          <td>{$row.value|escape}</td>
+        </tr>
+      {/foreach}
     </table>
   {/if}
 {/if}
 
-{if !empty($bottom) and !empty($rows) and !empty($statistics)}
+{if $bottom and !empty($rows) and !empty($statistics)}
   <table class="report-layout">
-    {if !empty($statistics.counts)}
+    {if $statistics.counts}
       {foreach from=$statistics.counts item=row}
         <tr>
           <th class="statistics" scope="row">{$row.title}</th>
           <td>
-            {if !empty($row.type) and $row.type eq 1024}
+            {if $row.type eq 1024}
               {$row.value|crmMoney|escape}
-            {elseif !empty($row.type) and $row.type eq 2}
+            {elseif $row.type eq 2}
               {$row.value|escape}
             {else}
                {$row.value|crmNumberFormat|escape}
index 4fe96f89205470c543a7665bcd45733f25c4cff7..fdb938fb143a6613d5d7ba873aeec00630cc992d 100644 (file)
@@ -147,12 +147,12 @@ class CRM_Report_Form_Contribute_DetailTest extends CiviReportTestCase {
    * Make sure the total amount of a contribution doesn't multiply by the number
    * of soft credits.
    */
-  public function testMultipleSoftCredits() {
+  public function testMultipleSoftCredits(): void {
     $this->quickCleanup($this->_tablesToTruncate);
 
     $solParams = [
       'first_name' => 'Solicitor 1',
-      'last_name' => 'User ' . rand(),
+      'last_name' => 'User',
       'contact_type' => 'Individual',
     ];
     $solicitor1Id = $this->individualCreate($solParams);
@@ -210,6 +210,7 @@ class CRM_Report_Form_Contribute_DetailTest extends CiviReportTestCase {
         'rowCount' => [
           'title' => 'Row(s) Listed',
           'value' => 1,
+          'type' => CRM_Utils_Type::T_INT,
         ],
         'amount' => [
           'title' => 'Total Amount (Contributions)',
index a757322475f70171c409fdab74c3e115b880293f..cb85435e19fd928454c673737ff9614864cb1064 100644 (file)
@@ -76,7 +76,7 @@ ENDOUTPUT;
    * tests for that - we're more interested in does it echo it in print
    * format.
    */
-  public function testOutputPrint() {
+  public function testOutputPrint(): void {
     // Create many contacts, in particular so that the report would be more
     // than a one-pager.
     for ($i = 0; $i < 110; $i++) {
@@ -114,8 +114,7 @@ ENDOUTPUT;
       ]);
     }
     catch (CRM_Core_Exception_PrematureExitException $e) {
-      $contents = ob_get_contents();
-      ob_end_clean();
+      $contents = ob_get_clean();
     }
     $this->assertStringContainsString('<title>CiviCRM Report</title>', $contents);
     $this->assertStringContainsString('test report', $contents);
@@ -133,7 +132,8 @@ ENDOUTPUT;
    * @runInSeparateProcess
    * @preserveGlobalState disabled
    */
-  public function testOutputPdf() {
+  public function testOutputPdf(): void {
+    $contents = '';
     // Create many contacts, in particular so that the report would be more
     // than a one-pager.
     for ($i = 0; $i < 110; $i++) {
@@ -171,8 +171,7 @@ ENDOUTPUT;
       ]);
     }
     catch (CRM_Core_Exception_PrematureExitException $e) {
-      $contents = ob_get_contents();
-      ob_end_clean();
+      $contents = ob_get_clean();
     }
     $this->assertStringStartsWith('%PDF', $contents);
     $this->assertStringContainsString("id_value={$last_contact['id']}", $contents);
@@ -181,7 +180,7 @@ ENDOUTPUT;
   /**
    * Test when you choose Csv from the actions dropdown.
    */
-  public function testOutputCsv() {
+  public function testOutputCsv(): void {
     // Create many contacts, in particular so that the report would be more
     // than a one-pager.
     for ($i = 0; $i < 110; $i++) {
index 0b6d23f0562dce392816178e2291b1abd54a5665..e246c4e1454b49e4d1236df4d9e1de3ee7260923 100644 (file)
@@ -1282,6 +1282,7 @@ class api_v3_ReportTemplateTest extends CiviUnitTestCase {
       'civicrm_contact_contact_source_link' => '/index.php?q=civicrm/contact/view&amp;reset=1&amp;cid=' . $this->contactIDs[2],
       'civicrm_contact_contact_source_hover' => 'View Contact Summary for this Contact',
       'civicrm_activity_activity_type_id_hover' => 'View Activity Record',
+      'class' => NULL,
     ];
     $row = $rows[0];
     // This link is not relative - skip for now