3 namespace Drupal\Tests\libraries\Kernel\ExternalLibrary;
5 use Drupal\Core\Extension\ModuleHandlerInterface;
6 use Drupal\Core\StreamWrapper\LocalStream;
7 use Drupal\Core\StringTranslation\StringTranslationTrait;
8 use Drupal\Core\StringTranslation\TranslationInterface;
9 use Drupal\libraries\StreamWrapper\LocalHiddenStreamTrait;
10 use Drupal\libraries\StreamWrapper\PrivateStreamTrait;
13 * Provides a stream wrapper for accessing test library files.
15 class TestLibraryFilesStream extends LocalStream {
17 use LocalHiddenStreamTrait;
18 use PrivateStreamTrait;
19 use StringTranslationTrait;
24 * @var \Drupal\Core\Extension\ModuleHandlerInterface
26 protected $moduleHandler;
36 * Constructs a stream wrapper for test library files.
38 * Dependency injection is generally not possible to implement for stream
39 * wrappers, because stream wrappers are initialized before the container is
40 * booted, but this stream wrapper is only registered explicitly from tests
41 * so it is possible here.
43 * @param \Drupal\Core\Extension\ModuleHandlerInterface $module_handler
45 * @param \Drupal\Core\StringTranslation\TranslationInterface $string_translation
46 * The string translation handler.
47 * @param string $directory
48 * The directory within the Libraries API's tests directory that is to be
49 * searched for test library files.
51 public function __construct(ModuleHandlerInterface $module_handler, TranslationInterface $string_translation, $directory) {
52 $this->moduleHandler = $module_handler;
53 $this->directory = (string) $directory;
55 $this->setStringTranslation($string_translation);
61 public function getName() {
62 $this->t('Test library files');
68 public function getDescription() {
69 $this->t('Provides access to test library files.');
75 public function getDirectoryPath() {
76 $module_path = $this->moduleHandler->getModule('libraries')->getPath();
77 return $module_path . '/tests/' . $this->directory;