// also load the class loader
require_once 'CRM/Core/ClassLoader.php';
CRM_Core_ClassLoader::singleton()->register();
- if (function_exists('_civix_phpunit_setUp')) { // FIXME: loosen coupling
+ if (function_exists('_civix_phpunit_setUp')) {
+ // FIXME: loosen coupling
_civix_phpunit_setUp();
}
}
+ /**
+ * Override to run the test and assert its state.
+ * @return mixed
+ * @throws \Exception
+ * @throws \PHPUnit_Framework_IncompleteTest
+ * @throws \PHPUnit_Framework_SkippedTest
+ */
protected function runTest() {
try {
return parent::runTest();
/**
* @param bool $perClass
* @param null $object
- * @return bool TRUE if the populate logic runs; FALSE if it is skipped
+ * @return bool
+ * TRUE if the populate logic runs; FALSE if it is skipped
*/
protected static function _populateDB($perClass = FALSE, &$object = NULL) {
* @match array Associative array of field name => expected value. Empty if asserting
* that a DELETE occurred
* @delete boolean True if we're checking that a DELETE action occurred.
+ * @param $daoName
+ * @param $id
+ * @param $match
+ * @param bool $delete
+ * @throws \PHPUnit_Framework_AssertionFailedError
*/
public function assertDBState($daoName, $id, $match, $delete = FALSE) {
if (empty($id)) {
}
}
- // Request a record from the DB by seachColumn+searchValue. Success if a record is found.
/**
+ * Request a record from the DB by seachColumn+searchValue. Success if a record is found.
* @param string $daoName
* @param $searchValue
* @param $returnColumn
return $value;
}
- // Request a record from the DB by seachColumn+searchValue. Success if returnColumn value is NULL.
/**
+ * Request a record from the DB by seachColumn+searchValue. Success if returnColumn value is NULL.
* @param string $daoName
* @param $searchValue
* @param $returnColumn
$this->assertNull($value, $message);
}
- // Request a record from the DB by id. Success if row not found.
/**
+ * Request a record from the DB by id. Success if row not found.
* @param string $daoName
* @param int $id
* @param null $message
$this->assertNull($value, $message);
}
- // Request a record from the DB by id. Success if row not found.
/**
+ * Request a record from the DB by id. Success if row not found.
* @param string $daoName
* @param int $id
* @param null $message
$this->assertEquals($id, $value, $message);
}
- // Compare a single column value in a retrieved DB record to an expected value
/**
+ * Compare a single column value in a retrieved DB record to an expected value
* @param string $daoName
* @param $searchValue
* @param $returnColumn
* @param $expectedValue
* @param $message
*/
- function assertDBCompareValue(
+ public function assertDBCompareValue(
$daoName, $searchValue, $returnColumn, $searchColumn,
$expectedValue, $message
) {
$this->assertEquals($value, $expectedValue, $message);
}
- // Compare all values in a single retrieved DB record to an array of expected values
/**
+ * Compare all values in a single retrieved DB record to an array of expected values
* @param string $daoName
* @param array $searchParams
* @param $expectedValues
*
* Example: $this->assertSql(2, 'select count(*) from foo where foo.bar like "%1"',
* array(1 => array("Whiz", "String")));
+ * @param $expected
+ * @param $query
+ * @param array $params
+ * @param string $message
*/
public function assertDBQuery($expected, $query, $params = array(), $message = '') {
if ($message) {
/**
* Check that a deleted item has been deleted
+ * @param $entity
+ * @param $id
*/
public function assertAPIDeleted($entity, $id) {
$this->callAPISuccess($entity, 'getcount', array('id' => $id), 0);
}
/**
- * This function exists to wrap api functions
+ * wrap api functions
* so we can ensure they succeed & throw exceptions without litterering the test with checks
*
* @param string $entity
* @param array $params
* @param string $type
* Per http://php.net/manual/en/function.gettype.php possible types.
- * - boolean
- * - integer
- * - double
- * - string
- * - array
- * - object
+ * - boolean
+ * - integer
+ * - double
+ * - string
+ * - array
+ * - object
*
* @return array|int
*/
* @param array $params
* @param array $checkAgainst
* Array to compare result against.
- * - boolean
- * - integer
- * - double
- * - string
- * - array
- * - object
+ * - boolean
+ * - integer
+ * - double
+ * - string
+ * - array
+ * - object
*
* @throws Exception
* @return array|int
'debug' => 1,
);
$result = $this->civicrm_api($entity, 'getcount', $params);
- if (!is_integer($result) || !empty($result['is_error']) || isset($result['values'])) {
+ if (!is_int($result) || !empty($result['is_error']) || isset($result['values'])) {
throw new Exception('Invalid getcount result : ' . print_r($result, TRUE) . " type :" . gettype($result));
}
if (is_int($count)) {
* so the distinction between set
* up & tested functions is clearer
*
- * @return array api Result
+ * @return array
+ * api Result
*/
public function createTestEntity() {
return $entity = $this->callAPISuccess($this->entity, 'create', $this->params);
/**
* 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
+ * @param array $params
+ * parameters for civicrm_contact_add api function call
+ * @param int $seq
+ * sequence number if creating multiple organizations
*
- * @return int id of Organisation created
+ * @return int
+ * id of Organisation created
*/
public function organizationCreate($params = array(), $seq = 0) {
if (!$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
+ * @param array $params
+ * parameters for civicrm_contact_add api function call
+ * @param int $seq
+ * sequence number if creating multiple individuals
*
- * @return int id of Individual created
+ * @return int
+ * id of Individual created
*/
public function individualCreate($params = array(), $seq = 0) {
$params = array_merge($this->sampleContact('Individual', $seq), $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
+ * @param array $params
+ * parameters for civicrm_contact_add api function call
+ * @param int $seq
+ * sequence number if creating multiple households
*
- * @return int id of Household created
+ * @return int
+ * id of Household created
*/
public function householdCreate($params = array(), $seq = 0) {
$params = array_merge($this->sampleContact('Household', $seq), $params);
/**
* Helper function for getting sample contact properties
*
- * @param enum contact type: Individual, Organization
- * @param int sequence number for the values of this type
+ * @param string $contact_type
+ * enum contact type: Individual, Organization
+ * @param int $seq
+ * sequence number for the values of this type
*
- * @return array properties of sample contact (ie. $params for API call)
+ * @return array
+ * properties of sample contact (ie. $params for API call)
*/
public function sampleContact($contact_type, $seq = 0) {
$samples = array(
);
$params = array('contact_type' => $contact_type);
foreach ($samples[$contact_type] as $key => $values) {
- $params[$key] = $values[$seq % sizeof($values)];
+ $params[$key] = $values[$seq % count($values)];
}
if ($contact_type == 'Individual') {
$params['email'] = strtolower(
*
* @throws Exception
*
- * @return int id of Household created
+ * @return int
+ * id of Household created
*/
private function _contactCreate($params) {
$result = $this->callAPISuccess('contact', 'create', $params);
}
/**
- * @param int $contactID
+ * Delete contact, ensuring it is not the domain contact
*
- * @return array|int
+ * @param int $contactID
+ * Contact ID to delete
*/
public function contactDelete($contactID) {
- $params = array(
- 'id' => $contactID,
- 'skip_undelete' => 1,
- 'debug' => 1,
- );
- $domain = new CRM_Core_BAO_Domain;
+ $domain = new CRM_Core_BAO_Domain();
$domain->contact_id = $contactID;
- if ($domain->find(TRUE)) {
- // we are finding tests trying to delete the domain contact in cleanup
- //since this is mainly for cleanup lets put a safeguard here
- return;
+ if (!$domain->find(TRUE)) {
+ $this->callAPISuccess('contact', 'delete', array(
+ 'id' => $contactID,
+ 'skip_undelete' => 1,
+ ));
}
- $result = $this->callAPISuccess('contact', 'delete', $params);
- return $result;
}
/**
* @throws Exception
*/
public function contactTypeDelete($contactTypeId) {
- require_once 'CRM/Contact/BAO/ContactType.php';
$result = CRM_Contact_BAO_ContactType::del($contactTypeId);
if (!$result) {
throw new Exception('Could not delete contact type');
public function membershipDelete($membershipID) {
$deleteParams = array('id' => $membershipID);
$result = $this->callAPISuccess('Membership', 'Delete', $deleteParams);
- return;
}
/**
return;
}
$result = $this->callAPISuccess('MembershipStatus', 'Delete', array('id' => $membershipStatusID));
- return;
}
/**
* @param array $params
* Array of contact id and event id values.
*
- * @return int $id of participant created
+ * @return int
+ * $id of participant created
*/
public function participantCreate($params) {
if (empty($params['contact_id'])) {
/**
* Create Payment Processor
*
- * @return object of Payment Processsor
+ * @return CRM_Financial_DAO_PaymentProcessor
+ * instance of Payment Processsor
*/
public function processorCreate() {
$processorParams = array(
* Create contribution page
*
* @param array $params
- * @return object of contribution page
+ * @return array
+ * Array of contribution page
*/
public function contributionPageCreate($params) {
$this->_pageParams = array(
* Create Tag
*
* @param array $params
- * @return array result of created tag
+ * @return array
+ * result of created tag
*/
public function tagCreate($params = array()) {
$defaults = array(
*
* @param int $tagId
* Id of the tag to be deleted.
+ *
+ * @return int
*/
public function tagDelete($tagId) {
require_once 'api/api.php';
* @param int $cID
* Contact_id.
*
- * @return int id of created contribution
+ * @return int
+ * id of created contribution
*/
public function pledgeCreate($cID) {
$params = array(
* Contact_id.
* @param int $cTypeID
* Id of financial type.
- *
* @param int $invoiceID
* @param int $trxnID
* @param int $paymentInstrumentID
* @param bool $isFee
- * @return int id of created contribution
+ *
+ * @return int
+ * id of created contribution
*/
public function contributionCreate($cID, $cTypeID = 1, $invoiceID = 67890, $trxnID = 12345, $paymentInstrumentID = 1, $isFee = TRUE) {
$params = array(
* @param array $params
* @param int $financialType
* Id of financial type.
- *
* @param int $invoiceID
* @param int $trxnID
- * @return int id of created contribution
+ *
+ * @return int
+ * id of created contribution
*/
public function onlineContributionCreate($params, $financialType, $invoiceID = 67890, $trxnID = 12345) {
$contribParams = array(
* @param array $params
* Name-value pair for an event.
*
- * @return array $event
+ * @return array
*/
public function eventCreate($params = array()) {
// if no contact was passed, make up a dummy event creator
*
* @param int $participantID
* @param int $contributionID
- * @return int $id of created payment
+ * @return int
+ * $id of created payment
*/
public function participantPaymentCreate($participantID, $contributionID = NULL) {
//Create Participant Payment record With Values
* Add a Location
*
* @param int $contactID
- * @return int location id of created location
+ * @return int
+ * location id of created location
*/
public function locationAdd($contactID) {
$address = array(
* Add a Location Type
*
* @param array $params
- * @return CRM_Core_DAO_LocationType location id of created location
+ * @return CRM_Core_DAO_LocationType
+ * location id of created location
*/
public function locationTypeCreate($params = NULL) {
if ($params === NULL) {
/**
* Delete a Location Type
*
- * @param int location type id
+ * @param int $locationTypeId
*/
public function locationTypeDelete($locationTypeId) {
$locationType = new CRM_Core_DAO_LocationType();
* Add a Group
*
* @param array $params
- * @return int groupId of created group
+ * @return int
+ * groupId of created group
*/
public function groupCreate($params = array()) {
$params = array_merge(array(
*
* @params array to add group
*
- * @param array $params
- * @return int groupId of created group
+ * @param int $groupID
+ * @param int $totalCount
+ * @return int
+ * groupId of created group
*/
public function groupContactCreate($groupID, $totalCount = 10) {
$params = array('group_id' => $groupID);
* Add a UF Join Entry
*
* @param array $params
- * @return int $id of created UF Join
+ * @return int
+ * $id of created UF Join
*/
public function ufjoinCreate($params = NULL) {
if ($params === NULL) {
/**
* Delete a UF Join Entry
*
- * @param array with missing uf_group_id
+ * @param array $params
+ * with missing uf_group_id
*/
public function ufjoinDelete($params = NULL) {
if ($params === NULL) {
*
* @param array $params
* Parameters.
+ * @return array
*/
public function activityTypeCreate($params) {
- $result = $this->callAPISuccess('ActivityType', 'create', $params);
- return $result;
+ return $this->callAPISuccess('ActivityType', 'create', $params);
}
/**
*
* @param int $activityTypeId
* Id of the activity type.
+ * @return array
*/
public function activityTypeDelete($activityTypeId) {
$params['activity_type_id'] = $activityTypeId;
- $result = $this->callAPISuccess('ActivityType', 'delete', $params);
- return $result;
+ return $this->callAPISuccess('ActivityType', 'delete', $params);
}
/**
//have a crack @ deleting it first in the hope this will prevent derailing our tests
$this->callAPISuccess('custom_group', 'get', array(
- 'title' => $params['title'],
- array('api.custom_group.delete' => 1),
- ));
+ 'title' => $params['title'],
+ array('api.custom_group.delete' => 1),
+ ));
return $this->callAPISuccess('custom_group', 'create', $params);
}
/**
* Existing function doesn't allow params to be over-ridden so need a new one
* this one allows you to only pass in the params you want to change
+ * @param array $params
+ * @return array|int
*/
public function CustomGroupCreateByParams($params = array()) {
$defaults = array(
/**
* Create custom group with multi fields
+ * @param array $params
+ * @return array|int
*/
public function CustomGroupMultipleCreateByParams($params = array()) {
$defaults = array(
/**
* Create custom group with multi fields
+ * @param array $params
+ * @return array
*/
public function CustomGroupMultipleCreateWithFields($params = array()) {
// also need to pass on $params['custom_field'] if not set but not in place yet
$ids['custom_group_id'] = $customGroup['id'];
$customField = $this->customFieldCreate(array(
- 'custom_group_id' => $ids['custom_group_id'],
- 'label' => 'field_1' . $ids['custom_group_id'],
- ));
+ 'custom_group_id' => $ids['custom_group_id'],
+ 'label' => 'field_1' . $ids['custom_group_id'],
+ ));
$ids['custom_field_id'][] = $customField['id'];
$customField = $this->customFieldCreate(array(
- 'custom_group_id' => $ids['custom_group_id'],
- 'default_value' => '',
- 'label' => 'field_2' . $ids['custom_group_id'],
- ));
+ 'custom_group_id' => $ids['custom_group_id'],
+ 'default_value' => '',
+ 'label' => 'field_2' . $ids['custom_group_id'],
+ ));
$ids['custom_field_id'][] = $customField['id'];
$customField = $this->customFieldCreate(array(
- 'custom_group_id' => $ids['custom_group_id'],
- 'default_value' => '',
- 'label' => 'field_3' . $ids['custom_group_id'],
- ));
+ 'custom_group_id' => $ids['custom_group_id'],
+ 'default_value' => '',
+ 'label' => 'field_3' . $ids['custom_group_id'],
+ ));
$ids['custom_field_id'][] = $customField['id'];
return $ids;
*
* @param string $function
* __FUNCTION__.
- * @param $filename
- * String $file __FILE__.
+ * @param string $filename
+ * $file __FILE__.
*
- * @return array $ids ids of created objects
+ * @return array
+ * ids of created objects
*/
public function entityCustomGroupWithSingleFieldCreate($function, $filename) {
$params = array('title' => $function);
*
* @param array $params
* (custom_group_id) is required.
- * @return array|int
+ * @return array
*/
public function customFieldCreate($params) {
$params = array_merge(array(
), $params);
$result = $this->callAPISuccess('custom_field', 'create', $params);
-
- if ($result['is_error'] == 0 && isset($result['id'])) {
- CRM_Core_BAO_CustomField::getTableColumnGroup($result['id'], 1);
- // force reset of enabled components to help grab custom fields
- CRM_Core_Component::getEnabledComponents(1);
- return $result;
- }
+ // these 2 functions are called with force to flush static caches
+ CRM_Core_BAO_CustomField::getTableColumnGroup($result['id'], 1);
+ CRM_Core_Component::getEnabledComponents(1);
+ return $result;
}
/**
* Create note
*
* @param int $cId
- * @return array $note
+ * @return array
*/
public function noteCreate($cId) {
$params = array(
* and debug related fields are unset
*
* @param array $result
- *
*/
public function tidyExampleResult(&$result) {
if (!is_array($result)) {
return TRUE;
}
}
+ return FALSE;
}
/**
* @param $tablesToTruncate
* @param bool $dropCustomValueTables
+ * @throws \Exception
*/
public function quickCleanup($tablesToTruncate, $dropCustomValueTables = FALSE) {
if ($this->tx) {
* Should the entity be deleted as part of this check.
* @param string $errorText
* Text to print on error.
- *
*/
/**
* @param array $params
* Actual calculated values.
* @param array $expected
* Expected values.
- *
*/
public function checkArrayEquals(&$actual, &$expected) {
self::unsetId($actual);
* Unset the key 'id' from the array
* @param array $unformattedArray
* The array from which the 'id' has to be unset.
- *
*/
public static function unsetId(&$unformattedArray) {
$formattedArray = array();
* Generate a temporary folder
*
* @param string $prefix
- * @return string $string
+ * @return string
*/
public function createTempDir($prefix = 'test-') {
$tempDir = CRM_Utils_File::tempdir($prefix);
/**
* Temporarily replace the singleton extension with a different one
+ * @param \CRM_Extension_System $system
*/
public function setExtensionSystem(CRM_Extension_System $system) {
if ($this->origExtensionSystem == NULL) {
* $this->createLoggedInUser();
* $this->_permissionedDisabledGroup = $this->groupCreate(array('title' => 'pick-me-disabled', 'is_active' => 0, 'name' => 'pick-me-disabled'));
* $this->_permissionedGroup = $this->groupCreate(array('title' => 'pick-me-active', 'is_active' => 1, 'name' => 'pick-me-active'));
- *
*/
public function setupACL() {
global $_REQUEST;
$contributionPriceSet = $this->callAPISuccess('price_set', 'getsingle', array('name' => 'default_contribution_amount'));
$firstID = $contributionPriceSet['id'];
$this->callAPISuccess('price_set', 'create', array(
- 'id' => $contributionPriceSet['id'],
- 'is_active' => 0,
- 'name' => 'old',
- ));
+ 'id' => $contributionPriceSet['id'],
+ 'is_active' => 0,
+ 'name' => 'old',
+ ));
unset($contributionPriceSet['id']);
$newPriceSet = $this->callAPISuccess('price_set', 'create', $contributionPriceSet);
$priceField = $this->callAPISuccess('price_field', 'getsingle', array(
- 'price_set_id' => $firstID,
- 'options' => array('limit' => 1),
- ));
+ 'price_set_id' => $firstID,
+ 'options' => array('limit' => 1),
+ ));
unset($priceField['id']);
$priceField['price_set_id'] = $newPriceSet['id'];
$newPriceField = $this->callAPISuccess('price_field', 'create', $priceField);
$priceFieldValue = $this->callAPISuccess('price_field_value', 'getsingle', array(
- 'price_set_id' => $firstID,
- 'sequential' => 1,
- 'options' => array('limit' => 1),
- ));
+ 'price_set_id' => $firstID,
+ 'sequential' => 1,
+ 'options' => array('limit' => 1),
+ ));
unset($priceFieldValue['id']);
//create some padding to use up ids
* 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
+ * @param array $params
+ * @return int $result['id'] payment processor id
*/
public function paymentProcessorCreate($params = array()) {
$params = array_merge(array(
'line_total' => 200,
'financial_type_id' => 1,
'price_field_id' => $this->callAPISuccess('price_field', 'getvalue', array(
- 'return' => 'id',
- 'label' => 'Membership Amount',
- )),
+ 'return' => 'id',
+ 'label' => 'Membership Amount',
+ )),
'price_field_value_id' => $this->callAPISuccess('price_field_value', 'getvalue', array(
- 'return' => 'id',
- 'label' => 'General',
- )),
+ 'return' => 'id',
+ 'label' => 'General',
+ )),
));
$this->callAPISuccess('membership_payment', 'create', array(
- 'contribution_id' => $this->_contributionID,
- 'membership_id' => $this->ids['membership'],
- ));
+ 'contribution_id' => $this->_contributionID,
+ 'membership_id' => $this->ids['membership'],
+ ));
}
/**
ob_end_clean();
}
}
+
}