Rename (some) labels to differ from names to simulate the fact they are different...
[civicrm-core.git] / tests / phpunit / CiviTest / CiviUnitTestCase.php
index 31e8091bc8aab2f1c56866f59d3a78cac1b8e9dc..8e0109380aadb6264aa0084535e9a5a7656548d4 100644 (file)
@@ -334,12 +334,6 @@ class CiviUnitTestCase extends PHPUnit\Framework\TestCase {
     // disable any left-over test extensions
     CRM_Core_DAO::executeQuery('DELETE FROM civicrm_extension WHERE full_name LIKE "test.%"');
 
-    $extensions = \CRM_Extension_System::singleton()->getManager();
-    $api4Status = $extensions->getStatus('org.civicrm.api4');
-    if ($api4Status != $extensions::STATUS_INSTALLED && $api4Status != $extensions::STATUS_UNKNOWN) {
-      $extensions->enable(['org.civicrm.api4']);
-    }
-
     // reset all the caches
     CRM_Utils_System::flushCache();
 
@@ -365,6 +359,7 @@ class CiviUnitTestCase extends PHPUnit\Framework\TestCase {
     $_REQUEST = $_GET = $_POST = [];
     error_reporting(E_ALL);
 
+    $this->renameLabels();
     $this->_sethtmlGlobals();
   }
 
@@ -457,6 +452,7 @@ class CiviUnitTestCase extends PHPUnit\Framework\TestCase {
    */
   protected function tearDown() {
     $this->_apiversion = 3;
+    $this->resetLabels();
 
     error_reporting(E_ALL & ~E_NOTICE);
     CRM_Utils_Hook::singleton()->reset();
@@ -1015,6 +1011,7 @@ class CiviUnitTestCase extends PHPUnit\Framework\TestCase {
       'is_monetary' => 0,
       'is_active' => 1,
       'is_show_location' => 0,
+      'is_email_confirm' => 1,
     ), $params);
 
     return $this->callAPISuccess('Event', 'create', $params);
@@ -1373,7 +1370,7 @@ class CiviUnitTestCase extends PHPUnit\Framework\TestCase {
     if (!isset($params['target_contact_id'])) {
       $params['target_contact_id'] = $this->individualCreate(array(
         'first_name' => 'Julia',
-        'Last_name' => 'Anderson',
+        'last_name' => 'Anderson',
         'prefix' => 'Ms.',
         'email' => 'julia_anderson@civicrm.org',
         'contact_type' => 'Individual',
@@ -2396,6 +2393,7 @@ AND    ( TABLE_NAME LIKE 'civicrm_value_%' )
       'contribution_page_id' => $this->_contributionPageID,
       'payment_processor_id' => $this->_paymentProcessorID,
       'is_test' => 0,
+      'receive_date' => '2019-07-25 07:34:23',
       'skipCleanMoney' => TRUE,
     ], $contributionParams);
     $contributionRecur = $this->callAPISuccess('contribution_recur', 'create', array_merge(array(
@@ -2439,6 +2437,7 @@ AND    ( TABLE_NAME LIKE 'civicrm_value_%' )
         'financial_type_id' => 1,
         'invoice_id' => 'abcd',
         'trxn_id' => 345,
+        'receive_date' => '2019-07-25 07:34:23',
       ));
     }
     $this->setupRecurringPaymentProcessorTransaction($recurParams);
@@ -2448,6 +2447,7 @@ AND    ( TABLE_NAME LIKE 'civicrm_value_%' )
       'membership_type_id' => $this->ids['membership_type'],
       'contribution_recur_id' => $this->_contributionRecurID,
       'format.only_id' => TRUE,
+      'source' => 'Payment',
     ));
     //CRM-15055 creates line items we don't want so get rid of them so we can set up our own line items
     CRM_Core_DAO::executeQuery("TRUNCATE civicrm_line_item");
@@ -3322,4 +3322,24 @@ AND    ( TABLE_NAME LIKE 'civicrm_value_%' )
     return $csv;
   }
 
+  /**
+   * Rename various labels to not match the names.
+   *
+   * Doing these mimics the fact the name != the label in international installs & triggers failures in
+   * code that expects it to.
+   */
+  protected function renameLabels() {
+    $replacements = ['Pending', 'Refunded'];
+    foreach ($replacements as $name) {
+      CRM_Core_DAO::executeQuery("UPDATE civicrm_option_value SET label = '{$name} Label**' where label = '{$name}' AND name = '{$name}'");
+    }
+  }
+
+  /**
+   * Undo any label renaming.
+   */
+  protected function resetLabels() {
+    CRM_Core_DAO::executeQuery("UPDATE civicrm_option_value SET label = REPLACE(name, ' Label**', '') WHERE label LIKE '% Label**'");
+  }
+
 }