From 3699ac58314ae2cda9c1363a0d51299f5659b851 Mon Sep 17 00:00:00 2001 From: demeritcowboy Date: Tue, 18 Aug 2020 10:27:12 -0400 Subject: [PATCH] e_notice on widget tab --- .../Form/ContributionPage/Widget.php | 2 +- .../CRM/Contribute/Form/ContributionTest.php | 28 +++++++++++++++++++ 2 files changed, 29 insertions(+), 1 deletion(-) diff --git a/CRM/Contribute/Form/ContributionPage/Widget.php b/CRM/Contribute/Form/ContributionPage/Widget.php index d59c1f6c45bc..7c6ee1bb991c 100644 --- a/CRM/Contribute/Form/ContributionPage/Widget.php +++ b/CRM/Contribute/Form/ContributionPage/Widget.php @@ -40,7 +40,7 @@ public function preProcess() { $this->assign('cpageId', $this->_id); - $this->assign('widgetExternUrl', CRM_Utils_System::externUrl('extern/widget', "cpageId={$this->_id}&widgetId={$this->_widget->id}&format=3")); + $this->assign('widgetExternUrl', CRM_Utils_System::externUrl('extern/widget', "cpageId={$this->_id}&widgetId=" . ($this->_widget->id ?? '') . "&format=3")); $config = CRM_Core_Config::singleton(); $title = CRM_Core_DAO::getFieldValue('CRM_Contribute_DAO_ContributionPage', diff --git a/tests/phpunit/CRM/Contribute/Form/ContributionTest.php b/tests/phpunit/CRM/Contribute/Form/ContributionTest.php index bb5e440731bf..12647109169d 100644 --- a/tests/phpunit/CRM/Contribute/Form/ContributionTest.php +++ b/tests/phpunit/CRM/Contribute/Form/ContributionTest.php @@ -1721,4 +1721,32 @@ public function testPreProcessContributionEdit() { unset($_REQUEST['id']); } + /** + * Mostly just check there's no errors opening the Widget tab on contribution + * pages. + */ + public function testOpeningWidgetAdminPage() { + $page_id = $this->callAPISuccess('ContributionPage', 'create', [ + 'title' => 'my page', + 'financial_type_id' => $this->_financialTypeId, + 'payment_processor' => $this->paymentProcessorID, + ])['id']; + + $form = new CRM_Contribute_Form_ContributionPage_Widget(); + $form->controller = new CRM_Core_Controller_Simple('CRM_Contribute_Form_ContributionPage_Widget', 'Widget'); + + $form->set('reset', '1'); + $form->set('action', 'update'); + $form->set('id', $page_id); + + ob_start(); + $form->controller->_actions['display']->perform($form, 'display'); + $contents = ob_get_contents(); + ob_end_clean(); + + // The page contents load later by ajax, so there's just the surrounding + // html available now, but we can check at least one thing while we're here. + $this->assertStringContainsString("selectedTab = 'widget';", $contents); + } + }