file_encrypt-8.x-1.x-dev/tests/src/Kernel/FileEncryptDownloadTest.php

tests/src/Kernel/FileEncryptDownloadTest.php
<?php

namespace Drupal\Tests\file_encrypt\Kernel;

use Drupal\file\Entity\File;
use Drupal\file_encrypt\EncryptStreamWrapper;
use Symfony\Component\HttpFoundation\Request;

/**
 * Tests downloading an encrypted file via HTTP.
 *
 * @group file_encrypt
 */
class FileEncryptDownloadTest extends FileEncryptTestBase {

  /**
   * The encrypted URI.
   *
   * @var string
   */
  protected $encryptedUri;

  /**
   * {@inheritdoc}
   */
  protected static $modules = ['file', 'user'];

  /**
   * {@inheritdoc}
   */
  protected function setUp(): void {
    parent::setUp();

    $this->installEntitySchema('file');
    $this->installSchema('file', 'file_usage');

    $uri = EncryptStreamWrapper::SCHEME . '://encryption_profile_1/example.txt';
    file_put_contents($uri, 'test-data');
    $this->encryptedUri = $uri;
    $file = File::create([
      'uri' => $this->encryptedUri,
      'uid' => 0,
    ]);
    $file->save();
    \Drupal::service('session')->set('anonymous_allowed_file_ids', [$file->id() => $file->id()]);
  }

  /**
   * Tests a file download via HTTP.
   */
  public function testFileDownloadViaHttp() {
    $request = Request::create('/encrypt/files/encryption_profile_1/example.txt');
    /** @var \Symfony\Component\HttpKernel\HttpKernelInterface $http_kernel */
    $http_kernel = $this->container->get('http_kernel');

    $response = $http_kernel->handle($request);
    $this->assertEquals(200, $response->getStatusCode());


    ob_start();
    $response->send();
    $out = ob_get_contents();
    ob_end_clean();
    // @fixme This doesn't yet catch the actual response.
  }

}

Главная | Обратная связь

drupal hosting | друпал хостинг | it patrol .inc