Unverified Commit 0231c1f3 authored by Alex Pott's avatar Alex Pott
Browse files

task: #3570172 Add cache header tests for custom file schemes

By: akalata
By: larowlan
By: xjm
By: mohit_aghera
By: benjifisher
By: neclimdul
By: mcdruid
(cherry picked from commit 843199c7)
parent 048a2d76
Loading
Loading
Loading
Loading
Loading
+14 −0
Original line number Diff line number Diff line
@@ -16,3 +16,17 @@ file.required_test:
    _form: '\Drupal\file_test\Form\FileRequiredTestForm'
  requirements:
    _access: 'TRUE'
file_test.dummy:
  path: '/system/dummy'
  defaults:
    _controller: '\Drupal\system\FileDownloadController::download'
    scheme: dummy-private
  requirements:
    _access: 'TRUE'
file_test.public:
  path: '/system/dummy-public'
  defaults:
    _controller: '\Drupal\system\FileDownloadController::download'
    scheme: dummy-public
  requirements:
    _access: 'TRUE'
+8 −0
Original line number Diff line number Diff line
@@ -22,5 +22,13 @@ services:
    tags:
      - { name: stream_wrapper, scheme: dummy1 }
      - { name: stream_wrapper, scheme: dummy2 }
  stream_wrapper.dummy_private:
    class: Drupal\file_test\StreamWrapper\DummyPrivateStreamWrapper
    tags:
      - { name: stream_wrapper, scheme: dummy-private }
  stream_wrapper.dummy_public:
    class: Drupal\file_test\StreamWrapper\DummyPublicStreamWrapper
    tags:
      - { name: stream_wrapper, scheme: dummy-public }
  Drupal\file_test\EventSubscriber\DummyMimeTypeMapLoadedSubscriber:
    autowire: true
+8 −0
Original line number Diff line number Diff line
@@ -40,6 +40,14 @@ public function fileDownload($uri): array|int|null {
      $file = reset($files);
      return $file->getDownloadHeaders();
    }
    if (\Drupal::keyValue('file_test')->get('file_test_active_stream_wrapper') === 'dummy-private') {
      return ['Cache-Control' => 'private'];
    }

    if (\Drupal::keyValue('file_test')->get('file_test_active_stream_wrapper') === 'dummy-public') {
      return ['Cache-Control' => 'public'];
    }

    FileTestHelper::logCall('download', [$uri]);
    return $this->getReturn('download');
  }
+28 −0
Original line number Diff line number Diff line
<?php

declare(strict_types=1);

namespace Drupal\file_test\StreamWrapper;

use Drupal\Core\Url;

/**
 * Helper class for testing the stream wrapper registry.
 *
 * Dummy stream wrapper implementation (dummy-private://).
 */
class DummyPrivateStreamWrapper extends DummyStreamWrapper {

  /**
   * {@inheritdoc}
   */
  public function getExternalUrl(): string {
    $path = str_replace('\\', '/', $this->getTarget());
    return Url::fromRoute(
      'file_test.dummy',
      ['filepath' => $path],
      ['absolute' => TRUE, 'path_processing' => FALSE, 'query' => ['file' => $path]]
    )->toString();
  }

}
+28 −0
Original line number Diff line number Diff line
<?php

declare(strict_types=1);

namespace Drupal\file_test\StreamWrapper;

use Drupal\Core\Url;

/**
 * Helper class for testing the stream wrapper registry.
 *
 * Dummy stream wrapper implementation (dummy-public://).
 */
class DummyPublicStreamWrapper extends DummyStreamWrapper {

  /**
   * {@inheritdoc}
   */
  public function getExternalUrl(): string {
    $path = str_replace('\\', '/', $this->getTarget());
    return Url::fromRoute(
      'file_test.public',
      ['filepath' => $path],
      ['absolute' => TRUE, 'path_processing' => FALSE, 'query' => ['file' => $path]]
    )->toString();
  }

}
Loading