class CiviUnitTestCase extends PHPUnit_Extensions_Database_TestCase {
/**
- * api version - easier to override than just a defin
+ * api version - easier to override than just a define
*/
protected $_apiversion = API_LATEST_VERSION;
/**
* Generic function to create Organisation, to be used in test cases
*
* @param array parameters for civicrm_contact_add api function call
+ * @param int sequence number if creating multiple organizations
*
* @return int id of Organisation created
*/
- function organizationCreate($params = array()) {
+ function organizationCreate($params = array(), $seq = 0) {
if (!$params) {
$params = array();
}
- $orgParams = array(
- 'organization_name' => 'Unit Test Organization',
- 'contact_type' => 'Organization',
- );
- return $this->_contactCreate(array_merge($orgParams, $params));
+ $params = array_merge($this->sampleContact('Organization', $seq), $params);
+ return $this->_contactCreate($params);
}
/**
* Generic function to create Individual, to be used in test cases
*
* @param array parameters for civicrm_contact_add api function call
+ * @param int sequence number if creating multiple individuals
*
* @return int id of Individual created
*/
- function individualCreate($params = array()) {
- $params = array_merge(array(
- 'first_name' => 'Anthony',
- 'middle_name' => 'J.',
- 'last_name' => 'Anderson',
- 'prefix_id' => 3,
- 'suffix_id' => 3,
- 'email' => 'anthony_anderson@civicrm.org',
- 'contact_type' => 'Individual',
- ), $params);
-
+ function individualCreate($params = array(), $seq = 0) {
+ $params = array_merge($this->sampleContact('Individual', $seq), $params);
return $this->_contactCreate($params);
}
* Generic function to create Household, to be used in test cases
*
* @param array parameters for civicrm_contact_add api function call
+ * @param int sequence number if creating multiple households
*
* @return int id of Household created
*/
- function householdCreate($params = array()) {
- $params = array_merge(array(
- 'household_name' => 'Unit Test household',
- 'contact_type' => 'Household',
- ), $params);
+ function householdCreate($params = array(), $seq = 0) {
+ $params = array_merge($this->sampleContact('Household', $seq), $params);
return $this->_contactCreate($params);
}
+ /**
+ * Helper function for getting sample contact properties
+ *
+ * @param enum contact type: Individual, Organization
+ * @param int sequence number for the values of this type
+ *
+ * @return array properties of sample contact (ie. $params for API call)
+ */
+ function sampleContact($contact_type, $seq = 0) {
+ $samples = array(
+ 'Individual' => array(
+ // The number of values in each list need to be coprime numbers to not have duplicates
+ 'first_name' => array('Anthony', 'Joe', 'Terrence', 'Lucie', 'Albert', 'Bill', 'Kim'),
+ 'middle_name' => array('J.', 'M.', 'P', 'L.', 'K.', 'A.', 'B.', 'C.', 'D', 'E.', 'Z.'),
+ 'last_name' => array('Anderson', 'Miller', 'Smith', 'Collins', 'Peterson'),
+ ),
+ 'Organization' => array(
+ 'organization_name' => array('Unit Test Organization', 'Acme', 'Roberts and Sons', 'Cryo Space Labs', 'Sharper Pens'),
+ ),
+ 'Household' => array(
+ 'household_name' => array('Unit Test household'),
+ ),
+ );
+ $params = array('contact_type' => $contact_type);
+ foreach ($samples[$contact_type] as $key => $values) {
+ $params[$key] = $values[$seq % sizeof($values)];
+ }
+ if ($contact_type == 'Individual' ) {
+ $employer = $this->sampleContact('Organization', $seq);
+ $params['email'] = strtolower(
+ $params['first_name'] . '_' . $params['last_name'] . '@civicrm.org'
+ );
+ $params['prefix_id'] = 3;
+ $params['suffix_id'] = 3;
+ }
+ return $params;
+ }
+
/**
* Private helper function for calling civicrm_contact_add
*
'civicrm_membership_type',
'civicrm_membership_payment',
'civicrm_membership_log',
- 'civicrm_membership_status',
+ 'civicrm_membership_block',
'civicrm_event',
'civicrm_participant',
'civicrm_participant_payment',
'civicrm_pledge',
+ 'civicrm_price_set_entity',
);
$this->quickCleanup($tablesToTruncate);
+ CRM_Core_DAO::executeQuery("DELETE FROM civicrm_membership_status WHERE name NOT IN('New', 'Current', 'Grace', 'Expired', 'Pending', 'Cancelled', 'Deceased')");
}
/*
* Function does a 'Get' on the entity & compares the fields in the Params with those returned
}
-/**
- * Create an instance of the paypal processor
- * @todo this isn't a great place to put it - but really it belongs on a class that extends
- * this parent class & we don't have a structure for that yet
- * There is another function to this effect on the PaypalPro test but it appears to be silently failing
- * & the best protection agains that is the functions this class affords
- */
- function paymentProcessorCreate($params = array()) {
- $params = array_merge(array(
- 'name' => 'demo',
- 'domain_id' => CRM_Core_Config::domainID(),
- 'payment_processor_type_id' => 'PayPal',
- 'is_active' => 1,
- 'is_default' => 0,
- 'is_test' => 1,
- 'user_name' => 'sunil._1183377782_biz_api1.webaccess.co.in',
- 'password' => '1183377788',
- 'signature' => 'APixCoQ-Zsaj-u3IH7mD5Do-7HUqA9loGnLSzsZga9Zr-aNmaJa3WGPH',
- 'url_site' => 'https://www.sandbox.paypal.com/',
- 'url_api' => 'https://api-3t.sandbox.paypal.com/',
- 'url_button' => 'https://www.paypal.com/en_US/i/btn/btn_xpressCheckout.gif',
- 'class_name' => 'Payment_PayPalImpl',
- 'billing_mode' => 3,
- 'financial_type_id' => 1,
- ),
- $params);
- if(!is_numeric($params['payment_processor_type_id'])) {
- // really the api should handle this through getoptions but it's not exactly api call so lets just sort it
- //here
- $params['payment_processor_type_id'] = $this->callAPISuccess('payment_processor_type', 'getvalue', array(
- 'name' => $params['payment_processor_type_id'],
- 'return' => 'id',
- ), 'integer');
- }
- $result = $this->callAPISuccess('payment_processor', 'create', $params);
- return $result['id'];
- }
-
+ /**
+ * Create an instance of the paypal processor
+ * @todo this isn't a great place to put it - but really it belongs on a class that extends
+ * this parent class & we don't have a structure for that yet
+ * There is another function to this effect on the PaypalPro test but it appears to be silently failing
+ * & the best protection agains that is the functions this class affords
+ */
+ function paymentProcessorCreate($params = array()) {
+ $params = array_merge(array(
+ 'name' => 'demo',
+ 'domain_id' => CRM_Core_Config::domainID(),
+ 'payment_processor_type_id' => 'PayPal',
+ 'is_active' => 1,
+ 'is_default' => 0,
+ 'is_test' => 1,
+ 'user_name' => 'sunil._1183377782_biz_api1.webaccess.co.in',
+ 'password' => '1183377788',
+ 'signature' => 'APixCoQ-Zsaj-u3IH7mD5Do-7HUqA9loGnLSzsZga9Zr-aNmaJa3WGPH',
+ 'url_site' => 'https://www.sandbox.paypal.com/',
+ 'url_api' => 'https://api-3t.sandbox.paypal.com/',
+ 'url_button' => 'https://www.paypal.com/en_US/i/btn/btn_xpressCheckout.gif',
+ 'class_name' => 'Payment_PayPalImpl',
+ 'billing_mode' => 3,
+ 'financial_type_id' => 1,
+ ),
+ $params);
+ if (!is_numeric($params['payment_processor_type_id'])) {
+ // really the api should handle this through getoptions but it's not exactly api call so lets just sort it
+ //here
+ $params['payment_processor_type_id'] = $this->callAPISuccess('payment_processor_type', 'getvalue', array(
+ 'name' => $params['payment_processor_type_id'],
+ 'return' => 'id',
+ ), 'integer');
+ }
+ $result = $this->callAPISuccess('payment_processor', 'create', $params);
+ return $result['id'];
+ }
/**
* @param $message
*
* @throws Exception
- */function CiviUnitTestCase_fatalErrorHandler($message) {
- throw new Exception("{$message['message']}: {$message['code']}");
-}
+ */
+ function CiviUnitTestCase_fatalErrorHandler($message) {
+ throw new Exception("{$message['message']}: {$message['code']}");
+ }
+
+ /**
+ * Helper function to create new mailing
+ * @return mixed
+ */
+ function createMailing() {
+ $params = array(
+ 'subject' => 'maild' . rand(),
+ 'body_text' => 'bdkfhdskfhduew',
+ 'name' => 'mailing name' . rand(),
+ 'created_id' => 1,
+ );
+
+ $result = $this->callAPISuccess('Mailing', 'create', $params);
+ return $result['id'];
+ }
+
+ /**
+ * Helper function to delete mailing
+ * @param $id
+ */
+ function deleteMailing($id) {
+ $params = array(
+ 'id' => $id,
+ );
+
+ $this->callAPISuccess('Mailing', 'delete', $params);
+ }
}