d2007f9e82a4065a597961de4e16dea3facd7037
[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 civicrm_api('setting', 'create', ['installed' => 1, 'domain_id' => 'all', 'version' => 3]);
48
49 // Rebuild triggers
50 civicrm_api('system', 'flush', ['version' => 3, 'triggers' => 1]);
51
52 \CRM_Core_BAO_ConfigSetting::setEnabledComponents([
53 'CiviEvent',
54 'CiviContribute',
55 'CiviMember',
56 'CiviMail',
57 'CiviReport',
58 'CiviPledge',
59 ]);
60
61 return TRUE;
62 }
63
64 }