You are here

class InstallTranslationFilePatternTest in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 core/modules/system/tests/src/Unit/Installer/InstallTranslationFilePatternTest.php \Drupal\Tests\system\Unit\Installer\InstallTranslationFilePatternTest

Tests for installer language support.

@group Installer

Hierarchy

Expanded class hierarchy of InstallTranslationFilePatternTest

File

core/modules/system/tests/src/Unit/Installer/InstallTranslationFilePatternTest.php, line 18
Contains \Drupal\Tests\system\Unit\Installer\InstallTranslationFilePatternTest.

Namespace

Drupal\Tests\system\Unit\Installer
View source
class InstallTranslationFilePatternTest extends UnitTestCase {

  /**
   * @var \Drupal\Core\StringTranslation\Translator\FileTranslation
   */
  protected $fileTranslation;

  /**
   * @var \ReflectionMethod
   */
  protected $filePatternMethod;

  /**
   * {@inheritdoc}
   */
  protected function setup() {
    parent::setUp();
    $this->fileTranslation = new FileTranslation('filename');
    $method = new \ReflectionMethod('\\Drupal\\Core\\StringTranslation\\Translator\\FileTranslation', 'getTranslationFilesPattern');
    $method
      ->setAccessible(true);
    $this->filePatternMethod = $method;
  }

  /**
   * @dataProvider providerValidTranslationFiles
   */
  public function testFilesPatternValid($langcode, $filename) {
    $pattern = $this->filePatternMethod
      ->invoke($this->fileTranslation, $langcode);
    $this
      ->assertNotEmpty(preg_match($pattern, $filename));
  }

  /**
   * @return array
   */
  public function providerValidTranslationFiles() {
    return array(
      array(
        'hu',
        'drupal-8.0.0-alpha1.hu.po',
      ),
      array(
        'ta',
        'drupal-8.10.10-beta12.ta.po',
      ),
      array(
        'hi',
        'drupal-8.0.0.hi.po',
      ),
    );
  }

  /**
   * @dataProvider providerInvalidTranslationFiles
   */
  public function testFilesPatternInvalid($langcode, $filename) {
    $pattern = $this->filePatternMethod
      ->invoke($this->fileTranslation, $langcode);
    $this
      ->assertEmpty(preg_match($pattern, $filename));
  }

  /**
   * @return array
   */
  public function providerInvalidTranslationFiles() {
    return array(
      array(
        'hu',
        'drupal-alpha1-*-hu.po',
      ),
      array(
        'ta',
        'drupal-beta12.ta',
      ),
      array(
        'hi',
        'drupal-hi.po',
      ),
      array(
        'de',
        'drupal-dummy-de.po',
      ),
      array(
        'hu',
        'drupal-10.0.1.alpha1-hu.po',
      ),
    );
  }

}

Members

Namesort descending Modifiers Type Description Overrides
InstallTranslationFilePatternTest::$filePatternMethod protected property
InstallTranslationFilePatternTest::$fileTranslation protected property
InstallTranslationFilePatternTest::providerInvalidTranslationFiles public function
InstallTranslationFilePatternTest::providerValidTranslationFiles public function
InstallTranslationFilePatternTest::setup protected function
InstallTranslationFilePatternTest::testFilesPatternInvalid public function @dataProvider providerInvalidTranslationFiles
InstallTranslationFilePatternTest::testFilesPatternValid public function @dataProvider providerValidTranslationFiles
UnitTestCase::$randomGenerator protected property The random generator.
UnitTestCase::$root protected property The app root.
UnitTestCase::assertArrayEquals protected function Asserts if two arrays are equal by sorting them first.
UnitTestCase::getBlockMockWithMachineName protected function Mocks a block with a block plugin.
UnitTestCase::getClassResolverStub protected function Returns a stub class resolver.
UnitTestCase::getConfigFactoryStub public function Returns a stub config factory that behaves according to the passed in array.
UnitTestCase::getConfigStorageStub public function Returns a stub config storage that returns the supplied configuration.
UnitTestCase::getContainerWithCacheTagsInvalidator protected function Sets up a container with a cache tags invalidator.
UnitTestCase::getRandomGenerator protected function Gets the random generator for the utility methods.
UnitTestCase::getStringTranslationStub public function Returns a stub translation manager that just returns the passed string.
UnitTestCase::randomMachineName public function Generates a unique random string containing letters and numbers.
UnitTestCase::setUp protected function 259