3 +--------------------------------------------------------------------+
4 | Copyright CiviCRM LLC. All rights reserved. |
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 +--------------------------------------------------------------------+
13 * Class CRM_Core_PaymentTest
16 class CRM_Core_PaymentTest
extends CiviUnitTestCase
{
19 * Test the payment method is adequately logged - we don't expect the processing to succeed
21 public function testHandlePaymentMethodLogging() {
22 $params = ['processor_name' => 'Paypal', 'data' => 'blah'];
24 CRM_Core_Payment
::handlePaymentMethod('method', $params);
26 catch (Exception
$e) {
29 $log = $this->callAPISuccess('SystemLog', 'get', []);
30 $this->assertEquals('payment_notification processor_name=Paypal', $log['values'][$log['id']]['message']);
34 * Test that CVV is always required for front facing pages.
36 public function testCVVSettingForContributionPages() {
37 Civi
::settings()->set('cvv_backoffice_required', 0);
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.");
44 $dummyPayment->setBackOffice(FALSE);
45 $paymentMetaData = $dummyPayment->getPaymentFormFieldsMetadata();
46 $this->assertEquals(1, $paymentMetaData["cvv2"]["is_required"], "CVV should always be required for front office.");
48 Civi
::settings()->set('cvv_backoffice_required', 1);
50 $dummyPayment->setBackOffice(TRUE);
51 $paymentMetaData = $dummyPayment->getPaymentFormFieldsMetadata();
52 $this->assertEquals(1, $paymentMetaData["cvv2"]["is_required"], "CVV should be required for back office.");
54 $dummyPayment->setBackOffice(FALSE);
55 $paymentMetaData = $dummyPayment->getPaymentFormFieldsMetadata();
56 $this->assertEquals(1, $paymentMetaData["cvv2"]["is_required"], "CVV should always be required for front office.");
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);
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));
72 $cancelGetter = new ReflectionMethod($processor, 'getReturnFailUrl');
73 $cancelGetter->setAccessible(TRUE);
74 $this->assertEquals($cancel, $cancelGetter->invoke($processor, NULL));