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 * Test various payment forms.
15 * This class is intended to be a place to build out testing of various forms - with the
16 * hope being to ensure all payment forms are consistently tested and to refine
17 * helper functions into a trait that could be available to
18 * extensions for testing - notably the eventcart which ideally should interact with core
19 * through approved interfaces - ideally even in tests.
21 * An approved interface would sit in the Civi directory and would at minimum support some functions
22 * to support using our processors in tests so we are testing a broader swath than just Dummy.
23 * Currently Authorize.net is also testable (uses Guzzle). At some point PaypalPro & Std should also be testable
24 * - allowing us to easily check payment forms work with the core processors which cover a reasonable amount of the
25 * expectations held by non-core processors .
27 * Note that this tests eventcart but is not in eventcart because I want to be sure about whether the
28 * traits supporting it make sense before making them available to extensions.
30 class CRM_Financial_Form_PaymentFormsTest
extends CiviUnitTestCase
{
32 use CRM_Core_Payment_AuthorizeNetTrait
;
35 * Generic test on event payment forms to make sure they submit without error with payment processing.
37 * @throws \CRM_Core_Exception
38 * @throws \CiviCRM_API3_Exception
40 public function testEventPaymentForms() {
41 $this->createAuthorizeNetProcessor();
42 $processors = [$this->ids
['PaymentProcessor']['anet']];
43 $eventID = $this->eventCreatePaid([
44 'end_date' => '+ 1 month',
45 'registration_end_date' => '+ 1 month',
46 'payment_processor' => $processors,
48 $this->createLoggedInUser();
51 'CRM_Event_Cart_Form_Checkout_ParticipantsAndPrices' => [
52 'forms' => ['CRM_Event_Cart_Form_Checkout_ParticipantsAndPrices', 'CRM_Event_Cart_Form_Checkout_Payment'],
55 'event' => [$eventID => ['participant' => [1 => ['email' => 'bob@example.com']]]],
56 'event_' . $eventID . '_price_' . $this->_ids
['price_field'][0] => $this->_ids
['price_field_value'][0],
62 'credit_card_number' => 4111111111111111,
63 'payment_processor_id' => $processors[0],
65 'credit_card_exp_date' => [
69 'credit_card_type' => 'Visa',
70 'billing_contact_email' => 'bobby@example.com',
71 'billing_first_name' => 'John',
72 'billing_middle_name' => '',
73 'billing_last_name' => "O'Connor",
74 'billing_street_address-5' => '8 Hobbitton Road',
75 'billing_city-5' => 'The Shire',
76 'billing_state_province_id-5' => 1012,
77 'billing_postal_code-5' => 5010,
78 'billing_country_id-5' => 1228,
81 $cart = CRM_Event_Cart_BAO_Cart
::find_or_create_for_current_session();
82 $cart->add_event($eventID);
84 foreach ($forms as $values) {
85 $_REQUEST = $values['REQUEST'];
87 foreach ($values['forms'] as $formName) {
88 $formValues = array_merge($genericParams, $values['submitValues'], ['qfKey' => $qfKey]);
89 $form = $this->getFormObject($formName, $formValues);
91 $form->buildQuickForm();
93 $qfKey = $form->controller
->_key
;
96 $participant = \Civi\Api4\Participant
::get(FALSE)
97 ->addWhere('status_id:name', '=', 'Registered')
100 $this->assertEquals($cart->id
, $participant['cart_id']);
101 $this->assertEquals(CRM_Core_PseudoConstant
::getKey('CRM_Event_BAO_Participant', 'status_id', 'Registered'), $participant['status_id']);
102 $this->assertRequestValid(['x_city' => 'The+Shire', 'x_state' => 'IL', 'x_amount' => 1.0]);