18
18
*/
19
19
class CRM_Contribute_Page_TabTest extends CiviUnitTestCase {
20
20
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
+
21
31
/**
22
32
* Test links render correctly for manual processor.
23
33
*
24
34
* @throws \API_Exception
25
35
* @throws \CiviCRM_API3_Exception
26
36
*/
27
- public function testLinks () {
28
- $ contactID = $ this ->individualCreate ();
29
- $ recurID = ContributionRecur::create ()->setValues ([
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 ();
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> ' ;
66
+ $ this ->assertEquals (
67
+ $ expected ,
68
+ $ this ->getDashboardActionHtml ()
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 ([
30
87
'contact_id ' => $ contactID ,
31
88
'amount ' => 10 ,
32
89
'frequency_interval ' => 'week ' ,
33
90
'start_date ' => 'now ' ,
34
91
'is_active ' => TRUE ,
35
92
'contribution_status_id:name ' => 'Pending ' ,
36
- ])
93
+ ], $ recurParams ) )
37
94
->addChain (
38
95
'contribution ' ,
39
96
Contribution::create ()->setValues ([
@@ -48,12 +105,27 @@ public function testLinks() {
48
105
$ page ->_contactId = $ contactID ;
49
106
$ page ->_action = CRM_Core_Action::VIEW ;
50
107
$ page ->browse ();
108
+ return [$ contactID , $ recurID ];
109
+ }
51
110
52
- $ templateVariable = CRM_Core_Smarty::singleton ()->get_template_vars ();
53
- $ this ->assertEquals ('Mr. Anthony Anderson II ' , $ templateVariable ['displayName ' ]);
54
- $ 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> " ,
55
- $ templateVariable ['activeRecurRows ' ][1 ]['action ' ]
56
- );
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 ' ];
119
+ }
120
+
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 ' ];
57
129
}
58
130
59
131
}
0 commit comments