|
18 | 18 | use Symfony\Component\DependencyInjection\Container;
|
19 | 19 | use Symfony\Component\DependencyInjection\ContainerInterface;
|
20 | 20 | use Symfony\Component\Yaml\Parser;
|
| 21 | +use SilverStripe\i18n\i18n; |
| 22 | +use SilverStripe\SupportedModules\MetaData; |
21 | 23 |
|
22 | 24 | /**
|
23 | 25 | * Locates test suite configuration based on module name.
|
@@ -141,6 +143,10 @@ public function execute(InputInterface $input, OutputInterface $output)
|
141 | 143 | $config['type'],
|
142 | 144 | $config['settings']
|
143 | 145 | );
|
| 146 | + |
| 147 | + // Set i18n locale |
| 148 | + $this->setI18nLocale($config); |
| 149 | + |
144 | 150 | return null;
|
145 | 151 | }
|
146 | 152 |
|
@@ -190,4 +196,30 @@ protected function loadSuiteConfiguration($suite, Module $module)
|
190 | 196 | 'settings' => $resolvedConfig,
|
191 | 197 | ];
|
192 | 198 | }
|
| 199 | + |
| 200 | + private function setI18nLocale(array $config): void |
| 201 | + { |
| 202 | + $path = $config['type']['settings']['paths'][0] ?? ''; |
| 203 | + $packagistName = ''; |
| 204 | + if (preg_match('#^vendor/([^/]+/[^/]+)/.+#', $path, $matches)) { |
| 205 | + // Running unit tests of a module in the vendor folder |
| 206 | + $packagistName = $matches[1]; |
| 207 | + } else { |
| 208 | + // Running unit tests of a module or project in the root folder |
| 209 | + $file = BASE_PATH . '/composer.json'; |
| 210 | + if (file_exists($file)) { |
| 211 | + $json = json_decode(file_get_contents($file), true); |
| 212 | + $packagistName = $json['name'] ?? ''; |
| 213 | + } |
| 214 | + } |
| 215 | + $metaData = MetaData::getMetaDataByPackagistName($packagistName); |
| 216 | + $isSupportedModule = !empty($metaData); |
| 217 | + if ($isSupportedModule) { |
| 218 | + // Anything that is in silverstripe/supported-module has behat tests in en_US |
| 219 | + // Update the default_locale config in case in case any config at the project level or any |
| 220 | + // installed optional module has set it to a non-en_US locale |
| 221 | + i18n::config()->set('default_locale', 'en_US'); |
| 222 | + i18n::set_locale('en_US'); |
| 223 | + } |
| 224 | + } |
193 | 225 | }
|
0 commit comments