Merge pull request #15841 from mattwire/participant_cleanup_removeparticipantfrominput
[civicrm-core.git] / tests / phpunit / CRM / Core / PaymentTest.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 * Class CRM_Core_PaymentTest
14 * @group headless
15 */
16 class CRM_Core_PaymentTest extends CiviUnitTestCase {
17
18 /**
19 * Test the payment method is adequately logged - we don't expect the processing to succeed
20 */
21 public function testHandlePaymentMethodLogging() {
22 $params = ['processor_name' => 'Paypal', 'data' => 'blah'];
23 try {
24 CRM_Core_Payment::handlePaymentMethod('method', $params);
25 }
26 catch (Exception $e) {
27
28 }
29 $log = $this->callAPISuccess('SystemLog', 'get', []);
30 $this->assertEquals('payment_notification processor_name=Paypal', $log['values'][$log['id']]['message']);
31 }
32
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
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
77 }