Merge pull request #17598 from seamuslee001/php74_packages
[civicrm-core.git] / Civi / Test / Data.php
index 8b90b5d493a8a4679656aea7f05b22fddd11a8ff..8cada62629b6cb198f3ad8cc6b5c6056bc29c390 100644 (file)
@@ -12,30 +12,37 @@ class Data {
    * @return bool
    */
   public function populate() {
-    \Civi\Test::schema()->truncateAll();
-
-    \Civi\Test::schema()->setStrict(FALSE);
-
-    // Ensure that when we populate the database it is done in utf8 mode
-    \Civi\Test::execute('SET NAMES utf8');
-    $sqlDir = dirname(dirname(__DIR__)) . "/sql";
-
-    $query2 = file_get_contents("$sqlDir/civicrm_data.mysql");
-    $query3 = file_get_contents("$sqlDir/test_data.mysql");
-    $query4 = file_get_contents("$sqlDir/test_data_second_domain.mysql");
-    if (\Civi\Test::execute($query2) === FALSE) {
-      throw new RuntimeException("Cannot load civicrm_data.mysql. Aborting.");
-    }
-    if (\Civi\Test::execute($query3) === FALSE) {
-      throw new RuntimeException("Cannot load test_data.mysql. Aborting.");
-    }
-    if (\Civi\Test::execute($query4) === FALSE) {
-      throw new RuntimeException("Cannot load test_data.mysql. Aborting.");
-    }
-
-    unset($query, $query2, $query3);
-
-    \Civi\Test::schema()->setStrict(TRUE);
+    \Civi\Test::asPreInstall(function() {
+      \Civi\Test::schema()->truncateAll();
+
+      \Civi\Test::schema()->setStrict(FALSE);
+
+      // Ensure that when we populate the database it is done in utf8 mode
+      \Civi\Test::execute('SET NAMES utf8');
+      $sqlDir = dirname(dirname(__DIR__)) . "/sql";
+
+      if (!isset(\Civi\Test::$statics['locale_data'])) {
+        $schema = new \CRM_Core_CodeGen_Schema(\Civi\Test::codeGen());
+        \Civi\Test::$statics['locale_data'] = $schema->generateLocaleDataSql('en_US');
+      }
+
+      $query2 = \Civi\Test::$statics['locale_data']["civicrm_data.mysql"];
+      $query3 = file_get_contents("$sqlDir/test_data.mysql");
+      $query4 = file_get_contents("$sqlDir/test_data_second_domain.mysql");
+      if (\Civi\Test::execute($query2) === FALSE) {
+        throw new RuntimeException("Cannot load civicrm_data.mysql. Aborting.");
+      }
+      if (\Civi\Test::execute($query3) === FALSE) {
+        throw new RuntimeException("Cannot load test_data.mysql. Aborting.");
+      }
+      if (\Civi\Test::execute($query4) === FALSE) {
+        throw new RuntimeException("Cannot load test_data.mysql. Aborting.");
+      }
+
+      unset($query, $query2, $query3);
+
+      \Civi\Test::schema()->setStrict(TRUE);
+    });
 
     // Rebuild triggers
     civicrm_api('system', 'flush', ['version' => 3, 'triggers' => 1]);