From 46de51586b90ffb00e617d144bb353206342e5aa Mon Sep 17 00:00:00 2001 From: Eileen McNaughton <emcnaughton@wikimedia.org> Date: Mon, 17 Jan 2022 21:04:27 +1300 Subject: [PATCH] Fix smarty notices in footer files --- CRM/Core/Form.php | 9 +++++++++ CRM/Core/Page.php | 3 +++ templates/CRM/common/contactFooter.tpl | 8 ++++---- templates/CRM/common/footer.tpl | 2 +- tests/phpunit/Civi/Test/ExampleHookTest.php | 18 +++++++++++++----- 5 files changed, 30 insertions(+), 10 deletions(-) diff --git a/CRM/Core/Form.php b/CRM/Core/Form.php index 829085db1a72..8ab1c22a0815 100644 --- a/CRM/Core/Form.php +++ b/CRM/Core/Form.php @@ -281,6 +281,15 @@ public function setContext() { 'context', // FormButtons.tpl (adds buttons to forms). 'linkButtons', + // Required for contactFooter.tpl. + // See CRM_Activity_Form_ActivityTest:testInboundEmailDisplaysWithLineBreaks. + 'external_identifier', + 'lastModified', + 'created_date', + 'changeLog', + // Required for footer.tpl, + // See CRM_Activity_Form_ActivityTest:testInboundEmailDisplaysWithLineBreaks. + 'footer_status_severity', ]; /** diff --git a/CRM/Core/Page.php b/CRM/Core/Page.php index 99742ac99ca0..e3aadfebcdac 100644 --- a/CRM/Core/Page.php +++ b/CRM/Core/Page.php @@ -124,6 +124,9 @@ class CRM_Core_Page { 'breadcrumb', 'pageTitle', 'isDeleted', + // Required for footer.tpl, + // See ExampleHookTest:testPageOutput. + 'footer_status_severity', ]; /** diff --git a/templates/CRM/common/contactFooter.tpl b/templates/CRM/common/contactFooter.tpl index d87f279f9707..db1f334b77ec 100644 --- a/templates/CRM/common/contactFooter.tpl +++ b/templates/CRM/common/contactFooter.tpl @@ -11,15 +11,15 @@ {strip} <div class="crm-footer" id="crm-record-log"> <span class="col1"> - {if !empty($external_identifier)}{ts}External ID{/ts}: {$external_identifier}{/if} + {if $external_identifier}{ts}External ID{/ts}: {$external_identifier}{/if} {if $action !== 2} {ts}Contact ID{/ts}: {$contactId}{/if} </span> - {if !empty($lastModified)} + {if $lastModified} {ts}Last Change by{/ts}: <a href="{crmURL p='civicrm/contact/view' q="action=view&reset=1&cid=`$lastModified.id`"}">{$lastModified.name}</a> ({$lastModified.date|crmDate}) - {if !empty($changeLog)} + {if $changeLog} <a href="{crmURL p='civicrm/contact/view' q="reset=1&action=browse&selectedChild=log&cid=`$contactId`"}" class="crm-log-view"><i class="crm-i fa-history" aria-hidden="true"></i> {ts}View Change Log{/ts}</a> {/if} {/if} - {if !empty($created_date)}<div class="contact-created-date">{ts}Created{/ts}: {$created_date|crmDate}</div>{/if} + {if $created_date}<div class="contact-created-date">{ts}Created{/ts}: {$created_date|crmDate}</div>{/if} </div> {/strip} diff --git a/templates/CRM/common/footer.tpl b/templates/CRM/common/footer.tpl index 4399e31d94b0..ddae7088b1f0 100644 --- a/templates/CRM/common/footer.tpl +++ b/templates/CRM/common/footer.tpl @@ -16,7 +16,7 @@ <div class="crm-footer" id="civicrm-footer"> {crmVersion assign=version} {ts}Powered by CiviCRM{/ts} <a href="https://download.civicrm.org/about/{$version}">{$version}</a>. - {if !empty($footer_status_severity)} + {if $footer_status_severity} <span class="status{if $footer_status_severity gt 3} crm-error{elseif $footer_status_severity gt 2} crm-warning{else} crm-ok{/if}"> <a href="{crmURL p='civicrm/a/#/status'}">{$footer_status_message}</a> </span> diff --git a/tests/phpunit/Civi/Test/ExampleHookTest.php b/tests/phpunit/Civi/Test/ExampleHookTest.php index 62998b41a4a1..efc59ebfdee0 100644 --- a/tests/phpunit/Civi/Test/ExampleHookTest.php +++ b/tests/phpunit/Civi/Test/ExampleHookTest.php @@ -2,6 +2,7 @@ namespace Civi\Test; use Civi\Angular\Page\Main; +use PHPUnit\Framework\TestCase; /** * This is an example of a barebones test which implements `HookInterface`. Methods are automatically scanned to @@ -17,7 +18,7 @@ * * @group headless */ -class ExampleHookTest extends \PHPUnit\Framework\TestCase implements HeadlessInterface, HookInterface { +class ExampleHookTest extends TestCase implements HeadlessInterface, HookInterface { /** * @var \CRM_Contact_DAO_Contact @@ -81,16 +82,23 @@ public function on_civi_api_prepare(\Civi\API\Event\PrepareEvent $event): void { $this->tracker['civi.api.prepare'][__FUNCTION__] = TRUE; } - public function testPageOutput() { + /** + * Basic run test. + */ + public function testPageOutput(): void { ob_start(); $p = new Main(); $p->run(); - $content = ob_get_contents(); - ob_end_clean(); + $content = ob_get_clean(); $this->assertRegExp('; hook_civicrm_alterContent on_hook_civicrm_alterContent;', $content); } - public function testGetFields() { + /** + * Test getfields calls hooks. + * + * @throws \CiviCRM_API3_Exception + */ + public function testGetFields(): void { $this->assertEquals([], $this->tracker['civi.api.resolve']); $this->assertEquals([], $this->tracker['civi.api.prepare']); \civicrm_api3('Contact', 'getfields', []);