Merge pull request #20115 from larssandergreen/fix-internal-anchor-URLs-in-mailings
[civicrm-core.git] / tests / phpunit / CRM / Logging / LoggingTest.php
index 2a92319f5586195608ec98936e3b797a0f122c09..050fce542a3d83edddb02a9c563186f94488c4b6 100644 (file)
@@ -6,19 +6,43 @@
  */
 class CRM_Logging_LoggingTest extends CiviUnitTestCase {
 
+  use CRMTraits_Custom_CustomDataTrait;
+
+  /**
+   * Has the db been set to multilingual.
+   *
+   * @var bool
+   */
+  protected $isDBMultilingual = FALSE;
+
   public function tearDown(): void {
     Civi::settings()->set('logging', FALSE);
-    CRM_Core_I18n_Schema::makeSinglelingual('en_US');
+    if ($this->isDBMultilingual) {
+      CRM_Core_I18n_Schema::makeSinglelingual('en_US');
+    }
     $logging = new CRM_Logging_Schema();
     $logging->dropAllLogTables();
+    $this->cleanupCustomGroups();
     parent::tearDown();
   }
 
+  /**
+   * Check that log tables are created even for non standard custom fields
+   * tables.
+   *
+   * @throws \API_Exception
+   */
+  public function testLoggingNonStandardCustomTableName(): void {
+    $this->createCustomGroupWithFieldOfType(['table_name' => 'abcd']);
+    Civi::settings()->set('logging', TRUE);
+    $this->assertNotEmpty(CRM_Core_DAO::singleValueQuery("SHOW tables LIKE 'log_abcd'"));
+  }
+
   /**
    * Test creating logging schema when database is in multilingual mode.
    */
   public function testMultilingualLogging(): void {
-    CRM_Core_I18n_Schema::makeMultilingual('en_US');
+    $this->makeMultilingual();
     Civi::settings()->set('logging', TRUE);
     $value = CRM_Core_DAO::singleValueQuery('SELECT id FROM log_civicrm_contact LIMIT 1', [], FALSE, FALSE);
     $this->assertNotNull($value, 'Logging not enabled successfully');
@@ -29,7 +53,7 @@ class CRM_Logging_LoggingTest extends CiviUnitTestCase {
    * Also test altering a multilingual table.
    */
   public function testMultilingualAlterSchemaLogging(): void {
-    CRM_Core_I18n_Schema::makeMultilingual('en_US');
+    $this->makeMultilingual();
     Civi::settings()->set('logging', TRUE);
     $logging = new CRM_Logging_Schema();
     $value = CRM_Core_DAO::singleValueQuery('SELECT id FROM log_civicrm_contact LIMIT 1', [], FALSE, FALSE);
@@ -67,4 +91,12 @@ class CRM_Logging_LoggingTest extends CiviUnitTestCase {
     );
   }
 
+  /**
+   * Convert the database to multilingual mode.
+   */
+  protected function makeMultilingual(): void {
+    CRM_Core_I18n_Schema::makeMultilingual('en_US');
+    $this->isDBMultilingual = TRUE;
+  }
+
 }