/** * Test the submit function with an invalid payment. * * We expect the contribution to be created but left pending. The payment has failed. * * Test covers CRM-16417 change to keep failed transactions. * * We are left with * - 1 Contribution with status = Pending * - 1 Line item * - 1 civicrm_financial_item. This is linked to the line item and has a status of 3 */ public function testSubmitCreditCardInvalid() { $form = new CRM_Contribute_Form_Contribution(); $this->paymentProcessor->setDoDirectPaymentResult(array('is_error' => 1)); try { $form->testSubmit(array('total_amount' => 50, 'financial_type_id' => 1, 'receive_date' => '04/21/2015', 'receive_date_time' => '11:27PM', 'contact_id' => $this->_individualId, 'payment_instrument_id' => array_search('Credit Card', $this->paymentInstruments), 'payment_processor_id' => $this->paymentProcessor->id, 'credit_card_exp_date' => array('M' => 5, 'Y' => 2012), 'credit_card_number' => '411111111111111'), CRM_Core_Action::ADD, 'live'); } catch (\Civi\Payment\Exception\PaymentProcessorException $e) { $this->callAPISuccessGetCount('Contribution', array('contact_id' => $this->_individualId, 'contribution_status_id' => 'Pending'), 1); $lineItem = $this->callAPISuccessGetSingle('line_item', array()); $this->assertEquals('50.00', $lineItem['unit_price']); $this->assertEquals('50.00', $lineItem['line_total']); $this->assertEquals(1, $lineItem['qty']); $this->assertEquals(1, $lineItem['financial_type_id']); $financialItem = $this->callAPISuccessGetSingle('financial_item', array('civicrm_line_item' => $lineItem['id'], 'entity_id' => $lineItem['id'])); $this->assertEquals('50.00', $financialItem['amount']); $this->assertEquals(3, $financialItem['status_id']); return; } $this->fail('An expected exception has not been raised.'); }
/** * Constructor * * @param string $mode the mode of operation: live or test * * @return void */ function __construct($mode, &$paymentProcessor) { parent::__construct($mode, $paymentProcessor); }