Version 1
[yaffs-website] / web / core / modules / system / tests / src / Unit / Installer / InstallTranslationFilePatternTest.php
1 <?php
2
3 namespace Drupal\Tests\system\Unit\Installer;
4
5 use Drupal\Core\StringTranslation\Translator\FileTranslation;
6 use Drupal\Tests\UnitTestCase;
7
8 /**
9  * Tests for installer language support.
10  *
11  * @group Installer
12  */
13 class InstallTranslationFilePatternTest extends UnitTestCase {
14
15   /**
16    * @var \Drupal\Core\StringTranslation\Translator\FileTranslation
17    */
18   protected $fileTranslation;
19
20   /**
21    * @var \ReflectionMethod
22    */
23   protected $filePatternMethod;
24
25   /**
26    * {@inheritdoc}
27    */
28   protected function setup() {
29     parent::setUp();
30     $this->fileTranslation = new FileTranslation('filename');
31     $method = new \ReflectionMethod('\Drupal\Core\StringTranslation\Translator\FileTranslation', 'getTranslationFilesPattern');
32     $method->setAccessible(TRUE);
33     $this->filePatternMethod = $method;
34   }
35
36   /**
37    * @dataProvider providerValidTranslationFiles
38    */
39   public function testFilesPatternValid($langcode, $filename) {
40     $pattern = $this->filePatternMethod->invoke($this->fileTranslation, $langcode);
41     $this->assertNotEmpty(preg_match($pattern, $filename));
42   }
43
44   /**
45    * @return array
46    */
47   public function providerValidTranslationFiles() {
48     return [
49       ['hu', 'drupal-8.0.0-alpha1.hu.po'],
50       ['ta', 'drupal-8.10.10-beta12.ta.po'],
51       ['hi', 'drupal-8.0.0.hi.po'],
52     ];
53   }
54
55   /**
56    * @dataProvider providerInvalidTranslationFiles
57    */
58   public function testFilesPatternInvalid($langcode, $filename) {
59     $pattern = $this->filePatternMethod->invoke($this->fileTranslation, $langcode);
60     $this->assertEmpty(preg_match($pattern, $filename));
61   }
62
63   /**
64    * @return array
65    */
66   public function providerInvalidTranslationFiles() {
67     return [
68       ['hu', 'drupal-alpha1-*-hu.po'],
69       ['ta', 'drupal-beta12.ta'],
70       ['hi', 'drupal-hi.po'],
71       ['de', 'drupal-dummy-de.po'],
72       ['hu', 'drupal-10.0.1.alpha1-hu.po'],
73     ];
74   }
75
76 }