Merge pull request #19943 from civicrm/5.36
[civicrm-core.git] / tests / phpunit / CRM / Core / PaymentTest.php
CommitLineData
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
be3c7eb3
TO
12use Civi\Test\Invasive;
13
e9479dcf
EM
14/**
15 * Class CRM_Core_PaymentTest
acb109b7 16 * @group headless
e9479dcf 17 */
414e3596 18class CRM_Core_PaymentTest extends CiviUnitTestCase {
414e3596 19
20 /**
100fef9d 21 * Test the payment method is adequately logged - we don't expect the processing to succeed
414e3596 22 */
00be9182 23 public function testHandlePaymentMethodLogging() {
9099cab3 24 $params = ['processor_name' => 'Paypal', 'data' => 'blah'];
414e3596 25 try {
26 CRM_Core_Payment::handlePaymentMethod('method', $params);
27 }
28 catch (Exception $e) {
29
e2bef985 30 }
9099cab3 31 $log = $this->callAPISuccess('SystemLog', 'get', []);
b929d2d1 32 $this->assertEquals('payment_notification processor_name=Paypal', $log['values'][$log['id']]['message']);
e2bef985 33 }
96025800 34
02d3eb1c
AP
35 /**
36 * Test that CVV is always required for front facing pages.
37 */
38 public function testCVVSettingForContributionPages() {
39 Civi::settings()->set('cvv_backoffice_required', 0);
40 $processor = NULL;
41 $dummyPayment = new CRM_Core_Payment_Dummy("test", $processor);
42 $dummyPayment->setBackOffice(TRUE);
43 $paymentMetaData = $dummyPayment->getPaymentFormFieldsMetadata();
44 $this->assertEquals(0, $paymentMetaData["cvv2"]["is_required"], "CVV should be non required for back office.");
45
46 $dummyPayment->setBackOffice(FALSE);
47 $paymentMetaData = $dummyPayment->getPaymentFormFieldsMetadata();
48 $this->assertEquals(1, $paymentMetaData["cvv2"]["is_required"], "CVV should always be required for front office.");
49
50 Civi::settings()->set('cvv_backoffice_required', 1);
51
52 $dummyPayment->setBackOffice(TRUE);
53 $paymentMetaData = $dummyPayment->getPaymentFormFieldsMetadata();
54 $this->assertEquals(1, $paymentMetaData["cvv2"]["is_required"], "CVV should be required for back office.");
55
56 $dummyPayment->setBackOffice(FALSE);
57 $paymentMetaData = $dummyPayment->getPaymentFormFieldsMetadata();
58 $this->assertEquals(1, $paymentMetaData["cvv2"]["is_required"], "CVV should always be required for front office.");
59 }
60
e4555ff1 61 public function testSettingUrl() {
62 /** @var CRM_Core_Payment_Dummy $processor */
63 $processor = \Civi\Payment\System::singleton()->getById($this->processorCreate());
64 $success = 'http://success.com';
65 $cancel = 'http://cancel.com';
66 $processor->setCancelUrl($cancel);
67 $processor->setSuccessUrl($success);
68
be3c7eb3
TO
69 $this->assertEquals($success, Invasive::call([$processor, 'getReturnSuccessUrl'], [NULL]));
70 $this->assertEquals($cancel, Invasive::call([$processor, 'getReturnFailUrl'], [NULL]));
e4555ff1 71 }
72
e2bef985 73}