* <http://www.gnu.org/licenses/>.
*/
+use Civi\Payment\System;
+
/**
* Include configuration
*/
*/
protected $_apiversion = API_LATEST_VERSION;
/**
- * Database has been initialized
+ * Database has been initialized.
*
* @var boolean
*/
private static $dbInit = FALSE;
/**
- * Database connection
+ * Database connection.
*
* @var PHPUnit_Extensions_Database_DB_IDatabaseConnection
*/
protected $_dbconn;
/**
- * The database name
+ * The database name.
*
* @var string
*/
static protected $_dbName;
/**
- * Track tables we have modified during a test
+ * Track tables we have modified during a test.
*/
protected $_tablesToTruncate = array();
protected $origExtensionSystem;
/**
- * Constructor
+ * Constructor.
*
* Because we are overriding the parent class constructor, we
* need to show the same arguments as exist in the constructor of
// 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();
}
/**
- * Create database connection for this instance
+ * Create database connection for this instance.
*
* Initialize the test database if it hasn't been initialized
*
}
/**
- * Required implementation of abstract method
+ * Required implementation of abstract method.
*/
protected function getDataSet() {
}
/**
* @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) {
}
/**
- * Common setup functions for all unit tests
+ * Common setup functions for all unit tests.
*/
protected function setUp() {
$session = CRM_Core_Session::singleton();
}
/**
- * Read everything from the datasets directory and insert into the db
+ * Read everything from the datasets directory and insert into the db.
*/
public function loadAllFixtures() {
$fixturesDir = __DIR__ . '/../../fixtures';
}
/**
- * Emulate a logged in user since certain functions use that
+ * Emulate a logged in user since certain functions use that.
* value to store a record in the DB (like activity)
* CRM-8180
*/
}
/**
- * Create default domain contacts for the two domains added during test class
+ * Create default domain contacts for the two domains added during test class.
* database population.
*/
public function createDomainContacts() {
}
/**
- * Common teardown functions for all unit tests
+ * Common teardown functions for all unit tests.
*/
protected function tearDown() {
error_reporting(E_ALL & ~E_NOTICE);
}
/**
- * Generic function to compare expected values after an api call to retrieved
+ * Generic function to compare expected values after an api call to retrieved.
* DB values.
*
* @daoName string DAO Name of object we're evaluating.
* @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
}
/**
- * Assert that a SQL query returns a given value
+ * Assert that a SQL query returns a given value.
*
* The first argument is an expected value. The remaining arguments are passed
* to CRM_Core_DAO::singleValueQuery
*
* 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) {
}
/**
- * Assert that two numbers are approximately equal
+ * Assert that two numbers are approximately equal.
*
* @param int|float $expected
* @param int|float $actual
}
/**
+ * Assert attributes are equal.
+ *
* @param $expectedValues
* @param $actualValues
- * @param null $message
+ * @param string $message
*
* @throws PHPUnit_Framework_AssertionFailedError
*/
}
/**
- * Check that api returned 'is_error' => 0
- * else provide full message
+ * Check that api returned 'is_error' => 0.
+ *
* @param array $apiResult
* Api result.
* @param string $prefix
}
/**
- * Check that api returned 'is_error' => 1
- * else provide full message
+ * Check that api returned 'is_error' => 1.
*
* @param array $apiResult
* Api result.
}
/**
- * Check that a deleted item has been deleted
+ * 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)) {
}
/**
- * This function exists to wrap api functions
+ * This function exists to wrap api functions.
* so we can ensure they succeed, generate and example & throw exceptions without litterering the test with checks
*
* @param string $entity
* @param string $file
* Pass this in to create a generated example.
* @param string $description
- * @param string|null $subfile
- * @param string|null $actionName
+ * @param string|null $exampleName
+ *
* @return array|int
*/
- public function callAPIAndDocument($entity, $action, $params, $function, $file, $description = "", $subfile = NULL, $actionName = NULL) {
+ public function callAPIAndDocument($entity, $action, $params, $function, $file, $description = "", $exampleName = NULL) {
$params['version'] = $this->_apiversion;
$result = $this->callAPISuccess($entity, $action, $params);
- $this->documentMe($params, $result, $function, $file, $description, $subfile, $actionName);
+ $this->documentMe($entity, $action, $params, $result, $function, $file, $description, $exampleName);
return $result;
}
/**
- * This function exists to wrap api functions
+ * This function exists to wrap api functions.
* so we can ensure they fail where expected & throw exceptions without litterering the test with checks
* @param string $entity
* @param string $action
* 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
+ * 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(
}
/**
- * Private helper function for calling civicrm_contact_add
+ * Private helper function for calling civicrm_contact_add.
*
* @param array $params
* For civicrm_contact_add api function call.
*
* @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');
}
/**
- * Delete Membership Type
+ * Delete Membership Type.
*
* @param array $params
*/
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;
}
/**
}
/**
- * Delete Relatinship Type
+ * Delete Relatinship Type.
*
* @param int $relationshipTypeID
*/
}
/**
- * Create Participant
+ * Create Participant.
*
* @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
+ * 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
+ * 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
+ * Create Tag.
*
* @param array $params
- * @return array result of created tag
+ * @return array
+ * result of created tag
*/
public function tagCreate($params = array()) {
$defaults = array(
}
/**
- * Delete Tag
+ * Delete Tag.
*
* @param int $tagId
* Id of the tag to be deleted.
+ *
+ * @return int
*/
public function tagDelete($tagId) {
require_once 'api/api.php';
}
/**
- * Create contribution
+ * Create contribution.
*
* @param int $cID
* Contact_id.
*
- * @return int id of created contribution
+ * @return int
+ * id of created contribution
*/
public function pledgeCreate($cID) {
$params = array(
}
/**
- * Delete contribution
+ * Delete contribution.
*
* @param int $pledgeId
*/
}
/**
- * Create contribution
+ * Create contribution.
*
* @param int $cID
* 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(
}
/**
- * Create online contribution
+ * 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
+ *
+ * @return int
+ * id of created contribution
*/
public function onlineContributionCreate($params, $financialType, $invoiceID = 67890, $trxnID = 12345) {
$contribParams = array(
}
/**
- * Delete contribution
+ * Delete contribution.
*
* @param int $contributionId
*
}
/**
- * Create an Event
+ * Create an Event.
*
* @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
}
/**
- * Delete event
+ * Delete event.
*
* @param int $id
* ID of the event.
}
/**
- * Delete participant
+ * Delete participant.
*
* @param int $participantID
*
}
/**
- * Create participant payment
+ * Create participant payment.
*
* @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
}
/**
- * Delete participant payment
+ * Delete participant payment.
*
* @param int $paymentID
*/
}
/**
- * Add a Location
+ * 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(
}
/**
- * Delete Locations of contact
+ * Delete Locations of contact.
*
* @param array $params
* Parameters.
}
/**
- * Add a Location Type
+ * 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
+ * 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
+ * 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(
/**
- * Function to add a Group
+ * Function to add a Group.
*
* @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);
}
/**
- * Delete a Group
+ * Delete a Group.
*
* @param int $gid
*/
}
/**
- * Create a UFField
+ * Create a UFField.
* @param array $params
*/
public function uFFieldCreate($params = array()) {
}
/**
- * Add a UF Join Entry
+ * 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
+ * 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) {
}
/**
- * Create Group for a contact
+ * Create Group for a contact.
*
* @param int $contactId
*/
}
/**
- * Delete Group for a contact
+ * Delete Group for a contact.
*
* @param int $contactId
*/
}
/**
- * Create Activity
+ * Create Activity.
*
* @param array $params
* @return array|int
}
/**
- * Create an activity type
+ * Create an activity type.
*
* @param array $params
* Parameters.
+ * @return array
*/
public function activityTypeCreate($params) {
- $result = $this->callAPISuccess('ActivityType', 'create', $params);
- return $result;
+ return $this->callAPISuccess('ActivityType', 'create', $params);
}
/**
- * Delete activity type
+ * Delete activity type.
*
* @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);
}
/**
- * Create custom group
+ * Create custom group.
*
* @param array $params
* @return array|int
//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
+ * 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
+ * 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);
}
/**
- * Delete custom group
+ * Delete custom group.
*
* @param int $customGroupID
*
}
/**
- * Create custom field
+ * Create custom field.
*
* @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;
}
/**
- * Delete custom field
+ * Delete custom field.
*
* @param int $customFieldID
*
}
/**
- * Create note
+ * Create note.
*
* @param int $cId
- * @return array $note
+ * @return array
*/
public function noteCreate($cId) {
$params = array(
}
/**
- * Enable CiviCampaign Component
+ * Enable CiviCampaign Component.
*/
public function enableCiviCampaign() {
CRM_Core_BAO_ConfigSetting::enableComponent('CiviCampaign');
/**
* Create test generated example in api/v3/examples.
+ *
* To turn this off (e.g. on the server) set
* define(DONT_DOCUMENT_TEST_CONFIG ,1);
* in your settings file
+ *
+ * @param string $entity
+ * @param string $action
* @param array $params
* Array as passed to civicrm_api function.
* @param array $result
* Array as received from the civicrm_api function.
- * @param string $function
+ * @param string $testFunction
* Calling function - generally __FUNCTION__.
- * @param string $filename
+ * @param string $testFile
* Called from file - generally __FILE__.
* @param string $description
* Descriptive text for the example file.
- * @param string $subfile
- * Name for subfile - if this is completed the example will be put in a subfolder (named by the entity).
- * @param string $action
- * Optional action - otherwise taken from function name.
+ * @param string $exampleName
+ * Name for this example file (CamelCase) - if ommitted the action name will be substituted.
*/
- public function documentMe($params, $result, $function, $filename, $description = "", $subfile = NULL, $action = NULL) {
+ private function documentMe($entity, $action, $params, $result, $testFunction, $testFile, $description = "", $exampleName = NULL) {
if (defined('DONT_DOCUMENT_TEST_CONFIG') && DONT_DOCUMENT_TEST_CONFIG) {
return;
}
- $entity = substr(basename($filename), 0, strlen(basename($filename)) - 8);
- //todo - this is a bit cludgey
- if (empty($action)) {
- if (strstr($function, 'Create')) {
- $action = empty($action) ? 'create' : $action;
- $entityAction = 'Create';
- }
- elseif (strstr($function, 'GetSingle')) {
- $action = empty($action) ? 'getsingle' : $action;
- $entityAction = 'GetSingle';
- }
- elseif (strstr($function, 'GetValue')) {
- $action = empty($action) ? 'getvalue' : $action;
- $entityAction = 'GetValue';
- }
- elseif (strstr($function, 'GetCount')) {
- $action = empty($action) ? 'getcount' : $action;
- $entityAction = 'GetCount';
- }
- elseif (strstr($function, 'GetFields')) {
- $action = empty($action) ? 'getfields' : $action;
- $entityAction = 'GetFields';
- }
- elseif (strstr($function, 'GetList')) {
- $action = empty($action) ? 'getlist' : $action;
- $entityAction = 'GetList';
- }
- elseif (strstr($function, 'GetActions')) {
- $action = empty($action) ? 'getactions' : $action;
- $entityAction = 'GetActions';
- }
- elseif (strstr($function, 'Get')) {
- $action = empty($action) ? 'get' : $action;
- $entityAction = 'Get';
- }
- elseif (strstr($function, 'Delete')) {
- $action = empty($action) ? 'delete' : $action;
- $entityAction = 'Delete';
- }
- elseif (strstr($function, 'Update')) {
- $action = empty($action) ? 'update' : $action;
- $entityAction = 'Update';
- }
- elseif (strstr($function, 'Subscribe')) {
- $action = empty($action) ? 'subscribe' : $action;
- $entityAction = 'Subscribe';
- }
- elseif (strstr($function, 'Submit')) {
- $action = empty($action) ? 'submit' : $action;
- $entityAction = 'Submit';
- }
- elseif (strstr($function, 'Apply')) {
- $action = empty($action) ? 'apply' : $action;
- $entityAction = 'Apply';
- }
- elseif (strstr($function, 'Replace')) {
- $action = empty($action) ? 'replace' : $action;
- $entityAction = 'Replace';
+ $entity = _civicrm_api_get_camel_name($entity);
+ $action = strtolower($action);
+
+ if (empty($exampleName)) {
+ // Attempt to convert lowercase action name to CamelCase.
+ // This is clunky/imperfect due to the convention of all lowercase actions.
+ $exampleName = CRM_Utils_String::convertStringToCamel($action);
+ $knownPrefixes = array(
+ 'Get',
+ 'Set',
+ 'Create',
+ 'Update',
+ 'Send',
+ );
+ foreach ($knownPrefixes as $prefix) {
+ if (strpos($exampleName, $prefix) === 0 && $prefix != $exampleName) {
+ $exampleName[strlen($prefix)] = strtoupper($exampleName[strlen($prefix)]);
+ }
}
}
- else {
- $entityAction = ucwords($action);
- }
$this->tidyExampleResult($result);
if (isset($params['version'])) {
unset($params['version']);
}
- // a cleverer person than me would do it in a single regex
- if (strstr($entity, 'UF')) {
- $fnPrefix = strtolower(preg_replace('/(?<! )(?<!^)(?<=UF)[A-Z]/', '_$0', $entity));
- }
- else {
- $fnPrefix = strtolower(preg_replace('/(?<! )(?<!^)[A-Z]/', '_$0', $entity));
+ // Format multiline description as array
+ $desc = array();
+ if (is_string($description) && strlen($description)) {
+ foreach (explode("\n", $description) as $line) {
+ $desc[] = trim($line);
+ }
}
$smarty = CRM_Core_Smarty::singleton();
- $smarty->assign('testfunction', $function);
- $function = $fnPrefix . "_" . strtolower($action);
- $smarty->assign('function', $function);
- $smarty->assign('fnPrefix', $fnPrefix);
+ $smarty->assign('testFunction', $testFunction);
+ $smarty->assign('function', _civicrm_api_get_entity_name_from_camel($entity) . "_$action");
$smarty->assign('params', $params);
$smarty->assign('entity', $entity);
- $smarty->assign('filename', basename($filename));
- $smarty->assign('description', $description);
+ $smarty->assign('testFile', basename($testFile));
+ $smarty->assign('description', $desc);
$smarty->assign('result', $result);
-
$smarty->assign('action', $action);
- if (empty($subfile)) {
- $subfile = $entityAction;
- }
+
if (file_exists('../tests/templates/documentFunction.tpl')) {
if (!is_dir("../api/v3/examples/$entity")) {
mkdir("../api/v3/examples/$entity");
}
- $f = fopen("../api/v3/examples/$entity/$subfile.php", "w+b");
+ $f = fopen("../api/v3/examples/$entity/$exampleName.php", "w+b");
fwrite($f, $smarty->fetch('../tests/templates/documentFunction.tpl'));
fclose($f);
}
* and debug related fields are unset
*
* @param array $result
- *
*/
public function tidyExampleResult(&$result) {
if (!is_array($result)) {
}
/**
- * Delete note
+ * Delete note.
*
* @param array $params
*
}
/**
- * Create custom field with Option Values
+ * Create custom field with Option Values.
*
* @param array $customGroup
* @param string $name
return TRUE;
}
}
+ return FALSE;
}
/**
* @param $tablesToTruncate
* @param bool $dropCustomValueTables
+ * @throws \Exception
*/
public function quickCleanup($tablesToTruncate, $dropCustomValueTables = FALSE) {
if ($this->tx) {
$this->restoreDefaultPriceSetConfig();
$var = TRUE;
CRM_Member_BAO_Membership::createRelatedMemberships($var, $var, TRUE);
+ Civi\Payment\System::singleton()->flushProcessors();
}
public function restoreDefaultPriceSetConfig() {
* Should the entity be deleted as part of this check.
* @param string $errorText
* Text to print on error.
- *
*/
/**
* @param array $params
}
/**
- * Get formatted values in the actual and expected result
+ * Get formatted values in the actual and expected result.
* @param array $actual
* 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
+ * 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
+ * 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
}
/**
- * Create an instance of the paypal processor
+ * 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
+ * @param array $params
+ * @return int $result['id'] payment processor id
*/
public function paymentProcessorCreate($params = array()) {
$params = array_merge(array(
}
/**
- * Set up initial recurring payment allowing subsequent IPN payments
+ * Set up initial recurring payment allowing subsequent IPN payments.
*/
public function setupRecurringPaymentProcessorTransaction() {
$contributionRecur = $this->callAPISuccess('contribution_recur', 'create', 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'],
+ ));
}
/**
}
/**
- * Helper function to create new mailing
+ * Helper function to create new mailing.
* @return mixed
*/
public function createMailing() {
$params = array(
'subject' => 'maild' . rand(),
- 'body_text' => 'bdkfhdskfhduew',
+ 'body_text' => 'bdkfhdskfhduew{domain.address}{action.optOutUrl}',
'name' => 'mailing name' . rand(),
'created_id' => 1,
- 'api.mailing_job.create' => 0,
);
$result = $this->callAPISuccess('Mailing', 'create', $params);
}
/**
- * Helper function to delete mailing
+ * Helper function to delete mailing.
* @param $id
*/
public function deleteMailing($id) {
}
/**
- * Wrap the entire test case in a transaction
+ * Wrap the entire test case in a transaction.
*
* Only subsequent DB statements will be wrapped in TX -- this cannot
* retroactively wrap old DB statements. Therefore, it makes sense to
ob_end_clean();
}
}
+
+ /**
+ * @param $exists
+ * @param array $apiResult
+ */
+ protected function assertAttachmentExistence($exists, $apiResult) {
+ $fileId = $apiResult['id'];
+ $this->assertTrue(is_numeric($fileId));
+ $this->assertEquals($exists, file_exists($apiResult['values'][$fileId]['path']));
+ $this->assertDBQuery($exists ? 1 : 0, 'SELECT count(*) FROM civicrm_file WHERE id = %1', array(
+ 1 => array($fileId, 'Int'),
+ ));
+ $this->assertDBQuery($exists ? 1 : 0, 'SELECT count(*) FROM civicrm_entity_file WHERE id = %1', array(
+ 1 => array($fileId, 'Int'),
+ ));
+ }
+
}