Commit | Line | Data |
---|---|---|
e2bef985 | 1 | <?php |
2 | /* | |
3 | +--------------------------------------------------------------------+ | |
7d61e75f | 4 | | Copyright CiviCRM LLC. All rights reserved. | |
e2bef985 | 5 | | | |
7d61e75f TO |
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 | | |
e2bef985 | 9 | +--------------------------------------------------------------------+ |
d25dd0ee | 10 | */ |
e2bef985 | 11 | |
e9479dcf EM |
12 | /** |
13 | * Class CRM_Core_PaymentTest | |
acb109b7 | 14 | * @group headless |
e9479dcf | 15 | */ |
414e3596 | 16 | class CRM_Core_PaymentTest extends CiviUnitTestCase { |
414e3596 | 17 | |
18 | /** | |
100fef9d | 19 | * Test the payment method is adequately logged - we don't expect the processing to succeed |
414e3596 | 20 | */ |
00be9182 | 21 | public function testHandlePaymentMethodLogging() { |
9099cab3 | 22 | $params = ['processor_name' => 'Paypal', 'data' => 'blah']; |
414e3596 | 23 | try { |
24 | CRM_Core_Payment::handlePaymentMethod('method', $params); | |
25 | } | |
26 | catch (Exception $e) { | |
27 | ||
e2bef985 | 28 | } |
9099cab3 | 29 | $log = $this->callAPISuccess('SystemLog', 'get', []); |
b929d2d1 | 30 | $this->assertEquals('payment_notification processor_name=Paypal', $log['values'][$log['id']]['message']); |
e2bef985 | 31 | } |
96025800 | 32 | |
02d3eb1c AP |
33 | /** |
34 | * Test that CVV is always required for front facing pages. | |
35 | */ | |
36 | public function testCVVSettingForContributionPages() { | |
37 | Civi::settings()->set('cvv_backoffice_required', 0); | |
38 | $processor = NULL; | |
39 | $dummyPayment = new CRM_Core_Payment_Dummy("test", $processor); | |
40 | $dummyPayment->setBackOffice(TRUE); | |
41 | $paymentMetaData = $dummyPayment->getPaymentFormFieldsMetadata(); | |
42 | $this->assertEquals(0, $paymentMetaData["cvv2"]["is_required"], "CVV should be non required for back office."); | |
43 | ||
44 | $dummyPayment->setBackOffice(FALSE); | |
45 | $paymentMetaData = $dummyPayment->getPaymentFormFieldsMetadata(); | |
46 | $this->assertEquals(1, $paymentMetaData["cvv2"]["is_required"], "CVV should always be required for front office."); | |
47 | ||
48 | Civi::settings()->set('cvv_backoffice_required', 1); | |
49 | ||
50 | $dummyPayment->setBackOffice(TRUE); | |
51 | $paymentMetaData = $dummyPayment->getPaymentFormFieldsMetadata(); | |
52 | $this->assertEquals(1, $paymentMetaData["cvv2"]["is_required"], "CVV should be required for back office."); | |
53 | ||
54 | $dummyPayment->setBackOffice(FALSE); | |
55 | $paymentMetaData = $dummyPayment->getPaymentFormFieldsMetadata(); | |
56 | $this->assertEquals(1, $paymentMetaData["cvv2"]["is_required"], "CVV should always be required for front office."); | |
57 | } | |
58 | ||
e4555ff1 | 59 | public function testSettingUrl() { |
60 | /** @var CRM_Core_Payment_Dummy $processor */ | |
61 | $processor = \Civi\Payment\System::singleton()->getById($this->processorCreate()); | |
62 | $success = 'http://success.com'; | |
63 | $cancel = 'http://cancel.com'; | |
64 | $processor->setCancelUrl($cancel); | |
65 | $processor->setSuccessUrl($success); | |
66 | ||
67 | // Using ReflectionUtils to access protected methods | |
68 | $successGetter = new ReflectionMethod($processor, 'getReturnSuccessUrl'); | |
69 | $successGetter->setAccessible(TRUE); | |
70 | $this->assertEquals($success, $successGetter->invoke($processor, NULL)); | |
71 | ||
72 | $cancelGetter = new ReflectionMethod($processor, 'getReturnFailUrl'); | |
73 | $cancelGetter->setAccessible(TRUE); | |
74 | $this->assertEquals($cancel, $cancelGetter->invoke($processor, NULL)); | |
75 | } | |
76 | ||
e2bef985 | 77 | } |