Commit | Line | Data |
---|---|---|
15a68d41 SL |
1 | <?php |
2 | ||
3 | /** | |
4 | * Class CRM_Core_DAOTest | |
5 | * @group headless | |
6 | */ | |
7 | class CRM_Logging_LoggingTest extends CiviUnitTestCase { | |
8 | ||
9 | public function setUp() { | |
10 | parent::setUp(); | |
11 | } | |
12 | ||
13 | public function tearDown() { | |
14 | CRM_Core_I18n_Schema::makeSinglelingual('en_US'); | |
15 | $logging = new CRM_Logging_Schema(); | |
16 | $logging->dropAllLogTables(); | |
9099cab3 | 17 | \Civi::$statics['CRM_Logging_Schema']['columnSpecs'] = []; |
15a68d41 SL |
18 | parent::tearDown(); |
19 | } | |
20 | ||
21 | /** | |
22 | * Test creating logging schema when database is in multilingual mode. | |
23 | */ | |
24 | public function testMultilingualLogging() { | |
25 | CRM_Core_I18n_Schema::makeMultilingual('en_US'); | |
26 | $logging = new CRM_Logging_Schema(); | |
27 | $logging->enableLogging(); | |
9099cab3 | 28 | $value = CRM_Core_DAO::singleValueQuery("SELECT id FROM log_civicrm_contact LIMIT 1", [], FALSE, FALSE); |
15a68d41 SL |
29 | $this->assertNotNull($value, 'Logging not enabled successfully'); |
30 | $logging->disableLogging(); | |
31 | } | |
32 | ||
15a68d41 SL |
33 | /** |
34 | * Test creating logging schema when database is in multilingual mode. | |
35 | * Also test altering a multilingual table. | |
36 | */ | |
37 | public function testMultilingualAlterSchemaLogging() { | |
38 | CRM_Core_I18n_Schema::makeMultilingual('en_US'); | |
39 | $logging = new CRM_Logging_Schema(); | |
40 | $logging->enableLogging(); | |
9099cab3 | 41 | $value = CRM_Core_DAO::singleValueQuery("SELECT id FROM log_civicrm_contact LIMIT 1", [], FALSE, FALSE); |
15a68d41 | 42 | $this->assertNotNull($value, 'Logging not enabled successfully'); |
9099cab3 CW |
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'] = []; | |
fcc20cec | 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); | |
15a68d41 | 49 | $query->fetch(); |
14e47fc1 | 50 | $create = explode("\n", $query->Create_Table); |
204aa6fb PF |
51 | // MySQL may return "DEFAULT 0" or "DEFAULT '0'" depending on version |
52 | $this->assertTrue( | |
53 | in_array(" `logging_test` int(11) DEFAULT '0'", $create) | |
54 | || in_array(" `logging_test` int(11) DEFAULT 0", $create) | |
55 | ); | |
fcc20cec | 56 | CRM_Core_DAO::executeQuery("ALTER TABLE `civicrm_option_value` DROP COLUMN `logging_test`", [], FALSE, NULL, FALSE, FALSE); |
57 | $query = CRM_Core_DAO::executeQuery("SHOW CREATE TABLE `log_civicrm_option_value`", [], TRUE, NULL, FALSE, FALSE); | |
14e47fc1 SL |
58 | $query->fetch(); |
59 | $domain = new CRM_Core_DAO_Domain(); | |
60 | $domain->find(TRUE); | |
61 | $locales = explode(CRM_Core_DAO::VALUE_SEPARATOR, $domain->locales); | |
fcc20cec | 62 | \Civi::$statics['CRM_Logging_Schema']['columnSpecs'] = []; |
14e47fc1 | 63 | CRM_Core_I18n_Schema::rebuildMultilingualSchema($locales); |
fcc20cec | 64 | $logging->fixSchemaDifferencesFor('civicrm_option_value'); |
65 | Civi::service('sql_triggers')->rebuild('civicrm_option_value'); | |
204aa6fb PF |
66 | $this->assertTrue( |
67 | in_array(" `logging_test` int(11) DEFAULT '0'", $create) | |
68 | || in_array(" `logging_test` int(11) DEFAULT 0", $create)); | |
15a68d41 SL |
69 | $logging->disableLogging(); |
70 | } | |
71 | ||
72 | } |