You are here

public function ModuleHandlerTest::testModuleStreamWrappers in Drupal 8

Same name and namespace in other branches
  1. 9 core/modules/system/tests/src/Kernel/Extension/ModuleHandlerTest.php \Drupal\Tests\system\Kernel\Extension\ModuleHandlerTest::testModuleStreamWrappers()
  2. 10 core/modules/system/tests/src/Kernel/Extension/ModuleHandlerTest.php \Drupal\Tests\system\Kernel\Extension\ModuleHandlerTest::testModuleStreamWrappers()

Tests whether module-provided stream wrappers are registered properly.

File

core/modules/system/tests/src/Kernel/Extension/ModuleHandlerTest.php, line 334

Class

ModuleHandlerTest
Tests ModuleHandler functionality.

Namespace

Drupal\Tests\system\Kernel\Extension

Code

public function testModuleStreamWrappers() {

  // file_test.module provides (among others) a 'dummy' stream wrapper.
  // Verify that it is not registered yet to prevent false positives.
  $stream_wrappers = \Drupal::service('stream_wrapper_manager')
    ->getWrappers();
  $this
    ->assertFalse(isset($stream_wrappers['dummy']));
  $this
    ->moduleInstaller()
    ->install([
    'file_test',
  ]);

  // Verify that the stream wrapper is available even without calling
  // \Drupal::service('stream_wrapper_manager')->getWrappers() again.
  // If the stream wrapper is not available file_exists() will raise a notice.
  file_exists('dummy://');
  $stream_wrappers = \Drupal::service('stream_wrapper_manager')
    ->getWrappers();
  $this
    ->assertTrue(isset($stream_wrappers['dummy']));
}