View source
<?php
namespace Drupal\Tests\system\Kernel\Installer;
use Drupal\Core\StringTranslation\Translator\FileTranslation;
use Drupal\KernelTests\KernelTestBase;
class InstallTranslationFilePatternTest extends KernelTestBase {
protected static $modules = [
'system',
];
protected $fileTranslation;
protected $filePatternMethod;
protected function setUp() : void {
parent::setUp();
$this->fileTranslation = new FileTranslation('filename', $this->container
->get('file_system'));
$method = new \ReflectionMethod('\\Drupal\\Core\\StringTranslation\\Translator\\FileTranslation', 'getTranslationFilesPattern');
$method
->setAccessible(TRUE);
$this->filePatternMethod = $method;
}
public function testFilesPatternValid($langcode, $filename) {
$pattern = $this->filePatternMethod
->invoke($this->fileTranslation, $langcode);
$this
->assertNotEmpty(preg_match($pattern, $filename));
}
public function providerValidTranslationFiles() {
return [
[
'hu',
'drupal-8.0.0-alpha1.hu.po',
],
[
'ta',
'drupal-8.10.10-beta12.ta.po',
],
[
'hi',
'drupal-8.0.0.hi.po',
],
];
}
public function testFilesPatternInvalid($langcode, $filename) {
$pattern = $this->filePatternMethod
->invoke($this->fileTranslation, $langcode);
$this
->assertEmpty(preg_match($pattern, $filename));
}
public function providerInvalidTranslationFiles() {
return [
[
'hu',
'drupal-alpha1-*-hu.po',
],
[
'ta',
'drupal-beta12.ta',
],
[
'hi',
'drupal-hi.po',
],
[
'de',
'drupal-dummy-de.po',
],
[
'hu',
'drupal-10.0.1.alpha1-hu.po',
],
];
}
}