// "initialize" CiviCRM to avoid problems when running single tests
// FIXME: look at it closer in second stage
- // initialize the object once db is loaded
- $config = CRM_Core_Config::singleton();
- Civi\Core\Container::singleton(TRUE);
-
- // when running unit tests, use mockup user framework
- $config->setUserFramework('UnitTests');
- $this->hookClass = CRM_Utils_Hook::singleton(TRUE);
- // also fix the fatal error handler to throw exceptions,
- // rather than exit
- $config->fatalErrorHandler = 'CiviUnitTestCase_fatalErrorHandler';
-
- // enable backtrace to get meaningful errors
- $config->backtrace = 1;
+ $GLOBALS['civicrm_setting']['domain']['fatalErrorHandler'] = 'CiviUnitTestCase_fatalErrorHandler';
+ $GLOBALS['civicrm_setting']['domain']['backtrace'] = 1;
// disable any left-over test extensions
CRM_Core_DAO::executeQuery('DELETE FROM civicrm_extension WHERE full_name LIKE "test.%"');
// reset all the caches
CRM_Utils_System::flushCache();
+ // initialize the object once db is loaded
+ \Civi::reset();
+ $config = CRM_Core_Config::singleton(TRUE, TRUE); // ugh, performance
+
+ // when running unit tests, use mockup user framework
+ $this->hookClass = CRM_Utils_Hook::singleton();
+
// Make sure the DB connection is setup properly
$config->userSystem->setMySQLTimeZone();
$env = new CRM_Utils_Check_Env();
CRM_Utils_Check::singleton()->assertValid($env->checkMysqlTime());
// clear permissions stub to not check permissions
- $config = CRM_Core_Config::singleton();
$config->userPermissionClass->permissions = NULL;
//flush component settings
* Create Payment Processor.
*
* @return CRM_Financial_DAO_PaymentProcessor
- * instance of Payment Processsor
+ * instance of Payment Processor
*/
public function processorCreate() {
$processorParams = array(
'url_recur' => 'http://dummy.com',
'billing_mode' => 1,
);
- $paymentProcessor = CRM_Financial_BAO_PaymentProcessor::create($processorParams);
- return $paymentProcessor;
+ return CRM_Financial_BAO_PaymentProcessor::create($processorParams);
+ }
+
+ /**
+ * Create Payment Processor.
+ *
+ * @param array $processorParams
+ *
+ * @return \CRM_Core_Payment_Dummy
+ * Instance of Dummy Payment Processor
+ */
+ public function dummyProcessorCreate($processorParams = array()) {
+ $paymentProcessor = $this->processorCreate($processorParams);
+ return Civi\Payment\System::singleton()->getById($paymentProcessor->id);
}
/**
*
* @param array $params
* Array of parameters.
- * @param int $cTypeID
- * Id of financial type.
- * @param int $invoiceID
- * @param int $trxnID
- * @param int $paymentInstrumentID
*
* @return int
* id of created contribution
*/
- public function contributionCreate($params, $cTypeID = 1, $invoiceID = 67890, $trxnID = 12345,
- $paymentInstrumentID = 1) {
+ public function contributionCreate($params) {
$params = array_merge(array(
'domain_id' => 1,
'total_amount' => 100.00,
'fee_amount' => 5.00,
'net_ammount' => 95.00,
- 'financial_type_id' => $cTypeID,
- 'payment_instrument_id' => empty($paymentInstrumentID) ? 1 : $paymentInstrumentID,
+ 'financial_type_id' => 1,
+ 'payment_instrument_id' => 1,
'non_deductible_amount' => 10.00,
- 'trxn_id' => $trxnID,
- 'invoice_id' => $invoiceID,
+ 'trxn_id' => 12345,
+ 'invoice_id' => 67890,
'source' => 'SSF',
'contribution_status_id' => 1,
), $params);
return $result['id'];
}
- /**
- * Create online contribution.
- *
- * @param array $params
- * @param int $financialType
- * Id of financial type.
- * @param int $invoiceID
- * @param int $trxnID
- *
- * @return int
- * id of created contribution
- */
- public function onlineContributionCreate($params, $financialType, $invoiceID = 67890, $trxnID = 12345) {
- $contribParams = array(
- 'contact_id' => $params['contact_id'],
- 'receive_date' => date('Ymd'),
- 'total_amount' => 100.00,
- 'financial_type_id' => $financialType,
- 'contribution_page_id' => $params['contribution_page_id'],
- 'trxn_id' => 12345,
- 'invoice_id' => 67890,
- 'source' => 'SSF',
- );
- $contribParams = array_merge($contribParams, $params);
- $result = $this->callAPISuccess('contribution', 'create', $contribParams);
-
- return $result['id'];
- }
-
/**
* Delete contribution.
*
* @return void
*/
public function setMockSettingsMetaData($extras) {
- CRM_Core_BAO_Setting::$_cache = array();
- $this->callAPISuccess('system', 'flush', array());
- CRM_Core_BAO_Setting::$_cache = array();
+ Civi::service('settings_manager')->flush();
CRM_Utils_Hook::singleton()
->setHook('civicrm_alterSettingsMetaData', function (&$metadata, $domainId, $profile) use ($extras) {
//create a contribution so our membership & contribution don't both have id = 1
$this->contributionCreate(array(
'contact_id' => $this->_contactID,
- 'is_test' => 1),
- 1, 'abcd', '345j');
+ 'is_test' => 1,
+ 'financial_type_id' => 1,
+ 'invoice_id' => 'abcd',
+ 'trxn_id' => 345,
+ ));
$this->setupRecurringPaymentProcessorTransaction();
$this->ids['membership'] = $this->callAPISuccess('membership', 'create', array(