4790df8a |
1 | <?php |
2 | /* |
3 | +--------------------------------------------------------------------+ |
4 | | Copyright CiviCRM LLC. All rights reserved. | |
5 | | | |
6 | | Use of this source code is governed by the AGPL 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 | use Civi\Api4\Contribution; |
13 | use Civi\Api4\ContributionRecur; |
14 | |
15 | /** |
16 | * Class CRM_Contribute_Page_AjaxTest |
17 | * @group headless |
18 | */ |
19 | class CRM_Contribute_Page_TabTest extends CiviUnitTestCase { |
20 | |
f3388b78 |
21 | /** |
22 | * Clean up after test. |
23 | * |
24 | * @throws \CRM_Core_Exception |
25 | */ |
26 | public function tearDown(): void { |
27 | $this->quickCleanUpFinancialEntities(); |
28 | parent::tearDown(); |
29 | } |
30 | |
4790df8a |
31 | /** |
32 | * Test links render correctly for manual processor. |
33 | * |
34 | * @throws \API_Exception |
35 | * @throws \CiviCRM_API3_Exception |
36 | */ |
f3388b78 |
37 | public function testLinksManual(): void { |
38 | [$contactID, $recurID] = $this->setupTemplate(); |
39 | |
40 | $templateVariable = CRM_Core_Smarty::singleton()->get_template_vars(); |
41 | $this->assertEquals('Mr. Anthony Anderson II', $templateVariable['displayName']); |
42 | $this->assertEquals("<span><a href=\"/index.php?q=civicrm/contact/view/contributionrecur&reset=1&id=" . $recurID . "&cid=" . $contactID . "&context=contribution\" class=\"action-item crm-hover-button\" title='View Recurring Payment' >View</a><a href=\"/index.php?q=civicrm/contribute/updaterecur&reset=1&action=update&crid=1&cid=3&context=contribution\" class=\"action-item crm-hover-button\" title='Edit Recurring Payment' >Edit</a><a href=\"/index.php?q=civicrm/contribute/unsubscribe&reset=1&crid=" . $recurID . "&cid=" . $contactID . "&context=contribution\" class=\"action-item crm-hover-button\" title='Cancel' >Cancel</a></span>", |
43 | $this->getActionHtml() |
44 | ); |
45 | } |
46 | |
47 | /** |
48 | * Test links render correctly for manual processor. |
49 | * |
50 | * @throws \API_Exception |
51 | * @throws \CiviCRM_API3_Exception |
52 | */ |
53 | public function testLinksPaypalStandard(): void { |
54 | $this->setupTemplate([ |
55 | 'payment_processor_id' => $this->paymentProcessorCreate(['payment_processor_type_id' => 'PayPal_Standard']), |
56 | 'contact_id' => $this->createLoggedInUser(), |
57 | ]); |
58 | $expected = '<span><a href="/index.php?q=civicrm/contact/view/contributionrecur&reset=1&id=1&cid=3&context=contribution" class="action-item crm-hover-button" title=\'View Recurring Payment\' >View</a><a href="/index.php?q=civicrm/contribute/updaterecur&reset=1&action=update&crid=1&cid=3&context=contribution" class="action-item crm-hover-button" title=\'Edit Recurring Payment\' >Edit</a></span><span class=\'btn-slide crm-hover-button\'>more<ul class=\'panel\'><li><a href="/index.php?q=civicrm/contribute/unsubscribe&reset=1&crid=1&cid=3&context=contribution" class="action-item crm-hover-button" title=\'Cancel\' >Cancel</a></li><li><a href="/index.php?q=civicrm/contribute/updatebilling&reset=1&crid=1&cid=3&context=contribution" class="action-item crm-hover-button" title=\'Change Billing Details\' >Change Billing Details</a></li></ul></span>'; |
59 | $this->assertEquals($expected, $this->getActionHtml()); |
60 | |
61 | $page = new CRM_Contribute_Page_UserDashboard(); |
62 | $page->run(); |
2d852c61 |
63 | $expected = '<span><a href="https://www.sandbox.paypal.com/cgi-bin/webscr?cmd=_subscr-find&alias=sunil._1183377782_biz_api1.webaccess.co.in" class="action-item crm-hover-button no-popup" title=\'Cancel\' >Cancel</a>' |
64 | . '<a href="/index.php?q=civicrm/contact/view/contributionrecur&reset=1&id=1&cid=3&context=dashboard" class="action-item crm-hover-button" title=\'View Recurring Payment\' >View</a>' |
65 | . '</span><span class=\'btn-slide crm-hover-button\'>more<ul class=\'panel\'><li><a href="/index.php?q=civicrm/contribute/updaterecur&reset=1&action=update&crid=1&cid=3&context=dashboard" class="action-item crm-hover-button" title=\'Edit Recurring Payment\' >Edit</a></li><li><a href="/index.php?q=civicrm/contribute/updatebilling&reset=1&crid=1&cid=3&context=dashboard" class="action-item crm-hover-button" title=\'Change Billing Details\' >Change Billing Details</a></li></ul></span>'; |
f3388b78 |
66 | $this->assertEquals( |
67 | $expected, |
2d852c61 |
68 | $this->getDashboardActionHtml() |
f3388b78 |
69 | ); |
70 | } |
71 | |
72 | /** |
73 | * Set up template for user dashboard. |
74 | * |
75 | * Create the recurring contribution, contribution and run the dashboard. |
76 | * |
77 | * @param array $recurParams |
78 | * |
79 | * @return array |
80 | * @throws \API_Exception |
81 | * @throws \CiviCRM_API3_Exception |
82 | * @throws \Civi\API\Exception\UnauthorizedException |
83 | */ |
84 | protected function setupTemplate($recurParams = []): array { |
85 | $contactID = $recurParams['contact_id'] ?? $this->individualCreate(); |
86 | $recurID = ContributionRecur::create()->setValues(array_merge([ |
4790df8a |
87 | 'contact_id' => $contactID, |
88 | 'amount' => 10, |
89 | 'frequency_interval' => 'week', |
90 | 'start_date' => 'now', |
91 | 'is_active' => TRUE, |
92 | 'contribution_status_id:name' => 'Pending', |
f3388b78 |
93 | ], $recurParams)) |
4790df8a |
94 | ->addChain( |
95 | 'contribution', |
96 | Contribution::create()->setValues([ |
97 | 'contribution_id' => '$id', |
98 | 'financial_type_id:name' => 'Donation', |
99 | 'total_amount' => 60, |
100 | 'receive_date' => 'now', |
101 | 'contact_id' => $contactID, |
102 | ]) |
103 | )->execute()->first()['id']; |
104 | $page = new CRM_Contribute_Page_Tab(); |
105 | $page->_contactId = $contactID; |
106 | $page->_action = CRM_Core_Action::VIEW; |
107 | $page->browse(); |
f3388b78 |
108 | return [$contactID, $recurID]; |
109 | } |
4790df8a |
110 | |
f3388b78 |
111 | /** |
112 | * Get the html assigned as actions. |
113 | * |
114 | * @return string |
115 | */ |
116 | protected function getActionHtml(): string { |
117 | return CRM_Core_Smarty::singleton() |
118 | ->get_template_vars()['activeRecurRows'][1]['action']; |
4790df8a |
119 | } |
120 | |
2d852c61 |
121 | /** |
122 | * Get the html assigned as actions. |
123 | * |
124 | * @return string |
125 | */ |
126 | protected function getDashboardActionHtml(): string { |
127 | return CRM_Core_Smarty::singleton() |
128 | ->get_template_vars()['recurRows'][1]['action']; |
129 | } |
130 | |
4790df8a |
131 | } |