You are here

class FlysystemRoutesTest in Flysystem 8

Same name and namespace in other branches
  1. 3.x tests/src/Unit/Routing/FlysystemRoutesTest.php \Drupal\Tests\flysystem\Unit\Routing\FlysystemRoutesTest
  2. 2.0.x tests/src/Unit/Routing/FlysystemRoutesTest.php \Drupal\Tests\flysystem\Unit\Routing\FlysystemRoutesTest
  3. 3.0.x tests/src/Unit/Routing/FlysystemRoutesTest.php \Drupal\Tests\flysystem\Unit\Routing\FlysystemRoutesTest

@coversDefaultClass \Drupal\flysystem\Routing\FlysystemRoutes @group flysystem

Hierarchy

Expanded class hierarchy of FlysystemRoutesTest

File

tests/src/Unit/Routing/FlysystemRoutesTest.php, line 18

Namespace

Drupal\Tests\flysystem\Unit\Routing
View source
class FlysystemRoutesTest extends UnitTestCase {

  /**
   * @var \Drupal\flysystem\FlysystemFactory
   */
  protected $factory;

  /**
   * @var \Drupal\Core\Extension\ModuleHandlerInterface
   */
  protected $moduleHandler;

  /**
   * @var \Drupal\flysystem\Routing\FlysystemRoutes
   */
  protected $router;

  /**
   * {@inheritdoc}
   */
  public function setUp() {
    $container = new ContainerBuilder();
    $stream_wrapper = $this
      ->prophesize(LocalStream::class);
    $stream_wrapper
      ->getDirectoryPath()
      ->willReturn('sites/default/files');
    $stream_wrapper_manager = $this
      ->prophesize(StreamWrapperManagerInterface::class);
    $stream_wrapper_manager
      ->getViaScheme('public')
      ->willReturn($stream_wrapper
      ->reveal());
    $this->moduleHandler = $this
      ->prophesize(ModuleHandlerInterface::class);
    $factory = $this
      ->prophesize(FlysystemFactory::class);
    $factory
      ->getSchemes()
      ->willReturn([
      'test',
    ]);
    $container
      ->set('flysystem_factory', $factory
      ->reveal());
    $container
      ->set('stream_wrapper_manager', $stream_wrapper_manager
      ->reveal());
    $container
      ->set('module_handler', $this->moduleHandler
      ->reveal());
    $this->router = FlysystemRoutes::create($container);
  }

  /**
   * @covers ::__construct
   * @covers ::create
   * @covers ::routes
   */
  public function testInvalidSettingsAreSkipped() {
    new Settings([
      'flysystem' => [
        'invalid' => [
          'driver' => 'local',
        ],
        'test' => [
          'driver' => 'local',
        ],
      ],
    ]);
    $this
      ->assertSame([], $this->router
      ->routes());
  }

  /**
   * @covers ::routes
   */
  public function testInvalidDriversAreSkipped() {
    new Settings([
      'flysystem' => [
        'test' => [
          'driver' => 'ftp',
        ],
      ],
    ]);
    $this
      ->assertSame([], $this->router
      ->routes());
  }

  /**
   * @covers ::routes
   */
  public function testDriversNotPublicAreSkipped() {
    new Settings([
      'flysystem' => [
        'test' => [
          'driver' => 'local',
        ],
      ],
    ]);
    $this
      ->assertSame([], $this->router
      ->routes());
  }

  /**
   * @covers ::routes
   */
  public function testLocalPathSameAsPublicIsSkipped() {
    new Settings([
      'flysystem' => [
        'test' => [
          'driver' => 'local',
          'public' => TRUE,
          'config' => [
            'public' => TRUE,
            'root' => 'sites/default/files',
          ],
        ],
      ],
    ]);
    $this
      ->assertSame([], $this->router
      ->routes());
  }

  /**
   * @covers ::routes
   */
  public function testValidRoutesReturned() {
    new Settings([
      'flysystem' => [
        'test' => [
          'driver' => 'local',
          'public' => TRUE,
          'config' => [
            'public' => TRUE,
            'root' => 'sites/default/files/flysystem',
          ],
        ],
      ],
    ]);
    $routes = $this->router
      ->routes();
    $this
      ->assertSame(1, count($routes));
    $this
      ->assertTrue(isset($routes['flysystem.test.serve']));
  }

  /**
   * @covers ::routes
   */
  public function testValidRoutesReturnedWithImageModule() {
    new Settings([
      'flysystem' => [
        'test' => [
          'driver' => 'local',
          'public' => TRUE,
          'config' => [
            'public' => TRUE,
            'root' => 'sites/default/files/flysystem',
          ],
        ],
      ],
    ]);
    $this->moduleHandler
      ->moduleExists('image')
      ->willReturn(TRUE);
    $routes = $this->router
      ->routes();
    $this
      ->assertSame(3, count($routes));
    $this
      ->assertTrue(isset($routes['flysystem.image_style']));
  }

}

Members

Namesort descending Modifiers Type Description Overrides
FlysystemRoutesTest::$factory protected property
FlysystemRoutesTest::$moduleHandler protected property
FlysystemRoutesTest::$router protected property
FlysystemRoutesTest::setUp public function Overrides UnitTestCase::setUp
FlysystemRoutesTest::testDriversNotPublicAreSkipped public function @covers ::routes
FlysystemRoutesTest::testInvalidDriversAreSkipped public function @covers ::routes
FlysystemRoutesTest::testInvalidSettingsAreSkipped public function @covers ::__construct @covers ::create @covers ::routes
FlysystemRoutesTest::testLocalPathSameAsPublicIsSkipped public function @covers ::routes
FlysystemRoutesTest::testValidRoutesReturned public function @covers ::routes
FlysystemRoutesTest::testValidRoutesReturnedWithImageModule public function @covers ::routes
PhpunitCompatibilityTrait::getMock Deprecated public function Returns a mock object for the specified class using the available method.
PhpunitCompatibilityTrait::setExpectedException Deprecated public function Compatibility layer for PHPUnit 6 to support PHPUnit 4 code.
UnitTestCase::$randomGenerator protected property The random generator.
UnitTestCase::$root protected property The app root. 1
UnitTestCase::assertArrayEquals protected function Asserts if two arrays are equal by sorting them first.
UnitTestCase::getBlockMockWithMachineName Deprecated protected function Mocks a block with a block plugin. 1
UnitTestCase::getClassResolverStub protected function Returns a stub class resolver.
UnitTestCase::getConfigFactoryStub public function Returns a stub config factory that behaves according to the passed array.
UnitTestCase::getConfigStorageStub public function Returns a stub config storage that returns the supplied configuration.
UnitTestCase::getContainerWithCacheTagsInvalidator protected function Sets up a container with a cache tags invalidator.
UnitTestCase::getRandomGenerator protected function Gets the random generator for the utility methods.
UnitTestCase::getStringTranslationStub public function Returns a stub translation manager that just returns the passed string.
UnitTestCase::randomMachineName public function Generates a unique random string containing letters and numbers.