You are here

class ModuleFunctionsTest in Flysystem 8

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

Tests module functions.

@group flysystem

Hierarchy

Expanded class hierarchy of ModuleFunctionsTest

File

tests/src/Unit/ModuleFunctionsTest.php, line 20

Namespace

Drupal\Tests\flysystem\Unit
View source
class ModuleFunctionsTest extends UnitTestCase {

  /**
   * The Flysystem factory prophecy object.
   *
   * @var \Prophecy\Prophecy\ObjectProphecy
   */
  protected $factory;

  /**
   * {@inheritdoc}
   */
  public function setUp() {
    parent::setUp();
    vfsStream::setup('module_file');
    require_once dirname(dirname(dirname(__DIR__))) . '/flysystem.module';
    $this->factory = $this
      ->prophesize(FlysystemFactory::class);
    $this->factory
      ->getSchemes()
      ->willReturn([
      'vfs',
    ]);
    $file_system_helper = $this
      ->prophesize(FileSystemInterface::class);
    $file_system_helper
      ->uriScheme(Argument::type('string'))
      ->will(function ($uri) {
      list($scheme) = explode('://', $uri[0]);
      return $scheme;
    });
    $guesser = $this
      ->prophesize(MimeTypeGuesserInterface::class);
    $guesser
      ->guess(Argument::type('string'))
      ->willReturn('txt/flysystem');
    $container = new ContainerBuilder();
    $container
      ->set('file_system', $file_system_helper
      ->reveal());
    $container
      ->set('flysystem_factory', $this->factory
      ->reveal());
    $container
      ->set('file.mime_type.guesser.extension', $guesser
      ->reveal());
    \Drupal::setContainer($container);
  }

  /**
   * Tests flysystem_cron() calls ensure.
   */
  public function testFlysystemCronCallsEnsure() {
    $this->factory
      ->ensure()
      ->shouldBeCalled();
    flysystem_cron();
  }

  /**
   * Tests flysystem_rebuild() calls ensure.
   */
  public function testFlysystemRebuildCallsEnsure() {
    $this->factory
      ->ensure()
      ->shouldBeCalled();
    flysystem_rebuild();
  }

  /**
   * Tests flysystem_file_download() handles valid schemes.
   */
  public function testFlysystemFileDownloadFindsValidScheme() {
    file_put_contents('vfs://module_file/file.txt', '1234');
    $return = flysystem_file_download('vfs://module_file/file.txt');
    $this
      ->assertSame(2, count($return));
    $this
      ->assertSame('txt/flysystem', $return['Content-Type']);
    $this
      ->assertSame(4, $return['Content-Length']);
  }

  /**
   * Tests flysystem_file_download() ignores invalid schemes.
   */
  public function testFlysystemFileDownloadIgnoresInvalidScheme() {
    $this
      ->assertNull(flysystem_file_download('invalid://module_file/file.txt'));
  }

}

Members

Namesort descending Modifiers Type Description Overrides
ModuleFunctionsTest::$factory protected property The Flysystem factory prophecy object.
ModuleFunctionsTest::setUp public function Overrides UnitTestCase::setUp
ModuleFunctionsTest::testFlysystemCronCallsEnsure public function Tests flysystem_cron() calls ensure.
ModuleFunctionsTest::testFlysystemFileDownloadFindsValidScheme public function Tests flysystem_file_download() handles valid schemes.
ModuleFunctionsTest::testFlysystemFileDownloadIgnoresInvalidScheme public function Tests flysystem_file_download() ignores invalid schemes.
ModuleFunctionsTest::testFlysystemRebuildCallsEnsure public function Tests flysystem_rebuild() calls ensure.
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.