Merge pull request #17719 from civicrm/5.27
[civicrm-core.git] / Civi / Test / Data.php
1 <?php
2 namespace Civi\Test;
3
4 use RuntimeException;
5
6 /**
7 * Class Data
8 */
9 class Data {
10
11 /**
12 * @return bool
13 */
14 public function populate() {
15 \Civi\Test::asPreInstall(function() {
16 \Civi\Test::schema()->truncateAll();
17
18 \Civi\Test::schema()->setStrict(FALSE);
19
20 // Ensure that when we populate the database it is done in utf8 mode
21 \Civi\Test::execute('SET NAMES utf8mb4');
22 $sqlDir = dirname(dirname(__DIR__)) . "/sql";
23
24 if (!isset(\Civi\Test::$statics['locale_data'])) {
25 $schema = new \CRM_Core_CodeGen_Schema(\Civi\Test::codeGen());
26 \Civi\Test::$statics['locale_data'] = $schema->generateLocaleDataSql('en_US');
27 }
28
29 $query2 = \Civi\Test::$statics['locale_data']["civicrm_data.mysql"];
30 $query3 = file_get_contents("$sqlDir/test_data.mysql");
31 $query4 = file_get_contents("$sqlDir/test_data_second_domain.mysql");
32 if (\Civi\Test::execute($query2) === FALSE) {
33 throw new RuntimeException("Cannot load civicrm_data.mysql. Aborting.");
34 }
35 if (\Civi\Test::execute($query3) === FALSE) {
36 throw new RuntimeException("Cannot load test_data.mysql. Aborting.");
37 }
38 if (\Civi\Test::execute($query4) === FALSE) {
39 throw new RuntimeException("Cannot load test_data.mysql. Aborting.");
40 }
41
42 unset($query, $query2, $query3);
43
44 \Civi\Test::schema()->setStrict(TRUE);
45 });
46
47 // Rebuild triggers
48 civicrm_api('system', 'flush', ['version' => 3, 'triggers' => 1]);
49
50 \CRM_Core_BAO_ConfigSetting::setEnabledComponents([
51 'CiviEvent',
52 'CiviContribute',
53 'CiviMember',
54 'CiviMail',
55 'CiviReport',
56 'CiviPledge',
57 ]);
58
59 return TRUE;
60 }
61
62 }