From 5896d037d1e8eac7cc88adc80923ada36fdfb5fd Mon Sep 17 00:00:00 2001 From: Tim Otten Date: Tue, 6 Jan 2015 13:49:54 -0800 Subject: [PATCH] INFRA-132 - tests/ - Misc --- tests/phpunit/CiviTest/CiviDBAssert.php | 3 +- .../phpunit/CiviTest/CiviSeleniumTestCase.php | 116 +++--- tests/phpunit/CiviTest/CiviTestSuite.php | 5 +- tests/phpunit/CiviTest/CiviUnitTestCase.php | 234 ++++++----- .../WebTest/Event/MultiprofileEventTest.php | 5 +- .../Import/ImportCiviSeleniumTestCase.php | 3 +- tests/phpunit/api/v3/ACLCachingTest.php | 2 +- tests/phpunit/api/v3/ACLPermissionTest.php | 17 +- tests/phpunit/api/v3/ActivityContactTest.php | 6 +- tests/phpunit/api/v3/AddressTest.php | 46 ++- tests/phpunit/api/v3/ContactTest.php | 287 ++++++++----- tests/phpunit/api/v3/ContributionPageTest.php | 64 ++- tests/phpunit/api/v3/ContributionTest.php | 389 ++++++++++-------- tests/phpunit/api/v3/DomainTest.php | 46 +-- tests/phpunit/api/v3/EmailTest.php | 51 +-- tests/phpunit/api/v3/JobTest.php | 70 ++-- tests/phpunit/api/v3/LineItemTest.php | 3 +- tests/phpunit/api/v3/MembershipTest.php | 61 ++- tests/phpunit/api/v3/OptionValueTest.php | 84 ++-- tests/phpunit/api/v3/PhoneTest.php | 11 +- tests/phpunit/api/v3/RelationshipTest.php | 148 ++++--- tests/phpunit/api/v3/SettingTest.php | 53 +-- 22 files changed, 1016 insertions(+), 688 deletions(-) diff --git a/tests/phpunit/CiviTest/CiviDBAssert.php b/tests/phpunit/CiviTest/CiviDBAssert.php index 0c7575ec52..f521833089 100644 --- a/tests/phpunit/CiviTest/CiviDBAssert.php +++ b/tests/phpunit/CiviTest/CiviDBAssert.php @@ -128,7 +128,8 @@ class CiviDBAssert { * @param $expectedValue * @param string $message */ - function assertDBCompareValue(&$testCase, $daoName, $searchValue, $returnColumn, $searchColumn, + function assertDBCompareValue( + &$testCase, $daoName, $searchValue, $returnColumn, $searchColumn, $expectedValue, $message ) { $value = CRM_Core_DAO::getFieldValue($daoName, $searchValue, $returnColumn, $searchColumn); diff --git a/tests/phpunit/CiviTest/CiviSeleniumTestCase.php b/tests/phpunit/CiviTest/CiviSeleniumTestCase.php index e761cb2e94..f7b70cb2b3 100644 --- a/tests/phpunit/CiviTest/CiviSeleniumTestCase.php +++ b/tests/phpunit/CiviTest/CiviSeleniumTestCase.php @@ -152,8 +152,8 @@ class CiviSeleniumTestCase extends PHPUnit_Extensions_SeleniumTestCase { /** * Authenticate as drupal user - * @param $user: (str) the key 'user' or 'admin', or a literal username - * @param $pass: (str) if $user is a literal username and not 'user' or 'admin', supply the password + * @param $user : (str) the key 'user' or 'admin', or a literal username + * @param $pass : (str) if $user is a literal username and not 'user' or 'admin', supply the password */ public function webtestLogin($user = 'user', $pass = NULL) { // If already logged in as correct user, do nothing @@ -667,7 +667,7 @@ class CiviSeleniumTestCase extends PHPUnit_Extensions_SeleniumTestCase { else { $params[strtolower($contactType) . '_name'] = "$name $contactType"; } - foreach($params as $param => $val) { + foreach ($params as $param => $val) { $this->type($param, $val); } $this->type('email-Primary', $params['email'] = "{$name}@example.com"); @@ -684,8 +684,9 @@ class CiviSeleniumTestCase extends PHPUnit_Extensions_SeleniumTestCase { /** * @deprecated in favor of createDialogContact */ - function webtestNewDialogContact($fname = 'Anthony', $lname = 'Anderson', $email = 'anthony@anderson.biz', - $type = 4, $selectId = 's2id_contact_id', $row = 1, $prefix = '') { + function webtestNewDialogContact( + $fname = 'Anthony', $lname = 'Anderson', $email = 'anthony@anderson.biz', + $type = 4, $selectId = 's2id_contact_id', $row = 1, $prefix = '') { // 4 - Individual profile // 5 - Organization profile // 6 - Household profile @@ -1037,32 +1038,33 @@ class CiviSeleniumTestCase extends PHPUnit_Extensions_SeleniumTestCase { * * @return null $pageId of newly created online contribution page. */ - function webtestAddContributionPage($hash = NULL, - $rand = NULL, - $pageTitle = NULL, - $processor = array('Test Processor' => 'Dummy'), - $amountSection = TRUE, - $payLater = TRUE, - $onBehalf = TRUE, - $pledges = TRUE, - $recurring = FALSE, - $membershipTypes = TRUE, - $memPriceSetId = NULL, - $friend = TRUE, - $profilePreId = 1, - $profilePostId = 7, - $premiums = TRUE, - $widget = TRUE, - $pcp = TRUE, - $isAddPaymentProcessor = TRUE, - $isPcpApprovalNeeded = FALSE, - $isSeparatePayment = FALSE, - $honoreeSection = TRUE, - $allowOtherAmount = TRUE, - $isConfirmEnabled = TRUE, - $financialType = 'Donation', - $fixedAmount = TRUE, - $membershipsRequired = TRUE + function webtestAddContributionPage( + $hash = NULL, + $rand = NULL, + $pageTitle = NULL, + $processor = array('Test Processor' => 'Dummy'), + $amountSection = TRUE, + $payLater = TRUE, + $onBehalf = TRUE, + $pledges = TRUE, + $recurring = FALSE, + $membershipTypes = TRUE, + $memPriceSetId = NULL, + $friend = TRUE, + $profilePreId = 1, + $profilePostId = 7, + $premiums = TRUE, + $widget = TRUE, + $pcp = TRUE, + $isAddPaymentProcessor = TRUE, + $isPcpApprovalNeeded = FALSE, + $isSeparatePayment = FALSE, + $honoreeSection = TRUE, + $allowOtherAmount = TRUE, + $isConfirmEnabled = TRUE, + $financialType = 'Donation', + $fixedAmount = TRUE, + $membershipsRequired = TRUE ) { if (!$hash) { $hash = substr(sha1(rand()), 0, 7); @@ -1682,8 +1684,9 @@ class CiviSeleniumTestCase extends PHPUnit_Extensions_SeleniumTestCase { * @param $expectedValue * @param string $message */ - function assertDBCompareValue($daoName, $searchValue, $returnColumn, $searchColumn, - $expectedValue, $message + function assertDBCompareValue( + $daoName, $searchValue, $returnColumn, $searchColumn, + $expectedValue, $message ) { if (!self::checkDoLocalDBTest()) { return; @@ -1732,16 +1735,17 @@ class CiviSeleniumTestCase extends PHPUnit_Extensions_SeleniumTestCase { /** * Add new Financial Account */ - function _testAddFinancialAccount($financialAccountTitle, - $financialAccountDescription = FALSE, - $accountingCode = FALSE, - $firstName = FALSE, - $financialAccountType = FALSE, - $taxDeductible = FALSE, - $isActive = FALSE, - $isTax = FALSE, - $taxRate = FALSE, - $isDefault = FALSE + function _testAddFinancialAccount( + $financialAccountTitle, + $financialAccountDescription = FALSE, + $accountingCode = FALSE, + $firstName = FALSE, + $financialAccountType = FALSE, + $taxDeductible = FALSE, + $isActive = FALSE, + $isTax = FALSE, + $taxRate = FALSE, + $isDefault = FALSE ) { $this->openCiviPage("admin/financial/financialAccount", "reset=1"); @@ -1811,7 +1815,8 @@ class CiviSeleniumTestCase extends PHPUnit_Extensions_SeleniumTestCase { /** * Edit Financial Account */ - function _testEditFinancialAccount($editfinancialAccount, + function _testEditFinancialAccount( + $editfinancialAccount, $financialAccountTitle = FALSE, $financialAccountDescription = FALSE, $accountingCode = FALSE, @@ -2096,11 +2101,11 @@ class CiviSeleniumTestCase extends PHPUnit_Extensions_SeleniumTestCase { * * @param array $customSets * Custom sets i.e entity wise sets want to be created and checked. - e.g $customSets = array(array('entity' => 'Contribution', 'subEntity' => 'Donation', - 'triggerElement' => $triggerElement)) - array $triggerElement: the element which is responsible for custom group to load - - which uses the entity info as its selection value + * e.g $customSets = array(array('entity' => 'Contribution', 'subEntity' => 'Donation', + * 'triggerElement' => $triggerElement)) + * array $triggerElement: the element which is responsible for custom group to load + * + * which uses the entity info as its selection value * @param array $pageUrl * The url which on which the ajax custom group load takes place. * @param bool $beforeTriggering @@ -2126,7 +2131,7 @@ class CiviSeleniumTestCase extends PHPUnit_Extensions_SeleniumTestCase { $this->waitForAjaxContent(); $this->checkForErrorsOnPage(); - foreach($return as $values) { + foreach ($return as $values) { foreach ($values as $entityType => $customData) { //initiate necessary variables list($entity, $entityData) = explode('_', $entityType); @@ -2146,7 +2151,7 @@ class CiviSeleniumTestCase extends PHPUnit_Extensions_SeleniumTestCase { } elseif ($elementType == 'checkbox') { $val = explode(',', $entityData); - foreach($val as $v) { + foreach ($val as $v) { $checkId = $this->getAttribute("xpath=//label[text()='{$v}']/@for"); $this->check($checkId); } @@ -2211,7 +2216,12 @@ class CiviSeleniumTestCase extends PHPUnit_Extensions_SeleniumTestCase { $customGroupTitle = preg_replace('/\s/', '_', trim($customGroupTitle)); $return[] = array( - "{$customSet['entity']}_{$customSet['subEntity']}" => array('cgtitle' => $customGroupTitle, 'gid' => $gid, 'triggerElement' => $customSet['triggerElement'])); + "{$customSet['entity']}_{$customSet['subEntity']}" => array( + 'cgtitle' => $customGroupTitle, + 'gid' => $gid, + 'triggerElement' => $customSet['triggerElement'] + ) + ); // Go home for a sec to give time for caches to clear $this->openCiviPage(''); @@ -2257,7 +2267,7 @@ class CiviSeleniumTestCase extends PHPUnit_Extensions_SeleniumTestCase { public function multiselect2($fieldid, $params) { // In the case of chainSelect, wait for options to load $this->waitForElementNotPresent('css=select.loading'); - foreach($params as $value) { + foreach ($params as $value) { $this->clickAt("xpath=//*[@id='$fieldid']/../div/ul//li/input"); $this->waitForElementPresent("xpath=//ul[@class='select2-results']"); $this->clickAt("xpath=//ul[@class='select2-results']//li/div[text()='$value']"); diff --git a/tests/phpunit/CiviTest/CiviTestSuite.php b/tests/phpunit/CiviTest/CiviTestSuite.php index e893941cac..cd28f109d4 100644 --- a/tests/phpunit/CiviTest/CiviTestSuite.php +++ b/tests/phpunit/CiviTest/CiviTestSuite.php @@ -109,8 +109,9 @@ class CiviTestSuite extends PHPUnit_Framework_TestSuite { * @internal param \Directory $object to scan * @return Test suite has been updated */ - protected function addAllTests(PHPUnit_Framework_TestSuite & $suite, - $myfile, SplFileInfo $dirInfo + protected function addAllTests( + PHPUnit_Framework_TestSuite &$suite, + $myfile, SplFileInfo $dirInfo ) { //echo get_class($this)."::addAllTests($myfile,".$dirInfo->getRealPath().")\n"; if (!$dirInfo->isReadable() diff --git a/tests/phpunit/CiviTest/CiviUnitTestCase.php b/tests/phpunit/CiviTest/CiviUnitTestCase.php index e1f06d8477..daa38f550c 100755 --- a/tests/phpunit/CiviTest/CiviUnitTestCase.php +++ b/tests/phpunit/CiviTest/CiviUnitTestCase.php @@ -197,7 +197,8 @@ class CiviUnitTestCase extends PHPUnit_Extensions_Database_TestCase { protected function runTest() { try { return parent::runTest(); - } catch (PEAR_Exception $e) { + } + catch (PEAR_Exception $e) { // PEAR_Exception has metadata in funny places, and PHPUnit won't log it nicely throw new Exception(\CRM_Core_Error::formatTextException($e), $e->getCode()); } @@ -347,7 +348,12 @@ class CiviUnitTestCase extends PHPUnit_Extensions_Database_TestCase { civicrm_api('system', 'flush', array('version' => 3, 'triggers' => 1)); CRM_Core_BAO_ConfigSetting::setEnabledComponents(array( - 'CiviEvent', 'CiviContribute', 'CiviMember', 'CiviMail', 'CiviReport', 'CiviPledge' + 'CiviEvent', + 'CiviContribute', + 'CiviMember', + 'CiviMail', + 'CiviReport', + 'CiviPledge' )); return TRUE; @@ -501,7 +507,8 @@ class CiviUnitTestCase extends PHPUnit_Extensions_Database_TestCase { CRM_Core_Transaction::forceRollbackIfEnabled(); \Civi\Core\Transaction\Manager::singleton(TRUE); - } else { + } + else { CRM_Core_Transaction::forceRollbackIfEnabled(); \Civi\Core\Transaction\Manager::singleton(TRUE); @@ -569,7 +576,7 @@ class CiviUnitTestCase extends PHPUnit_Extensions_Database_TestCase { // Otherwise check matches of DAO field values against expected values in $match. if ($object->find(TRUE)) { - $fields = & $object->fields(); + $fields = &$object->fields(); foreach ($fields as $name => $value) { $dbName = $value['name']; if (isset($match[$name])) { @@ -659,8 +666,9 @@ class CiviUnitTestCase extends PHPUnit_Extensions_Database_TestCase { * @param $expectedValue * @param $message */ - function assertDBCompareValue($daoName, $searchValue, $returnColumn, $searchColumn, - $expectedValue, $message + function assertDBCompareValue( + $daoName, $searchValue, $returnColumn, $searchColumn, + $expectedValue, $message ) { $value = CRM_Core_DAO::getFieldValue($daoName, $searchValue, $returnColumn, $searchColumn, TRUE); $this->assertEquals($value, $expectedValue, $message); @@ -691,7 +699,8 @@ class CiviUnitTestCase extends PHPUnit_Extensions_Database_TestCase { * array(1 => array("Whiz", "String"))); */ public function assertDBQuery($expected, $query, $params = array(), $message = '') { - if ($message) { $message .= ': '; + if ($message) { + $message .= ': '; } $actual = CRM_Core_DAO::singleValueQuery($query, $params); $this->assertEquals($expected, $actual, @@ -744,7 +753,7 @@ class CiviUnitTestCase extends PHPUnit_Extensions_Database_TestCase { public function assertAttributesEquals($expectedValues, $actualValues, $message = NULL) { foreach ($expectedValues as $paramName => $paramValue) { if (isset($actualValues[$paramName])) { - $this->assertEquals($paramValue, $actualValues[$paramName], "Value Mismatch On $paramName - value 1 is " . print_r($paramValue, TRUE) . " value 2 is " . print_r($actualValues[$paramName], TRUE) ); + $this->assertEquals($paramValue, $actualValues[$paramName], "Value Mismatch On $paramName - value 1 is " . print_r($paramValue, TRUE) . " value 2 is " . print_r($actualValues[$paramName], TRUE)); } else { $this->fail("Attribute '$paramName' not present in actual array."); @@ -792,10 +801,10 @@ class CiviUnitTestCase extends PHPUnit_Extensions_Database_TestCase { } $errorMessage = empty($apiResult['error_message']) ? '' : " " . $apiResult['error_message']; - if(!empty($apiResult['debug_information'])) { + if (!empty($apiResult['debug_information'])) { $errorMessage .= "\n " . print_r($apiResult['debug_information'], TRUE); } - if(!empty($apiResult['trace'])){ + if (!empty($apiResult['trace'])) { $errorMessage .= "\n" . print_r($apiResult['trace'], TRUE); } $this->assertEquals(0, $apiResult['is_error'], $prefix . $errorMessage); @@ -815,8 +824,8 @@ class CiviUnitTestCase extends PHPUnit_Extensions_Database_TestCase { if (!empty($prefix)) { $prefix .= ': '; } - if($expectedError && !empty($apiResult['is_error'])){ - $this->assertEquals($expectedError, $apiResult['error_message'], 'api error message not as expected' . $prefix ); + if ($expectedError && !empty($apiResult['is_error'])) { + $this->assertEquals($expectedError, $apiResult['error_message'], 'api error message not as expected' . $prefix); } $this->assertEquals(1, $apiResult['is_error'], "api call should have failed but it succeeded " . $prefix . (print_r($apiResult, TRUE))); $this->assertNotEmpty($apiResult['error_message']); @@ -851,10 +860,10 @@ class CiviUnitTestCase extends PHPUnit_Extensions_Database_TestCase { public function assertAPIArrayComparison($result, $expected, $valuesToExclude = array(), $prefix = '') { $valuesToExclude = array_merge($valuesToExclude, array('debug', 'xdebug', 'sequential')); foreach ($valuesToExclude as $value) { - if(isset($result[$value])) { + if (isset($result[$value])) { unset($result[$value]); } - if(isset($expected[$value])) { + if (isset($expected[$value])) { unset($expected[$value]); } } @@ -934,13 +943,13 @@ class CiviUnitTestCase extends PHPUnit_Extensions_Database_TestCase { 'debug' => 1, ); $result = $this->civicrm_api($entity, 'getvalue', $params); - if($type){ - if($type == 'integer'){ + if ($type) { + if ($type == 'integer') { // api seems to return integers as strings $this->assertTrue(is_numeric($result), "expected a numeric value but got " . print_r($result, 1)); } - else{ - $this->assertType($type, $result, "returned result should have been of type $type but was " ); + else { + $this->assertType($type, $result, "returned result should have been of type $type but was "); } } return $result; @@ -970,10 +979,10 @@ class CiviUnitTestCase extends PHPUnit_Extensions_Database_TestCase { 'debug' => 1, ); $result = $this->civicrm_api($entity, 'getsingle', $params); - if(!is_array($result) || !empty($result['is_error']) || isset($result['values'])) { + if (!is_array($result) || !empty($result['is_error']) || isset($result['values'])) { throw new Exception('Invalid getsingle result' . print_r($result, TRUE)); } - if($checkAgainst){ + if ($checkAgainst) { // @todo - have gone with the fn that unsets id? should we check id? $this->checkArrayEquals($result, $checkAgainst); } @@ -996,10 +1005,10 @@ class CiviUnitTestCase extends PHPUnit_Extensions_Database_TestCase { 'debug' => 1, ); $result = $this->civicrm_api($entity, 'getcount', $params); - if(!is_integer($result) || !empty($result['is_error']) || isset($result['values'])) { + if (!is_integer($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)){ + if (is_int($count)) { $this->assertEquals($count, $result, "incorrect count returned from $entity getcount"); } return $result; @@ -1021,7 +1030,7 @@ class CiviUnitTestCase extends PHPUnit_Extensions_Database_TestCase { * @param string|null $actionName * @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 = "", $subfile = NULL, $actionName = NULL) { $params['version'] = $this->_apiversion; $result = $this->callAPISuccess($entity, $action, $params); $this->documentMe($params, $result, $function, $file, $description, $subfile, $actionName); @@ -1058,7 +1067,7 @@ class CiviUnitTestCase extends PHPUnit_Extensions_Database_TestCase { * * @return array api Result */ - public function createTestEntity(){ + public function createTestEntity() { return $entity = $this->callAPISuccess($this->entity, 'create', $this->params); } @@ -1121,7 +1130,13 @@ class CiviUnitTestCase extends PHPUnit_Extensions_Database_TestCase { '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'), + 'organization_name' => array( + 'Unit Test Organization', + 'Acme', + 'Roberts and Sons', + 'Cryo Space Labs', + 'Sharper Pens' + ), ), 'Household' => array( 'household_name' => array('Unit Test household'), @@ -1131,10 +1146,10 @@ class CiviUnitTestCase extends PHPUnit_Extensions_Database_TestCase { foreach ($samples[$contact_type] as $key => $values) { $params[$key] = $values[$seq % sizeof($values)]; } - if ($contact_type == 'Individual' ) { + if ($contact_type == 'Individual') { $params['email'] = strtolower( - $params['first_name'] . '_' . $params['last_name'] . '@civicrm.org' - ); + $params['first_name'] . '_' . $params['last_name'] . '@civicrm.org' + ); $params['prefix_id'] = 3; $params['suffix_id'] = 3; } @@ -1307,7 +1322,7 @@ class CiviUnitTestCase extends PHPUnit_Extensions_Database_TestCase { 'is_reserved' => 1, 'is_active' => 1, ), - $params + $params ); $result = $this->callAPISuccess('relationship_type', 'create', $params); @@ -1359,10 +1374,10 @@ class CiviUnitTestCase extends PHPUnit_Extensions_Database_TestCase { * @return int $id of participant created */ public function participantCreate($params) { - if(empty($params['contact_id'])){ + if (empty($params['contact_id'])) { $params['contact_id'] = $this->individualCreate(); } - if(empty($params['event_id'])){ + if (empty($params['event_id'])) { $event = $this->eventCreate(); $params['event_id'] = $event['id']; } @@ -1773,17 +1788,17 @@ class CiviUnitTestCase extends PHPUnit_Extensions_Database_TestCase { */ public function groupCreate($params = array()) { $params = array_merge(array( - 'name' => 'Test Group 1', - 'domain_id' => 1, - 'title' => 'New Test Group Created', - 'description' => 'New Test Group Created', - 'is_active' => 1, - 'visibility' => 'Public Pages', - 'group_type' => array( - '1' => 1, - '2' => 1, - ), - ), $params); + 'name' => 'Test Group 1', + 'domain_id' => 1, + 'title' => 'New Test Group Created', + 'description' => 'New Test Group Created', + 'is_active' => 1, + 'visibility' => 'Public Pages', + 'group_type' => array( + '1' => 1, + '2' => 1, + ), + ), $params); $result = $this->callAPISuccess('Group', 'create', $params); return $result['id']; @@ -2003,7 +2018,10 @@ class CiviUnitTestCase extends PHPUnit_Extensions_Database_TestCase { } //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))); + $this->callAPISuccess('custom_group', 'get', array( + 'title' => $params['title'], + array('api.custom_group.delete' => 1) + )); return $this->callAPISuccess('custom_group', 'create', $params); } @@ -2045,14 +2063,25 @@ class CiviUnitTestCase extends PHPUnit_Extensions_Database_TestCase { $customGroup = $this->CustomGroupMultipleCreateByParams($params); $ids['custom_group_id'] = $customGroup['id']; - $customField = $this->customFieldCreate(array('custom_group_id' => $ids['custom_group_id'], 'label' => 'field_1' . $ids['custom_group_id'])); + $customField = $this->customFieldCreate(array( + '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'])); + $customField = $this->customFieldCreate(array( + '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'])); + $customField = $this->customFieldCreate(array( + 'custom_group_id' => $ids['custom_group_id'], + 'default_value' => '', + 'label' => 'field_3' . $ids['custom_group_id'] + )); $ids['custom_field_id'][] = $customField['id']; return $ids; @@ -2251,7 +2280,7 @@ class CiviUnitTestCase extends PHPUnit_Extensions_Database_TestCase { } $this->tidyExampleResult($result); - if(isset($params['version'])) { + if (isset($params['version'])) { unset($params['version']); } // a cleverer person than me would do it in a single regex @@ -2293,8 +2322,8 @@ class CiviUnitTestCase extends PHPUnit_Extensions_Database_TestCase { * @param array $result * */ - public function tidyExampleResult(&$result){ - if(!is_array($result)) { + public function tidyExampleResult(&$result) { + if (!is_array($result)) { return; } $fieldsToChange = array( @@ -2316,17 +2345,17 @@ class CiviUnitTestCase extends PHPUnit_Extensions_Database_TestCase { $keysToUnset = array('xdebug', 'undefined_fields'); foreach ($keysToUnset as $unwantedKey) { - if(isset($result[$unwantedKey])) { + if (isset($result[$unwantedKey])) { unset($result[$unwantedKey]); } } if (isset($result['values'])) { - if(!is_array($result['values'])) { + if (!is_array($result['values'])) { return; } $resultArray = &$result['values']; } - elseif(is_array($result)) { + elseif (is_array($result)) { $resultArray = &$result; } else { @@ -2334,30 +2363,30 @@ class CiviUnitTestCase extends PHPUnit_Extensions_Database_TestCase { } foreach ($resultArray as $index => &$values) { - if(!is_array($values)) { + if (!is_array($values)) { continue; } - foreach($values as $key => &$value) { - if(substr($key, 0, 3) == 'api' && is_array($value)) { - if(isset($value['is_error'])) { + foreach ($values as $key => &$value) { + if (substr($key, 0, 3) == 'api' && is_array($value)) { + if (isset($value['is_error'])) { // we have a std nested result format $this->tidyExampleResult($value); } - else{ + else { foreach ($value as &$nestedResult) { // this is an alternative syntax for nested results a keyed array of results $this->tidyExampleResult($nestedResult); } } } - if(in_array($key, $keysToUnset)) { + if (in_array($key, $keysToUnset)) { unset($values[$key]); break; } - if(array_key_exists($key, $fieldsToChange) && !empty($value)) { + if (array_key_exists($key, $fieldsToChange) && !empty($value)) { $value = $fieldsToChange[$key]; } - if(is_string($value)) { + if (is_string($value)) { $value = addslashes($value); } } @@ -2557,14 +2586,14 @@ AND ( TABLE_NAME LIKE 'civicrm_value_%' ) if ($type == CRM_Utils_Type::T_DATE) { $dateFields[] = $settings['name']; // we should identify both real names & unique names as dates - if($field != $settings['name']) { + if ($field != $settings['name']) { $dateFields[] = $field; } } - if($type == CRM_Utils_Type::T_DATE + CRM_Utils_Type::T_TIME) { + if ($type == CRM_Utils_Type::T_DATE + CRM_Utils_Type::T_TIME) { $dateTimeFields[] = $settings['name']; // we should identify both real names & unique names as dates - if($field != $settings['name']) { + if ($field != $settings['name']) { $dateTimeFields[] = $field; } } @@ -2724,9 +2753,10 @@ AND ( TABLE_NAME LIKE 'civicrm_value_%' ) $this->callAPISuccess('system', 'flush', array()); CRM_Core_BAO_Setting::$_cache = array(); - CRM_Utils_Hook::singleton()->setHook('civicrm_alterSettingsMetaData', function (&$metadata, $domainId, $profile) use ($extras) { - $metadata = array_merge($metadata, $extras); - }); + CRM_Utils_Hook::singleton() + ->setHook('civicrm_alterSettingsMetaData', function (&$metadata, $domainId, $profile) use ($extras) { + $metadata = array_merge($metadata, $extras); + }); $fields = $this->callAPISuccess('setting', 'getfields', array()); foreach ($extras as $key => $spec) { @@ -2741,7 +2771,7 @@ AND ( TABLE_NAME LIKE 'civicrm_value_%' ) public function financialAccountDelete($name) { $financialAccount = new CRM_Financial_DAO_FinancialAccount(); $financialAccount->name = $name; - if($financialAccount->find(TRUE)) { + if ($financialAccount->find(TRUE)) { $entityFinancialType = new CRM_Financial_DAO_EntityFinancialAccount(); $entityFinancialType->financial_account_id = $financialAccount->id; $entityFinancialType->delete(); @@ -2938,7 +2968,7 @@ AND ( TABLE_NAME LIKE 'civicrm_value_%' ) 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, + 'option_group_id' => $optionGroupID, 'label' => 'pick me', 'value' => 55, )); @@ -2991,14 +3021,25 @@ AND ( TABLE_NAME LIKE 'civicrm_value_%' ) public 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')); + $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))); + $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))); + $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 @@ -3016,24 +3057,24 @@ AND ( TABLE_NAME LIKE 'civicrm_value_%' ) */ public 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'])) { + '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( @@ -3100,10 +3141,19 @@ AND ( TABLE_NAME LIKE 'civicrm_value_%' ) 'unit_price' => 200, 'line_total' => 200, 'financial_type_id' => 1, - 'price_field_id' => $this->callAPISuccess('price_field', 'getvalue', array('return' => 'id', 'label' => 'Membership Amount')), - 'price_field_value_id' => $this->callAPISuccess('price_field_value', 'getvalue', array('return' => 'id', 'label' => 'General')), + 'price_field_id' => $this->callAPISuccess('price_field', 'getvalue', array( + 'return' => 'id', + 'label' => 'Membership Amount' + )), + 'price_field_value_id' => $this->callAPISuccess('price_field_value', 'getvalue', array( + 'return' => 'id', + 'label' => 'General' + )), )); - $this->callAPISuccess('membership_payment', 'create', array('contribution_id' => $this->_contributionID, 'membership_id' => $this->ids['membership'])); + $this->callAPISuccess('membership_payment', 'create', array( + 'contribution_id' => $this->_contributionID, + 'membership_id' => $this->ids['membership'] + )); } /** diff --git a/tests/phpunit/WebTest/Event/MultiprofileEventTest.php b/tests/phpunit/WebTest/Event/MultiprofileEventTest.php index 7acfd73754..86d75c8dd9 100644 --- a/tests/phpunit/WebTest/Event/MultiprofileEventTest.php +++ b/tests/phpunit/WebTest/Event/MultiprofileEventTest.php @@ -636,8 +636,9 @@ class WebTest_Event_MultiprofileEventTest extends CiviSeleniumTestCase { * @param $email1 * @param $email2 */ - function _testEventRegistration($eventPageId, $customId, $firstName, $lastName, - $participantfname, $participantlname, $email1, $email2 + function _testEventRegistration( + $eventPageId, $customId, $firstName, $lastName, + $participantfname, $participantlname, $email1, $email2 ) { $this->openCiviPage("event/register", "id={$eventPageId}&reset=1", "_qf_Register_upload-bottom"); $this->select("additional_participants", "value=1"); diff --git a/tests/phpunit/WebTest/Import/ImportCiviSeleniumTestCase.php b/tests/phpunit/WebTest/Import/ImportCiviSeleniumTestCase.php index 182b668b84..9f2a544308 100644 --- a/tests/phpunit/WebTest/Import/ImportCiviSeleniumTestCase.php +++ b/tests/phpunit/WebTest/Import/ImportCiviSeleniumTestCase.php @@ -57,7 +57,8 @@ class ImportCiviSeleniumTestCase extends CiviSeleniumTestCase { * saveMappingName : to override mapping name * */ - function importCSVComponent($component, + function importCSVComponent( + $component, $headers, $rows, $contactType = 'Individual', diff --git a/tests/phpunit/api/v3/ACLCachingTest.php b/tests/phpunit/api/v3/ACLCachingTest.php index 4dd7ef511e..8a7fc611db 100644 --- a/tests/phpunit/api/v3/ACLCachingTest.php +++ b/tests/phpunit/api/v3/ACLCachingTest.php @@ -34,7 +34,6 @@ require_once 'CiviTest/CiviUnitTestCase.php'; * @package CiviCRM_APIv3 * @subpackage API_Contact */ - class api_v3_ACLCachingTest extends CiviUnitTestCase { protected $_apiversion = 3; protected $_params; @@ -44,6 +43,7 @@ class api_v3_ACLCachingTest extends CiviUnitTestCase { public function setUp() { parent::setUp(); } + /** * (non-PHPdoc) * @see CiviUnitTestCase::tearDown() diff --git a/tests/phpunit/api/v3/ACLPermissionTest.php b/tests/phpunit/api/v3/ACLPermissionTest.php index d695ed106d..efebb37bcf 100644 --- a/tests/phpunit/api/v3/ACLPermissionTest.php +++ b/tests/phpunit/api/v3/ACLPermissionTest.php @@ -33,7 +33,6 @@ require_once 'CiviTest/CiviUnitTestCase.php'; * @package CiviCRM_APIv3 * @subpackage API_Contact */ - class api_v3_ACLPermissionTest extends CiviUnitTestCase { protected $_apiversion = 3; public $DBResetRequired = FALSE; @@ -233,10 +232,19 @@ class api_v3_ACLPermissionTest extends CiviUnitTestCase { public function setupCoreACL() { $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')); + $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' + )); $this->setupACL(); } + /** * @dataProvider entities * confirm that without check permissions we still get 2 contacts returned @@ -267,6 +275,7 @@ class api_v3_ACLPermissionTest extends CiviUnitTestCase { )); $this->assertEquals(2, $result['count']); } + /** * @dataProvider entities * confirm that with check permissions we don't get entities @@ -310,7 +319,7 @@ class api_v3_ACLPermissionTest extends CiviUnitTestCase { */ public function setUpEntities($entity) { $baoObj = new CRM_Core_DAO(); - $baoObj->createTestObject( _civicrm_api3_get_BAO($entity), array(), 2, 0); + $baoObj->createTestObject(_civicrm_api3_get_BAO($entity), array(), 2, 0); CRM_Core_Config::singleton()->userPermissionClass->permissions = array( 'access CiviCRM', 'access CiviContribute', diff --git a/tests/phpunit/api/v3/ActivityContactTest.php b/tests/phpunit/api/v3/ActivityContactTest.php index 7ed66e4817..8de021d7f1 100644 --- a/tests/phpunit/api/v3/ActivityContactTest.php +++ b/tests/phpunit/api/v3/ActivityContactTest.php @@ -47,9 +47,9 @@ class api_v3_ActivityContactTest extends CiviUnitTestCase { parent::setUp(); $this->useTransaction(TRUE); - $this->_contactID = $this->organizationCreate(); - $activity = $this->activityCreate(); - $this->_activityID = $activity['id']; + $this->_contactID = $this->organizationCreate(); + $activity = $this->activityCreate(); + $this->_activityID = $activity['id']; CRM_Core_PseudoConstant::flush(); $this->_params = array( 'contact_id' => $this->_contactID, diff --git a/tests/phpunit/api/v3/AddressTest.php b/tests/phpunit/api/v3/AddressTest.php index 6abce24415..1b52ce81c5 100644 --- a/tests/phpunit/api/v3/AddressTest.php +++ b/tests/phpunit/api/v3/AddressTest.php @@ -86,7 +86,7 @@ class api_v3_AddressTest extends CiviUnitTestCase { 'location_type_id' => $this->_locationType->id, 'contact_id' => $this->_contactID, ); - $subfile = "AddressParse"; + $subfile = "AddressParse"; $description = "Demonstrates Use of address parsing param"; $result = $this->callAPIAndDocument('address', 'create', $params, __FUNCTION__, __FILE__, $description, $subfile); $this->assertEquals(54, $result['values'][$result['id']]['street_number'], 'In line ' . __LINE__); @@ -127,7 +127,10 @@ class api_v3_AddressTest extends CiviUnitTestCase { 'master_id' => $address['id'], ); $this->callAPISuccess('address', 'create', array_merge($this->_params, $individualParams)); - $this->callAPISuccess('relationship', 'getcount', array('contact_id_a' => $individualID, 'contact_id_b' => $this->_contactID)); + $this->callAPISuccess('relationship', 'getcount', array( + 'contact_id_a' => $individualID, + 'contact_id_b' => $this->_contactID + )); } /** @@ -141,7 +144,10 @@ class api_v3_AddressTest extends CiviUnitTestCase { 'master_id' => $address['id'], ); $this->callAPISuccess('address', 'create', array_merge($this->_params, $individualParams)); - $this->callAPISuccess('relationship', 'getcount', array('contact_id_a' => $individualID, 'contact_id_b' => $this->_contactID)); + $this->callAPISuccess('relationship', 'getcount', array( + 'contact_id_a' => $individualID, + 'contact_id_b' => $this->_contactID + )); } /** @@ -163,7 +169,11 @@ class api_v3_AddressTest extends CiviUnitTestCase { $this->callAPISuccessGetCount('relationship', array('contact_id_a' => $individualID), 2); $this->markTestIncomplete('Remainder of test checks that employer relationship is disabled when new one is created but turns out to be not happening - by design?'); $this->callAPISuccessGetCount('relationship', array('contact_id_a' => $individualID, 'is_active' => FALSE), 1); - $this->callAPISuccessGetCount('relationship', array('contact_id_a' => $individualID, 'is_active' => TRUE, 'contact_id_b' => $organisation2ID), 1); + $this->callAPISuccessGetCount('relationship', array( + 'contact_id_a' => $individualID, + 'is_active' => TRUE, + 'contact_id_b' => $organisation2ID + ), 1); } @@ -178,7 +188,7 @@ class api_v3_AddressTest extends CiviUnitTestCase { $result = $this->callAPISuccess('address', 'create', $params); unset($params['is_primary']); $params['id'] = $result['id']; - $result = $this->callAPISuccess('address', 'create', $params); + $result = $this->callAPISuccess('address', 'create', $params); $this->callAPISuccess('address', 'get', array('contact_id' => $params['contact_id'])); $this->assertEquals(1, $result['count']); $this->assertEquals(1, $result['values'][$result['id']]['is_primary']); @@ -201,7 +211,7 @@ class api_v3_AddressTest extends CiviUnitTestCase { $result = $this->callAPIAndDocument('address', 'delete', array('id' => $create['id']), __FUNCTION__, __FILE__); $this->assertEquals(1, $result['count'], 'In line ' . __LINE__); $get = $this->callAPISuccess('address', 'get', array( - 'location_type_id' => $this->_locationType->id, + 'location_type_id' => $this->_locationType->id, )); $this->assertEquals(0, $get['count'], 'Contact not successfully deleted In line ' . __LINE__); } @@ -242,9 +252,9 @@ class api_v3_AddressTest extends CiviUnitTestCase { public function testGetAddressSort() { $create = $this->callAPISuccess('address', 'create', $this->_params); $this->callAPISuccess('address', 'create', array_merge($this->_params, array('street_address' => 'yzy'))); - $subfile = "AddressSort"; + $subfile = "AddressSort"; $description = "Demonstrates Use of sort filter"; - $params = array( + $params = array( 'options' => array( 'sort' => 'street_address DESC', 'limit' => 2, @@ -262,10 +272,10 @@ class api_v3_AddressTest extends CiviUnitTestCase { */ public function testGetAddressLikeSuccess() { $this->callAPISuccess('address', 'create', $this->_params); - $subfile = "AddressLike"; + $subfile = "AddressLike"; $description = "Demonstrates Use of Like"; - $params = array( - 'street_address' => array('LIKE' => '%mb%'), + $params = array( + 'street_address' => array('LIKE' => '%mb%'), 'sequential' => 1, ); $result = $this->callAPIAndDocument('Address', 'Get', $params, __FUNCTION__, __FILE__, $description, $subfile); @@ -279,7 +289,7 @@ class api_v3_AddressTest extends CiviUnitTestCase { */ public function testGetAddressLikeFail() { $create = $this->callAPISuccess('address', 'create', $this->_params); - $params = array( + $params = array( 'street_address' => array('LIKE' => "'%xy%'"), 'sequential' => 1, ); @@ -319,9 +329,9 @@ class api_v3_AddressTest extends CiviUnitTestCase { $this->assertApiSuccess($address1, 'In line ' . __LINE__); //now we check & make sure it has been set to primary $check = $this->callAPISuccess('address', 'getcount', array( - 'is_primary' => 1, - 'id' => $address1['id'], - )); + 'is_primary' => 1, + 'id' => $address1['id'], + )); $this->assertEquals(1, $check); $this->callAPISuccess('address', 'delete', array('id' => $address1['id'])); } @@ -333,9 +343,9 @@ class api_v3_AddressTest extends CiviUnitTestCase { $address1 = $this->callAPISuccess('address', 'create', $this->_params); $this->callAPISuccess('address', 'create', $this->_params); $check = $this->callAPISuccess('address', 'getcount', array( - 'is_primary' => 1, - 'contact_id' => $this->_contactID, - )); + 'is_primary' => 1, + 'contact_id' => $this->_contactID, + )); $this->assertEquals(1, $check); $this->callAPISuccess('address', 'delete', array('id' => $address1['id'])); } diff --git a/tests/phpunit/api/v3/ContactTest.php b/tests/phpunit/api/v3/ContactTest.php index 713b33e5c0..325fcdb49f 100644 --- a/tests/phpunit/api/v3/ContactTest.php +++ b/tests/phpunit/api/v3/ContactTest.php @@ -40,7 +40,6 @@ require_once 'CiviTest/CiviUnitTestCase.php'; * @package CiviCRM_APIv3 * @subpackage API_Contact */ - class api_v3_ContactTest extends CiviUnitTestCase { public $DBResetRequired = FALSE; protected $_apiversion; @@ -121,7 +120,7 @@ class api_v3_ContactTest extends CiviUnitTestCase { 'contact_type' => 'Individual', 'last_name' => 'test xyz', 'contact_sub_type' => array('Student', 'Staff'), - ); + ); $contact = $this->callAPISuccess('contact', 'create', $params); $cid = $contact['id']; @@ -301,6 +300,7 @@ class api_v3_ContactTest extends CiviUnitTestCase { $contact = $this->callAPISuccess('contact', 'create', $params); $this->assertEquals(1, $contact['id']); } + /** * Verify that attempt to create organization contact without organization name fails */ @@ -311,6 +311,7 @@ class api_v3_ContactTest extends CiviUnitTestCase { ); $this->callAPIFailure('contact', 'create', $params); } + /** * Check with complete array + custom field * Note that the test is written on purpose without any @@ -325,7 +326,10 @@ class api_v3_ContactTest extends CiviUnitTestCase { $description = "/*this demonstrates setting a custom field through the API "; $result = $this->callAPIAndDocument($this->_entity, 'create', $params, __FUNCTION__, __FILE__, $description); - $check = $this->callAPISuccess($this->_entity, 'get', array('return.custom_' . $ids['custom_field_id'] => 1, 'id' => $result['id'])); + $check = $this->callAPISuccess($this->_entity, 'get', array( + 'return.custom_' . $ids['custom_field_id'] => 1, + 'id' => $result['id'] + )); $this->assertEquals("custom string", $check['values'][$check['id']]['custom_' . $ids['custom_field_id']]); $this->customFieldDelete($ids['custom_field_id']); @@ -349,7 +353,7 @@ class api_v3_ContactTest extends CiviUnitTestCase { /* * Test creating a current employer through API */ - public function testContactCreateCurrentEmployer(){ + public function testContactCreateCurrentEmployer() { //here we will just do the get for set-up purposes $count = $this->callAPISuccess('contact', 'getcount', array( 'organization_name' => 'new employer org', @@ -357,19 +361,21 @@ class api_v3_ContactTest extends CiviUnitTestCase { )); $this->assertEquals(0, $count); $employerResult = $this->callAPISuccess('contact', 'create', array_merge($this->_params, array( - 'current_employer' => 'new employer org',) + 'current_employer' => 'new employer org', + ) )); // do it again as an update to check it doesn't cause an error $employerResult = $this->callAPISuccess('contact', 'create', array_merge($this->_params, array( 'current_employer' => 'new employer org', - 'id' => $employerResult['id']) + 'id' => $employerResult['id'] + ) )); $expectedCount = 1; $this->callAPISuccess('contact', 'getcount', array( - 'organization_name' => 'new employer org', - 'contact_type' => 'Organization' - ), - $expectedCount); + 'organization_name' => 'new employer org', + 'contact_type' => 'Organization' + ), + $expectedCount); $result = $this->callAPISuccess('contact', 'getsingle', array( 'id' => $employerResult['id'], @@ -378,14 +384,16 @@ class api_v3_ContactTest extends CiviUnitTestCase { $this->assertEquals('new employer org', $result['current_employer']); } + /* * Test creating a current employer through API * - check it will re-activate a de-activated employer */ - public function testContactCreateDuplicateCurrentEmployerEnables(){ + public function testContactCreateDuplicateCurrentEmployerEnables() { //set up - create employer relationship $employerResult = $this->callAPISuccess('contact', 'create', array_merge($this->_params, array( - 'current_employer' => 'new employer org',) + 'current_employer' => 'new employer org', + ) )); $relationship = $this->callAPISuccess('relationship', 'get', array( 'contact_id_a' => $employerResult['id'], @@ -401,11 +409,13 @@ class api_v3_ContactTest extends CiviUnitTestCase { //re-set the current employer - thus enabling the relationshp $this->callAPISuccess('contact', 'create', array_merge($this->_params, array( 'current_employer' => 'new employer org', - 'id' => $employerResult['id']) + 'id' => $employerResult['id'] + ) )); //check is_active is now 1 $relationship = $this->callAPISuccess('relationship', 'getsingle', array( - 'return' => 'is_active',)); + 'return' => 'is_active', + )); $this->assertEquals(1, $relationship['is_active']); } @@ -415,7 +425,12 @@ class api_v3_ContactTest extends CiviUnitTestCase { */ public function testGetDeceasedRetrieved() { $this->callAPISuccess($this->_entity, 'create', $this->_params); - $c2 = $this->callAPISuccess($this->_entity, 'create', array('first_name' => 'bb', 'last_name' => 'ccc', 'contact_type' => 'Individual', 'is_deceased' => 1)); + $c2 = $this->callAPISuccess($this->_entity, 'create', array( + 'first_name' => 'bb', + 'last_name' => 'ccc', + 'contact_type' => 'Individual', + 'is_deceased' => 1 + )); $result = $this->callAPISuccess($this->_entity, 'get', array('is_deceased' => 0)); $this->assertFalse(array_key_exists($c2['id'], $result['values'])); } @@ -425,13 +440,17 @@ class api_v3_ContactTest extends CiviUnitTestCase { */ public function testGetSort() { $c1 = $this->callAPISuccess($this->_entity, 'create', $this->_params); - $c2 = $this->callAPISuccess($this->_entity, 'create', array('first_name' => 'bb', 'last_name' => 'ccc', 'contact_type' => 'Individual')); - $result = $this->callAPISuccess($this->_entity, 'get', array( - 'sort' => 'first_name ASC', - 'return.first_name' => 1, - 'sequential' => 1, - 'rowCount' => 1, + $c2 = $this->callAPISuccess($this->_entity, 'create', array( + 'first_name' => 'bb', + 'last_name' => 'ccc', + 'contact_type' => 'Individual' )); + $result = $this->callAPISuccess($this->_entity, 'get', array( + 'sort' => 'first_name ASC', + 'return.first_name' => 1, + 'sequential' => 1, + 'rowCount' => 1, + )); $this->assertEquals('abc1', $result['values'][0]['first_name']); $result = $this->callAPISuccess($this->_entity, 'get', array( @@ -445,14 +464,23 @@ class api_v3_ContactTest extends CiviUnitTestCase { $this->callAPISuccess($this->_entity, 'delete', array('id' => $c1['id'])); $this->callAPISuccess($this->_entity, 'delete', array('id' => $c2['id'])); } + /* * Test that we can retrieve contacts using * 'id' => array('IN' => array('3,4')) syntax */ public function testGetINIDArray() { $c1 = $this->callAPISuccess($this->_entity, 'create', $this->_params); - $c2 = $this->callAPISuccess($this->_entity, 'create', array('first_name' => 'bb', 'last_name' => 'ccc', 'contact_type' => 'Individual')); - $c3 = $this->callAPISuccess($this->_entity, 'create', array('first_name' => 'hh', 'last_name' => 'll', 'contact_type' => 'Individual')); + $c2 = $this->callAPISuccess($this->_entity, 'create', array( + 'first_name' => 'bb', + 'last_name' => 'ccc', + 'contact_type' => 'Individual' + )); + $c3 = $this->callAPISuccess($this->_entity, 'create', array( + 'first_name' => 'hh', + 'last_name' => 'll', + 'contact_type' => 'Individual' + )); $result = $this->callAPISuccess($this->_entity, 'get', array('id' => array('IN' => array($c1['id'], $c3['id'])))); $this->assertEquals(2, $result['count']); $this->assertEquals(array($c1['id'], $c3['id']), array_keys($result['values'])); @@ -460,6 +488,7 @@ class api_v3_ContactTest extends CiviUnitTestCase { $this->callAPISuccess($this->_entity, 'delete', array('id' => $c2['id'])); $this->callAPISuccess($this->_entity, 'delete', array('id' => $c3['id'])); } + /* * Test variants on deleted behaviour */ @@ -475,10 +504,10 @@ class api_v3_ContactTest extends CiviUnitTestCase { $countDefault = $this->callAPISuccess('contact', 'getcount', array()); $countDeleted = $this->callAPISuccess('contact', 'getcount', array( 'contact_is_deleted' => 1, - )); + )); $countNotDeleted = $this->callAPISuccess('contact', 'getcount', array( 'contact_is_deleted' => 0, - )); + )); $this->callAPISuccess('contact', 'delete', array('id' => $contact1['id'])); $this->callAPISuccess('contact', 'delete', array('id' => $contact2['id'])); $this->assertEquals(1, $countNotDeleted, 'contact_is_deleted => 0 is respected in line ' . __LINE__); @@ -493,24 +522,28 @@ class api_v3_ContactTest extends CiviUnitTestCase { * Test that sort works - new syntax */ public function testGetSortNewSYntax() { - $c1 = $this->callAPISuccess($this->_entity, 'create', $this->_params); - $c2 = $this->callAPISuccess($this->_entity, 'create', array('first_name' => 'bb', 'last_name' => 'ccc', 'contact_type' => 'Individual')); + $c1 = $this->callAPISuccess($this->_entity, 'create', $this->_params); + $c2 = $this->callAPISuccess($this->_entity, 'create', array( + 'first_name' => 'bb', + 'last_name' => 'ccc', + 'contact_type' => 'Individual' + )); $result = $this->callAPISuccess($this->_entity, 'getvalue', array( 'return' => 'first_name', - 'options' => array( - 'limit' => 1, - 'sort' => 'first_name', - ), - )); + 'options' => array( + 'limit' => 1, + 'sort' => 'first_name', + ), + )); $this->assertEquals('abc1', $result, 'in line' . __LINE__); $result = $this->callAPISuccess($this->_entity, 'getvalue', array( - 'return' => 'first_name', - 'options' => array( - 'limit' => 1, - 'sort' => 'first_name DESC', - ), - )); + 'return' => 'first_name', + 'options' => array( + 'limit' => 1, + 'sort' => 'first_name DESC', + ), + )); $this->assertEquals('bb', $result); $this->callAPISuccess($this->_entity, 'delete', array('id' => $c1['id'])); @@ -545,7 +578,10 @@ class api_v3_ContactTest extends CiviUnitTestCase { $subfile = "CustomFieldGet"; $result = $this->callAPISuccess($this->_entity, 'create', $params); - $check = $this->callAPIAndDocument($this->_entity, 'get', array('return.custom_' . $ids['custom_field_id'] => 1, 'id' => $result['id']), __FUNCTION__, __FILE__, $description, $subfile); + $check = $this->callAPIAndDocument($this->_entity, 'get', array( + 'return.custom_' . $ids['custom_field_id'] => 1, + 'id' => $result['id'] + ), __FUNCTION__, __FILE__, $description, $subfile); $this->assertEquals("custom string", $check['values'][$check['id']]['custom_' . $ids['custom_field_id']]); $fields = ($this->callAPISuccess('contact', 'getfields', $params)); @@ -579,20 +615,28 @@ class api_v3_ContactTest extends CiviUnitTestCase { /** * Check that address name is returned if required */ - public function testGetReturnAddressName () { + public function testGetReturnAddressName() { $contactID = $this->individualCreate(); - $this->callAPISuccess('address', 'create', array('contact_id' => $contactID, 'address_name' => 'My house', 'location_type_id' => 'Home', 'street_address' => '1 my road')); - $result = $this->callAPISuccessGetSingle('contact', array('return' => 'address_name, street_address', 'id' => $contactID)); + $this->callAPISuccess('address', 'create', array( + 'contact_id' => $contactID, + 'address_name' => 'My house', + 'location_type_id' => 'Home', + 'street_address' => '1 my road' + )); + $result = $this->callAPISuccessGetSingle('contact', array( + 'return' => 'address_name, street_address', + 'id' => $contactID + )); $this->assertEquals('1 my road', $result['street_address']); $this->assertEquals('My house', $result['address_name']); } public function testGetGroupIDFromContact() { - $groupId = $this->groupCreate(); + $groupId = $this->groupCreate(); $description = "Get all from group and display contacts"; - $subFile = "GroupFilterUsingContactAPI"; - $params = array( + $subFile = "GroupFilterUsingContactAPI"; + $params = array( 'email' => 'man2@yahoo.com', 'contact_type' => 'Individual', 'location_type_id' => 1, @@ -628,7 +672,7 @@ class api_v3_ContactTest extends CiviUnitTestCase { // testing as string $params = array( - 'filter.group_id' => array($groupId, 26), + 'filter.group_id' => array($groupId, 26), 'contact_type' => 'Individual', ); $result = $this->callAPIAndDocument('contact', 'get', $params, __FUNCTION__, __FILE__, $description, $subFile); @@ -636,12 +680,12 @@ class api_v3_ContactTest extends CiviUnitTestCase { //test in conjunction with other criteria $params = array( - 'filter.group_id' => array($groupId, 26), + 'filter.group_id' => array($groupId, 26), 'contact_type' => 'Organization', ); $this->callAPISuccess('contact', 'get', $params); $params = array( - 'filter.group_id' => array(26, 27), + 'filter.group_id' => array(26, 27), 'contact_type' => 'Individual', ); $result = $this->callAPISuccess('contact', 'get', $params); @@ -653,8 +697,8 @@ class api_v3_ContactTest extends CiviUnitTestCase { */ public function testCreateIndividualWithContributionDottedSyntax() { $description = "test demonstrates the syntax to create 2 chained entities"; - $subFile = "ChainTwoWebsites"; - $params = array( + $subFile = "ChainTwoWebsites"; + $params = array( 'first_name' => 'abc3', 'last_name' => 'xyz3', 'contact_type' => 'Individual', @@ -662,7 +706,7 @@ class api_v3_ContactTest extends CiviUnitTestCase { 'api.contribution.create' => array( 'receive_date' => '2010-01-01', 'total_amount' => 100.00, - 'financial_type_id' => $this->_financialTypeId, + 'financial_type_id' => $this->_financialTypeId, 'payment_instrument_id' => 1, 'non_deductible_amount' => 10.00, 'fee_amount' => 50.00, @@ -704,7 +748,7 @@ class api_v3_ContactTest extends CiviUnitTestCase { 'api.contribution.create' => array( 'receive_date' => '2010-01-01', 'total_amount' => 100.00, - 'financial_type_id' => $this->_financialTypeId, + 'financial_type_id' => $this->_financialTypeId, 'payment_instrument_id' => 1, 'non_deductible_amount' => 10.00, 'fee_amount' => 50.00, @@ -726,8 +770,8 @@ class api_v3_ContactTest extends CiviUnitTestCase { ); $description = "demonstrates creating two websites as an array"; - $subfile = "ChainTwoWebsitesSyntax2"; - $result = $this->callAPIAndDocument('Contact', 'create', $params, __FUNCTION__, __FILE__, $description, $subfile); + $subfile = "ChainTwoWebsitesSyntax2"; + $result = $this->callAPIAndDocument('Contact', 'create', $params, __FUNCTION__, __FILE__, $description, $subfile); $this->assertEquals(1, $result['id']); // the callAndDocument doesn't check the chained call @@ -756,6 +800,7 @@ class api_v3_ContactTest extends CiviUnitTestCase { // delete the contact $this->callAPISuccess('contact', 'delete', $contact); } + /** * Verify that attempt to create individual contact with no data fails */ @@ -765,6 +810,7 @@ class api_v3_ContactTest extends CiviUnitTestCase { ); $this->callAPIFailure('contact', 'create', $params); } + /** * Verify that attempt to create individual contact with first * and last names, email and location type succeeds @@ -793,9 +839,9 @@ class api_v3_ContactTest extends CiviUnitTestCase { $employer2 = $this->organizationCreate(); $params = array( - 'email' => 'man4@yahoo.com', - 'contact_type' => 'Individual', - 'employer_id' => $employer, + 'email' => 'man4@yahoo.com', + 'contact_type' => 'Individual', + 'employer_id' => $employer, ); $result = $this->callAPISuccess('contact', 'create', $params); @@ -849,6 +895,7 @@ class api_v3_ContactTest extends CiviUnitTestCase { $this->callAPISuccess('contact', 'delete', $contact); } + /** * Verify that attempt to create household contact with inadequate details * fails @@ -1020,7 +1067,7 @@ class api_v3_ContactTest extends CiviUnitTestCase { public function testContactDelete() { $contactID = $this->individualCreate(); $params = array( - 'id' => $contactID , + 'id' => $contactID, ); $this->callAPIAndDocument('contact', 'delete', $params, __FUNCTION__, __FILE__); } @@ -1209,10 +1256,16 @@ class api_v3_ContactTest extends CiviUnitTestCase { $result = $this->callAPISuccess('contact', 'get', array('birth_date_high' => date('Y-m-d', strtotime('-6 years')))); $this->assertEquals(1, $result['count']); $this->assertEquals(date('Y-m-d', strtotime('first day of next month -20 years')), $result['values'][$contact3['id']]['birth_date']); - $result = $this->callAPISuccess('contact', 'get', array('birth_date_low' => date('Y-m-d', strtotime('-6 years')), 'birth_date_high' => date('Y-m-d', strtotime('- 3 years')))); + $result = $this->callAPISuccess('contact', 'get', array( + 'birth_date_low' => date('Y-m-d', strtotime('-6 years')), + 'birth_date_high' => date('Y-m-d', strtotime('- 3 years')) + )); $this->assertEquals(1, $result['count']); $this->assertEquals(date('Y-m-d', strtotime('first day of next month -5 years')), $result['values'][$contact2['id']]['birth_date']); - $result = $this->callAPISuccess('contact', 'get', array('birth_date_low' => '-6 years', 'birth_date_high' => '- 3 years')); + $result = $this->callAPISuccess('contact', 'get', array( + 'birth_date_low' => '-6 years', + 'birth_date_high' => '- 3 years' + )); $this->assertEquals(1, $result['count']); $this->assertEquals(date('Y-m-d', strtotime('first day of next month -5 years')), $result['values'][$contact2['id']]['birth_date']); } @@ -1234,7 +1287,10 @@ class api_v3_ContactTest extends CiviUnitTestCase { $result = $this->callAPISuccess('contact', 'get', array('deceased_date_high' => date('Y-m-d', strtotime('-6 years')))); $this->assertEquals(1, $result['count']); $this->assertEquals(date('Y-m-d', strtotime('first day of next month -20 years')), $result['values'][$contact3['id']]['deceased_date']); - $result = $this->callAPISuccess('contact', 'get', array('deceased_date_low' => '-6 years', 'deceased_date_high' => date('Y-m-d', strtotime('- 3 years')))); + $result = $this->callAPISuccess('contact', 'get', array( + 'deceased_date_low' => '-6 years', + 'deceased_date_high' => date('Y-m-d', strtotime('- 3 years')) + )); $this->assertEquals(1, $result['count']); $this->assertEquals(date('Y-m-d', strtotime('first day of next month -5 years')), $result['values'][$contact2['id']]['deceased_date']); } @@ -1287,7 +1343,10 @@ class api_v3_ContactTest extends CiviUnitTestCase { $this->assertEquals($result[$key], $value); } //now we check they are still returned with 'return' key - $result = $this->callAPISuccess('contact', 'getsingle', array('id' => $contactID, 'return' => array_keys($extraParams))); + $result = $this->callAPISuccess('contact', 'getsingle', array( + 'id' => $contactID, + 'return' => array_keys($extraParams) + )); foreach ($extraParams as $key => $value) { $this->assertEquals($result[$key], $value); } @@ -1297,10 +1356,10 @@ class api_v3_ContactTest extends CiviUnitTestCase { $contactID = $this->householdCreate(); $this->callAPISuccessGetCount('phone', array('contact_id' => $contactID), 0); $params = array( - 'contact_id' => $contactID, - 'household_name' => 'Household 1', - 'contact_type' => 'Household', - 'api.phone.create' => array( + 'contact_id' => $contactID, + 'household_name' => 'Household 1', + 'contact_type' => 'Household', + 'api.phone.create' => array( 0 => array( 'phone' => '111-111-1111', 'location_type_id' => 1, @@ -1317,6 +1376,7 @@ class api_v3_ContactTest extends CiviUnitTestCase { $this->callAPISuccessGetCount('phone', array('contact_id' => $contactID), 2); } + /** * Test for Contact.get id=@user:username (with an invalid username) */ @@ -1343,10 +1403,10 @@ class api_v3_ContactTest extends CiviUnitTestCase { $ids = $this->entityCustomGroupWithSingleFieldCreate(__FUNCTION__, __FILE__); $params['custom_' . $ids['custom_field_id']] = "custom string"; - $moreids = $this->CustomGroupMultipleCreateWithFields(); + $moreids = $this->CustomGroupMultipleCreateWithFields(); $description = "/*this demonstrates the usage of chained api functions. In this case no notes or custom fields have been created "; - $subfile = "APIChainedArray"; - $params = array( + $subfile = "APIChainedArray"; + $params = array( 'first_name' => 'abc3', 'last_name' => 'xyz3', 'contact_type' => 'Individual', @@ -1390,7 +1450,8 @@ class api_v3_ContactTest extends CiviUnitTestCase { 'api.website.get' => array(), 'api.Contribution.get' => array( 'total_amount' => '120.00', - ), 'api.CustomValue.get' => 1, + ), + 'api.CustomValue.get' => 1, 'api.Note.get' => 1, ); $result = $this->callAPIAndDocument('Contact', 'Get', $params, __FUNCTION__, __FILE__, $description, $subfile); @@ -1469,7 +1530,10 @@ class api_v3_ContactTest extends CiviUnitTestCase { $ids = $this->entityCustomGroupWithSingleFieldCreate(__FUNCTION__, __FILE__); $params['custom_' . $ids['custom_field_id']] = "custom string"; $moreids = $this->CustomGroupMultipleCreateWithFields(); - $andmoreids = $this->CustomGroupMultipleCreateWithFields(array('title' => "another group", 'name' => 'another name')); + $andmoreids = $this->CustomGroupMultipleCreateWithFields(array( + 'title' => "another group", + 'name' => 'another name' + )); $description = "/*this demonstrates the usage of chained api functions. A variety of techniques are used"; $subfile = "APIChainedArrayMultipleCustom"; $params = array( @@ -1480,7 +1544,7 @@ class api_v3_ContactTest extends CiviUnitTestCase { 'api.contribution.create' => array( 'receive_date' => '2010-01-01', 'total_amount' => 100.00, - 'financial_type_id' => 1, + 'financial_type_id' => 1, 'payment_instrument_id' => 1, 'non_deductible_amount' => 10.00, 'fee_amount' => 50.00, @@ -1493,7 +1557,7 @@ class api_v3_ContactTest extends CiviUnitTestCase { 'api.contribution.create.1' => array( 'receive_date' => '2011-01-01', 'total_amount' => 120.00, - 'financial_type_id' => 1, + 'financial_type_id' => 1, 'payment_instrument_id' => 1, 'non_deductible_amount' => 10.00, 'fee_amount' => 50.00, @@ -1517,10 +1581,12 @@ class api_v3_ContactTest extends CiviUnitTestCase { $result = $this->callAPISuccess('Contact', 'create', $params); $result = $this->callAPISuccess('Contact', 'create', array( 'contact_type' => 'Individual', - 'id' => $result['id'], 'custom_' . - $moreids['custom_field_id'][0] => "value 3", 'custom_' . - $ids['custom_field_id'] => "value 4", - )); + 'id' => $result['id'], + 'custom_' . + $moreids['custom_field_id'][0] => "value 3", + 'custom_' . + $ids['custom_field_id'] => "value 4", + )); $params = array( 'id' => $result['id'], @@ -1537,6 +1603,7 @@ class api_v3_ContactTest extends CiviUnitTestCase { $this->assertEquals(0, $result['values'][$result['id']]['api.CustomValue.get']['is_error']); $this->assertEquals('http://civicrm.org', $result['values'][$result['id']]['api.website.getValue']); } + /* * Test checks siusage of $values to pick & choose inputs */ @@ -1546,7 +1613,7 @@ class api_v3_ContactTest extends CiviUnitTestCase { $subfile = "APIChainedArrayValuesFromSiblingFunction"; $params = array( 'display_name' => 'batman', - 'contact_type' => 'Individual', + 'contact_type' => 'Individual', 'api.tag.create' => array('name' => '$value.id', 'description' => '$value.display_name', 'format.only_id' => 1), 'api.entity_tag.create' => array('tag_id' => '$value.api.tag.create'), ); @@ -1570,11 +1637,12 @@ class api_v3_ContactTest extends CiviUnitTestCase { $description = "This demonstrates use of the 'format.is_success' param. This param causes only the success or otherwise of the function to be returned as BOOLEAN"; $subfile = "FormatIsSuccess_True"; - $params = array('id' => 17, 'format.is_success' => 1); - $result = $this->callAPIAndDocument('Contact', 'Get', $params, __FUNCTION__, __FILE__, $description, $subfile); + $params = array('id' => 17, 'format.is_success' => 1); + $result = $this->callAPIAndDocument('Contact', 'Get', $params, __FUNCTION__, __FILE__, $description, $subfile); $this->assertEquals(1, $result); $this->callAPISuccess('Contact', 'Delete', $params); } + /* * test TrueFalse format */ @@ -1583,10 +1651,11 @@ class api_v3_ContactTest extends CiviUnitTestCase { $description = "This demonstrates use of the 'format.is_success' param. This param causes only the success or otherwise of the function to be returned as BOOLEAN"; $subfile = "FormatIsSuccess_Fail"; - $params = array('id' => 500, 'format.is_success' => 1); - $result = $this->callAPIAndDocument('Contact', 'Create', $params, __FUNCTION__, __FILE__, $description, $subfile); + $params = array('id' => 500, 'format.is_success' => 1); + $result = $this->callAPIAndDocument('Contact', 'Create', $params, __FUNCTION__, __FILE__, $description, $subfile); $this->assertEquals(0, $result); } + /* * test Single Entity format */ @@ -1596,8 +1665,8 @@ class api_v3_ContactTest extends CiviUnitTestCase { /* This param causes the only contact to be returned as an array without the other levels. /* it will be ignored if there is not exactly 1 result"; $subfile = "GetSingleContact"; - $params = array('id' => 17); - $result = $this->callAPIAndDocument('Contact', 'GetSingle', $params, __FUNCTION__, __FILE__, $description, $subfile); + $params = array('id' => 17); + $result = $this->callAPIAndDocument('Contact', 'GetSingle', $params, __FUNCTION__, __FILE__, $description, $subfile); $this->assertEquals('Test Contact', $result['display_name']); $this->callAPISuccess('Contact', 'Delete', $params); } @@ -1610,11 +1679,12 @@ class api_v3_ContactTest extends CiviUnitTestCase { $description = "/*This demonstrates use of the 'getCount' action /* This param causes the count of the only function to be returned as an integer"; $subfile = "GetCountContact"; - $params = array('id' => 17); - $result = $this->callAPIAndDocument('Contact', 'GetCount', $params, __FUNCTION__, __FILE__, $description, $subfile); + $params = array('id' => 17); + $result = $this->callAPIAndDocument('Contact', 'GetCount', $params, __FUNCTION__, __FILE__, $description, $subfile); $this->assertEquals('1', $result); $this->callAPISuccess('Contact', 'Delete', $params); } + /* * Test id only format */ @@ -1624,8 +1694,8 @@ class api_v3_ContactTest extends CiviUnitTestCase { /* This param causes the id of the only entity to be returned as an integer. /* it will be ignored if there is not exactly 1 result"; $subfile = "FormatOnlyID"; - $params = array('id' => 17, 'format.only_id' => 1); - $result = $this->callAPIAndDocument('Contact', 'Get', $params, __FUNCTION__, __FILE__, $description, $subfile); + $params = array('id' => 17, 'format.only_id' => 1); + $result = $this->callAPIAndDocument('Contact', 'Get', $params, __FUNCTION__, __FILE__, $description, $subfile); $this->assertEquals('17', $result); $this->callAPISuccess('Contact', 'Delete', $params); } @@ -1639,8 +1709,8 @@ class api_v3_ContactTest extends CiviUnitTestCase { /* This param causes only a single value of the only entity to be returned as an string. /* it will be ignored if there is not exactly 1 result"; $subFile = "FormatSingleValue"; - $params = array('id' => 17, 'return' => 'display_name'); - $result = $this->callAPIAndDocument('Contact', 'getvalue', $params, __FUNCTION__, __FILE__, $description, $subFile, 'getvalue'); + $params = array('id' => 17, 'return' => 'display_name'); + $result = $this->callAPIAndDocument('Contact', 'getvalue', $params, __FUNCTION__, __FILE__, $description, $subFile, 'getvalue'); $this->assertEquals('Test Contact', $result); $this->callAPISuccess('Contact', 'Delete', $params); } @@ -1651,7 +1721,7 @@ class api_v3_ContactTest extends CiviUnitTestCase { public function testContactCreationPermissions() { $params = array( 'contact_type' => 'Individual', - 'first_name' => 'Foo', + 'first_name' => 'Foo', 'last_name' => 'Bear', 'check_permissions' => TRUE, ); @@ -1665,16 +1735,32 @@ class api_v3_ContactTest extends CiviUnitTestCase { } public function testContactUpdatePermissions() { - $params = array('contact_type' => 'Individual', 'first_name' => 'Foo', 'last_name' => 'Bear', 'check_permissions' => TRUE); + $params = array( + 'contact_type' => 'Individual', + 'first_name' => 'Foo', + 'last_name' => 'Bear', + 'check_permissions' => TRUE + ); $result = $this->callAPISuccess('contact', 'create', $params); $config = CRM_Core_Config::singleton(); - $params = array('id' => $result['id'], 'contact_type' => 'Individual', 'last_name' => 'Bar', 'check_permissions' => TRUE); + $params = array( + 'id' => $result['id'], + 'contact_type' => 'Individual', + 'last_name' => 'Bar', + 'check_permissions' => TRUE + ); $config->userPermissionClass->permissions = array('access CiviCRM'); $result = $this->callAPIFailure('contact', 'update', $params); $this->assertEquals('API permission check failed for contact/update call; insufficient permission: require access CiviCRM and edit all contacts', $result['error_message'], 'lacking permissions should not be enough to update a contact'); - $config->userPermissionClass->permissions = array('access CiviCRM', 'add contacts', 'view all contacts', 'edit all contacts', 'import contacts'); + $config->userPermissionClass->permissions = array( + 'access CiviCRM', + 'add contacts', + 'view all contacts', + 'edit all contacts', + 'import contacts' + ); $this->callAPISuccess('contact', 'update', $params, NULL, 'overfluous permissions should be enough to update a contact'); } @@ -1843,10 +1929,14 @@ class api_v3_ContactTest extends CiviUnitTestCase { /** * CRM-14263 check that API is not affected by search profile related bug */ - public function testReturnCityProfile () { + public function testReturnCityProfile() { $contactID = $this->individualCreate(); CRM_Core_Config::singleton()->defaultSearchProfileID = 1; - $this->callAPISuccess('address', 'create', array('contact_id' => $contactID, 'city' => 'Cool City', 'location_type_id' => 1)); + $this->callAPISuccess('address', 'create', array( + 'contact_id' => $contactID, + 'city' => 'Cool City', + 'location_type_id' => 1 + )); $result = $this->callAPISuccess('contact', 'get', array('city' => 'Cool City', 'return' => 'contact_type')); $this->assertEquals(1, $result['count']); } @@ -1863,7 +1953,10 @@ class api_v3_ContactTest extends CiviUnitTestCase { $result = $this->callAPISuccess('contact', 'getlist', array('input' => $name)); $this->assertEquals(2, $result['count'], 'In line ' . __LINE__); // Force-exclude the deceased contact - $result = $this->callAPISuccess('contact', 'getlist', array('input' => $name, 'params' => array('is_deceased' => 0))); + $result = $this->callAPISuccess('contact', 'getlist', array( + 'input' => $name, + 'params' => array('is_deceased' => 0) + )); $this->assertEquals(1, $result['count'], 'In line ' . __LINE__); $this->assertEquals($contact, $result['values'][0]['id'], 'In line ' . __LINE__); } diff --git a/tests/phpunit/api/v3/ContributionPageTest.php b/tests/phpunit/api/v3/ContributionPageTest.php index 12c05dbf85..36d833ecc2 100644 --- a/tests/phpunit/api/v3/ContributionPageTest.php +++ b/tests/phpunit/api/v3/ContributionPageTest.php @@ -34,7 +34,6 @@ require_once 'CiviTest/CiviUnitTestCase.php'; * @package CiviCRM_APIv3 * @subpackage API_Contribution */ - class api_v3_ContributionPageTest extends CiviUnitTestCase { protected $_apiversion = 3; protected $testAmount = 34567; @@ -61,6 +60,7 @@ class api_v3_ContributionPageTest extends CiviUnitTestCase { public $DBResetRequired = TRUE; + public function setUp() { parent::setUp(); $this->contactIds[] = $this->individualCreate(); @@ -110,7 +110,7 @@ class api_v3_ContributionPageTest extends CiviUnitTestCase { $createResult = $this->callAPISuccess($this->_entity, 'create', $this->params); $this->id = $createResult['id']; $getParams = array( - 'amount' => ''. $this->testAmount, // 3456 + 'amount' => '' . $this->testAmount, // 3456 'currency' => 'NZD', 'financial_type_id' => 1, ); @@ -148,6 +148,7 @@ class api_v3_ContributionPageTest extends CiviUnitTestCase { $this->callAPISuccess('contribution_page', 'submit', $submitParams); $this->callAPISuccess('contribution', 'getsingle', array('contribution_page_id' => $this->_ids['contribution_page'])); } + /** * Test submit with a membership block in place */ @@ -238,12 +239,15 @@ class api_v3_ContributionPageTest extends CiviUnitTestCase { 'payment_processor' => 1, 'credit_card_number' => '4111111111111111', 'credit_card_type' => 'Visa', - 'credit_card_exp_date' => array('M' => 9, 'Y' => 2040 ), + 'credit_card_exp_date' => array('M' => 9, 'Y' => 2040), 'cvv2' => 123, ); $this->callAPIAndDocument('contribution_page', 'submit', $submitParams, __FUNCTION__, __FILE__, 'submit contribution page', NULL, 'Submit'); - $contributions = $this->callAPISuccess('contribution', 'get', array('contribution_page_id' => $this->_ids['contribution_page'], 'contribution_status_id' => 1)); + $contributions = $this->callAPISuccess('contribution', 'get', array( + 'contribution_page_id' => $this->_ids['contribution_page'], + 'contribution_status_id' => 1 + )); $this->assertCount(2, $contributions['values']); $membershipPayment = $this->callAPISuccess('membership_payment', 'getsingle', array()); $this->assertTrue(in_array($membershipPayment['contribution_id'], array_keys($contributions['values']))); @@ -278,7 +282,7 @@ class api_v3_ContributionPageTest extends CiviUnitTestCase { 'payment_processor' => 1, 'credit_card_number' => '4111111111111111', 'credit_card_type' => 'Visa', - 'credit_card_exp_date' => array('M' => 9, 'Y' => 2040 ), + 'credit_card_exp_date' => array('M' => 9, 'Y' => 2040), 'cvv2' => 123, 'is_recur' => 1, 'frequency_interval' => 1, @@ -286,7 +290,10 @@ class api_v3_ContributionPageTest extends CiviUnitTestCase { ); $this->callAPIAndDocument('contribution_page', 'submit', $submitParams, __FUNCTION__, __FILE__, 'submit contribution page', NULL, 'Submit'); - $contribution = $this->callAPISuccess('contribution', 'getsingle', array('contribution_page_id' => $this->_ids['contribution_page'], 'contribution_status_id' => 1)); + $contribution = $this->callAPISuccess('contribution', 'getsingle', array( + 'contribution_page_id' => $this->_ids['contribution_page'], + 'contribution_status_id' => 1 + )); $membershipPayment = $this->callAPISuccess('membership_payment', 'getsingle', array()); $this->assertEquals($membershipPayment['contribution_id'], $contribution['id']); $membership = $this->callAPISuccessGetSingle('membership', array('id' => $membershipPayment['membership_id'])); @@ -299,7 +306,11 @@ class api_v3_ContributionPageTest extends CiviUnitTestCase { $submitParams['contact_id'] = $contribution['contact_id']; $dummyPP->setDoDirectPaymentResult(array('contribution_status_id' => 1, 'trxn_id' => 'create_second_success')); $this->callAPISuccess('contribution_page', 'submit', $submitParams); - $this->callAPISuccess('contribution', 'getsingle', array('id' => array('NOT IN' => array($contribution['id'])), 'contribution_page_id' => $this->_ids['contribution_page'], 'contribution_status_id' => 1)); + $this->callAPISuccess('contribution', 'getsingle', array( + 'id' => array('NOT IN' => array($contribution['id'])), + 'contribution_page_id' => $this->_ids['contribution_page'], + 'contribution_status_id' => 1 + )); $renewedMembership = $this->callAPISuccessGetSingle('membership', array('id' => $membershipPayment['membership_id'])); $this->assertEquals(date('Y-m-d', strtotime('+ 1 year', strtotime($membership['end_date']))), $renewedMembership['end_date']); $recurringContribution = $this->callAPISuccess('contribution_recur', 'getsingle', array('id' => $contribution['contribution_recur_id'])); @@ -333,7 +344,7 @@ class api_v3_ContributionPageTest extends CiviUnitTestCase { 'payment_processor' => 1, 'credit_card_number' => '4111111111111111', 'credit_card_type' => 'Visa', - 'credit_card_exp_date' => array('M' => 9, 'Y' => 2040 ), + 'credit_card_exp_date' => array('M' => 9, 'Y' => 2040), 'cvv2' => 123, 'is_recur' => 1, 'frequency_interval' => 1, @@ -341,7 +352,10 @@ class api_v3_ContributionPageTest extends CiviUnitTestCase { ); $this->callAPIAndDocument('contribution_page', 'submit', $submitParams, __FUNCTION__, __FILE__, 'submit contribution page', NULL, 'Submit'); - $contribution = $this->callAPISuccess('contribution', 'getsingle', array('contribution_page_id' => $this->_ids['contribution_page'], 'contribution_status_id' => 2)); + $contribution = $this->callAPISuccess('contribution', 'getsingle', array( + 'contribution_page_id' => $this->_ids['contribution_page'], + 'contribution_status_id' => 2 + )); $membershipPayment = $this->callAPISuccess('membership_payment', 'getsingle', array()); $this->assertEquals($membershipPayment['contribution_id'], $contribution['id']); $membership = $this->callAPISuccessGetSingle('membership', array('id' => $membershipPayment['membership_id'])); @@ -349,21 +363,28 @@ class api_v3_ContributionPageTest extends CiviUnitTestCase { $this->assertEquals(5, $membership['status_id']); //@todo - check with Joe about these not existing //$this->callAPISuccess('line_item', 'getsingle', array('contribution_id' => $contribution['id'], 'entity_id' => $membership['id'])); - $this->callAPISuccess('contribution', 'completetransaction', array('id' => $contribution['id'], 'trxn_id' => 'ipn_called')); + $this->callAPISuccess('contribution', 'completetransaction', array( + 'id' => $contribution['id'], + 'trxn_id' => 'ipn_called' + )); $membership = $this->callAPISuccessGetSingle('membership', array('id' => $membershipPayment['membership_id'])); //renew it with processor setting completed - should extend membership $submitParams = array_merge($submitParams, array( - 'contact_id' => $contribution['contact_id'], - 'is_recur' => 1, - 'frequency_interval' => 1, - 'frequency_unit' => 'month',) + 'contact_id' => $contribution['contact_id'], + 'is_recur' => 1, + 'frequency_interval' => 1, + 'frequency_unit' => 'month', + ) ); $dummyPP->setDoDirectPaymentResult(array('contribution_status_id' => 2)); $this->callAPISuccess('contribution_page', 'submit', $submitParams); $newContribution = $this->callAPISuccess('contribution', 'getsingle', array( - 'id' => array( - 'NOT IN' => array($contribution['id'])), 'contribution_page_id' => $this->_ids['contribution_page'], - 'contribution_status_id' => 2) + 'id' => array( + 'NOT IN' => array($contribution['id']) + ), + 'contribution_page_id' => $this->_ids['contribution_page'], + 'contribution_status_id' => 2 + ) ); $renewedMembership = $this->callAPISuccessGetSingle('membership', array('id' => $membershipPayment['membership_id'])); @@ -402,7 +423,10 @@ class api_v3_ContributionPageTest extends CiviUnitTestCase { * This function ensures it exists & populates $this->_ids with it's data */ public function setUpMembershipBlockPriceSet() { - $this->_ids['price_set'][] = $this->callAPISuccess('price_set', 'getvalue', array('name' => 'default_membership_type_amount', 'return' => 'id')); + $this->_ids['price_set'][] = $this->callAPISuccess('price_set', 'getvalue', array( + 'name' => 'default_membership_type_amount', + 'return' => 'id' + )); if (empty($this->_ids['membership_type'])) { $this->_ids['membership_type'] = array($this->membershipTypeCreate(array('minimum_fee' => 2))); } @@ -438,7 +462,7 @@ class api_v3_ContributionPageTest extends CiviUnitTestCase { $this->_ids['price_set'][] = $priceSet['id']; } $priceSetID = reset($this->_ids['price_set']); - CRM_Price_BAO_PriceSet::addTo('civicrm_contribution_page', $contributionPageResult['id'], $priceSetID ); + CRM_Price_BAO_PriceSet::addTo('civicrm_contribution_page', $contributionPageResult['id'], $priceSetID); if (empty($this->_ids['price_field'])) { $priceField = $this->callAPISuccess('price_field', 'create', array( @@ -472,7 +496,7 @@ class api_v3_ContributionPageTest extends CiviUnitTestCase { // put stuff here that should happen before all tests in this unit } - public static function tearDownAfterClass(){ + public static function tearDownAfterClass() { $tablesToTruncate = array( 'civicrm_contact', 'civicrm_financial_type', diff --git a/tests/phpunit/api/v3/ContributionTest.php b/tests/phpunit/api/v3/ContributionTest.php index 9adb5138cf..7325571d49 100644 --- a/tests/phpunit/api/v3/ContributionTest.php +++ b/tests/phpunit/api/v3/ContributionTest.php @@ -35,7 +35,6 @@ require_once 'CiviTest/CiviMailUtils.php'; * @package CiviCRM_APIv3 * @subpackage API_Contribution */ - class api_v3_ContributionTest extends CiviUnitTestCase { /** @@ -61,7 +60,7 @@ class api_v3_ContributionTest extends CiviUnitTestCase { 'contact_id' => $this->_individualId, 'receive_date' => '20120511', 'total_amount' => 100.00, - 'financial_type_id' => $this->_financialTypeId, + 'financial_type_id' => $this->_financialTypeId, 'non_deductible_amount' => 10.00, 'fee_amount' => 5.00, 'net_amount' => 95.00, @@ -89,7 +88,7 @@ class api_v3_ContributionTest extends CiviUnitTestCase { 'is_allow_other_amount' => 1, 'min_amount' => 10, 'max_amount' => 1000, - ); + ); } public function tearDown() { @@ -244,12 +243,13 @@ class api_v3_ContributionTest extends CiviUnitTestCase { $this->assertEquals(2, $contribution['count']); $this->callAPISuccess('Contribution', 'Delete', array( - 'id' => $this->_contribution['id'], + 'id' => $this->_contribution['id'], )); $this->callAPISuccess('Contribution', 'Delete', array( - 'id' => $contribution2['id'], + 'id' => $contribution2['id'], )); } + ///////////////// civicrm_contribution_ public function testCreateEmptyContributionIDUseDonation() { $params = array( @@ -275,7 +275,7 @@ class api_v3_ContributionTest extends CiviUnitTestCase { 'contribution_type_id' => 3, ); $contribution = $this->callAPISuccess('contribution', 'create', $params); - $contribution = $this->callAPISuccess('contribution', 'getsingle', array( 'id' => $contribution['id'])); + $contribution = $this->callAPISuccess('contribution', 'getsingle', array('id' => $contribution['id'])); $this->assertEquals(3, $contribution['financial_type_id']); } @@ -309,9 +309,9 @@ class api_v3_ContributionTest extends CiviUnitTestCase { * and / or moved to the automated test suite */ public function testCreateGetFieldsWithCustom() { - $ids = $this->entityCustomGroupWithSingleFieldCreate(__FUNCTION__, __FILE__); + $ids = $this->entityCustomGroupWithSingleFieldCreate(__FUNCTION__, __FILE__); $idsContact = $this->entityCustomGroupWithSingleFieldCreate(__FUNCTION__, 'ContactTest.php'); - $result = $this->callAPISuccess('Contribution', 'getfields', array()); + $result = $this->callAPISuccess('Contribution', 'getfields', array()); $this->assertArrayHasKey('custom_' . $ids['custom_field_id'], $result['values']); $this->assertArrayNotHasKey('custom_' . $idsContact['custom_field_id'], $result['values']); $this->customFieldDelete($ids['custom_field_id']); @@ -326,7 +326,7 @@ class api_v3_ContributionTest extends CiviUnitTestCase { 'contact_id' => $this->_individualId, 'receive_date' => '20120511', 'total_amount' => 100.00, - 'financial_type_id' => $this->_financialTypeId, + 'financial_type_id' => $this->_financialTypeId, 'payment_instrument_id' => 1, 'non_deductible_amount' => 10.00, 'fee_amount' => 50.00, @@ -346,6 +346,7 @@ class api_v3_ContributionTest extends CiviUnitTestCase { )); $this->assertEquals(0, $lineItems['count']); } + /* * Test checks that passing in line items suppresses the create mechanism */ @@ -409,7 +410,7 @@ class api_v3_ContributionTest extends CiviUnitTestCase { $contribution = $this->callAPIAndDocument('contribution', 'create', $params, __FUNCTION__, __FILE__); $this->assertEquals($contribution['values'][$contribution['id']]['contact_id'], $this->_individualId); $this->assertEquals($contribution['values'][$contribution['id']]['total_amount'], 100.00); - $this->assertEquals($contribution['values'][$contribution['id']]['financial_type_id'], 1 ); + $this->assertEquals($contribution['values'][$contribution['id']]['financial_type_id'], 1); $this->assertEquals($contribution['values'][$contribution['id']]['trxn_id'], 12345); $this->assertEquals($contribution['values'][$contribution['id']]['invoice_id'], 67890); $this->assertEquals($contribution['values'][$contribution['id']]['source'], 'SSF'); @@ -419,13 +420,14 @@ class api_v3_ContributionTest extends CiviUnitTestCase { 'contribution_id' => $contribution['id'], 'entity_table' => 'civicrm_contribution', 'sequential' => 1, - )); + )); $this->assertEquals(1, $lineItems['count']); $this->assertEquals($contribution['id'], $lineItems['values'][0]['entity_id']); $this->assertEquals($contribution['id'], $lineItems['values'][0]['contribution_id']); $this->_checkFinancialRecords($contribution, 'offline'); $this->contributionGetnCheck($params, $contribution['id']); } + /** * Test create with valid payment instument */ @@ -439,7 +441,10 @@ class api_v3_ContributionTest extends CiviUnitTestCase { $this->assertArrayHasKey('payment_instrument', $contribution['values'][0]); $this->assertEquals('EFT', $contribution['values'][0]['payment_instrument']); - $this->callAPISuccess('contribution', 'create', array('id' => $contribution['id'], 'payment_instrument' => 'Credit Card')); + $this->callAPISuccess('contribution', 'create', array( + 'id' => $contribution['id'], + 'payment_instrument' => 'Credit Card' + )); $contribution = $this->callAPISuccess('contribution', 'get', array( 'sequential' => 1, 'id' => $contribution['id'] @@ -453,24 +458,39 @@ class api_v3_ContributionTest extends CiviUnitTestCase { $params2 = $this->_params + array('payment_instrument' => 'Cash'); $this->callAPISuccess('contribution', 'create', $params); $this->callAPISuccess('contribution', 'create', $params2); - $contribution = $this->callAPISuccess('contribution', 'get', array( 'sequential' => 1, 'contribution_payment_instrument_id' => 'Cash')); + $contribution = $this->callAPISuccess('contribution', 'get', array( + 'sequential' => 1, + 'contribution_payment_instrument_id' => 'Cash' + )); $this->assertArrayHasKey('payment_instrument', $contribution['values'][0]); $this->assertEquals('Cash', $contribution['values'][0]['payment_instrument']); $this->assertEquals(1, $contribution['count']); - $contribution = $this->callAPISuccess('contribution', 'get', array('sequential' => 1, 'payment_instrument_id' => 'EFT')); + $contribution = $this->callAPISuccess('contribution', 'get', array( + 'sequential' => 1, + 'payment_instrument_id' => 'EFT' + )); $this->assertArrayHasKey('payment_instrument', $contribution['values'][0]); $this->assertEquals('EFT', $contribution['values'][0]['payment_instrument']); $this->assertEquals(1, $contribution['count']); - $contribution = $this->callAPISuccess('contribution', 'get', array( 'sequential' => 1, 'payment_instrument_id' => 5)); + $contribution = $this->callAPISuccess('contribution', 'get', array( + 'sequential' => 1, + 'payment_instrument_id' => 5 + )); $this->assertArrayHasKey('payment_instrument', $contribution['values'][0]); $this->assertEquals('EFT', $contribution['values'][0]['payment_instrument']); $this->assertEquals(1, $contribution['count']); - $contribution = $this->callAPISuccess('contribution', 'get', array( 'sequential' => 1, 'payment_instrument' => 'EFT')); + $contribution = $this->callAPISuccess('contribution', 'get', array( + 'sequential' => 1, + 'payment_instrument' => 'EFT' + )); $this->assertArrayHasKey('payment_instrument', $contribution['values'][0]); $this->assertEquals('EFT', $contribution['values'][0]['payment_instrument']); $this->assertEquals(1, $contribution['count']); - $contribution = $this->callAPISuccess('contribution', 'create', array('id' => $contribution['id'], 'payment_instrument' => 'Credit Card')); - $contribution = $this->callAPISuccess('contribution', 'get', array( 'sequential' => 1, 'id' => $contribution['id'] )); + $contribution = $this->callAPISuccess('contribution', 'create', array( + 'id' => $contribution['id'], + 'payment_instrument' => 'Credit Card' + )); + $contribution = $this->callAPISuccess('contribution', 'get', array('sequential' => 1, 'id' => $contribution['id'])); $this->assertArrayHasKey('payment_instrument', $contribution['values'][0]); $this->assertEquals('Credit Card', $contribution['values'][0]['payment_instrument']); $this->assertEquals(1, $contribution['count']); @@ -562,8 +582,8 @@ class api_v3_ContributionTest extends CiviUnitTestCase { */ public function testCreateContributionWithNote() { $description = "Demonstrates creating contribution with Note Entity"; - $subfile = "ContributionCreateWithNote"; - $params = array( + $subfile = "ContributionCreateWithNote"; + $params = array( 'contact_id' => $this->_individualId, 'receive_date' => '2012-01-01', 'total_amount' => 100.00, @@ -580,13 +600,17 @@ class api_v3_ContributionTest extends CiviUnitTestCase { ); $contribution = $this->callAPIAndDocument('contribution', 'create', $params, __FUNCTION__, __FILE__, $description, $subfile); - $result = $this->callAPISuccess('note', 'get', array('entity_table' => 'civicrm_contribution', 'entity_id' => $contribution['id'], 'sequential' => 1)); + $result = $this->callAPISuccess('note', 'get', array( + 'entity_table' => 'civicrm_contribution', + 'entity_id' => $contribution['id'], + 'sequential' => 1 + )); $this->assertEquals('my contribution note', $result['values'][0]['note']); $this->callAPISuccess('contribution', 'delete', array('id' => $contribution['id'])); } public function testCreateContributionWithNoteUniqueNameAliases() { - $params = array( + $params = array( 'contact_id' => $this->_individualId, 'receive_date' => '2012-01-01', 'total_amount' => 100.00, @@ -603,7 +627,11 @@ class api_v3_ContributionTest extends CiviUnitTestCase { ); $contribution = $this->callAPISuccess('contribution', 'create', $params); - $result = $this->callAPISuccess('note', 'get', array('entity_table' => 'civicrm_contribution', 'entity_id' => $contribution['id'], 'sequential' => 1)); + $result = $this->callAPISuccess('note', 'get', array( + 'entity_table' => 'civicrm_contribution', + 'entity_id' => $contribution['id'], + 'sequential' => 1 + )); $this->assertEquals('my contribution note', $result['values'][0]['note']); $this->callAPISuccess('contribution', 'delete', array('id' => $contribution['id'])); } @@ -614,15 +642,18 @@ class api_v3_ContributionTest extends CiviUnitTestCase { */ public function testCreateContributionWithSoftCredt() { $description = "Demonstrates creating contribution with SoftCredit"; - $subfile = "ContributionCreateWithSoftCredit"; - $contact2 = $this->callAPISuccess('Contact', 'create', array('display_name' => 'superman', 'contact_type' => 'Individual')); - $softparams = array( + $subfile = "ContributionCreateWithSoftCredit"; + $contact2 = $this->callAPISuccess('Contact', 'create', array( + 'display_name' => 'superman', + 'contact_type' => 'Individual' + )); + $softparams = array( 'contact_id' => $contact2['id'], 'amount' => 50, 'soft_credit_type_id' => 3 ); - $params = $this->_params + array('soft_credit' => array(1 => $softparams)); + $params = $this->_params + array('soft_credit' => array(1 => $softparams)); $contribution = $this->callAPIAndDocument('contribution', 'create', $params, __FUNCTION__, __FILE__, $description, $subfile); $result = $this->callAPISuccess('contribution', 'get', array('return' => 'soft_credit', 'sequential' => 1)); @@ -636,11 +667,14 @@ class api_v3_ContributionTest extends CiviUnitTestCase { public function testCreateContributionWithSoftCreditDefaults() { $description = "Demonstrates creating contribution with Soft Credit defaults for amount and type"; - $subfile = "ContributionCreateWithSoftCreditDefaults"; - $contact2 = $this->callAPISuccess('Contact', 'create', array('display_name' => 'superman', 'contact_type' => 'Individual')); + $subfile = "ContributionCreateWithSoftCreditDefaults"; + $contact2 = $this->callAPISuccess('Contact', 'create', array( + 'display_name' => 'superman', + 'contact_type' => 'Individual' + )); $params = $this->_params + array( - 'soft_credit_to' => $contact2['id'], - ); + 'soft_credit_to' => $contact2['id'], + ); $contribution = $this->callAPIAndDocument('contribution', 'create', $params, __FUNCTION__, __FILE__, $description, $subfile); $result = $this->callAPISuccess('contribution', 'get', array('return' => 'soft_credit', 'sequential' => 1)); @@ -655,11 +689,14 @@ class api_v3_ContributionTest extends CiviUnitTestCase { public function testCreateContributionWithHonoreeContact() { $description = "Demonstrates creating contribution with Soft Credit by passing in honor_contact_id"; - $subfile = "ContributionCreateWithHonoreeContact"; - $contact2 = $this->callAPISuccess('Contact', 'create', array('display_name' => 'superman', 'contact_type' => 'Individual')); + $subfile = "ContributionCreateWithHonoreeContact"; + $contact2 = $this->callAPISuccess('Contact', 'create', array( + 'display_name' => 'superman', + 'contact_type' => 'Individual' + )); $params = $this->_params + array( - 'honor_contact_id' => $contact2['id'], - ); + 'honor_contact_id' => $contact2['id'], + ); $contribution = $this->callAPIAndDocument('contribution', 'create', $params, __FUNCTION__, __FILE__, $description, $subfile); $result = $this->callAPISuccess('contribution', 'get', array('return' => 'soft_credit', 'sequential' => 1)); @@ -681,7 +718,7 @@ class api_v3_ContributionTest extends CiviUnitTestCase { $page = $this->callAPISuccess('contribution_page', 'create', $this->_pageParams); $this->assertAPISuccess($page); require_once 'api/v3/examples/Contribution/Create.php'; - $result = contribution_create_example(); + $result = contribution_create_example(); $this->assertAPISuccess($result); $contributionId = $result['id']; $expectedResult = contribution_create_expectedresult(); @@ -710,7 +747,7 @@ class api_v3_ContributionTest extends CiviUnitTestCase { $this->assertEquals($contribution['values'][$contribution['id']]['total_amount'], 100.00); $this->assertEquals($contribution['values'][$contribution['id']]['fee_amount'], 50.00); $this->assertEquals($contribution['values'][$contribution['id']]['net_amount'], 50.00); - $this->assertEquals($contribution['values'][$contribution['id']]['financial_type_id'], 1 ); + $this->assertEquals($contribution['values'][$contribution['id']]['financial_type_id'], 1); $this->assertEquals($contribution['values'][$contribution['id']]['trxn_id'], 12345); $this->assertEquals($contribution['values'][$contribution['id']]['invoice_id'], 67890); $this->assertEquals($contribution['values'][$contribution['id']]['source'], 'SSF'); @@ -721,16 +758,16 @@ class api_v3_ContributionTest extends CiviUnitTestCase { 'entity_id' => $contribution['id'], 'entity_table' => 'civicrm_contribution', 'sequential' => 1, - )); + )); $this->assertEquals(1, $lineItems['count']); $this->assertEquals($contribution['id'], $lineItems['values'][0]['entity_id']); $this->assertEquals($contribution['id'], $lineItems['values'][0]['contribution_id']); $lineItems = $this->callAPISuccess('line_item', 'get', array( - 'entity_id' => $contribution['id'], - 'contribution_id' => $contribution['id'], - 'entity_table' => 'civicrm_contribution', - 'sequential' => 1, + 'entity_id' => $contribution['id'], + 'contribution_id' => $contribution['id'], + 'entity_table' => 'civicrm_contribution', + 'sequential' => 1, )); $this->assertEquals(1, $lineItems['count']); $this->_checkFinancialRecords($contribution, 'feeAmount'); @@ -742,7 +779,7 @@ class api_v3_ContributionTest extends CiviUnitTestCase { */ public function testCreateContributionOnline() { CRM_Financial_BAO_PaymentProcessor::create($this->_processorParams); - $contributionPage = $this->callAPISuccess( 'contribution_page', 'create', $this->_pageParams ); + $contributionPage = $this->callAPISuccess('contribution_page', 'create', $this->_pageParams); $this->assertAPISuccess($contributionPage); $params = array( 'contact_id' => $this->_individualId, @@ -761,7 +798,7 @@ class api_v3_ContributionTest extends CiviUnitTestCase { $contribution = $this->callAPIAndDocument('contribution', 'create', $params, __FUNCTION__, __FILE__); $this->assertEquals($contribution['values'][$contribution['id']]['contact_id'], $this->_individualId); $this->assertEquals($contribution['values'][$contribution['id']]['total_amount'], 100.00); - $this->assertEquals($contribution['values'][$contribution['id']]['financial_type_id'], 1 ); + $this->assertEquals($contribution['values'][$contribution['id']]['financial_type_id'], 1); $this->assertEquals($contribution['values'][$contribution['id']]['trxn_id'], 12345); $this->assertEquals($contribution['values'][$contribution['id']]['invoice_id'], 67890); $this->assertEquals($contribution['values'][$contribution['id']]['source'], 'SSF'); @@ -796,7 +833,7 @@ class api_v3_ContributionTest extends CiviUnitTestCase { public function testCreateContributionPayLaterOnline() { CRM_Financial_BAO_PaymentProcessor::create($this->_processorParams); $this->_pageParams['is_pay_later'] = 1; - $contributionPage = $this->callAPISuccess( 'contribution_page', 'create', $this->_pageParams ); + $contributionPage = $this->callAPISuccess('contribution_page', 'create', $this->_pageParams); $this->assertAPISuccess($contributionPage); $params = array( 'contact_id' => $this->_individualId, @@ -815,7 +852,7 @@ class api_v3_ContributionTest extends CiviUnitTestCase { $contribution = $this->callAPIAndDocument('contribution', 'create', $params, __FUNCTION__, __FILE__); $this->assertEquals($contribution['values'][$contribution['id']]['contact_id'], $this->_individualId); $this->assertEquals($contribution['values'][$contribution['id']]['total_amount'], 100.00); - $this->assertEquals($contribution['values'][$contribution['id']]['financial_type_id'], 1 ); + $this->assertEquals($contribution['values'][$contribution['id']]['financial_type_id'], 1); $this->assertEquals($contribution['values'][$contribution['id']]['trxn_id'], 12345); $this->assertEquals($contribution['values'][$contribution['id']]['invoice_id'], 67890); $this->assertEquals($contribution['values'][$contribution['id']]['source'], 'SSF'); @@ -829,7 +866,7 @@ class api_v3_ContributionTest extends CiviUnitTestCase { */ public function testCreateContributionPendingOnline() { $paymentProcessor = CRM_Financial_BAO_PaymentProcessor::create($this->_processorParams); - $contributionPage = $this->callAPISuccess( 'contribution_page', 'create', $this->_pageParams ); + $contributionPage = $this->callAPISuccess('contribution_page', 'create', $this->_pageParams); $this->assertAPISuccess($contributionPage); $params = array( 'contact_id' => $this->_individualId, @@ -846,7 +883,7 @@ class api_v3_ContributionTest extends CiviUnitTestCase { $contribution = $this->callAPIAndDocument('contribution', 'create', $params, __FUNCTION__, __FILE__); $this->assertEquals($contribution['values'][$contribution['id']]['contact_id'], $this->_individualId); $this->assertEquals($contribution['values'][$contribution['id']]['total_amount'], 100.00); - $this->assertEquals($contribution['values'][$contribution['id']]['financial_type_id'], 1 ); + $this->assertEquals($contribution['values'][$contribution['id']]['financial_type_id'], 1); $this->assertEquals($contribution['values'][$contribution['id']]['trxn_id'], 12345); $this->assertEquals($contribution['values'][$contribution['id']]['invoice_id'], 67890); $this->assertEquals($contribution['values'][$contribution['id']]['source'], 'SSF'); @@ -860,7 +897,10 @@ class api_v3_ContributionTest extends CiviUnitTestCase { public function testCreateBAODefaults() { unset($this->_params['contribution_source_id'], $this->_params['payment_instrument_id']); $contribution = $this->callAPISuccess('contribution', 'create', $this->_params); - $contribution = $this->callAPISuccess('contribution', 'getsingle', array('id' => $contribution['id'], 'api.contribution.delete' => 1)); + $contribution = $this->callAPISuccess('contribution', 'getsingle', array( + 'id' => $contribution['id'], + 'api.contribution.delete' => 1 + )); $this->assertEquals(1, $contribution['contribution_status_id']); $this->assertEquals('Check', $contribution['payment_instrument']); } @@ -884,15 +924,16 @@ class api_v3_ContributionTest extends CiviUnitTestCase { $newParams = array( 'id' => $contribution['id'], - 'total_amount' => '125'); + 'total_amount' => '125' + ); $contribution = $this->callAPISuccess('contribution', 'create', $newParams); $lineItems = $this->callAPISuccess('line_item', 'getvalue', array( - 'entity_id' => $contribution['id'], - 'entity_table' => 'civicrm_contribution', - 'sequential' => 1, - 'return' => 'line_total', + 'entity_id' => $contribution['id'], + 'entity_table' => 'civicrm_contribution', + 'sequential' => 1, + 'return' => 'line_total', )); $this->assertEquals('125.00', $lineItems); @@ -920,8 +961,9 @@ class api_v3_ContributionTest extends CiviUnitTestCase { $contribution = $this->callAPISuccess('contribution', 'create', $contribParams); $newParams = array_merge($contribParams, array( - 'id' => $contribution['id'], - 'contribution_status_id' => 1,) + 'id' => $contribution['id'], + 'contribution_status_id' => 1, + ) ); $contribution = $this->callAPISuccess('contribution', 'create', $newParams); $contribution = $contribution['values'][$contribution['id']]; @@ -946,8 +988,9 @@ class api_v3_ContributionTest extends CiviUnitTestCase { $contribution = $this->callAPISuccess('contribution', 'create', $contribParams); $newParams = array_merge($contribParams, array( - 'id' => $contribution['id'], - 'payment_instrument_id' => $instrumentId,) + 'id' => $contribution['id'], + 'payment_instrument_id' => $instrumentId, + ) ); $contribution = $this->callAPISuccess('contribution', 'create', $newParams); $this->assertAPISuccess($contribution); @@ -969,8 +1012,8 @@ class api_v3_ContributionTest extends CiviUnitTestCase { ); $contribution = $this->callAPISuccess('contribution', 'create', $contribParams); $newParams = array_merge($contribParams, array( - 'id' => $contribution['id'], - 'contribution_status_id' => 7, + 'id' => $contribution['id'], + 'contribution_status_id' => 7, ) ); @@ -993,8 +1036,8 @@ class api_v3_ContributionTest extends CiviUnitTestCase { ); $contribution = $this->callAPISuccess('contribution', 'create', $contribParams); $newParams = array_merge($contribParams, array( - 'id' => $contribution['id'], - 'contribution_status_id' => 2, + 'id' => $contribution['id'], + 'contribution_status_id' => 2, ) ); $this->callAPIFailure('contribution', 'create', $newParams, ts('Cannot change contribution status from Completed to Pending.')); @@ -1017,8 +1060,8 @@ class api_v3_ContributionTest extends CiviUnitTestCase { ); $contribution = $this->callAPISuccess('contribution', 'create', $contribParams); $newParams = array_merge($contribParams, array( - 'id' => $contribution['id'], - 'contribution_status_id' => 3, + 'id' => $contribution['id'], + 'contribution_status_id' => 3, ) ); $contribution = $this->callAPISuccess('contribution', 'create', $newParams); @@ -1041,8 +1084,8 @@ class api_v3_ContributionTest extends CiviUnitTestCase { ); $contribution = $this->callAPISuccess('contribution', 'create', $contribParams); $newParams = array_merge($contribParams, array( - 'id' => $contribution['id'], - 'financial_type_id' => 3, + 'id' => $contribution['id'], + 'financial_type_id' => 3, ) ); $contribution = $this->callAPISuccess('contribution', 'create', $newParams); @@ -1056,7 +1099,10 @@ class api_v3_ContributionTest extends CiviUnitTestCase { public function testCreateUpdateWithoutChangingPendingStatus() { $contribution = $this->callAPISuccess('contribution', 'create', array_merge($this->_params, array('contribution_status_id' => 2))); $this->callAPISuccess('contribution', 'create', array('id' => $contribution['id'], 'source' => 'new source')); - $contribution = $this->callAPISuccess('contribution', 'getsingle', array('id' => $contribution['id'], 'api.contribution.delete' => 1)); + $contribution = $this->callAPISuccess('contribution', 'getsingle', array( + 'id' => $contribution['id'], + 'api.contribution.delete' => 1 + )); $this->assertEquals(2, $contribution['contribution_status_id']); } //To Update Contribution @@ -1111,7 +1157,7 @@ class api_v3_ContributionTest extends CiviUnitTestCase { $this->assertEquals($contribution['values'][$contributionID]['contact_id'], $this->_individualId); $this->assertEquals($contribution['values'][$contributionID]['total_amount'], 110.00); - $this->assertEquals($contribution['values'][$contributionID]['financial_type_id'], $this->_financialTypeId ); + $this->assertEquals($contribution['values'][$contributionID]['financial_type_id'], $this->_financialTypeId); $this->assertEquals($contribution['values'][$contributionID]['instrument_id'], $old_payment_instrument); $this->assertEquals($contribution['values'][$contributionID]['non_deductible_amount'], 10.00); $this->assertEquals($contribution['values'][$contributionID]['fee_amount'], $old_fee_amount); @@ -1186,7 +1232,7 @@ class api_v3_ContributionTest extends CiviUnitTestCase { $this->assertEquals($p['contact_id'], $res['contact_id']); $this->assertEquals($p['total_amount'], $res['total_amount']); - $this->assertEquals($p['financial_type_id'], $res['financial_type_id'] ); + $this->assertEquals($p['financial_type_id'], $res['financial_type_id']); $this->assertEquals($p['net_amount'], $res['net_amount']); $this->assertEquals($p['non_deductible_amount'], $res['non_deductible_amount']); $this->assertEquals($p['fee_amount'], $res['fee_amount']); @@ -1238,7 +1284,7 @@ class api_v3_ContributionTest extends CiviUnitTestCase { $this->assertEquals($p2['contact_id'], $res['contact_id']); $this->assertEquals($p2['total_amount'], $res['total_amount']); - $this->assertEquals($p2['financial_type_id'], $res['financial_type_id'] ); + $this->assertEquals($p2['financial_type_id'], $res['financial_type_id']); $this->assertEquals($p2['net_amount'], $res['net_amount']); $this->assertEquals($p2['non_deductible_amount'], $res['non_deductible_amount']); $this->assertEquals($p2['fee_amount'], $res['fee_amount']); @@ -1258,7 +1304,7 @@ class api_v3_ContributionTest extends CiviUnitTestCase { * that person */ public function testCompleteTransaction() { - $mut = new CiviMailUtils( $this, TRUE ); + $mut = new CiviMailUtils($this, TRUE); $this->createLoggedInUser(); $params = array_merge($this->_params, array('contribution_status_id' => 2)); $contribution = $this->callAPISuccess('contribution', 'create', $params); @@ -1281,7 +1327,7 @@ class api_v3_ContributionTest extends CiviUnitTestCase { * tests. */ public function testCompleteTransactionWithReceiptDateSet() { - $mut = new CiviMailUtils( $this, TRUE ); + $mut = new CiviMailUtils($this, TRUE); $this->createLoggedInUser(); $params = array_merge($this->_params, array('contribution_status_id' => 2, 'receipt_date' => 'now')); $contribution = $this->callAPISuccess('contribution', 'create', $params); @@ -1302,14 +1348,18 @@ class api_v3_ContributionTest extends CiviUnitTestCase { * that person */ public function testCompleteTransactionWithParticipantRecord() { - $mut = new CiviMailUtils( $this, TRUE ); + $mut = new CiviMailUtils($this, TRUE); $mut->clearMessages(); $this->createLoggedInUser(); $contributionID = $this->createPendingParticipantContribution(); $this->callAPISuccess('contribution', 'completetransaction', array( - 'id' => $contributionID,) + 'id' => $contributionID, + ) ); - $participantStatus = $this->callAPISuccessGetValue('participant', array('id' => $this->_ids['participant'], 'return' => 'participant_status_id')); + $participantStatus = $this->callAPISuccessGetValue('participant', array( + 'id' => $this->_ids['participant'], + 'return' => 'participant_status_id' + )); $this->assertEquals(1, $participantStatus); $mut->checkMailLog(array( 'Annual CiviCRM meet', @@ -1375,14 +1425,14 @@ class api_v3_ContributionTest extends CiviUnitTestCase { )); $priceSetID = $priceSet['id']; - CRM_Price_BAO_PriceSet::addTo('civicrm_contribution_page', $contributionPageResult['id'], $priceSetID ); + CRM_Price_BAO_PriceSet::addTo('civicrm_contribution_page', $contributionPageResult['id'], $priceSetID); $priceField = $this->callAPISuccess('price_field', 'create', array( - 'price_set_id' => $priceSetID , + 'price_set_id' => $priceSetID, 'label' => 'Goat Breed', 'html_type' => 'Radio', )); $priceFieldValue = $this->callAPISuccess('price_field_value', 'create', array( - 'price_set_id' => $priceSetID , + 'price_set_id' => $priceSetID, 'price_field_id' => $priceField['id'], 'label' => 'Long Haired Goat', 'amount' => 20, @@ -1392,7 +1442,7 @@ class api_v3_ContributionTest extends CiviUnitTestCase { ); $this->_ids['price_field_value'] = array($priceFieldValue['id']); $priceFieldValue = $this->callAPISuccess('price_field_value', 'create', array( - 'price_set_id' => $priceSetID , + 'price_set_id' => $priceSetID, 'price_field_id' => $priceField['id'], 'label' => 'Shoe-eating Goat', 'amount' => 10, @@ -1412,7 +1462,7 @@ class api_v3_ContributionTest extends CiviUnitTestCase { * Set up a pending transaction with a specific price field id * @param int $priceFieldValueID */ - public function setUpPendingContribution($priceFieldValueID){ + public function setUpPendingContribution($priceFieldValueID) { $contactID = $this->individualCreate(); $membership = $this->callAPISuccess('membership', 'create', array( 'contact_id' => $contactID, @@ -1456,11 +1506,11 @@ class api_v3_ContributionTest extends CiviUnitTestCase { * Test sending a mail via the API */ public function testSendMail() { - $mut = new CiviMailUtils( $this, TRUE ); + $mut = new CiviMailUtils($this, TRUE); $contribution = $this->callAPISuccess('contribution', 'create', $this->_params); $this->callAPISuccess('contribution', 'sendconfirmation', array( - 'id' => $contribution['id'], - 'receipt_from_email' => 'api@civicrm.org', + 'id' => $contribution['id'], + 'receipt_from_email' => 'api@civicrm.org', ) ); $mut->checkMailLog(array( @@ -1478,7 +1528,7 @@ class api_v3_ContributionTest extends CiviUnitTestCase { * Test sending a mail via the API */ public function testSendMailEvent() { - $mut = new CiviMailUtils( $this, TRUE ); + $mut = new CiviMailUtils($this, TRUE); $contribution = $this->callAPISuccess('contribution', 'create', $this->_params); $event = $this->eventCreate(array( 'is_email_confirm' => 1, @@ -1501,8 +1551,8 @@ class api_v3_ContributionTest extends CiviUnitTestCase { 'contribution_id' => $contribution['id'], )); $this->callAPISuccess('contribution', 'sendconfirmation', array( - 'id' => $contribution['id'], - 'receipt_from_email' => 'api@civicrm.org', + 'id' => $contribution['id'], + 'receipt_from_email' => 'api@civicrm.org', ) ); @@ -1524,7 +1574,7 @@ class api_v3_ContributionTest extends CiviUnitTestCase { $contribution = $this->callAPISuccess('Contribution', 'Get', array( 'id' => $id, - )); + )); if ($delete) { $this->callAPISuccess('contribution', 'delete', array('id' => $id)); @@ -1545,13 +1595,16 @@ class api_v3_ContributionTest extends CiviUnitTestCase { * Create a pending contribution & linked pending participant record * (along with an event) */ - public function createPendingParticipantContribution(){ + public function createPendingParticipantContribution() { $event = $this->eventCreate(array('is_email_confirm' => 1, 'confirm_from_email' => 'test@civicrm.org')); $participantID = $this->participantCreate(array('event_id' => $event['id'], 'status_id' => 6)); - $this->_ids['participant'] = $participantID; + $this->_ids['participant'] = $participantID; $params = array_merge($this->_params, array('contribution_status_id' => 2, 'financial_type_id' => 'Event Fee')); $contribution = $this->callAPISuccess('contribution', 'create', $params); - $this->callAPISuccess('participant_payment', 'create', array('contribution_id' => $contribution['id'], 'participant_id' => $participantID)); + $this->callAPISuccess('participant_payment', 'create', array( + 'contribution_id' => $contribution['id'], + 'participant_id' => $participantID + )); $this->callAPISuccess('line_item', 'get', array( 'entity_id' => $contribution['id'], 'entity_table' => 'civicrm_contribution', @@ -1603,8 +1656,8 @@ class api_v3_ContributionTest extends CiviUnitTestCase { public function _checkFinancialItem($contId, $context) { if ($context != 'paylater') { $params = array( - 'entity_id' => $contId, - 'entity_table' => 'civicrm_contribution', + 'entity_id' => $contId, + 'entity_table' => 'civicrm_contribution', ); $trxn = current(CRM_Financial_BAO_FinancialItem::retrieveEntityFinancialTrxn($params, TRUE)); $entityParams = array( @@ -1620,8 +1673,8 @@ class api_v3_ContributionTest extends CiviUnitTestCase { $lineItems = CRM_Price_BAO_LineItem::getLineItems($contId, 'contribution'); foreach ($lineItems as $key => $item) { $params = array( - 'entity_id' => $key, - 'entity_table' => 'civicrm_line_item', + 'entity_id' => $key, + 'entity_table' => 'civicrm_line_item', ); $compareParams = array('status_id' => 1); $this->assertDBCompareValues('CRM_Financial_DAO_FinancialItem', $params, $compareParams); @@ -1629,34 +1682,34 @@ class api_v3_ContributionTest extends CiviUnitTestCase { } elseif ($context == 'refund') { $compareParams = array( - 'status_id' => 1, - 'financial_account_id' => 1, - 'amount' => -100, + 'status_id' => 1, + 'financial_account_id' => 1, + 'amount' => -100, ); } elseif ($context == 'cancelPending') { $compareParams = array( - 'status_id' => 3, - 'financial_account_id' => 1, - 'amount' => -100, + 'status_id' => 3, + 'financial_account_id' => 1, + 'amount' => -100, ); } elseif ($context == 'changeFinancial') { $lineKey = key(CRM_Price_BAO_LineItem::getLineItems($contId, 'contribution')); $params = array( - 'entity_id' => $lineKey, - 'amount' => -100, + 'entity_id' => $lineKey, + 'amount' => -100, ); $compareParams = array( - 'financial_account_id' => 1, + 'financial_account_id' => 1, ); $this->assertDBCompareValues('CRM_Financial_DAO_FinancialItem', $params, $compareParams); $params = array( - 'financial_account_id' => 3, - 'entity_id' => $lineKey, + 'financial_account_id' => 3, + 'entity_id' => $lineKey, ); $compareParams = array( - 'amount' => 100, + 'amount' => 100, ); } if ($context != 'paylater') { @@ -1671,52 +1724,52 @@ class api_v3_ContributionTest extends CiviUnitTestCase { */ public function _checkFinancialTrxn($contribution, $context, $instrumentId = NULL) { $trxnParams = array( - 'entity_id' => $contribution['id'], - 'entity_table' => 'civicrm_contribution', + 'entity_id' => $contribution['id'], + 'entity_table' => 'civicrm_contribution', ); $trxn = current(CRM_Financial_BAO_FinancialItem::retrieveEntityFinancialTrxn($trxnParams, TRUE)); $params = array( - 'id' => $trxn['financial_trxn_id'], + 'id' => $trxn['financial_trxn_id'], ); if ($context == 'payLater') { $relationTypeId = key(CRM_Core_PseudoConstant::accountOptionValues('account_relationship', NULL, " AND v.name LIKE 'Accounts Receivable Account is' ")); $compareParams = array( - 'status_id' => 1, - 'from_financial_account_id' => CRM_Contribute_PseudoConstant::financialAccountType($contribution['financial_type_id'], $relationTypeId), + 'status_id' => 1, + 'from_financial_account_id' => CRM_Contribute_PseudoConstant::financialAccountType($contribution['financial_type_id'], $relationTypeId), ); } elseif ($context == 'refund') { $compareParams = array( - 'to_financial_account_id' => 6, - 'total_amount' => -100, - 'status_id' => 7, + 'to_financial_account_id' => 6, + 'total_amount' => -100, + 'status_id' => 7, ); } elseif ($context == 'cancelPending') { $compareParams = array( - 'from_financial_account_id' => 7, - 'total_amount' => -100, - 'status_id' => 3, + 'from_financial_account_id' => 7, + 'total_amount' => -100, + 'status_id' => 3, ); } elseif ($context == 'changeFinancial' || $context == 'paymentInstrument') { $entityParams = array( - 'entity_id' => $contribution['id'], - 'entity_table' => 'civicrm_contribution', - 'amount' => -100, + 'entity_id' => $contribution['id'], + 'entity_table' => 'civicrm_contribution', + 'amount' => -100, ); $trxn = current(CRM_Financial_BAO_FinancialItem::retrieveEntityFinancialTrxn($entityParams)); $trxnParams1 = array( 'id' => $trxn['financial_trxn_id'], ); $compareParams = array( - 'total_amount' => -100, - 'status_id' => 1, + 'total_amount' => -100, + 'status_id' => 1, ); if ($context == 'paymentInstrument') { $compareParams += array( - 'to_financial_account_id' => CRM_Financial_BAO_FinancialTypeAccount::getInstrumentFinancialAccount(4), - 'payment_instrument_id' => 4, + 'to_financial_account_id' => CRM_Financial_BAO_FinancialTypeAccount::getInstrumentFinancialAccount(4), + 'payment_instrument_id' => 4, ); } else { @@ -1739,23 +1792,23 @@ class api_v3_ContributionTest extends CiviUnitTestCase { /** * @return mixed */ - public function _addPaymentInstrument () { + public function _addPaymentInstrument() { $gId = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_OptionGroup', 'payment_instrument', 'id', 'name'); $optionParams = array( - 'option_group_id' => $gId, - 'label' => 'Test Card', - 'name' => 'Test Card', - 'value' => '6', - 'weight' => '6', - 'is_active' => 1, + 'option_group_id' => $gId, + 'label' => 'Test Card', + 'name' => 'Test Card', + 'value' => '6', + 'weight' => '6', + 'is_active' => 1, ); $optionValue = $this->callAPISuccess('option_value', 'create', $optionParams); $relationTypeId = key(CRM_Core_PseudoConstant::accountOptionValues('account_relationship', NULL, " AND v.name LIKE 'Asset Account is' ")); $financialParams = array( - 'entity_table' => 'civicrm_option_value', - 'entity_id' => $optionValue['id'], - 'account_relationship' => $relationTypeId, - 'financial_account_id' => 7, + 'entity_table' => 'civicrm_option_value', + 'entity_id' => $optionValue['id'], + 'account_relationship' => $relationTypeId, + 'financial_account_id' => 7, ); CRM_Financial_BAO_FinancialTypeAccount::add($financialParams, CRM_Core_DAO::$_nullArray); $this->assertNotEmpty($optionValue['values'][$optionValue['id']]['value']); @@ -1768,8 +1821,8 @@ class api_v3_ContributionTest extends CiviUnitTestCase { */ public function _checkFinancialRecords($params, $context) { $entityParams = array( - 'entity_id' => $params['id'], - 'entity_table' => 'civicrm_contribution', + 'entity_id' => $params['id'], + 'entity_table' => 'civicrm_contribution', ); $contribution = $this->callAPISuccess('contribution', 'getsingle', array('id' => $params['id'])); $this->assertEquals($contribution['total_amount'] - $contribution['fee_amount'], $contribution['net_amount']); @@ -1780,13 +1833,13 @@ class api_v3_ContributionTest extends CiviUnitTestCase { } $trxn = current(CRM_Financial_BAO_FinancialItem::retrieveEntityFinancialTrxn($entityParams)); $trxnParams = array( - 'id' => $trxn['financial_trxn_id'], + 'id' => $trxn['financial_trxn_id'], ); if ($context != 'online' && $context != 'payLater') { $compareParams = array( - 'to_financial_account_id' => 6, - 'total_amount' => 100, - 'status_id' => 1, + 'to_financial_account_id' => 6, + 'total_amount' => 100, + 'status_id' => 1, ); } if ($context == 'feeAmount') { @@ -1794,65 +1847,65 @@ class api_v3_ContributionTest extends CiviUnitTestCase { } elseif ($context == 'online') { $compareParams = array( - 'to_financial_account_id' => 12, - 'total_amount' => 100, - 'status_id' => 1, + 'to_financial_account_id' => 12, + 'total_amount' => 100, + 'status_id' => 1, ); } elseif ($context == 'payLater') { $compareParams = array( - 'to_financial_account_id' => 7, - 'total_amount' => 100, - 'status_id' => 2, + 'to_financial_account_id' => 7, + 'total_amount' => 100, + 'status_id' => 2, ); } $this->assertDBCompareValues('CRM_Financial_DAO_FinancialTrxn', $trxnParams, $compareParams); $entityParams = array( - 'financial_trxn_id' => $trxn['financial_trxn_id'], - 'entity_table' => 'civicrm_financial_item', + 'financial_trxn_id' => $trxn['financial_trxn_id'], + 'entity_table' => 'civicrm_financial_item', ); $entityTrxn = current(CRM_Financial_BAO_FinancialItem::retrieveEntityFinancialTrxn($entityParams)); $fitemParams = array( - 'id' => $entityTrxn['entity_id'], + 'id' => $entityTrxn['entity_id'], ); $compareParams = array( - 'amount' => 100, - 'status_id' => 1, - 'financial_account_id' => 1, + 'amount' => 100, + 'status_id' => 1, + 'financial_account_id' => 1, ); if ($context == 'payLater') { $compareParams = array( - 'amount' => 100, - 'status_id' => 3, - 'financial_account_id' => 1, + 'amount' => 100, + 'status_id' => 3, + 'financial_account_id' => 1, ); } $this->assertDBCompareValues('CRM_Financial_DAO_FinancialItem', $fitemParams, $compareParams); if ($context == 'feeAmount') { $maxParams = array( - 'entity_id' => $params['id'], - 'entity_table' => 'civicrm_contribution', + 'entity_id' => $params['id'], + 'entity_table' => 'civicrm_contribution', ); $maxTrxn = current(CRM_Financial_BAO_FinancialItem::retrieveEntityFinancialTrxn($maxParams, TRUE)); $trxnParams = array( - 'id' => $maxTrxn['financial_trxn_id'], + 'id' => $maxTrxn['financial_trxn_id'], ); $compareParams = array( - 'to_financial_account_id' => 5, - 'from_financial_account_id' => 6, - 'total_amount' => 50, - 'status_id' => 1, + 'to_financial_account_id' => 5, + 'from_financial_account_id' => 6, + 'total_amount' => 50, + 'status_id' => 1, ); $trxnId = CRM_Core_BAO_FinancialTrxn::getFinancialTrxnId($params['id'], 'DESC'); $this->assertDBCompareValues('CRM_Financial_DAO_FinancialTrxn', $trxnParams, $compareParams); $fitemParams = array( - 'entity_id' => $trxnId['financialTrxnId'], - 'entity_table' => 'civicrm_financial_trxn', + 'entity_id' => $trxnId['financialTrxnId'], + 'entity_table' => 'civicrm_financial_trxn', ); $compareParams = array( - 'amount' => 50, - 'status_id' => 1, - 'financial_account_id' => 5, + 'amount' => 50, + 'status_id' => 1, + 'financial_account_id' => 5, ); $this->assertDBCompareValues('CRM_Financial_DAO_FinancialItem', $fitemParams, $compareParams); } diff --git a/tests/phpunit/api/v3/DomainTest.php b/tests/phpunit/api/v3/DomainTest.php index a311f868a8..874fea3a41 100644 --- a/tests/phpunit/api/v3/DomainTest.php +++ b/tests/phpunit/api/v3/DomainTest.php @@ -39,7 +39,6 @@ class api_v3_DomainTest extends CiviUnitTestCase { where cleanDB() is called. */ - public $DBResetRequired = FALSE; protected $_apiversion = 3; @@ -61,27 +60,27 @@ class api_v3_DomainTest extends CiviUnitTestCase { $defaultLocationType = CRM_Core_BAO_LocationType::getDefault(); $location = array(); $domContact = $this->callAPISuccess('contact', 'create', array( - 'contact_type' => 'Organization', - 'organization_name' => 'new org', - 'api.phone.create' => array( - 'location_type_id' => $defaultLocationType->id, - 'phone_type_id' => 1, - 'phone' => '456-456', - ), - 'api.address.create' => array( - 'location_type_id' => $defaultLocationType->id, - 'street_address' => '45 Penny Lane', + 'contact_type' => 'Organization', + 'organization_name' => 'new org', + 'api.phone.create' => array( + 'location_type_id' => $defaultLocationType->id, + 'phone_type_id' => 1, + 'phone' => '456-456', ), - 'api.email.create' => array( - 'location_type_id' => $defaultLocationType->id, - 'email' => 'my@email.com', - ) + 'api.address.create' => array( + 'location_type_id' => $defaultLocationType->id, + 'street_address' => '45 Penny Lane', + ), + 'api.email.create' => array( + 'location_type_id' => $defaultLocationType->id, + 'email' => 'my@email.com', + ) ) ); $this->callAPISuccess('domain', 'create', array( - 'id' => 1, - 'contact_id' => $domContact['id'], + 'id' => 1, + 'contact_id' => $domContact['id'], ) ); $this->params = array( @@ -150,17 +149,16 @@ class api_v3_DomainTest extends CiviUnitTestCase { */ - public function testGetCurrentDomainTwice() { $domain = $this->callAPISuccess('domain', 'getvalue', array( - 'current_domain' => 1, - 'return' => 'name', - )); + 'current_domain' => 1, + 'return' => 'name', + )); $this->assertEquals('Default Domain Name', $domain, print_r($domain, TRUE)); $domain = $this->callAPISuccess('domain', 'getvalue', array( - 'current_domain' => 1, - 'return' => 'name', - )); + 'current_domain' => 1, + 'return' => 'name', + )); $this->assertEquals('Default Domain Name', $domain, print_r($domain, TRUE)); } diff --git a/tests/phpunit/api/v3/EmailTest.php b/tests/phpunit/api/v3/EmailTest.php index a5895ddb6c..77608a0191 100644 --- a/tests/phpunit/api/v3/EmailTest.php +++ b/tests/phpunit/api/v3/EmailTest.php @@ -46,11 +46,11 @@ class api_v3_EmailTest extends CiviUnitTestCase { $this->_contactID = $this->organizationCreate(NULL); $this->_locationType = $this->locationTypeCreate(NULL); $this->_locationType2 = $this->locationTypeCreate(array( - 'name' => 'New Location Type 2', - 'vcard_name' => 'New Location Type 2', - 'description' => 'Another Location Type', - 'is_active' => 1, - )); + 'name' => 'New Location Type 2', + 'vcard_name' => 'New Location Type 2', + 'description' => 'Another Location Type', + 'is_active' => 1, + )); $this->_params = array( 'contact_id' => $this->_contactID, 'location_type_id' => $this->_locationType->id, @@ -75,6 +75,7 @@ class api_v3_EmailTest extends CiviUnitTestCase { $this->assertNotNull($result['values'][$result['id']]['id'], 'In line ' . __LINE__); $delresult = $this->callAPISuccess('email', 'delete', array('id' => $result['id'])); } + /* * If a new email is set to is_primary the prev should no longer be * @@ -82,7 +83,6 @@ class api_v3_EmailTest extends CiviUnitTestCase { */ - public function testCreateEmailPrimaryHandlingChangeToPrimary() { $params = $this->_params; unset($params['is_primary']); @@ -90,20 +90,20 @@ class api_v3_EmailTest extends CiviUnitTestCase { //now we check & make sure it has been set to primary $expected = 1; $check = $this->callAPISuccess('email', 'getcount', array( - 'is_primary' => 1, - 'id' => $email1['id'], + 'is_primary' => 1, + 'id' => $email1['id'], ), $expected - ); + ); } public function testCreateEmailPrimaryHandlingChangeExisting() { $email1 = $this->callAPISuccess('email', 'create', $this->_params); $email2 = $this->callAPISuccess('email', 'create', $this->_params); $check = $this->callAPISuccess('email', 'getcount', array( - 'is_primary' => 1, - 'contact_id' => $this->_contactID, - )); + 'is_primary' => 1, + 'contact_id' => $this->_contactID, + )); $this->assertEquals(1, $check); } @@ -123,6 +123,7 @@ class api_v3_EmailTest extends CiviUnitTestCase { $this->assertEquals($get['count'], 1); $delresult = $this->callAPISuccess('email', 'delete', array('id' => $result['id'])); } + public function testDeleteEmail() { $params = array( 'contact_id' => $this->_contactID, @@ -134,7 +135,7 @@ class api_v3_EmailTest extends CiviUnitTestCase { ); //check there are no emails to start with $get = $this->callAPISuccess('email', 'get', array( - 'location_type_id' => $this->_locationType->id, + 'location_type_id' => $this->_locationType->id, )); $this->assertEquals(0, $get['count'], 'email already exists ' . __LINE__); @@ -152,8 +153,8 @@ class api_v3_EmailTest extends CiviUnitTestCase { public function testReplaceEmail() { // check there are no emails to start with $get = $this->callAPISuccess('email', 'get', array( - 'contact_id' => $this->_contactID, - )); + 'contact_id' => $this->_contactID, + )); $this->assertEquals(0, $get['count'], 'email already exists ' . __LINE__); // initialize email list with three emails at loc #1 and two emails at loc #2 @@ -192,8 +193,8 @@ class api_v3_EmailTest extends CiviUnitTestCase { // check emails at location #1 or #2 $get = $this->callAPISuccess('email', 'get', array( - 'contact_id' => $this->_contactID, - )); + 'contact_id' => $this->_contactID, + )); $this->assertEquals(5, $get['count'], 'Incorrect email count at ' . __LINE__); // replace the subset of emails in location #1, but preserve location #2 @@ -236,8 +237,8 @@ class api_v3_EmailTest extends CiviUnitTestCase { // check emails $get = $this->callAPISuccess('email', 'get', array( - 'contact_id' => $this->_contactID, - )); + 'contact_id' => $this->_contactID, + )); $this->assertAPISuccess($get, 'In line ' . __LINE__); $this->assertEquals(0, $get['count'], 'Incorrect email count at ' . __LINE__); } @@ -246,8 +247,8 @@ class api_v3_EmailTest extends CiviUnitTestCase { // check there are no emails to start with $get = $this->callAPISuccess('email', 'get', array( - 'contact_id' => $this->_contactID, - )); + 'contact_id' => $this->_contactID, + )); $this->assertAPISuccess($get, 'In line ' . __LINE__); $this->assertEquals(0, $get['count'], 'email already exists ' . __LINE__); $description = "example demonstrates use of Replace in a nested API call"; @@ -291,8 +292,8 @@ class api_v3_EmailTest extends CiviUnitTestCase { // check emails at location #1 or #2 $get = $this->callAPISuccess('email', 'get', array( - 'contact_id' => $this->_contactID, - )); + 'contact_id' => $this->_contactID, + )); $this->assertEquals(5, $get['count'], 'Incorrect email count at ' . __LINE__); // replace the subset of emails in location #1, but preserve location #2 @@ -331,8 +332,8 @@ class api_v3_EmailTest extends CiviUnitTestCase { public function testReplaceEmailWithId() { // check there are no emails to start with $get = $this->callAPISuccess('email', 'get', array( - 'contact_id' => $this->_contactID, - )); + 'contact_id' => $this->_contactID, + )); $this->assertEquals(0, $get['count'], 'email already exists ' . __LINE__); // initialize email address diff --git a/tests/phpunit/api/v3/JobTest.php b/tests/phpunit/api/v3/JobTest.php index 69518bf13a..3cda472aaf 100644 --- a/tests/phpunit/api/v3/JobTest.php +++ b/tests/phpunit/api/v3/JobTest.php @@ -67,7 +67,8 @@ class api_v3_JobTest extends CiviUnitTestCase { */ public function testCreateWithoutName() { $params = array( - 'is_active' => 1, ); + 'is_active' => 1, + ); $result = $this->callAPIFailure('job', 'create', $params, 'Mandatory key(s) missing from params array: run_frequency, name, api_entity, api_action' ); @@ -137,7 +138,8 @@ class api_v3_JobTest extends CiviUnitTestCase { */ public function testDeleteWithIncorrectData() { $params = array( - 'id' => 'abcd', ); + 'id' => 'abcd', + ); $result = $this->callAPIFailure('job', 'delete', $params); } @@ -152,21 +154,24 @@ class api_v3_JobTest extends CiviUnitTestCase { } /** - - public function testCallUpdateGreetingMissingParams() { - $result = $this->callAPISuccess($this->_entity, 'update_greeting', array('gt' => 1)); - $this->assertEquals('Mandatory key(s) missing from params array: ct', $result['error_message']); - } - - public function testCallUpdateGreetingIncorrectParams() { - $result = $this->callAPISuccess($this->_entity, 'update_greeting', array('gt' => 1, 'ct' => 'djkfhdskjfhds')); - $this->assertEquals('ct `djkfhdskjfhds` is not valid.', $result['error_message']); - } - /* + * + * public function testCallUpdateGreetingMissingParams() { + * $result = $this->callAPISuccess($this->_entity, 'update_greeting', array('gt' => 1)); + * $this->assertEquals('Mandatory key(s) missing from params array: ct', $result['error_message']); + * } + * + * public function testCallUpdateGreetingIncorrectParams() { + * $result = $this->callAPISuccess($this->_entity, 'update_greeting', array('gt' => 1, 'ct' => 'djkfhdskjfhds')); + * $this->assertEquals('ct `djkfhdskjfhds` is not valid.', $result['error_message']); + * } + * /* * Note that this test is about tesing the metadata / calling of the function & doesn't test the success of the called function */ public function testCallUpdateGreetingSuccess() { - $result = $this->callAPISuccess($this->_entity, 'update_greeting', array('gt' => 'postal_greeting', 'ct' => 'Individual')); + $result = $this->callAPISuccess($this->_entity, 'update_greeting', array( + 'gt' => 'postal_greeting', + 'ct' => 'Individual' + )); } public function testCallUpdateGreetingCommaSeparatedParamsSuccess() { @@ -188,7 +193,7 @@ class api_v3_JobTest extends CiviUnitTestCase { $membershipTypeID = $this->membershipTypeCreate(); $this->membershipStatusCreate(); $createTotal = 30; - for($i = 1; $i <= $createTotal; $i++) { + for ($i = 1; $i <= $createTotal; $i++) { $contactID = $this->individualCreate(); $groupID = $this->groupCreate(array('name' => $i, 'title' => $i)); $result = $this->callAPISuccess('action_schedule', 'create', array( @@ -203,7 +208,11 @@ class api_v3_JobTest extends CiviUnitTestCase { 'group_id' => $groupID, 'limit_to' => FALSE, )); - $this->callAPISuccess('group_contact', 'create', array('contact_id' => $contactID, 'status' => 'Added', 'group_id' => $groupID)); + $this->callAPISuccess('group_contact', 'create', array( + 'contact_id' => $contactID, + 'status' => 'Added', + 'group_id' => $groupID + )); } $result = $this->callAPISuccess('job', 'send_reminder', array()); $successfulCronCount = CRM_Core_DAO::singleValueQuery("SELECT count(*) FROM civicrm_action_log"); @@ -220,19 +229,23 @@ class api_v3_JobTest extends CiviUnitTestCase { $this->membershipStatusCreate(); $createTotal = 3; $groupID = $this->groupCreate(array('name' => 'Texan drawlers', 'title' => 'a...')); - for($i = 1; $i <= $createTotal; $i++) { + for ($i = 1; $i <= $createTotal; $i++) { $contactID = $this->individualCreate(); - if($i == 2) { + if ($i == 2) { $theChosenOneID = $contactID; } - if($i < 3) { - $this->callAPISuccess('group_contact', 'create', array('contact_id' => $contactID, 'status' => 'Added', 'group_id' => $groupID)); + if ($i < 3) { + $this->callAPISuccess('group_contact', 'create', array( + 'contact_id' => $contactID, + 'status' => 'Added', + 'group_id' => $groupID + )); } - if($i > 1) { + if ($i > 1) { $this->callAPISuccess('membership', 'create', array( - 'contact_id' => $contactID, - 'membership_type_id' => $membershipTypeID, - 'join_date' => '+ 1 hour', + 'contact_id' => $contactID, + 'membership_type_id' => $membershipTypeID, + 'join_date' => '+ 1 hour', ) ); } @@ -260,7 +273,10 @@ class api_v3_JobTest extends CiviUnitTestCase { $individualID = $this->individualCreate(); $orgID = $this->organizationCreate(); CRM_Utils_Hook_UnitTests::singleton()->setHook('civicrm_pre', array($this, 'hookPreRelationship')); - $relationshipTypeID = $this->callAPISuccess('relationship_type', 'getvalue', array('return' => 'id', 'name_a_b' => 'Employee of')); + $relationshipTypeID = $this->callAPISuccess('relationship_type', 'getvalue', array( + 'return' => 'id', + 'name_a_b' => 'Employee of' + )); $result = $this->callAPISuccess('relationship', 'create', array( 'relationship_type_id' => $relationshipTypeID, 'contact_id_a' => $individualID, @@ -284,10 +300,10 @@ class api_v3_JobTest extends CiviUnitTestCase { * @param array $params */ public function hookPreRelationship($op, $objectName, $id, &$params) { - if($op == 'delete') { + if ($op == 'delete') { return; } - if($params['is_active']) { + if ($params['is_active']) { $params['description'] = 'Hooked'; } else { diff --git a/tests/phpunit/api/v3/LineItemTest.php b/tests/phpunit/api/v3/LineItemTest.php index 4359297119..a32a05db7c 100644 --- a/tests/phpunit/api/v3/LineItemTest.php +++ b/tests/phpunit/api/v3/LineItemTest.php @@ -85,7 +85,8 @@ class api_v3_LineItemTest extends CiviUnitTestCase { } public function testDeleteLineItem() { - $getParams = array( 'entity_table' => 'civicrm_contribution', + $getParams = array( + 'entity_table' => 'civicrm_contribution', ); $getResult = $this->callAPISuccess($this->_entity, 'get', $getParams); $deleteParams = array('id' => $getResult['id']); diff --git a/tests/phpunit/api/v3/MembershipTest.php b/tests/phpunit/api/v3/MembershipTest.php index 6818ef3aec..113154c2e6 100644 --- a/tests/phpunit/api/v3/MembershipTest.php +++ b/tests/phpunit/api/v3/MembershipTest.php @@ -57,7 +57,11 @@ class api_v3_MembershipTest extends CiviUnitTestCase { $this->_apiversion = 3; $this->_contactID = $this->individualCreate(); $this->_membershipTypeID = $this->membershipTypeCreate(array('member_of_contact_id' => $this->_contactID)); - $this->_membershipTypeID2 = $this->membershipTypeCreate(array('period_type' => 'fixed', 'fixed_period_start_day' => '301', 'fixed_period_rollover_day' => '1111')); + $this->_membershipTypeID2 = $this->membershipTypeCreate(array( + 'period_type' => 'fixed', + 'fixed_period_start_day' => '301', + 'fixed_period_rollover_day' => '1111' + )); $this->_membershipStatusID = $this->membershipStatusCreate('test status'); CRM_Member_PseudoConstant::membershipType(NULL, TRUE); @@ -79,9 +83,9 @@ class api_v3_MembershipTest extends CiviUnitTestCase { public function tearDown() { $this->quickCleanup(array( - 'civicrm_membership', - 'civicrm_membership_payment', - 'civicrm_membership_log', + 'civicrm_membership', + 'civicrm_membership_payment', + 'civicrm_membership_log', ), TRUE ); @@ -148,7 +152,7 @@ class api_v3_MembershipTest extends CiviUnitTestCase { $result = $membership['values'][$this->_membershipID]; $this->callAPISuccess('Membership', 'Delete', array( 'id' => $this->_membershipID, - )); + )); $this->assertEquals($result['contact_id'], $this->_contactID, "In line " . __LINE__); $this->assertEquals($result['membership_type_id'], $this->_membershipTypeID, "In line " . __LINE__); $this->assertEquals($result['status_id'], $this->_membershipStatusID, "In line " . __LINE__); @@ -204,6 +208,7 @@ class api_v3_MembershipTest extends CiviUnitTestCase { $this->assertEquals(1, $membership['count']); $this->assertEquals(array($this->_membershipID2), array_keys($membership['values'])); } + /** * Test civicrm_membership_get with params not array. * Gets treated as contact_id, memberships expected. @@ -228,6 +233,7 @@ class api_v3_MembershipTest extends CiviUnitTestCase { $this->assertEquals($result['is_override'], 1, "In line " . __LINE__); $this->assertEquals($result['id'], $membership['id']); } + /** * Test civicrm_membership_get with params not array. * Gets treated as contact_id, memberships expected. @@ -254,6 +260,7 @@ class api_v3_MembershipTest extends CiviUnitTestCase { $this->assertEquals($result['contact_id'], $this->_contactID); $this->assertEquals($result['membership_type_id'], $this->_membershipTypeID2); } + /** * Check with complete array + custom field * Note that the test is written on purpose without any @@ -331,10 +338,10 @@ class api_v3_MembershipTest extends CiviUnitTestCase { * Memberships expected. */ public function testGetOnlyActive() { - $description = "Demonstrates use of 'filter' active_only' param"; + $description = "Demonstrates use of 'filter' active_only' param"; $this->_membershipID = $this->contactMembershipCreate($this->_params); - $subfile = 'filterIsCurrent'; - $params = array( + $subfile = 'filterIsCurrent'; + $params = array( 'contact_id' => $this->_contactID, 'active_only' => 1, ); @@ -395,7 +402,7 @@ class api_v3_MembershipTest extends CiviUnitTestCase { 'period_type' => 'rolling', 'member_of_contact_id' => $membershipOrgId, 'domain_id' => 1, - 'financial_type_id' => 1, + 'financial_type_id' => 1, 'relationship_type_id' => $relTypeID, 'relationship_direction' => 'b_a', 'is_active' => 1, @@ -425,7 +432,7 @@ class api_v3_MembershipTest extends CiviUnitTestCase { $this->assertEquals($this->_membershipStatusID, $membership['status_id']); $this->callAPISuccess('Membership', 'Delete', array( 'id' => $membership['id'], - )); + )); $this->membershipTypeDelete(array('id' => $memType['id'])); $this->relationshipTypeDelete($relTypeID); $this->contactDelete($membershipOrgId); @@ -618,6 +625,7 @@ class api_v3_MembershipTest extends CiviUnitTestCase { $this->assertEquals($this->_contactID, $result['values'][$result['id']]['contact_id'], " in line " . __LINE__); $this->assertEquals($result['id'], $result['values'][$result['id']]['id'], " in line " . __LINE__); } + /* * Check for useful message if contact doesn't exist */ @@ -637,6 +645,7 @@ class api_v3_MembershipTest extends CiviUnitTestCase { 'contact_id is not valid : 999' ); } + public function testMembershipCreateWithInvalidStatus() { $params = $this->_params; $params['status_id'] = 999; @@ -667,7 +676,10 @@ class api_v3_MembershipTest extends CiviUnitTestCase { $params['custom_' . $ids['custom_field_id']] = "custom string"; $result = $this->callAPIAndDocument($this->_entity, 'create', $params, __FUNCTION__, __FILE__); - $check = $this->callAPISuccess($this->_entity, 'get', array('id' => $result['id'], 'contact_id' => $this->_contactID)); + $check = $this->callAPISuccess($this->_entity, 'get', array( + 'id' => $result['id'], + 'contact_id' => $this->_contactID + )); $this->assertEquals("custom string", $check['values'][$result['id']]['custom_' . $ids['custom_field_id']], ' in line ' . __LINE__); } @@ -719,7 +731,7 @@ class api_v3_MembershipTest extends CiviUnitTestCase { $result = $this->callAPISuccess('membership', 'create', $params); $this->callAPISuccess('Membership', 'Delete', array( 'id' => $result['id'], - )); + )); $this->assertEquals($result['id'], $membershipID, "in line " . __LINE__); } @@ -743,7 +755,7 @@ class api_v3_MembershipTest extends CiviUnitTestCase { $result = $this->callAPISuccess('membership', 'create', $params); $this->callAPISuccess('Membership', 'Delete', array( 'id' => $result['id'], - )); + )); $this->assertEquals($result['id'], $membershipID, "in line " . __LINE__); } @@ -781,14 +793,14 @@ class api_v3_MembershipTest extends CiviUnitTestCase { 'source' => 'changed', 'contact_id' => $this->_contactID, 'status_id' => $this->_membershipStatusID, - 'membership_type_id' => $this->_membershipTypeID, + 'membership_type_id' => $this->_membershipTypeID, 'skipStatusCal' => 1, ); $result = $this->callAPISuccess('membership', 'create', $params); $this->assertEquals($result['id'], $membershipID, "in line " . __LINE__); $this->callAPISuccess('Membership', 'Delete', array( 'id' => $result['id'], - )); + )); } /** @@ -800,13 +812,19 @@ class api_v3_MembershipTest extends CiviUnitTestCase { $params = $this->_params; $params['custom_' . $ids['custom_field_id']] = "custom string"; $result = $this->callAPIAndDocument($this->_entity, 'create', $params, __FUNCTION__, __FILE__); - $result = $this->callAPISuccess($this->_entity, 'create', array('id' => $result['id'], 'custom_' . $ids['custom_field_id'] => "new custom")); - $check = $this->callAPISuccess($this->_entity, 'get', array('id' => $result['id'], 'contact_id' => $this->_contactID)); + $result = $this->callAPISuccess($this->_entity, 'create', array( + 'id' => $result['id'], + 'custom_' . $ids['custom_field_id'] => "new custom" + )); + $check = $this->callAPISuccess($this->_entity, 'get', array( + 'id' => $result['id'], + 'contact_id' => $this->_contactID + )); $this->assertEquals("new custom", $check['values'][$result['id']]['custom_' . $ids['custom_field_id']], ' in line ' . __LINE__); $this->callAPISuccess('Membership', 'Delete', array( 'id' => $check['id'], - )); + )); $this->customFieldDelete($ids['custom_field_id']); $this->customGroupDelete($ids['custom_group_id']); @@ -849,7 +867,8 @@ class api_v3_MembershipTest extends CiviUnitTestCase { 'end_date' => '2008-12-21', 'source' => 'Payment', 'is_override' => 1, - 'status_id' => $this->_membershipStatusID, ); + 'status_id' => $this->_membershipStatusID, + ); $this->callAPIFailure('membership', 'create', $params); @@ -886,6 +905,7 @@ class api_v3_MembershipTest extends CiviUnitTestCase { 'id' => $result['id'], )); } + /** * Test civicrm_contact_memberships_create with membership_contact_id * membership). @@ -941,6 +961,7 @@ class api_v3_MembershipTest extends CiviUnitTestCase { $this->assertEquals('2009-01-21', $result['start_date']); $this->assertEquals('2009-12-21', $result['end_date']); } + /** * Test that if membership start date is not set it defaults to correct end date * - fixed @@ -967,6 +988,7 @@ class api_v3_MembershipTest extends CiviUnitTestCase { $this->assertEquals('2009-01-21', $result['start_date']); $this->assertEquals('2009-12-21', $result['end_date']); } + /** * Test that if membership end date is not set it defaults to correct end date * - rolling @@ -980,6 +1002,7 @@ class api_v3_MembershipTest extends CiviUnitTestCase { $this->assertEquals('2008-03-01', $result['start_date']); $this->assertEquals('2010-02-28', $result['end_date']); } + /** * Test that if membership end date is not set it defaults to correct end date * - rolling diff --git a/tests/phpunit/api/v3/OptionValueTest.php b/tests/phpunit/api/v3/OptionValueTest.php index 78e968504f..71c42ce2a0 100644 --- a/tests/phpunit/api/v3/OptionValueTest.php +++ b/tests/phpunit/api/v3/OptionValueTest.php @@ -74,12 +74,13 @@ class api_v3_OptionValueTest extends CiviUnitTestCase { $result = $this->callAPISuccess('option_value', 'get', array( 'option_group_id' => 1, - 'value' => '1', )); + 'value' => '1', + )); $result2 = $this->callAPISuccess('option_value', 'get', array( 'option_group_id' => 1, - 'value' => '1', - 'options' => array('offset' => 1), - )); + 'value' => '1', + 'options' => array('offset' => 1), + )); $this->assertGreaterThan($result2['count'], $result['count']); } @@ -88,17 +89,17 @@ class api_v3_OptionValueTest extends CiviUnitTestCase { */ public function testGetSingleValueOptionValueSort() { $description = "demonstrates use of Sort param (available in many api functions). Also, getsingle"; - $subfile = 'SortOption'; - $result = $this->callAPISuccess('option_value', 'getsingle', array( + $subfile = 'SortOption'; + $result = $this->callAPISuccess('option_value', 'getsingle', array( 'option_group_id' => 1, - 'options' => array( - 'sort' => 'label ASC', - 'limit' => 1, - ), - )); + 'options' => array( + 'sort' => 'label ASC', + 'limit' => 1, + ), + )); $params = array( 'option_group_id' => 1, - 'options' => array( + 'options' => array( 'sort' => 'label DESC', 'limit' => 1, ), @@ -112,13 +113,14 @@ class api_v3_OptionValueTest extends CiviUnitTestCase { */ public function testGetValueOptionPagination() { $pageSize = 10; - $page1 = $this->callAPISuccess('option_value', 'get', array('options' => array('limit' => $pageSize) )); + $page1 = $this->callAPISuccess('option_value', 'get', array('options' => array('limit' => $pageSize))); $page2 = $this->callAPISuccess('option_value', 'get', array( 'options' => array( - 'limit' => $pageSize, - // if you use it for pagination, option.offset=pageSize*pageNumber - 'offset' => $pageSize - 1, - ), )); + 'limit' => $pageSize, + // if you use it for pagination, option.offset=pageSize*pageNumber + 'offset' => $pageSize - 1, + ), + )); $this->assertEquals($pageSize, $page1['count'], "Check only 10 retrieved in the 1st page " . __LINE__); $this->assertEquals($pageSize, $page2['count'], "Check only 10 retrieved in the 2nd page " . __LINE__); @@ -159,7 +161,7 @@ class api_v3_OptionValueTest extends CiviUnitTestCase { 'name' => 'from_email_address', 'sequential' => 1, 'api.option_value.create' => array('domain_id' => 2, 'name' => 'my@y.com'), - )); + )); $optionValueId = $result['values'][0]['api.option_value.create']['id']; $domain_id = $this->callAPISuccess('option_value', 'getvalue', array( @@ -176,13 +178,13 @@ class api_v3_OptionValueTest extends CiviUnitTestCase { $result = $this->callAPISuccess('option_group', 'get', array( 'name' => 'from_email_address', 'sequential' => 1, - 'api.option_value.create' => array('component_id' => 2, 'name' => 'my@y.com'), + 'api.option_value.create' => array('component_id' => 2, 'name' => 'my@y.com'), )); $this->assertAPISuccess($result); $optionValueId = $result['values'][0]['api.option_value.create']['id']; $component_id = $this->callAPISuccess('option_value', 'getvalue', array( 'id' => $optionValueId, - 'return' => 'component_id', + 'return' => 'component_id', )); $this->assertEquals(2, $component_id); } @@ -194,17 +196,17 @@ class api_v3_OptionValueTest extends CiviUnitTestCase { $result = $this->callAPISuccess('option_group', 'get', array( 'name' => 'from_email_address', 'sequential' => 1, - 'api.option_value.create' => array( + 'api.option_value.create' => array( 'component_id' => 'CiviContribute', 'name' => 'my@y.com' - ), + ), )); $this->assertAPISuccess($result); $optionValueId = $result['values'][0]['api.option_value.create']['id']; $component_id = $this->callAPISuccess('option_value', 'getvalue', array( 'id' => $optionValueId, - 'return' => 'component_id', + 'return' => 'component_id', )); $this->assertEquals(2, $component_id); } @@ -216,16 +218,17 @@ class api_v3_OptionValueTest extends CiviUnitTestCase { $result = $this->callAPISuccess('option_group', 'get', array( 'name' => 'from_email_address', 'sequential' => 1, - 'api.option_value.create' => array( + 'api.option_value.create' => array( 'component_id' => 'CiviContribute', - 'name' => 'my@y.com'), + 'name' => 'my@y.com' + ), )); $this->assertAPISuccess($result); $optionValueId = $result['values'][0]['api.option_value.create']['id']; $component_id = $this->callAPISuccess('option_value', 'getvalue', array( 'id' => $optionValueId, - 'return' => 'component_id', + 'return' => 'component_id', )); $this->assertEquals(2, $component_id); } @@ -236,18 +239,19 @@ class api_v3_OptionValueTest extends CiviUnitTestCase { public function testCRM12133CreateOptionWeightNoValue() { $optionGroup = $this->callAPISuccess( 'option_group', 'get', array( - 'name' => 'gender', - 'sequential' => 1, )); + 'name' => 'gender', + 'sequential' => 1, + )); $this->assertAPISuccess($optionGroup); $params = array( 'option_group_id' => $optionGroup['id'], 'label' => 'my@y.com', - 'weight' => 3, + 'weight' => 3, ); $optionValue = $this->callAPISuccess('option_value', 'create', $params); $this->assertAPISuccess($optionValue); $params['weight'] = 4; - $optionValue2 = $this->callAPISuccess('option_value', 'create', $params ); + $optionValue2 = $this->callAPISuccess('option_value', 'create', $params); $this->assertAPISuccess($optionValue2); $options = $this->callAPISuccess('option_value', 'get', array('option_group_id' => $optionGroup['id'])); $this->assertNotEquals($options['values'][$optionValue['id']]['value'], $options['values'][$optionValue2['id']]['value']); @@ -263,7 +267,8 @@ class api_v3_OptionValueTest extends CiviUnitTestCase { public function testCreateOptionNoName() { $optionGroup = $this->callAPISuccess('option_group', 'get', array( 'name' => 'gender', - 'sequential' => 1, )); + 'sequential' => 1, + )); $params = array('option_group_id' => $optionGroup['id'], 'label' => 'my@y.com'); $optionValue = $this->callAPISuccess('option_value', 'create', $params); @@ -277,7 +282,7 @@ class api_v3_OptionValueTest extends CiviUnitTestCase { */ public function testCRM11876CreateOptionPseudoConstantUpdated() { $optionGroupID = $this->callAPISuccess('option_group', 'getvalue', array( - 'name' => 'payment_instrument', + 'name' => 'payment_instrument', 'return' => 'id', )); $newOption = (string) time(); @@ -311,7 +316,7 @@ class api_v3_OptionValueTest extends CiviUnitTestCase { $res = $this->callAPISuccess('option_value', 'create', array('id' => $ov['id'], 'is_active' => 0)); $val = $this->callAPISuccess('option_value', 'getvalue', array( 'id' => $ov['id'], - 'return' => 'is_active', + 'return' => 'is_active', )); $this->assertEquals($val, 0, "update with no group id is not proper" . __LINE__); } @@ -322,16 +327,23 @@ class api_v3_OptionValueTest extends CiviUnitTestCase { */ public function testUpdateOptionValueWithGroupId() { // create a option group - $og = $this->callAPISuccess('option_group', 'create', array('name' => 'our test Option Group for with group id', 'is_active' => 1)); + $og = $this->callAPISuccess('option_group', 'create', array( + 'name' => 'our test Option Group for with group id', + 'is_active' => 1 + )); // create a option value $ov = $this->callAPISuccess('option_value', 'create', array('option_group_id' => $og['id'], 'label' => 'test option value') ); // update option value without 'option_group_id' - $this->callAPISuccess('option_value', 'create', array('id' => $ov['id'], 'option_group_id' => $og['id'], 'is_active' => 0)); + $this->callAPISuccess('option_value', 'create', array( + 'id' => $ov['id'], + 'option_group_id' => $og['id'], + 'is_active' => 0 + )); $val = $this->callAPISuccess('option_value', 'getvalue', array( 'id' => $ov['id'], - 'return' => 'is_active', + 'return' => 'is_active', )); $this->assertEquals($val, 0, "update with group id is not proper " . __LINE__); } diff --git a/tests/phpunit/api/v3/PhoneTest.php b/tests/phpunit/api/v3/PhoneTest.php index 01141df86b..eb55bc4e8e 100644 --- a/tests/phpunit/api/v3/PhoneTest.php +++ b/tests/phpunit/api/v3/PhoneTest.php @@ -47,8 +47,8 @@ class api_v3_PhoneTest extends CiviUnitTestCase { parent::setUp(); $this->useTransaction(); - $this->_contactID = $this->organizationCreate(); - $loc = $this->locationTypeCreate(); + $this->_contactID = $this->organizationCreate(); + $loc = $this->locationTypeCreate(); $this->_locationType = $loc->id; CRM_Core_PseudoConstant::flush(); $this->_params = array( @@ -138,11 +138,12 @@ class api_v3_PhoneTest extends CiviUnitTestCase { $phone1 = $this->callAPISuccess('phone', 'create', $params); //now we check & make sure it has been set to primary $check = $this->callAPISuccess('phone', 'getcount', array( - 'is_primary' => 1, - 'id' => $phone1['id'], - )); + 'is_primary' => 1, + 'id' => $phone1['id'], + )); $this->assertEquals(1, $check); } + public function testCreatePhonePrimaryHandlingChangeExisting() { $phone1 = $this->callAPISuccess('phone', 'create', $this->_params); $phone2 = $this->callAPISuccess('phone', 'create', $this->_params); diff --git a/tests/phpunit/api/v3/RelationshipTest.php b/tests/phpunit/api/v3/RelationshipTest.php index fb7a8c6a53..dc7c1e85b2 100644 --- a/tests/phpunit/api/v3/RelationshipTest.php +++ b/tests/phpunit/api/v3/RelationshipTest.php @@ -1,28 +1,28 @@ _cId_a = $this->individualCreate(); - $this->_cId_a_2 = $this->individualCreate(array('last_name' => 'c2', 'email' => 'c@w.com', 'contact_type' => 'Individual')); + $this->_cId_a_2 = $this->individualCreate(array( + 'last_name' => 'c2', + 'email' => 'c@w.com', + 'contact_type' => 'Individual' + )); $this->_cId_b = $this->organizationCreate(); $this->_cId_b2 = $this->organizationCreate(array('organization_name' => ' Org 2')); $this->_entity = 'relationship'; @@ -178,7 +182,7 @@ class api_v3_RelationshipTest extends CiviUnitTestCase { 'contact_id_b' => $this->_cId_b, 'relationship_type_id' => $this->_relTypeID, 'start_date' => '2008-12-20', - 'end_date' => NULL, + 'end_date' => NULL, 'is_active' => 1, ); $relationship = $this->callAPISuccess('relationship', 'create', $params); @@ -248,7 +252,6 @@ class api_v3_RelationshipTest extends CiviUnitTestCase { } - /** * Check relationship creation */ @@ -282,6 +285,7 @@ class api_v3_RelationshipTest extends CiviUnitTestCase { $params['id'] = $result['id']; $this->callAPISuccess('relationship', 'delete', $params); } + /** * Ensure disabling works */ @@ -301,6 +305,7 @@ class api_v3_RelationshipTest extends CiviUnitTestCase { $this->assertEquals('blah', $result['values'][$result['id']]['description']); $this->assertEquals(1, $result['values'][$result['id']]['is_permission_b_a']); } + /** * Check relationship creation */ @@ -329,7 +334,7 @@ class api_v3_RelationshipTest extends CiviUnitTestCase { if ($key == 'note') { continue; } - if($key == 'end_date'){ + if ($key == 'end_date') { $this->assertTrue(empty($values[$key])); continue; } @@ -711,39 +716,40 @@ class api_v3_RelationshipTest extends CiviUnitTestCase { $rel2Params['end_date'] = 'yesterday'; $rel2 = $this->callAPISuccess('relationship', 'create', $rel2Params); } + /* * Test using various operators */ public function testGetTypeOperators() { $relTypeParams = array( - 'name_a_b' => 'Relation 3 for delete', - 'name_b_a' => 'Relation 6 for delete', - 'description' => 'Testing relationship type 2', - 'contact_type_a' => 'Individual', - 'contact_type_b' => 'Organization', - 'is_reserved' => 1, - 'is_active' => 1, + 'name_a_b' => 'Relation 3 for delete', + 'name_b_a' => 'Relation 6 for delete', + 'description' => 'Testing relationship type 2', + 'contact_type_a' => 'Individual', + 'contact_type_b' => 'Organization', + 'is_reserved' => 1, + 'is_active' => 1, ); $relationType2 = $this->relationshipTypeCreate($relTypeParams); $relTypeParams = array( - 'name_a_b' => 'Relation 8 for delete', - 'name_b_a' => 'Relation 9 for delete', - 'description' => 'Testing relationship type 7', - 'contact_type_a' => 'Individual', - 'contact_type_b' => 'Organization', - 'is_reserved' => 1, - 'is_active' => 1, + 'name_a_b' => 'Relation 8 for delete', + 'name_b_a' => 'Relation 9 for delete', + 'description' => 'Testing relationship type 7', + 'contact_type_a' => 'Individual', + 'contact_type_b' => 'Organization', + 'is_reserved' => 1, + 'is_active' => 1, ); $relationType3 = $this->relationshipTypeCreate($relTypeParams); $relTypeParams = array( - 'name_a_b' => 'Relation 6 for delete', - 'name_b_a' => 'Relation 88for delete', - 'description' => 'Testing relationship type 00', - 'contact_type_a' => 'Individual', - 'contact_type_b' => 'Organization', - 'is_reserved' => 1, - 'is_active' => 1, + 'name_a_b' => 'Relation 6 for delete', + 'name_b_a' => 'Relation 88for delete', + 'description' => 'Testing relationship type 00', + 'contact_type_a' => 'Individual', + 'contact_type_b' => 'Organization', + 'is_reserved' => 1, + 'is_active' => 1, ); $relationType4 = $this->relationshipTypeCreate($relTypeParams); @@ -751,9 +757,9 @@ class api_v3_RelationshipTest extends CiviUnitTestCase { $rel2 = $this->callAPISuccess('relationship', 'create', array_merge($this->_params, array('relationship_type_id' => $relationType2))); $rel3 = $this->callAPISuccess('relationship', 'create', array_merge($this->_params, - array('relationship_type_id' => $relationType3))); + array('relationship_type_id' => $relationType3))); $rel4 = $this->callAPISuccess('relationship', 'create', array_merge($this->_params, - array('relationship_type_id' => $relationType4))); + array('relationship_type_id' => $relationType4))); $getParams = array( 'relationship_type_id' => array('IN' => array($relationType2, $relationType3)) @@ -769,7 +775,7 @@ class api_v3_RelationshipTest extends CiviUnitTestCase { $description = "demonstrates use of NOT IN filter"; $subfile = 'NotInRelationshipType'; $getParams = array( - 'relationship_type_id' => array('NOT IN' => array($relationType2, $relationType3)) + 'relationship_type_id' => array('NOT IN' => array($relationType2, $relationType3)) ); $result = $this->callAPIAndDocument('relationship', 'get', $getParams, __FUNCTION__, __FILE__, $description, $subfile); $this->assertEquals($result['count'], 2); @@ -778,7 +784,7 @@ class api_v3_RelationshipTest extends CiviUnitTestCase { $description = "demonstrates use of BETWEEN filter"; $subfile = 'BetweenRelationshipType'; $getParams = array( - 'relationship_type_id' => array('BETWEEN' => array($relationType2, $relationType4)) + 'relationship_type_id' => array('BETWEEN' => array($relationType2, $relationType4)) ); $result = $this->callAPIAndDocument('relationship', 'get', $getParams, __FUNCTION__, __FILE__, $description, $subfile); $this->assertEquals($result['count'], 3); @@ -787,13 +793,14 @@ class api_v3_RelationshipTest extends CiviUnitTestCase { $description = "demonstrates use of Not BETWEEN filter"; $subfile = 'NotBetweenRelationshipType'; $getParams = array( - 'relationship_type_id' => array('NOT BETWEEN' => array($relationType2, $relationType4)) + 'relationship_type_id' => array('NOT BETWEEN' => array($relationType2, $relationType4)) ); $result = $this->callAPIAndDocument('relationship', 'get', $getParams, __FUNCTION__, __FILE__, $description, $subfile); $this->assertEquals($result['count'], 1); $this->AssertEquals(array($rel1['id']), array_keys($result['values'])); } + /** * Check with invalid relationshipType Id */ @@ -897,8 +904,9 @@ class api_v3_RelationshipTest extends CiviUnitTestCase { public function testGetRelationshipByTypeDAO() { $this->ids['relationship'] = $this->callAPISuccess($this->_entity, 'create', array('format.only_id' => TRUE) + $this->_params); $result = $this->callAPISuccess($this->_entity, 'getcount', array( - 'contact_id_a' => $this->_cId_a,), - 1); + 'contact_id_a' => $this->_cId_a, + ), + 1); $result = $this->callAPISuccess($this->_entity, 'get', array( 'contact_id_a' => $this->_cId_a, 'relationship_type_id' => $this->_relTypeID, @@ -928,14 +936,16 @@ class api_v3_RelationshipTest extends CiviUnitTestCase { $this->callAPISuccess($this->_entity, 'create', array_merge($this->_params, array( 'relationship_type_id' => $relType2, - 'contact_id_b' => $this->_cId_b2)) + 'contact_id_b' => $this->_cId_b2 + )) ); //relationshp 3 $this->callAPISuccess($this->_entity, 'create', array_merge($this->_params, array( 'relationship_type_id' => $relType3, - 'contact_id_b' => $org3)) + 'contact_id_b' => $org3 + )) ); $result = $this->callAPISuccess($this->_entity, 'get', array( @@ -966,14 +976,16 @@ class api_v3_RelationshipTest extends CiviUnitTestCase { $this->callAPISuccess($this->_entity, 'create', array_merge($this->_params, array( 'relationship_type_id' => $relType2, - 'contact_id_b' => $this->_cId_b2)) + 'contact_id_b' => $this->_cId_b2 + )) ); //relationshp 3 $this->callAPISuccess($this->_entity, 'create', array_merge($this->_params, array( 'relationship_type_id' => $relType3, - 'contact_id_b' => $org3)) + 'contact_id_b' => $org3 + )) ); $result = $this->callAPISuccess($this->_entity, 'get', array( @@ -1010,14 +1022,16 @@ class api_v3_RelationshipTest extends CiviUnitTestCase { $this->callAPISuccess($this->_entity, 'create', array_merge($this->_params, array( 'relationship_type_id' => $relType2, - 'contact_id_b' => $this->_cId_b2)) + 'contact_id_b' => $this->_cId_b2 + )) ); //relationshp 3 $this->callAPISuccess($this->_entity, 'create', array_merge($this->_params, array( 'relationship_type_id' => $relType3, - 'contact_id_b' => $org3)) + 'contact_id_b' => $org3 + )) ); //relationshp 4 with reveral @@ -1025,7 +1039,8 @@ class api_v3_RelationshipTest extends CiviUnitTestCase { array_merge($this->_params, array( 'relationship_type_id' => $relType1, 'contact_id_a' => $this->_cId_a, - 'contact_id_b' => $this->_cId_a_2)) + 'contact_id_b' => $this->_cId_a_2 + )) ); $result = $this->callAPISuccess($this->_entity, 'get', array( @@ -1062,14 +1077,16 @@ class api_v3_RelationshipTest extends CiviUnitTestCase { $this->callAPISuccess($this->_entity, 'create', array_merge($this->_params, array( 'relationship_type_id' => $relType2, - 'contact_id_b' => $this->_cId_b2)) + 'contact_id_b' => $this->_cId_b2 + )) ); //relationshp 3 $this->callAPISuccess($this->_entity, 'create', array_merge($this->_params, array( 'relationship_type_id' => $relType3, - 'contact_id_b' => $org3)) + 'contact_id_b' => $org3 + )) ); //relationshp 4 with reveral @@ -1077,7 +1094,8 @@ class api_v3_RelationshipTest extends CiviUnitTestCase { array_merge($this->_params, array( 'relationship_type_id' => $relType1, 'contact_id_a' => $this->_cId_a, - 'contact_id_b' => $this->_cId_a_2)) + 'contact_id_b' => $this->_cId_a_2 + )) ); $result = $this->callAPISuccess($this->_entity, 'get', array( diff --git a/tests/phpunit/api/v3/SettingTest.php b/tests/phpunit/api/v3/SettingTest.php index d276964fb8..f68ee6be01 100644 --- a/tests/phpunit/api/v3/SettingTest.php +++ b/tests/phpunit/api/v3/SettingTest.php @@ -53,21 +53,21 @@ class api_v3_SettingTest extends CiviUnitTestCase { $params = array( 'name' => 'Default Domain Name', ); - $result = $this->callAPISuccess( 'domain', 'get', $params); - if(empty($result['id'])){ - $result = $this->callAPISuccess( 'domain', 'create', $params ); + $result = $this->callAPISuccess('domain', 'get', $params); + if (empty($result['id'])) { + $result = $this->callAPISuccess('domain', 'create', $params); } $params['name'] = 'Second Domain'; - $result = $this->callAPISuccess( 'domain', 'get', $params); - if(empty($result['id'])){ - $result = $this->callAPISuccess( 'domain', 'create', $params ); + $result = $this->callAPISuccess('domain', 'get', $params); + if (empty($result['id'])) { + $result = $this->callAPISuccess('domain', 'create', $params); } $this->_domainID2 = $result['id']; $params['name'] = 'A-team domain'; - $result = $this->callAPISuccess( 'domain', 'get', $params); - if(empty($result['id'])){ - $result = $this->callAPISuccess( 'domain', 'create', $params ); + $result = $this->callAPISuccess('domain', 'get', $params); + if (empty($result['id'])) { + $result = $this->callAPISuccess('domain', 'create', $params); } $this->_domainID3 = $result['id']; $this->_currentDomain = CRM_Core_Config::domainID(); @@ -89,8 +89,9 @@ class api_v3_SettingTest extends CiviUnitTestCase { global $civicrm_root; $metaDataFolders[] = $civicrm_root . '/tests/phpunit/api/v3/settings'; } + /** - /** + * /** * Check getfields works */ public function testGetFields() { @@ -271,7 +272,7 @@ class api_v3_SettingTest extends CiviUnitTestCase { $getResult = $this->callAPISuccess('setting', 'get', $params); $this->assertEquals(0, $getResult['values'][$this->_currentDomain]['track_civimail_replies']); $params = array( - 'domain_id' => $this->_domainID2, + 'domain_id' => $this->_domainID2, 'track_civimail_replies' => '1', ); $result = $this->callAPISuccess('setting', 'create', $params); @@ -398,7 +399,8 @@ class api_v3_SettingTest extends CiviUnitTestCase { public function testGetConfigSetting() { $settings = $this->callAPISuccess('setting', 'get', array( 'name' => 'defaultCurrency', - 'sequential' => 1,) + 'sequential' => 1, + ) ); $this->assertEquals('USD', $settings['values'][0]['defaultCurrency']); } @@ -409,15 +411,17 @@ class api_v3_SettingTest extends CiviUnitTestCase { public function testGetSetConfigSettingMultipleDomains() { $settings = $this->callAPISuccess('setting', 'create', array( 'defaultCurrency' => 'USD', - 'domain_id' => $this->_currentDomain) + 'domain_id' => $this->_currentDomain + ) ); $settings = $this->callAPISuccess('setting', 'create', array( 'defaultCurrency' => 'CAD', - 'domain_id' => $this->_domainID2) + 'domain_id' => $this->_domainID2 + ) ); $settings = $this->callAPISuccess('setting', 'get', array( 'return' => 'defaultCurrency', - 'domain_id' => 'all', + 'domain_id' => 'all', ) ); $this->assertEquals('USD', $settings['values'][$this->_currentDomain]['defaultCurrency']); @@ -431,7 +435,7 @@ class api_v3_SettingTest extends CiviUnitTestCase { */ public function testGetValueConfigSetting() { $params = array( - 'name' => 'monetaryThousandSeparator', + 'name' => 'monetaryThousandSeparator', 'group' => 'Localization Setting', ); $result = $this->callAPISuccess('setting', 'getvalue', $params); @@ -440,7 +444,7 @@ class api_v3_SettingTest extends CiviUnitTestCase { public function testGetValue() { $params = array( - 'name' => 'petition_contacts', + 'name' => 'petition_contacts', 'group' => 'Campaign Preferences' ); $description = "Demonstrates getvalue action - intended for runtime use as better caching than get"; @@ -468,13 +472,13 @@ class api_v3_SettingTest extends CiviUnitTestCase { */ public function testRevert() { $params = array( - 'address_format' => 'xyz', + 'address_format' => 'xyz', 'mailing_format' => 'bcs', ); $result = $this->callAPISuccess('setting', 'create', $params); $this->assertAPISuccess($result, "in line " . __LINE__); $revertParams = array( - 'name' => 'address_format' + 'name' => 'address_format' ); $result = $this->callAPISuccess('setting', 'get', $params); //make sure it's set @@ -485,7 +489,7 @@ class api_v3_SettingTest extends CiviUnitTestCase { $result = $this->callAPISuccess('setting', 'get', $params); $this->assertEquals("{contact.address_name}\n{contact.street_address}\n{contact.supplemental_address_1}\n{contact.supplemental_address_2}\n{contact.city}{, }{contact.state_province}{ }{contact.postal_code}\n{contact.country}", $result['values'][CRM_Core_Config::domainID()]['address_format']); $params = array( - 'return' => array('mailing_format'), + 'return' => array('mailing_format'), ); $result = $this->callAPISuccess('setting', 'get', $params); //make sure it's unchanged @@ -497,7 +501,7 @@ class api_v3_SettingTest extends CiviUnitTestCase { */ public function testRevertAll() { $params = array( - 'address_format' => 'xyz', + 'address_format' => 'xyz', 'mailing_format' => 'bcs', ); $result = $this->callAPISuccess('setting', 'create', $params); @@ -521,17 +525,18 @@ class api_v3_SettingTest extends CiviUnitTestCase { 'name' => 'B Team Domain', ); $dom = $this->callAPISuccess('domain', 'create', $domparams); - $params = array( 'domain_id' => 'all', + $params = array( + 'domain_id' => 'all', ); $result = $this->callAPISuccess('setting', 'get', $params); $params = array( - 'address_format' => 'xyz', + 'address_format' => 'xyz', 'mailing_format' => 'bcs', 'domain_id' => $this->_domainID2, ); $result = $this->callAPISuccess('setting', 'create', $params); $params = array( - 'domain_id' => $dom['id'], + 'domain_id' => $dom['id'], ); $result = $this->callAPISuccess('setting', 'get', $params); $this->assertAPISuccess($result, "in line " . __LINE__); -- 2.25.1