X-Git-Url: https://vcs.fsf.org/?a=blobdiff_plain;f=tests%2Fphpunit%2FCiviTest%2FCiviUnitTestCase.php;h=3b09fa937584f8df463456ddca86c5f3b2b4b973;hb=8d787e4ec628c060855052d5894e67c462df4e5b;hp=324bb4ac2ebde36f03463cef41312b3f1fb12381;hpb=9773289f21f8583680a6987c2a596ad11706a472;p=civicrm-core.git diff --git a/tests/phpunit/CiviTest/CiviUnitTestCase.php b/tests/phpunit/CiviTest/CiviUnitTestCase.php index 324bb4ac2e..3b09fa9375 100644 --- a/tests/phpunit/CiviTest/CiviUnitTestCase.php +++ b/tests/phpunit/CiviTest/CiviUnitTestCase.php @@ -64,11 +64,6 @@ class CiviUnitTestCase extends PHPUnit_Extensions_Database_TestCase { */ private static $dbInit = FALSE; - /** - * Does the current setup support ONLY_FULL_GROUP_BY mode - */ - protected $_supportFullGroupBy; - /** * Database connection. * @@ -296,8 +291,6 @@ class CiviUnitTestCase extends PHPUnit_Extensions_Database_TestCase { // Get and save a connection to the database $this->_dbconn = $this->getConnection(); - $this->_supportFullGroupBy = CRM_Utils_SQL::supportsFullGroupBy(); - // reload database before each test // $this->_populateDB(); @@ -559,7 +552,7 @@ class CiviUnitTestCase extends PHPUnit_Extensions_Database_TestCase { $expectedValue, $message ) { $value = CRM_Core_DAO::getFieldValue($daoName, $searchValue, $returnColumn, $searchColumn, TRUE); - $this->assertEquals($value, $expectedValue, $message); + $this->assertEquals($expectedValue, $value, $message); } /** @@ -1605,6 +1598,23 @@ class CiviUnitTestCase extends PHPUnit_Extensions_Database_TestCase { return $this->callAPISuccess('Event', 'create', $params); } + /** + * Create a paid event. + * + * @param array $params + * + * @return array + */ + protected function eventCreatePaid($params) { + $event = $this->eventCreate($params); + $this->priceSetID = $this->eventPriceSetCreate(55, 0, 'Radio'); + CRM_Price_BAO_PriceSet::addTo('civicrm_event', $event['id'], $this->priceSetID); + $priceSet = CRM_Price_BAO_PriceSet::getSetDetail($this->priceSetID, TRUE, FALSE); + $priceSet = CRM_Utils_Array::value($this->priceSetID, $priceSet); + $this->eventFeeBlock = CRM_Utils_Array::value('fields', $priceSet); + return $event; + } + /** * Delete event. * @@ -2081,10 +2091,6 @@ class CiviUnitTestCase extends PHPUnit_Extensions_Database_TestCase { $params = array_merge($defaults, $params); - if (strlen($params['title']) > 13) { - $params['title'] = substr($params['title'], 0, 13); - } - //have a crack @ deleting it first in the hope this will prevent derailing our tests $this->callAPISuccess('custom_group', 'get', array( 'title' => $params['title'], @@ -2577,6 +2583,8 @@ AND ( TABLE_NAME LIKE 'civicrm_value_%' ) $var = TRUE; CRM_Member_BAO_Membership::createRelatedMemberships($var, $var, TRUE); $this->disableTaxAndInvoicing(); + $this->setCurrencySeparators(','); + CRM_Core_PseudoConstant::flush('taxRates'); System::singleton()->flushProcessors(); } @@ -3075,7 +3083,6 @@ AND ( TABLE_NAME LIKE 'civicrm_value_%' ) if (!$isProfile) { //flush cache CRM_ACL_BAO_Cache::resetCache(); - CRM_Contact_BAO_Group::getPermissionClause(TRUE); CRM_ACL_API::groupPermission('whatever', 9999, NULL, 'civicrm_saved_search', NULL, NULL, TRUE); } } @@ -3325,11 +3332,12 @@ AND ( TABLE_NAME LIKE 'civicrm_value_%' ) * * @param int $feeTotal * @param int $minAmt + * @param string $type * * @return int * Price Set ID. */ - protected function eventPriceSetCreate($feeTotal, $minAmt = 0) { + protected function eventPriceSetCreate($feeTotal, $minAmt = 0, $type = 'Text') { // creating price set, price field $paramsSet['title'] = 'Price Set'; $paramsSet['name'] = CRM_Utils_String::titleToVar('Price Set'); @@ -3337,17 +3345,13 @@ AND ( TABLE_NAME LIKE 'civicrm_value_%' ) $paramsSet['extends'] = 1; $paramsSet['min_amount'] = $minAmt; - $priceset = CRM_Price_BAO_PriceSet::create($paramsSet); - $priceSetId = $priceset->id; + $priceSet = CRM_Price_BAO_PriceSet::create($paramsSet); + $this->_ids['price_set'] = $priceSet->id; - //Checking for priceset added in the table. - $this->assertDBCompareValue('CRM_Price_BAO_PriceSet', $priceSetId, 'title', - 'id', $paramsSet['title'], 'Check DB for created priceset' - ); $paramsField = array( 'label' => 'Price Field', 'name' => CRM_Utils_String::titleToVar('Price Field'), - 'html_type' => 'Text', + 'html_type' => $type, 'price' => $feeTotal, 'option_label' => array('1' => 'Price Field'), 'option_value' => array('1' => $feeTotal), @@ -3358,13 +3362,22 @@ AND ( TABLE_NAME LIKE 'civicrm_value_%' ) 'weight' => 1, 'options_per_line' => 1, 'is_active' => array('1' => 1), - 'price_set_id' => $priceset->id, + 'price_set_id' => $this->_ids['price_set'], 'is_enter_qty' => 1, 'financial_type_id' => $this->getFinancialTypeId('Event Fee'), ); + if ($type === 'Radio') { + $paramsField['is_enter_qty'] = 0; + $paramsField['option_value'][2] = $paramsField['option_weight'][2] = $paramsField['option_amount'][2] = 100; + $paramsField['option_label'][2] = $paramsField['option_name'][2] = 'hundy'; + } CRM_Price_BAO_PriceField::create($paramsField); + $fields = $this->callAPISuccess('PriceField', 'get', array('price_set_id' => $this->_ids['price_set'])); + $this->_ids['price_field'] = array_keys($fields['values']); + $fieldValues = $this->callAPISuccess('PriceFieldValue', 'get', array('price_field_id' => $this->_ids['price_field'][0])); + $this->_ids['price_field_value'] = array_keys($fieldValues['values']); - return $priceSetId; + return $this->_ids['price_set']; } /** @@ -3549,7 +3562,6 @@ AND ( TABLE_NAME LIKE 'civicrm_value_%' ) protected function setPermissions($permissions) { CRM_Core_Config::singleton()->userPermissionClass->permissions = $permissions; $this->flushFinancialTypeStatics(); - CRM_Contact_BAO_Group::getPermissionClause(TRUE); } /** @@ -3929,4 +3941,35 @@ AND ( TABLE_NAME LIKE 'civicrm_value_%' ) return $form; } + /** + * Get possible thousand separators. + * + * @return array + */ + public function getThousandSeparators() { + return array(array('.'), array(',')); + } + + /** + * Set the separators for thousands and decimal points. + * + * @param string $thousandSeparator + */ + protected function setCurrencySeparators($thousandSeparator) { + Civi::settings()->set('monetaryThousandSeparator', $thousandSeparator); + Civi::settings() + ->set('monetaryDecimalPoint', ($thousandSeparator === ',' ? '.' : ',')); + } + + /** + * Format money as it would be input. + * + * @param string $amount + * + * @return string + */ + protected function formatMoneyInput($amount) { + return CRM_Utils_Money::format($amount, NULL, '%a'); + } + }