dev/cloud-native#16 Migrate Contribution Page widget extern url to use the normal...
[civicrm-core.git] / tests / phpunit / E2E / Extern / WidgetTest.php
1 <?php
2 /*
3 +--------------------------------------------------------------------+
4 | Copyright CiviCRM LLC. All rights reserved. |
5 | |
6 | This work is published under the GNU AGPLv3 license with some |
7 | permitted exceptions and without any warranty. For full license |
8 | and copyright information, see https://civicrm.org/licensing |
9 +--------------------------------------------------------------------+
10 */
11
12 /**
13 * Verify Contribution Page Widget endpoint works correctly.
14 * @group e2e
15 */
16 class E2E_Extern_WidgetTest extends CiviEndToEndTestCase {
17
18 use \Civi\Test\Api3TestTrait;
19
20 /**
21 * @var string
22 */
23 public $url;
24
25 /**
26 * Return widget Javascript.
27 */
28 public function testWidget() {
29 if (CIVICRM_UF !== 'Drupal8') {
30 $endpoints['traditional'] = CRM_Core_Resources::singleton()->getUrl('civicrm', 'extern/widget.php');
31 }
32 $endpoints['normal'] = CRM_Utils_System::url('civicrm/contribute/widget', NULL, TRUE, NULL, FALSE, TRUE);
33 foreach ($endpoints as $key => $url) {
34 $this->url = $url;
35 $contributionPage = $this->contributionPageCreate();
36 $widgetParams = [
37 'is_active' => 1,
38 'title' => $contributionPage['values'][$contributionPage['id']]['title'],
39 'contribution_page_id' => $contributionPage['id'],
40 'button_title' => 'Contribute!',
41 'color_title' => '#2786c2',
42 'color_button' => '#ffffff',
43 'color_bar' => '#2786c2',
44 'color_main_text' => '#ffffff',
45 'color_main' => '#96c0e7',
46 'color_main_bg' => '#b7e2ff',
47 'color_bg' => '#96c0e7',
48 'color_about_link' => '#556c82',
49 'color_homepage_link' => '#ffffff',
50 ];
51 $widget = new \CRM_Contribute_DAO_Widget();
52 $widget->copyValues($widgetParams);
53 $widget->save();
54 $widget->find(TRUE);
55 $query = ['cpageId' => $contributionPage['id'], 'widgetId' => $widget->id, 'format' => 3];
56 $client = CRM_Utils_HttpClient::singleton();
57 list($status, $data) = $client->post($this->url, $query);
58 $this->assertEquals(CRM_Utils_HttpClient::STATUS_OK, $status);
59 $check = substr(trim(substr($data, strpos($data, '{'))), 0, -1);
60 $decodedData = json_decode($check, TRUE);
61 $expected = [
62 'currencySymbol' => '$',
63 'is_error' => FALSE,
64 'is_active' => TRUE,
65 'title' => 'Test Contribution Page',
66 'logo' => NULL,
67 'button_title' => 'Contribute!',
68 'about' => NULL,
69 'num_donors' => '0 Donors',
70 'money_raised' => 'Raised $ 0.00 of $ 10,000.00',
71 'money_raised_amount' => '$ 0.00',
72 'campaign_start' => 'Campaign is ongoing',
73 'money_target' => 10000,
74 'money_raised_percentage' => '0%',
75 'money_target_display' => '$ 10,000.00',
76 'money_low' => 0,
77 'home_url' => '<a href=' . "'" . CRM_Core_Config::singleton()->userFrameworkBaseURL . "'" . ' class=\'crm-home-url\' style=\'color:#ffffff\'>Learn more.</a>',
78 'homepage_link' => NULL,
79 'colors' => [
80 'title' => '#2786c2',
81 'button' => '#ffffff',
82 'bar' => '#2786c2',
83 'main_text' => '#ffffff',
84 'main' => '#96c0e7',
85 'main_bg' => '#b7e2ff',
86 'bg' => '#96c0e7',
87 'about_link' => '#556c82',
88 ],
89 ];
90 $this->assertEquals($expected, $decodedData, 'Data not matched for endpoint ' . $key);
91 }
92 }
93
94 /**
95 * Create contribution page.
96 *
97 * @param array $params
98 *
99 * @return array
100 * Array of contribution page
101 */
102 public function contributionPageCreate($params = []) {
103 $this->_pageParams = array_merge([
104 'title' => 'Test Contribution Page',
105 'financial_type_id' => 1,
106 'currency' => 'USD',
107 'financial_account_id' => 1,
108 'is_active' => 1,
109 'is_allow_other_amount' => 1,
110 'min_amount' => 10,
111 'max_amount' => 1000,
112 'goal_amount' => '10000',
113 ], $params);
114 return $this->callAPISuccess('contribution_page', 'create', $this->_pageParams);
115 }
116
117 }