private function LocaleCompareTest::makePoFile

Creates a translation file and tests its timestamp.

Parameters

string $path: Path of the file relative to the public file path.

string $filename: Name of the file to create.

integer $timestamp: Timestamp to set the file to. Defaults to current time.

string $data: Translation data to put into the file. Po header data will be added.

1 call to LocaleCompareTest::makePoFile()
LocaleCompareTest::testCompareCheckLocal in drupal/core/modules/locale/lib/Drupal/locale/Tests/LocaleCompareTest.php
Checks if local or remote translation sources are detected.

File

drupal/core/modules/locale/lib/Drupal/locale/Tests/LocaleCompareTest.php, line 78
Definition of Drupal\locale\Tests\LocaleCompareTest.

Class

LocaleCompareTest
Tests for comparing status of existing project translations with available translations.

Namespace

Drupal\locale\Tests

Code

private function makePoFile($path, $filename, $timestamp = NULL, $data = '') {
  $timestamp = $timestamp ? $timestamp : REQUEST_TIME;
  $path = 'public://' . $path;
  $po_header = <<<EOF
msgid ""
msgstr ""
"Project-Id-Version: Drupal 8\\n"
"MIME-Version: 1.0\\n"
"Content-Type: text/plain; charset=UTF-8\\n"
"Content-Transfer-Encoding: 8bit\\n"
"Plural-Forms: nplurals=2; plural=(n > 1);\\n"

EOF;
  file_prepare_directory($path, FILE_CREATE_DIRECTORY);
  $file = entity_create('file', array(
    'uid' => 1,
    'filename' => $filename,
    'uri' => $path . '/' . $filename,
    'filemime' => 'text/x-gettext-translation',
    'timestamp' => $timestamp,
    'status' => FILE_STATUS_PERMANENT,
  ));
  file_put_contents($file->uri, $po_header . $data);
  touch(drupal_realpath($file->uri), $timestamp);
  $file
    ->save();
}