Merge pull request #16766 from seamuslee001/5_23_2_release_notes
[civicrm-core.git] / tests / phpunit / CiviTest / CiviUnitTestCase.php
index 68f77a6ec7f118638d6202a393ed5e51e03448a9..173c06e6e1ebf239ecc31515661961246b5db6ec 100644 (file)
@@ -90,12 +90,14 @@ class CiviUnitTestCase extends PHPUnit\Framework\TestCase {
   protected $_tablesToTruncate = [];
 
   /**
-   * @var array of temporary directory names
+   * @var array
+   * Array of temporary directory names
    */
   protected $tempDirs;
 
   /**
-   * @var bool populateOnce allows to skip db resets in setUp
+   * @var bool
+   * populateOnce allows to skip db resets in setUp
    *
    *  WARNING! USE WITH CAUTION - IT'LL RENDER DATA DEPENDENCIES
    *  BETWEEN TESTS WHEN RUN IN SUITE. SUITABLE FOR LOCAL, LIMITED
@@ -103,21 +105,22 @@ class CiviUnitTestCase extends PHPUnit\Framework\TestCase {
    *
    *  IF POSSIBLE, USE $this->DBResetRequired = FALSE IN YOUR TEST CASE!
    *
-   *  see also: http://forum.civicrm.org/index.php/topic,18065.0.html
+   * @see http://forum.civicrm.org/index.php/topic,18065.0.html
    */
   public static $populateOnce = FALSE;
 
   /**
-   * @var bool DBResetRequired allows skipping DB reset
-   *               in specific test case. If you still need
-   *               to reset single test (method) of such case, call
-   *               $this->cleanDB() in the first line of this
-   *               test (method).
+   * DBResetRequired allows skipping DB reset
+   * in specific test case. If you still need
+   * to reset single test (method) of such case, call
+   * $this->cleanDB() in the first line of this
+   * test (method).
+   * @var bool
    */
   public $DBResetRequired = TRUE;
 
   /**
-   * @var CRM_Core_Transaction|NULL
+   * @var CRM_Core_Transaction|null
    */
   private $tx = NULL;
 
@@ -138,12 +141,13 @@ class CiviUnitTestCase extends PHPUnit\Framework\TestCase {
    *
    * $this->hookClass->setHook('civicrm_aclWhereClause', array($this, 'aclWhereHookAllResults'));
    *
-   * @var CRM_Utils_Hook_UnitTests hookClass
+   * @var \CRM_Utils_Hook_UnitTests
    */
   public $hookClass = NULL;
 
   /**
-   * @var array common values to be re-used multiple times within a class - usually to create the relevant entity
+   * @var array
+   * Common values to be re-used multiple times within a class - usually to create the relevant entity
    */
   protected $_params = [];
 
@@ -1005,6 +1009,7 @@ class CiviUnitTestCase extends PHPUnit\Framework\TestCase {
    *   Name-value pair for an event.
    *
    * @return array
+   * @throws \CRM_Core_Exception
    */
   public function eventCreate($params = []) {
     // if no contact was passed, make up a dummy event creator
@@ -1046,12 +1051,16 @@ class CiviUnitTestCase extends PHPUnit\Framework\TestCase {
    *
    * @param array $options
    *
+   * @param string $key
+   *   Index for storing event ID in ids array.
+   *
    * @return array
    *
    * @throws \CRM_Core_Exception
    */
-  protected function eventCreatePaid($params, $options = [['name' => 'hundy', 'amount' => 100]]) {
+  protected function eventCreatePaid($params, $options = [['name' => 'hundy', 'amount' => 100]], $key = 'event') {
     $event = $this->eventCreate($params);
+    $this->ids['event'][$key] = (int) $event['id'];
     $this->priceSetID = $this->ids['PriceSet'][] = $this->eventPriceSetCreate(55, 0, 'Radio', $options);
     CRM_Price_BAO_PriceSet::addTo('civicrm_event', $event['id'], $this->priceSetID);
     $priceSet = CRM_Price_BAO_PriceSet::getSetDetail($this->priceSetID, TRUE, FALSE);
@@ -1280,10 +1289,7 @@ class CiviUnitTestCase extends PHPUnit\Framework\TestCase {
    * @return int
    */
   public function smartGroupCreate($smartGroupParams = [], $groupParams = [], $contactType = 'Household') {
-    $smartGroupParams = array_merge([
-      'formValues' => ['contact_type' => ['IN' => [$contactType]]],
-    ],
-      $smartGroupParams);
+    $smartGroupParams = array_merge(['form_values' => ['contact_type' => ['IN' => [$contactType]]]], $smartGroupParams);
     $savedSearch = CRM_Contact_BAO_SavedSearch::create($smartGroupParams);
 
     $groupParams['saved_search_id'] = $savedSearch->id;
@@ -3021,7 +3027,6 @@ VALUES
       [
         'invoicing' => 1,
         'invoice_prefix' => 'INV_',
-        'credit_notes_prefix' => 'CN_',
         'due_date' => 10,
         'due_date_period' => 'days',
         'notes' => '',
@@ -3258,14 +3263,52 @@ VALUES
   /**
    * Set the separators for thousands and decimal points.
    *
+   * Use setMonetaryDecimalPoint and setMonetaryThousandSeparator instead
+   *
    * @param string $thousandSeparator
+   * @deprecated
    */
   protected function setCurrencySeparators($thousandSeparator) {
+    // Jaap Jansma: I do think the code below is a bit useless. It does an assumption
+    // that when the thousand separator is a comma, the decimal is point. It
+    // does not cater for a situation where the thousand separator is a [space]
+    // Latter is the Norwegian localization.
     Civi::settings()->set('monetaryThousandSeparator', $thousandSeparator);
     Civi::settings()
       ->set('monetaryDecimalPoint', ($thousandSeparator === ',' ? '.' : ','));
   }
 
+  /**
+   * Sets the thousand separator.
+   *
+   * If you use this function also set the decimal separator: setMonetaryDecimalSeparator
+   *
+   * @param $thousandSeparator
+   */
+  protected function setMonetaryThousandSeparator($thousandSeparator) {
+    Civi::settings()->set('monetaryThousandSeparator', $thousandSeparator);
+  }
+
+  /**
+   * Sets the decimal separator.
+   *
+   * If you use this function also set the thousand separator setMonetaryDecimalPoint
+   *
+   * @param $decimalPoint
+   */
+  protected function setMonetaryDecimalPoint($decimalPoint) {
+    Civi::settings()->set('monetaryDecimalPoint', $decimalPoint);
+  }
+
+  /**
+   * Sets the default currency.
+   *
+   * @param $currency
+   */
+  protected function setDefaultCurrency($currency) {
+    Civi::settings()->set('defaultCurrency', $currency);
+  }
+
   /**
    * Format money as it would be input.
    *