function FileTranslatorTest::testPrivate

Tests storing files in the private file system.

File

translators/tmgmt_file/tests/src/Functional/FileTranslatorTest.php, line 467

Class

FileTranslatorTest
Tests for the file translator.

Namespace

Drupal\Tests\tmgmt_file\Functional

Code

function testPrivate() {

  // Create a translator using the private file system.
  // @todo: Test the configuration UI.
  $translator = $this
    ->createTranslator([
    'plugin' => 'file',
    'settings' => [
      'export_format' => 'xlf',
      'xliff_processing' => TRUE,
      'scheme' => 'private',
    ],
  ]);
  $job = $this
    ->createJob();
  $job->translator = $translator
    ->id();
  $job
    ->addItem('test_source', 'test', '1');
  $job
    ->addItem('test_source', 'test', '2');
  $job
    ->requestTranslation();
  $messages = $job
    ->getMessages();
  $message = reset($messages);
  $this
    ->drupalGet('admin/tmgmt/jobs');
  $this
    ->clickLink('Manage');

  // Assert that the label field is only shown once in page.
  $this
    ->assertCount(1, $this
    ->xpath('//div[@id="tmgmt-ui-label"]'));
  $download_url = $message->variables->{'@link'};
  $this
    ->assertFalse((bool) strpos('< a', $download_url));
  $this
    ->drupalGet($download_url);

  // Verify that the URL is served using the private file system and the
  // access checks work.
  $this
    ->assertNotEmpty(preg_match('|system/files|', $download_url));
  $this
    ->assertSession()
    ->statusCodeEquals(200);
  $this
    ->drupalLogout();

  // Verify that access is now protected.
  $this
    ->drupalGet($download_url);
  $this
    ->assertSession()
    ->statusCodeEquals(403);
}