Merge pull request #15884 from kainuk/issue-lab-1365
[civicrm-core.git] / Civi / Test / Data.php
CommitLineData
728bbd5b
TO
1<?php
2namespace Civi\Test;
3
4use RuntimeException;
5
6/**
7 * Class Data
8 */
9class Data {
10
11 /**
12 * @return bool
13 */
14 public function populate() {
9d114ab6
TO
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 utf8');
22 $sqlDir = dirname(dirname(__DIR__)) . "/sql";
23
c0d84418
TO
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"];
9d114ab6
TO
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 });
728bbd5b
TO
46
47 // Rebuild triggers
c64f69d9 48 civicrm_api('system', 'flush', ['version' => 3, 'triggers' => 1]);
728bbd5b 49
c64f69d9 50 \CRM_Core_BAO_ConfigSetting::setEnabledComponents([
728bbd5b
TO
51 'CiviEvent',
52 'CiviContribute',
53 'CiviMember',
54 'CiviMail',
55 'CiviReport',
56 'CiviPledge',
c64f69d9 57 ]);
728bbd5b
TO
58
59 return TRUE;
60 }
61
62}