/**
  * Test the submit function on the contribution page.
  */
 public function testSubmitUpdate()
 {
     $form = new CRM_Contribute_Form_Contribution();
     $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('Check', $this->paymentInstruments), 'contribution_status_id' => 1, 'price_set_id' => 0), CRM_Core_Action::ADD);
     $contribution = $this->callAPISuccessGetSingle('Contribution', array('contact_id' => $this->_individualId));
     $form->testSubmit(array('total_amount' => 45, 'net_amount' => 45, 'financial_type_id' => 1, 'receive_date' => '04/21/2015', 'receive_date_time' => '11:27PM', 'contact_id' => $this->_individualId, 'payment_instrument_id' => array_search('Check', $this->paymentInstruments), 'contribution_status_id' => 1, 'price_set_id' => 0, 'id' => $contribution['id']), CRM_Core_Action::UPDATE);
     $contribution = $this->callAPISuccessGetSingle('Contribution', array('contact_id' => $this->_individualId));
     $this->assertEquals(45, (int) $contribution['total_amount']);
     $financialTransactions = $this->callAPISuccess('FinancialTrxn', 'get', array('sequential' => TRUE));
     $this->assertEquals(2, $financialTransactions['count']);
     $this->assertEquals(50, $financialTransactions['values'][0]['total_amount']);
     $this->assertEquals(-5, $financialTransactions['values'][1]['total_amount']);
     $this->assertEquals(-5, $financialTransactions['values'][1]['net_amount']);
     $lineItem = $this->callAPISuccessGetSingle('LineItem', array());
     $this->assertEquals(45, $lineItem['line_total']);
 }
/**
 * Implements hook_civicrm_buildForm().
 *
 * Set default credit card values when in test mode.
 *
 * @param string $formName
 * @param CRM_Contribute_Form_Contribution|CRM_Event_Form_Participant $form
 */
function ewayrecurring_civicrm_buildForm($formName, &$form)
{
    $formWhiteList = array('CRM_Contribute_Form_Contribution', 'CRM_Event_Form_Participant');
    if (!in_array($formName, $formWhiteList)) {
        return;
    }
    //CRM_Core_Resources::singleton()->addScriptUrl('https://secure.ewaypayments.com/scripts/eCrypt.js');
    if (!$form->_mode == 'live' || !civicrm_api3('setting', 'getvalue', array('group' => 'eway', 'name' => 'eway_developer_mode'))) {
        return;
    }
    $processorIDs = implode(',', array_keys($form->_processors));
    $hasNonEway = CRM_Core_DAO::singleValueQuery("\n    SELECT count(*) FROM civicrm_payment_processor p\n    WHERE class_name NOT LIKE '%Eway%'\n    AND id IN ({$processorIDs});\n  ");
    if ($hasNonEway) {
        return;
    }
    CRM_Core_Session::setStatus(ts('Eway is in test mode. Test credentials have been pre-filled. No live transaction will be submitted'));
    $defaults['credit_card_number'] = '4444333322221111';
    $defaults['credit_card_type'] = 'Visa';
    $defaults['cvv2'] = '567';
    $defaults['credit_card_exp_date[Y]'] = 21;
    $defaults['credit_card_exp_date[M]'] = '1';
    $defaults['credit_card_exp_date'] = array('M' => 1, 'Y' => 2021);
    $form->setDefaults($defaults);
}