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