X-Git-Url: https://vcs.fsf.org/?a=blobdiff_plain;f=Civi%2FTest.php;h=a0d67697470284b41d3fd5fc4909198b8659d3d0;hb=5b6ef63d89f640b8f97b1d7b21f00e2c1a34dc80;hp=1d9db12079521969e442e86d704ae96fc8fd90ff;hpb=101f1f244307b4eb1c022049ae706dd415daef13;p=civicrm-core.git diff --git a/Civi/Test.php b/Civi/Test.php index 1d9db12079..a0d6769747 100644 --- a/Civi/Test.php +++ b/Civi/Test.php @@ -59,7 +59,8 @@ class Test { public static function dsn($part = NULL) { if (!isset(self::$singletons['dsn'])) { require_once "DB.php"; - self::$singletons['dsn'] = \DB::parseDSN(CIVICRM_DSN); + $dsn = \CRM_Utils_SQL::autoSwitchDSN(CIVICRM_DSN); + self::$singletons['dsn'] = \DB::parseDSN($dsn); } if ($part === NULL) { @@ -181,6 +182,46 @@ class Test { return self::$singletons['data']; } + /** + * @return \Civi\Test\ExampleDataLoader + */ + public static function examples(): \Civi\Test\ExampleDataLoader { + if (!isset(self::$singletons['examples'])) { + self::$singletons['examples'] = new \Civi\Test\ExampleDataLoader(); + } + return self::$singletons['examples']; + } + + /** + * Lookup the content of an example data-set. + * + * This helper is for the common case of looking up the data for a specific example. + * If you need more detailed information (eg the list of examples or other metadata), + * then use `\Civi\Test::examples(): ExampleDataLoader`. It provides more methods. + * + * @param string $name + * Symbolic name of the data-set. + * @return array + * The example data. + */ + public static function example(string $name): array { + $result = static::examples()->getFull($name); + if (!isset($result['data'])) { + throw new \CRM_Core_Exception("Failed to load example data-set: $name"); + } + return $result['data']; + } + + /** + * @return \Civi\Test\EventChecker + */ + public static function eventChecker() { + if (!isset(self::$singletons['eventChecker'])) { + self::$singletons['eventChecker'] = new \Civi\Test\EventChecker(); + } + return self::$singletons['eventChecker']; + } + /** * Prepare and execute a batch of SQL statements. *