X-Git-Url: https://vcs.fsf.org/?a=blobdiff_plain;f=tests%2Fphpunit%2FCiviTest%2FCiviUnitTestCase.php;h=9be2eda3cd74d3f67f8bd14d44aa173624b76815;hb=4aef704e5b2cd4d3a740701530e6489bc31eeab2;hp=64680ad68246158cdcdab44f882729a95f20af1c;hpb=561b2d1b77687aba1342327a5363b9d4dfecc680;p=civicrm-core.git diff --git a/tests/phpunit/CiviTest/CiviUnitTestCase.php b/tests/phpunit/CiviTest/CiviUnitTestCase.php index 64680ad682..9be2eda3cd 100644 --- a/tests/phpunit/CiviTest/CiviUnitTestCase.php +++ b/tests/phpunit/CiviTest/CiviUnitTestCase.php @@ -58,7 +58,7 @@ define('API_LATEST_VERSION', 3); 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; /** @@ -166,10 +166,16 @@ class CiviUnitTestCase extends PHPUnit_Extensions_Database_TestCase { } } + /** + * @return bool + */ function requireDBReset() { return $this->DBResetRequired; } + /** + * @return string + */ static function getDBName() { $dbName = !empty($GLOBALS['mysql_db']) ? $GLOBALS['mysql_db'] : 'civicrm_tests_dev'; return $dbName; @@ -313,7 +319,7 @@ class CiviUnitTestCase extends PHPUnit_Extensions_Database_TestCase { $GLOBALS['_PEAR_ERRORSTACK_OVERRIDE_CALLBACK'] = array(); $env = new CRM_Utils_Check_Env(); - CRM_Utils_Check::singleton()->assertValid($env->checkAll()); + CRM_Utils_Check::singleton()->assertValid($env->checkMysqlTime()); } /** @@ -371,6 +377,7 @@ class CiviUnitTestCase extends PHPUnit_Extensions_Database_TestCase { else { error_reporting(E_ALL & ~E_NOTICE); } + $this->_sethtmlGlobals(); } /** @@ -515,6 +522,16 @@ class CiviUnitTestCase extends PHPUnit_Extensions_Database_TestCase { } // Request a record from the DB by seachColumn+searchValue. Success if a record is found. + /** + * @param $daoName + * @param $searchValue + * @param $returnColumn + * @param $searchColumn + * @param $message + * + * @return null|string + * @throws PHPUnit_Framework_AssertionFailedError + */ function assertDBNotNull($daoName, $searchValue, $returnColumn, $searchColumn, $message) { if (empty($searchValue)) { $this->fail("empty value passed to assertDBNotNull"); @@ -526,12 +543,24 @@ class CiviUnitTestCase extends PHPUnit_Extensions_Database_TestCase { } // Request a record from the DB by seachColumn+searchValue. Success if returnColumn value is NULL. + /** + * @param $daoName + * @param $searchValue + * @param $returnColumn + * @param $searchColumn + * @param $message + */ function assertDBNull($daoName, $searchValue, $returnColumn, $searchColumn, $message) { $value = CRM_Core_DAO::getFieldValue($daoName, $searchValue, $returnColumn, $searchColumn, TRUE); $this->assertNull($value, $message); } // Request a record from the DB by id. Success if row not found. + /** + * @param $daoName + * @param $id + * @param null $message + */ function assertDBRowNotExist($daoName, $id, $message = NULL) { $message = $message ? $message : "$daoName (#$id) should not exist"; $value = CRM_Core_DAO::getFieldValue($daoName, $id, 'id', 'id', TRUE); @@ -539,6 +568,11 @@ class CiviUnitTestCase extends PHPUnit_Extensions_Database_TestCase { } // Request a record from the DB by id. Success if row not found. + /** + * @param $daoName + * @param $id + * @param null $message + */ function assertDBRowExist($daoName, $id, $message = NULL) { $message = $message ? $message : "$daoName (#$id) should exist"; $value = CRM_Core_DAO::getFieldValue($daoName, $id, 'id', 'id', TRUE); @@ -546,6 +580,14 @@ class CiviUnitTestCase extends PHPUnit_Extensions_Database_TestCase { } // Compare a single column value in a retrieved DB record to an expected value + /** + * @param $daoName + * @param $searchValue + * @param $returnColumn + * @param $searchColumn + * @param $expectedValue + * @param $message + */ function assertDBCompareValue($daoName, $searchValue, $returnColumn, $searchColumn, $expectedValue, $message ) { @@ -554,6 +596,11 @@ class CiviUnitTestCase extends PHPUnit_Extensions_Database_TestCase { } // Compare all values in a single retrieved DB record to an array of expected values + /** + * @param $daoName + * @param $searchParams + * @param $expectedValues + */ function assertDBCompareValues($daoName, $searchParams, $expectedValues) { //get the values from db $dbValues = array(); @@ -614,6 +661,13 @@ class CiviUnitTestCase extends PHPUnit_Extensions_Database_TestCase { $this->assertTrue(abs($actual - $expected) < $tolerance, $message); } + /** + * @param $expectedValues + * @param $actualValues + * @param null $message + * + * @throws PHPUnit_Framework_AssertionFailedError + */ function assertAttributesEquals($expectedValues, $actualValues, $message = NULL) { foreach ($expectedValues as $paramName => $paramValue) { if (isset($actualValues[$paramName])) { @@ -625,6 +679,10 @@ class CiviUnitTestCase extends PHPUnit_Extensions_Database_TestCase { } } + /** + * @param $key + * @param $list + */ function assertArrayKeyExists($key, &$list) { $result = isset($list[$key]) ? TRUE : FALSE; $this->assertTrue($result, ts("%1 element exists?", @@ -632,6 +690,10 @@ class CiviUnitTestCase extends PHPUnit_Extensions_Database_TestCase { )); } + /** + * @param $key + * @param $list + */ function assertArrayValueNotNull($key, &$list) { $this->assertArrayKeyExists($key, $list); @@ -667,8 +729,10 @@ class CiviUnitTestCase extends PHPUnit_Extensions_Database_TestCase { /** * check that api returned 'is_error' => 1 * else provide full message + * * @param array $apiResult api result * @param string $prefix extra test to add to message + * @param null $expectedError */ function assertAPIFailure($apiResult, $prefix = '', $expectedError = NULL) { if (!empty($prefix)) { @@ -681,6 +745,11 @@ class CiviUnitTestCase extends PHPUnit_Extensions_Database_TestCase { $this->assertNotEmpty($apiResult['error_message']); } + /** + * @param $expected + * @param $actual + * @param string $message + */ function assertType($expected, $actual, $message = '') { return $this->assertInternalType($expected, $actual, $message); } @@ -696,8 +765,11 @@ class CiviUnitTestCase extends PHPUnit_Extensions_Database_TestCase { /** * check that api returned 'is_error' => 1 * else provide full message - * @param array $apiResult api result + * @param $result + * @param $expected + * @param array $valuesToExclude * @param string $prefix extra test to add to message + * @internal param array $apiResult api result */ function assertAPIArrayComparison($result, $expected, $valuesToExclude = array(), $prefix = '') { $valuesToExclude = array_merge($valuesToExclude, array('debug', 'xdebug', 'sequential')); @@ -727,6 +799,7 @@ class CiviUnitTestCase extends PHPUnit_Extensions_Database_TestCase { /** * This function exists to wrap api functions * so we can ensure they succeed & throw exceptions without litterering the test with checks + * * @param string $entity * @param string $action * @param array $params @@ -734,6 +807,8 @@ class CiviUnitTestCase extends PHPUnit_Extensions_Database_TestCase { * getcount, getsingle. Note that for getvalue the type is checked rather than the value * for getsingle the array is compared against an array passed in - the id is not compared (for * better or worse ) + * + * @return array|int */ function callAPISuccess($entity, $action, $params, $checkAgainst = NULL) { $params = array_merge(array( @@ -759,6 +834,7 @@ class CiviUnitTestCase extends PHPUnit_Extensions_Database_TestCase { * This function exists to wrap api getValue function & check the result * so we can ensure they succeed & throw exceptions without litterering the test with checks * There is a type check in this + * * @param string $entity * @param array $params * @param string $type - per http://php.net/manual/en/function.gettype.php possible types @@ -768,6 +844,8 @@ class CiviUnitTestCase extends PHPUnit_Extensions_Database_TestCase { * - string * - array * - object + * + * @return array|int */ function callAPISuccessGetValue($entity, $params, $type = NULL) { $params += array( @@ -790,6 +868,7 @@ class CiviUnitTestCase extends PHPUnit_Extensions_Database_TestCase { /** * This function exists to wrap api getsingle function & check the result * so we can ensure they succeed & throw exceptions without litterering the test with checks + * * @param string $entity * @param array $params * @param array $checkAgainst - array to compare result against @@ -799,6 +878,9 @@ class CiviUnitTestCase extends PHPUnit_Extensions_Database_TestCase { * - string * - array * - object + * + * @throws Exception + * @return array|int */ function callAPISuccessGetSingle($entity, $params, $checkAgainst = NULL) { $params += array( @@ -815,13 +897,17 @@ class CiviUnitTestCase extends PHPUnit_Extensions_Database_TestCase { } return $result; } + /** * This function exists to wrap api getValue function & check the result * so we can ensure they succeed & throw exceptions without litterering the test with checks * There is a type check in this * @param string $entity * @param array $params - * @param string $type - per http://php.net/manual/en/function.gettype.php possible types + * @param null $count + * @throws Exception + * @return array|int + * @internal param string $type - per http://php.net/manual/en/function.gettype.php possible types * - boolean * - integer * - double @@ -872,6 +958,8 @@ class CiviUnitTestCase extends PHPUnit_Extensions_Database_TestCase { * @param string $action * @param array $params * @param string $expectedErrorMessage error + * @param null $extraOutput + * @return array|int */ function callAPIFailure($entity, $action, $params, $expectedErrorMessage = NULL, $extraOutput = NULL) { if (is_array($params)) { @@ -900,38 +988,28 @@ class CiviUnitTestCase extends PHPUnit_Extensions_Database_TestCase { * 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); } @@ -939,17 +1017,53 @@ class CiviUnitTestCase extends PHPUnit_Extensions_Database_TestCase { * 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 * @@ -968,6 +1082,11 @@ class CiviUnitTestCase extends PHPUnit_Extensions_Database_TestCase { return $result['id']; } + /** + * @param $contactID + * + * @return array|int + */ function contactDelete($contactID) { $params = array( 'id' => $contactID, @@ -985,6 +1104,11 @@ class CiviUnitTestCase extends PHPUnit_Extensions_Database_TestCase { return $result; } + /** + * @param $contactTypeId + * + * @throws Exception + */ function contactTypeDelete($contactTypeId) { require_once 'CRM/Contact/BAO/ContactType.php'; $result = CRM_Contact_BAO_ContactType::del($contactTypeId); @@ -993,6 +1117,11 @@ class CiviUnitTestCase extends PHPUnit_Extensions_Database_TestCase { } } + /** + * @param array $params + * + * @return mixed + */ function membershipTypeCreate($params = array()) { CRM_Member_PseudoConstant::flush('membershipType'); CRM_Core_Config::clearDBCache(); @@ -1007,7 +1136,7 @@ class CiviUnitTestCase extends PHPUnit_Extensions_Database_TestCase { 'financial_type_id' => 1, 'is_active' => 1, 'sequential' => 1, - 'visibility' => 1, + 'visibility' => 'Public', ), $params); $result = $this->callAPISuccess('MembershipType', 'Create', $params); @@ -1018,6 +1147,11 @@ class CiviUnitTestCase extends PHPUnit_Extensions_Database_TestCase { return $result['id']; } + /** + * @param $params + * + * @return mixed + */ function contactMembershipCreate($params) { $pre = array( 'join_date' => '2007-01-21', @@ -1039,19 +1173,27 @@ class CiviUnitTestCase extends PHPUnit_Extensions_Database_TestCase { /** * Function to delete Membership Type * - * @param int $membershipTypeID + * @param $params + * @internal param int $membershipTypeID */ function membershipTypeDelete($params) { - $result = $this->callAPISuccess('MembershipType', 'Delete', $params); - return; + $this->callAPISuccess('MembershipType', 'Delete', $params); } + /** + * @param $membershipID + */ function membershipDelete($membershipID) { $deleteParams = array('id' => $membershipID); $result = $this->callAPISuccess('Membership', 'Delete', $deleteParams); return; } + /** + * @param string $name + * + * @return mixed + */ function membershipStatusCreate($name = 'test member status') { $params['name'] = $name; $params['start_event'] = 'start_date'; @@ -1064,6 +1206,9 @@ class CiviUnitTestCase extends PHPUnit_Extensions_Database_TestCase { return $result['id']; } + /** + * @param $membershipStatusID + */ function membershipStatusDelete($membershipStatusID) { if (!$membershipStatusID) { return; @@ -1072,6 +1217,11 @@ class CiviUnitTestCase extends PHPUnit_Extensions_Database_TestCase { return; } + /** + * @param array $params + * + * @return mixed + */ function relationshipTypeCreate($params = array()) { $params = array_merge(array( 'name_a_b' => 'Relation 1 for relationship type create', @@ -1100,6 +1250,11 @@ class CiviUnitTestCase extends PHPUnit_Extensions_Database_TestCase { $this->callAPISuccess('relationship_type', 'delete', $params); } + /** + * @param null $params + * + * @return mixed + */ function paymentProcessorTypeCreate($params = NULL) { if (is_null($params)) { $params = array( @@ -1172,6 +1327,7 @@ class CiviUnitTestCase extends PHPUnit_Extensions_Database_TestCase { /** * Function to create contribution page * + * @param $params * @return object of contribution page */ function contributionPageCreate($params) { @@ -1193,6 +1349,7 @@ class CiviUnitTestCase extends PHPUnit_Extensions_Database_TestCase { /** * Function to create Tag * + * @param array $params * @return array result of created tag */ function tagCreate($params = array()) { @@ -1223,7 +1380,9 @@ class CiviUnitTestCase extends PHPUnit_Extensions_Database_TestCase { /** * Add entity(s) to the tag * - * @param array $params + * @param array $params + * + * @return bool */ function entityTagAdd($params) { $result = $this->callAPISuccess('entity_tag', 'create', $params); @@ -1233,8 +1392,9 @@ class CiviUnitTestCase extends PHPUnit_Extensions_Database_TestCase { /** * Function to create contribution * - * @param int $cID contact_id - * @param int $cTypeID id of financial type + * @param int $cID contact_id + * + * @internal param int $cTypeID id of financial type * * @return int id of created contribution */ @@ -1261,7 +1421,8 @@ class CiviUnitTestCase extends PHPUnit_Extensions_Database_TestCase { /** * Function to delete contribution * - * @param int $contributionId + * @param $pledgeId + * @internal param int $contributionId */ function pledgeDelete($pledgeId) { $params = array( @@ -1273,9 +1434,13 @@ class CiviUnitTestCase extends PHPUnit_Extensions_Database_TestCase { /** * Function to create contribution * - * @param int $cID contact_id - * @param int $cTypeID id of financial type + * @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 */ function contributionCreate($cID, $cTypeID = 1, $invoiceID = 67890, $trxnID = 12345, $paymentInstrumentID = 1, $isFee = TRUE) { @@ -1306,8 +1471,11 @@ class CiviUnitTestCase extends PHPUnit_Extensions_Database_TestCase { /** * Function to create online contribution * - * @param int $financialType id of financial type + * @param $params + * @param int $financialType id of financial type * + * @param int $invoiceID + * @param int $trxnID * @return int id of created contribution */ function onlineContributionCreate($params, $financialType, $invoiceID = 67890, $trxnID = 12345) { @@ -1331,6 +1499,8 @@ class CiviUnitTestCase extends PHPUnit_Extensions_Database_TestCase { * Function to delete contribution * * @param int $contributionId + * + * @return array|int */ function contributionDelete($contributionId) { $params = array( @@ -1382,7 +1552,9 @@ class CiviUnitTestCase extends PHPUnit_Extensions_Database_TestCase { /** * Function to delete event * - * @param int $id ID of the event + * @param int $id ID of the event + * + * @return array|int */ function eventDelete($id) { $params = array( @@ -1395,6 +1567,8 @@ class CiviUnitTestCase extends PHPUnit_Extensions_Database_TestCase { * Function to delete participant * * @param int $participantID + * + * @return array|int */ function participantDelete($participantID) { $params = array( @@ -1406,6 +1580,8 @@ class CiviUnitTestCase extends PHPUnit_Extensions_Database_TestCase { /** * Function to create participant payment * + * @param $participantID + * @param null $contributionID * @return int $id of created payment */ function participantPaymentCreate($participantID, $contributionID = NULL) { @@ -1434,6 +1610,7 @@ class CiviUnitTestCase extends PHPUnit_Extensions_Database_TestCase { /** * Function to add a Location * + * @param $contactID * @return int location id of created location */ function locationAdd($contactID) { @@ -1473,6 +1650,7 @@ class CiviUnitTestCase extends PHPUnit_Extensions_Database_TestCase { /** * Function to add a Location Type * + * @param null $params * @return int location id of created location */ function locationTypeCreate($params = NULL) { @@ -1510,8 +1688,8 @@ class CiviUnitTestCase extends PHPUnit_Extensions_Database_TestCase { * * @params array to add group * + * @param array $params * @return int groupId of created group - * */ function groupCreate($params = array()) { $params = array_merge(array( @@ -1534,7 +1712,8 @@ class CiviUnitTestCase extends PHPUnit_Extensions_Database_TestCase { /** * Function to delete a Group * - * @param int $id + * @param $gid + * @internal param int $id */ function groupDelete($gid) { @@ -1563,9 +1742,11 @@ class CiviUnitTestCase extends PHPUnit_Extensions_Database_TestCase { ), $params); $this->callAPISuccess('uf_field', 'create', $params); } + /** * Function to add a UF Join Entry * + * @param null $params * @return int $id of created UF Join */ function ufjoinCreate($params = NULL) { @@ -1620,7 +1801,8 @@ class CiviUnitTestCase extends PHPUnit_Extensions_Database_TestCase { /** * Function to delete Group for a contact * - * @param array $params + * @param $contactId + * @internal param array $params */ function contactGroupDelete($contactId) { $params = array( @@ -1633,7 +1815,9 @@ class CiviUnitTestCase extends PHPUnit_Extensions_Database_TestCase { /** * Function to create Activity * - * @param int $contactId + * @param null $params + * @return array|int + * @internal param int $contactId */ function activityCreate($params = NULL) { @@ -1696,8 +1880,10 @@ class CiviUnitTestCase extends PHPUnit_Extensions_Database_TestCase { /** * Function to create custom group * - * @param string $className - * @param string $title name of custom group + * @param array $params + * @return array|int + * @internal param string $className + * @internal param string $title name of custom group */ function customGroupCreate($params = array()) { $defaults = array( @@ -1775,10 +1961,10 @@ class CiviUnitTestCase extends PHPUnit_Extensions_Database_TestCase { * participant:testCreateWithCustom for how to use this * * @param string $function __FUNCTION__ - * @param string $file __FILE__ + * @param $filename + * @internal param string $file __FILE__ * * @return array $ids ids of created objects - * */ function entityCustomGroupWithSingleFieldCreate($function, $filename) { $params = array('title' => $function); @@ -1794,7 +1980,9 @@ class CiviUnitTestCase extends PHPUnit_Extensions_Database_TestCase { /** * Function to delete custom group * - * @param int $customGroupID + * @param int $customGroupID + * + * @return array|int */ function customGroupDelete($customGroupID) { $params['id'] = $customGroupID; @@ -1805,8 +1993,9 @@ class CiviUnitTestCase extends PHPUnit_Extensions_Database_TestCase { * Function to create custom field * * @param array $params (custom_group_id) is required - * @param string $name name of custom field - * @param int $apiversion API version to use + * @return array|int + * @internal param string $name name of custom field + * @internal param int $apiversion API version to use */ function customFieldCreate($params) { $params = array_merge(array( @@ -1832,6 +2021,8 @@ class CiviUnitTestCase extends PHPUnit_Extensions_Database_TestCase { * Function to delete custom field * * @param int $customFieldID + * + * @return array|int */ function customFieldDelete($customFieldID) { @@ -1844,6 +2035,7 @@ class CiviUnitTestCase extends PHPUnit_Extensions_Database_TestCase { * * @params array $params name-value pair for an event * + * @param $cId * @return array $note */ function noteCreate($cId) { @@ -1986,7 +2178,10 @@ class CiviUnitTestCase extends PHPUnit_Extensions_Database_TestCase { /** * Tidy up examples array so that fields that change often ..don't * and debug related fields are unset - * @param array $params + * + * @param $result + * + * @internal param array $params */ function tidyExampleResult(&$result){ if(!is_array($result)) { @@ -2072,8 +2267,10 @@ class CiviUnitTestCase extends PHPUnit_Extensions_Database_TestCase { /** * Function to create custom field with Option Values * - * @param array $customGroup - * @param string $name name of custom field + * @param array $customGroup + * @param string $name name of custom field + * + * @return array|int */ function customFieldOptionValueCreate($customGroup, $name) { $fieldParams = array( @@ -2107,6 +2304,11 @@ class CiviUnitTestCase extends PHPUnit_Extensions_Database_TestCase { return $this->callAPISuccess('custom_field', 'create', $params); } + /** + * @param $entities + * + * @return bool + */ function confirmEntitiesDeleted($entities) { foreach ($entities as $entity) { @@ -2118,6 +2320,10 @@ class CiviUnitTestCase extends PHPUnit_Extensions_Database_TestCase { } } + /** + * @param $tablesToTruncate + * @param bool $dropCustomValueTables + */ function quickCleanup($tablesToTruncate, $dropCustomValueTables = FALSE) { if ($dropCustomValueTables) { $tablesToTruncate[] = 'civicrm_custom_group'; @@ -2165,13 +2371,16 @@ AND ( TABLE_NAME LIKE 'civicrm_value_%' ) 'civicrm_membership', 'civicrm_membership_type', 'civicrm_membership_payment', - 'civicrm_membership_status', + 'civicrm_membership_log', + '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 @@ -2183,6 +2392,15 @@ AND ( TABLE_NAME LIKE 'civicrm_value_%' ) * @param string $errorText text to print on error * */ + /** + * @param $params + * @param $id + * @param $entity + * @param int $delete + * @param string $errorText + * + * @throws Exception + */ function getAndCheck($params, $id, $entity, $delete = 1, $errorText = '') { $result = $this->callAPISuccessGetSingle($entity, array( @@ -2319,7 +2537,8 @@ AND ( TABLE_NAME LIKE 'civicrm_value_%' ) /** * Generate a temporary folder * - * @return $string + * @param string $prefix + * @return string $string */ function createTempDir($prefix = 'test-') { $tempDir = CRM_Utils_File::tempdir($prefix); @@ -2380,6 +2599,9 @@ AND ( TABLE_NAME LIKE 'civicrm_value_%' ) } } + /** + * @param $name + */ function financialAccountDelete($name) { $financialAccount = new CRM_Financial_DAO_FinancialAccount(); $financialAccount->name = $name; @@ -2585,6 +2807,8 @@ AND ( TABLE_NAME LIKE 'civicrm_value_%' ) * */ function setupACL() { + global $_REQUEST; + $_REQUEST = $this->_params; CRM_Core_Config::singleton()->userPermissionClass->permissions = array('access CiviCRM'); $optionGroupID = $this->callAPISuccessGetValue('option_group', array('return' => 'id', 'name' => 'acl_role')); $optionValue = $this->callAPISuccess('option_value', 'create', array('option_group_id' => $optionGroupID, @@ -2632,49 +2856,105 @@ AND ( TABLE_NAME LIKE 'civicrm_value_%' ) )); //flush cache CRM_ACL_BAO_Cache::resetCache(); - CRM_ACL_API::groupPermission('whatever', 9999, NULL, 'civicrm_saved_search', NULL, NULL, TRUE); + CRM_Contact_BAO_Group::getPermissionClause(TRUE); + CRM_ACL_API::groupPermission('whatever', 9999, NULL, 'civicrm_saved_search', NULL, NULL, TRUE); } -/** - * 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']; - } - - -function CiviUnitTestCase_fatalErrorHandler($message) { - throw new Exception("{$message['message']}: {$message['code']}"); -} + /** + * alter default price set so that the field numbers are not all 1 (hiding errors) + */ + function offsetDefaultPriceSet() { + $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')); + 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))); + 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))); + + unset($priceFieldValue['id']); + //create some padding to use up ids + $this->callAPISuccess('price_field_value', 'create', $priceFieldValue); + $this->callAPISuccess('price_field_value', 'create', $priceFieldValue); + $this->callAPISuccess('price_field_value', 'create', array_merge($priceFieldValue, array('price_field_id' => $newPriceField['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']}"); + } + + /** + * 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); + } }