return $this->sourceDigest;
}
- protected function init() {
+ /**
+ * @return static
+ */
+ public function init() {
if (!$this->database || !$this->tables) {
$specification = new CRM_Core_CodeGen_Specification();
$specification->parse($this->schemaPath, $this->buildVersion);
$this->database = $specification->database;
$this->tables = $specification->tables;
}
+ return $this;
}
}
echo "Installing {$dbName} schema\n";
\Civi\Test::schema()->dropAll();
}, 'headless-drop')
- ->sqlFile($civiRoot . "/sql/civicrm.mysql")
+ ->coreSchema()
->sql("DELETE FROM civicrm_extension")
->callback(function ($ctx) {
\Civi\Test::data()->populate();
return self::$singletons['schema'];
}
+ /**
+ * @return \CRM_Core_CodeGen_Main
+ */
+ public static function codeGen() {
+ if (!isset(self::$singletons['codeGen'])) {
+ $civiRoot = dirname(__DIR__);
+ $codeGen = new \CRM_Core_CodeGen_Main("$civiRoot/CRM/Core/DAO", "$civiRoot/sql", $civiRoot, "$civiRoot/templates", NULL, "UnitTests", NULL, "$civiRoot/xml/schema/Schema.xml", NULL);
+ $codeGen->init();
+ self::$singletons['codeGen'] = $codeGen;
+ }
+ return self::$singletons['codeGen'];
+ }
+
/**
* @return \Civi\Test\Data
*/
namespace Civi\Test;
use Civi\Test\CiviEnvBuilder\CallbackStep;
+use Civi\Test\CiviEnvBuilder\CoreSchemaStep;
use Civi\Test\CiviEnvBuilder\ExtensionsStep;
use Civi\Test\CiviEnvBuilder\SqlFileStep;
use Civi\Test\CiviEnvBuilder\SqlStep;
return $this->addStep(new CallbackStep($callback, $signature));
}
+ /**
+ * Generate the core SQL tables.
+ *
+ * @return \Civi\Test\CiviEnvBuilder
+ */
+ public function coreSchema() {
+ return $this->addStep(new CoreSchemaStep());
+ }
+
public function sql($sql) {
return $this->addStep(new SqlStep($sql));
}
--- /dev/null
+<?php
+namespace Civi\Test\CiviEnvBuilder;
+
+/**
+ * Class CoreSchemaStep
+ * @package Civi\Test\CiviEnvBuilder
+ *
+ * An initialization step which loads the core SQL schema.
+ *
+ * Note that the computation of the schema is cached for the duration of
+ * the PHP process (\Civi\Test::$statics).
+ */
+class CoreSchemaStep implements StepInterface {
+
+ /**
+ * @return array
+ * - digest: string
+ * - content: string
+ */
+ public function getSql() {
+ if (!isset(\Civi\Test::$statics['core_schema_sql'])) {
+ $schema = new \CRM_Core_CodeGen_Schema(\Civi\Test::codeGen());
+ $files = $schema->generateCreateSql();
+ \Civi\Test::$statics['core_schema_sql'] = [
+ 'digest' => md5($files['civicrm.mysql']),
+ 'content' => $files['civicrm.mysql'],
+ ];
+ }
+ return \Civi\Test::$statics['core_schema_sql'];
+ }
+
+ public function getSig() {
+ return $this->getSql()['digest'];
+ }
+
+ public function isValid() {
+ return TRUE;
+ }
+
+ /**
+ * @param \Civi\Test\CiviEnvBuilder $ctx
+ */
+ public function run($ctx) {
+ $sql = $this->getSql();
+ if (\Civi\Test::execute($sql['content']) === FALSE) {
+ throw new \RuntimeException("Cannot execute SQL");
+ }
+ }
+
+}
\Civi\Test::execute('SET NAMES utf8');
$sqlDir = dirname(dirname(__DIR__)) . "/sql";
- $query2 = file_get_contents("$sqlDir/civicrm_data.mysql");
+ 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) {