4 * Class CRM_Core_DAOTest
7 class CRM_Logging_LoggingTest
extends CiviUnitTestCase
{
9 public function tearDown(): void
{
10 CRM_Core_I18n_Schema
::makeSinglelingual('en_US');
11 $logging = new CRM_Logging_Schema();
12 $logging->dropAllLogTables();
13 \Civi
::$statics['CRM_Logging_Schema']['columnSpecs'] = [];
18 * Test creating logging schema when database is in multilingual mode.
20 public function testMultilingualLogging() {
21 CRM_Core_I18n_Schema
::makeMultilingual('en_US');
22 $logging = new CRM_Logging_Schema();
23 $logging->enableLogging();
24 $value = CRM_Core_DAO
::singleValueQuery("SELECT id FROM log_civicrm_contact LIMIT 1", [], FALSE, FALSE);
25 $this->assertNotNull($value, 'Logging not enabled successfully');
26 $logging->disableLogging();
30 * Test creating logging schema when database is in multilingual mode.
31 * Also test altering a multilingual table.
33 public function testMultilingualAlterSchemaLogging() {
34 CRM_Core_I18n_Schema
::makeMultilingual('en_US');
35 $logging = new CRM_Logging_Schema();
36 $logging->enableLogging();
37 $value = CRM_Core_DAO
::singleValueQuery("SELECT id FROM log_civicrm_contact LIMIT 1", [], FALSE, FALSE);
38 $this->assertNotNull($value, 'Logging not enabled successfully');
39 CRM_Core_DAO
::executeQuery("ALTER TABLE `civicrm_option_value` ADD COLUMN `logging_test` INT DEFAULT '0'", [], FALSE, NULL, FALSE, FALSE);
40 CRM_Core_I18n_Schema
::rebuildMultilingualSchema(['en_US']);
41 \Civi
::$statics['CRM_Logging_Schema']['columnSpecs'] = [];
42 $logging->fixSchemaDifferencesFor('civicrm_option_value');
43 Civi
::service('sql_triggers')->rebuild('civicrm_option_value');
44 $query = CRM_Core_DAO
::executeQuery("SHOW CREATE TABLE `log_civicrm_option_value`", [], TRUE, NULL, FALSE, FALSE);
46 $create = explode("\n", $query->Create_Table
);
47 // MySQL may return "DEFAULT 0" or "DEFAULT '0'" depending on version
49 in_array(" `logging_test` int(11) DEFAULT '0'", $create)
50 ||
in_array(" `logging_test` int(11) DEFAULT 0", $create)
51 ||
in_array(" `logging_test` int DEFAULT '0'", $create)
52 ||
in_array(" `logging_test` int DEFAULT 0", $create)
54 CRM_Core_DAO
::executeQuery("ALTER TABLE `civicrm_option_value` DROP COLUMN `logging_test`", [], FALSE, NULL, FALSE, FALSE);
55 $query = CRM_Core_DAO
::executeQuery("SHOW CREATE TABLE `log_civicrm_option_value`", [], TRUE, NULL, FALSE, FALSE);
57 $domain = new CRM_Core_DAO_Domain();
59 $locales = explode(CRM_Core_DAO
::VALUE_SEPARATOR
, $domain->locales
);
60 \Civi
::$statics['CRM_Logging_Schema']['columnSpecs'] = [];
61 CRM_Core_I18n_Schema
::rebuildMultilingualSchema($locales);
62 $logging->fixSchemaDifferencesFor('civicrm_option_value');
63 Civi
::service('sql_triggers')->rebuild('civicrm_option_value');
65 in_array(" `logging_test` int(11) DEFAULT '0'", $create)
66 ||
in_array(" `logging_test` int(11) DEFAULT 0", $create)
67 ||
in_array(" `logging_test` int DEFAULT '0'", $create)
68 ||
in_array(" `logging_test` int DEFAULT 0", $create)
70 $logging->disableLogging();