Skip to content

Commit

Permalink
dev/cloud-native#16 Migrate Contribution Page widget extern url to us…
Browse files Browse the repository at this point in the history
…e the normal CMS routing mechanism

Update test to test both endpoints
  • Loading branch information
seamuslee001 committed Aug 8, 2020
1 parent 28a74ee commit c10bf28
Show file tree
Hide file tree
Showing 5 changed files with 79 additions and 5 deletions.
51 changes: 51 additions & 0 deletions CRM/Contribute/Page/Widget.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
<?php
/*
+--------------------------------------------------------------------+
| Copyright CiviCRM LLC. All rights reserved. |
| |
| This work is published under the GNU AGPLv3 license with some |
| permitted exceptions and without any warranty. For full license |
| and copyright information, see https://civicrm.org/licensing |
+--------------------------------------------------------------------+
*/

/**
*
* @package CRM
* @copyright CiviCRM LLC https://civicrm.org/licensing
*/
class CRM_Contribute_Page_Widget extends CRM_Core_Page {

/**
* the main function that is called when the page
* loads, it decides the which action has to be taken for the page.
*
* @throws \CRM_Core_Exception
* @throws \CiviCRM_API3_Exception
*/
public function run() {
$config = CRM_Core_Config::singleton();
$template = CRM_Core_Smarty::singleton();

$cpageId = CRM_Utils_Request::retrieve('cpageId', 'Positive');
$widgetId = CRM_Utils_Request::retrieve('widgetId', 'Positive');
$format = CRM_Utils_Request::retrieve('format', 'Positive');
$includePending = CRM_Utils_Request::retrieve('includePending', 'Boolean');

$jsonvar = 'jsondata';
if (isset($format)) {
$jsonvar .= $cpageId;
}

$data = CRM_Contribute_BAO_Widget::getContributionPageData($cpageId, $widgetId, $includePending);

$output = '
var ' . $jsonvar . ' = ' . json_encode($data) . ';
';

CRM_Core_Page_AJAX::setJsHeaders(60);
echo $output;
CRM_Utils_System::civiExit();
}

}
8 changes: 8 additions & 0 deletions CRM/Contribute/xml/Menu/Contribute.xml
Original file line number Diff line number Diff line change
Expand Up @@ -329,4 +329,12 @@
<page_callback>CRM_Member_Page_RecurringContributions</page_callback>
<access_arguments>access CiviContribute</access_arguments>
</item>
<item>
<path>civicrm/contribute/widget</path>
<title>CiviContribute</title>
<page_callback>CRM_Contribute_Page_Widget</page_callback>
<access_callback>1</access_callback>
<weight>0</weight>
<is_public>true</is_public>
</item>
</menu>
4 changes: 4 additions & 0 deletions CRM/Utils/System.php
Original file line number Diff line number Diff line change
Expand Up @@ -349,6 +349,10 @@ public static function migrateExternUrl(\Civi\Core\Event\GenericHookEvent $e) {
$e->url = $mkRouteUri('civicrm/mailing/url', $e->query);
break;

case 'router:extern/widget':
$e->url = $mkRouteUri('civicrm/contribute/widget', $e->query);
break;

// Otherwise, keep the default.
}
}
Expand Down
2 changes: 1 addition & 1 deletion sql/civicrm_generated.mysql

Large diffs are not rendered by default.

19 changes: 15 additions & 4 deletions tests/phpunit/E2E/Extern/WidgetTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,26 @@ class E2E_Extern_WidgetTest extends CiviEndToEndTestCase {
*/
public $url;

public function setUp() {
$this->url = CRM_Core_Resources::singleton()->getUrl('civicrm', 'extern/widget.php');
/**
* @return array
*/
public function getEndPoints() {
$endpoints = [];

if (CIVICRM_UF !== 'Drupal8') {
$endpoints['traditional'] = [CRM_Core_Resources::singleton()->getUrl('civicrm', 'extern/widget.php')];
}
$endpoints['normal'] = [CRM_Utils_System::url('civicrm/contribute/widget', NULL, TRUE, NULL, FALSE, TRUE)];

return $endpoints;
}

/**
* Return widget Javascript.
*
* @dataProvider getEndPoints
*/
public function testWidget() {
public function testWidget($url) {
$this->url = $url;
$contributionPage = $this->contributionPageCreate();
$widgetParams = [
'is_active' => 1,
Expand Down

0 comments on commit c10bf28

Please sign in to comment.