From 3b1d224bd9cd948fc0492632fd0854d6e078fa4f Mon Sep 17 00:00:00 2001 From: Tim Otten Date: Mon, 27 Jan 2020 17:13:10 -0800 Subject: [PATCH] E2E_Core_LocalizedDataTest - Adaptation for composer/D8/git-style deployments --- tests/phpunit/E2E/Core/LocalizedDataTest.php | 48 ++++++++++++++++++-- 1 file changed, 43 insertions(+), 5 deletions(-) diff --git a/tests/phpunit/E2E/Core/LocalizedDataTest.php b/tests/phpunit/E2E/Core/LocalizedDataTest.php index 151625ed13..14e01a714e 100644 --- a/tests/phpunit/E2E/Core/LocalizedDataTest.php +++ b/tests/phpunit/E2E/Core/LocalizedDataTest.php @@ -21,11 +21,8 @@ class LocalizedDataTest extends \CiviEndToEndTestCase { * && phpunit6 tests/phpunit/E2E/Core/LocalizedDataTest.php */ public function testLocalizedData() { - $getSql = function($locale) { - $path = \Civi::paths()->getPath("[civicrm.root]/sql/civicrm_data.{$locale}.mysql"); - $this->assertFileExists($path); - return file_get_contents($path); - }; + $getSql = $this->getSqlFunc(); + $sqls = [ 'de_DE' => $getSql('de_DE'), 'fr_FR' => $getSql('fr_FR'), @@ -45,4 +42,45 @@ class LocalizedDataTest extends \CiviEndToEndTestCase { $this->assertFalse($match('fr_FR', 'de_DE'), 'The French SQL should not match the German pattern.'); } + /** + * @return callable + * The SQL loader -- function(string $locale): string + */ + private function getSqlFunc() { + // Some deployment styles use stored files, and some generate SQL programmatically. + // This heuristic discerns the style by UF name, although a better heuristic might be to check + // for composer at CMS root. This works in a pinch. + $uf = CIVICRM_UF; + $installerTypes = [ + 'Drupal' => [$this, '_getSqlFile'], + 'Drupal8' => [$this, '_getSqlLive'], + 'WordPress' => [$this, '_getSqlFile'], + 'Backdrop' => [$this, '_getSqlFile'], + 'Joomla' => [$this, '_getSqlFile'], + ]; + if (isset($installerTypes[$uf])) { + return $installerTypes[$uf]; + } + else { + throw new \RuntimeException("Failed to determine installation type for $uf"); + } + } + + private function _getSqlFile($locale) { + $path = \Civi::paths()->getPath("[civicrm.root]/sql/civicrm_data.{$locale}.mysql"); + $this->assertFileExists($path); + return file_get_contents($path); + } + + private function _getSqlLive($locale) { + $schema = new \CRM_Core_CodeGen_Schema(\Civi\Test::codeGen()); + $files = $schema->generateLocaleDataSql($locale); + foreach ($files as $file => $content) { + if (preg_match(';^civicrm_data\.;', $file)) { + return $content; + } + } + throw new \Exception("Faield to generate $locale"); + } + } -- 2.25.1