6 * Class LocalizedDataTest
10 class LocalizedDataTest
extends \CiviEndToEndTestCase
{
13 * Smoke test to check that "civicrm_data*.mysql" files contain
16 * Note: As currently written, this test relies on the output of setup.sh/GenCode.
17 * Consequently, if you're running locally while iterating on the code, you may find
18 * the following command helps with your dev-test loop:
20 * $ env CIVICRM_LOCALES=en_US,fr_FR,de_DE ./bin/setup.sh -g \
21 * && phpunit6 tests/phpunit/E2E/Core/LocalizedDataTest.php
23 public function testLocalizedData() {
24 $getSql = $this->getSqlFunc();
27 'de_DE' => $getSql('de_DE'),
28 'fr_FR' => $getSql('fr_FR'),
31 'de_DE' => '/new_organization.*Neue Organisation/i',
32 'fr_FR' => '/new_organization.*Nouvelle organisation/i',
35 $match = function($sqlLocale, $patLocale) use ($pats, $sqls) {
36 return (bool) preg_match($pats[$patLocale], $sqls[$sqlLocale]);
39 $this->assertTrue($match('de_DE', 'de_DE'), 'The German SQL should match the German pattern.');
40 $this->assertTrue($match('fr_FR', 'fr_FR'), 'The French SQL should match the French pattern.');
41 $this->assertFalse($match('de_DE', 'fr_FR'), 'The German SQL should not match the French pattern.');
42 $this->assertFalse($match('fr_FR', 'de_DE'), 'The French SQL should not match the German pattern.');
47 * The SQL loader -- function(string $locale): string
49 private function getSqlFunc() {
50 // Some deployment styles use stored files, and some generate SQL programmatically.
51 // This heuristic discerns the style by UF name, although a better heuristic might be to check
52 // for composer at CMS root. This works in a pinch.
55 'Drupal' => [$this, '_getSqlFile'],
56 'Drupal8' => [$this, '_getSqlLive'],
57 'WordPress' => [$this, '_getSqlFile'],
58 'Backdrop' => [$this, '_getSqlFile'],
59 'Joomla' => [$this, '_getSqlFile'],
61 if (isset($installerTypes[$uf])) {
62 return $installerTypes[$uf];
65 throw new \
RuntimeException("Failed to determine installation type for $uf");
69 private function _getSqlFile($locale) {
70 $path = \Civi
::paths()->getPath("[civicrm.root]/sql/civicrm_data.{$locale}.mysql");
71 $this->assertFileExists($path);
72 return file_get_contents($path);
75 private function _getSqlLive($locale) {
76 $schema = new \
CRM_Core_CodeGen_Schema(\Civi\Test
::codeGen());
77 $files = $schema->generateLocaleDataSql($locale);
78 foreach ($files as $file => $content) {
79 if (preg_match(';^civicrm_data\.;', $file)) {
83 throw new \
Exception("Faield to generate $locale");