class LegacyFileSystemTest

Same name and namespace in other branches
  1. 11.x core/tests/Drupal/KernelTests/Core/File/LegacyFileSystemTest.php \Drupal\KernelTests\Core\File\LegacyFileSystemTest

Tests the legacy file system functions.

@group file @group legacy @coversDefaultClass \Drupal\Core\File\FileSystem

Hierarchy

Expanded class hierarchy of LegacyFileSystemTest

File

core/tests/Drupal/KernelTests/Core/File/LegacyFileSystemTest.php, line 16

Namespace

Drupal\KernelTests\Core\File
View source
class LegacyFileSystemTest extends FileTestBase {
  
  /**
   * The file system under test.
   */
  protected FileSystemInterface $fileSystem;
  
  /**
   * {@inheritdoc}
   */
  protected function setUp() : void {
    parent::setUp();
    $this->fileSystem = $this->container
      ->get('file_system');
  }
  
  /**
   * @covers ::copy
   */
  public function testCopyWithDeprecatedFileExists() : void {
    $uri = 'public://test.txt';
    touch($uri);
    $this->expectDeprecation('Passing the $fileExists argument as an integer to Drupal\\Core\\File\\FileSystem::copy() is deprecated in drupal:10.3.0 and is removed from drupal:12.0.0. Use \\Drupal\\Core\\File\\FileExists enum instead. See https://www.drupal.org/node/3426517');
    $newUri = $this->fileSystem
      ->copy($uri, $uri, FileSystemInterface::EXISTS_RENAME);
    $this->assertFileExists($newUri);
  }
  
  /**
   * @covers ::move
   */
  public function testMoveWithDeprecatedFileExists() : void {
    $uri = 'public://test.txt';
    touch($uri);
    $this->expectDeprecation('Passing the $fileExists argument as an integer to Drupal\\Core\\File\\FileSystem::move() is deprecated in drupal:10.3.0 and is removed from drupal:12.0.0. Use \\Drupal\\Core\\File\\FileExists enum instead. See https://www.drupal.org/node/3426517');
    $newUri = $this->fileSystem
      ->move($uri, $uri, FileSystemInterface::EXISTS_RENAME);
    $this->assertFileExists($newUri);
  }
  
  /**
   * @covers ::saveData
   */
  public function testSaveDataWithDeprecatedFileExists() : void {
    $data = $this->randomMachineName(8);
    $uri = 'public://test.txt';
    touch($uri);
    $this->expectDeprecation('Passing the $fileExists argument as an integer to Drupal\\Core\\File\\FileSystem::saveData() is deprecated in drupal:10.3.0 and is removed from drupal:12.0.0. Use \\Drupal\\Core\\File\\FileExists enum instead. See https://www.drupal.org/node/3426517');
    $newUri = $this->fileSystem
      ->saveData($data, $uri, FileSystemInterface::EXISTS_RENAME);
    $this->assertFileExists($newUri);
  }
  
  /**
   * @covers ::getDestinationFilename
   */
  public function testGetDestinationFilenameWithDeprecatedFileExists() : void {
    $uri = 'public://test.txt';
    touch($uri);
    $newUri = $this->fileSystem
      ->getDestinationFilename($uri, FileSystemInterface::EXISTS_RENAME);
    $this->assertStringStartsWith('public://test_', $newUri);
    $this->assertNotEquals($newUri, $uri);
  }
  
  /**
   * @covers ::copy
   */
  public function testCopyWithOutOfBoundsIntPositive() : void {
    $uri = 'public://test.txt';
    $destination = 'public://test2.txt';
    touch($uri);
    $this->expectDeprecation('Passing the $fileExists argument as an integer to Drupal\\Core\\File\\FileSystem::copy() is deprecated in drupal:10.3.0 and is removed from drupal:12.0.0. Use \\Drupal\\Core\\File\\FileExists enum instead. See https://www.drupal.org/node/3426517');
    $this->fileSystem
      ->copy($uri, $destination, \PHP_INT_MAX);
  }
  
  /**
   * @covers ::copy
   */
  public function testCopyWithOutOfBoundsIntNegative() : void {
    $uri = 'public://test.txt';
    $destination = 'public://test2.txt';
    touch($uri);
    $this->expectDeprecation('Passing the $fileExists argument as an integer to Drupal\\Core\\File\\FileSystem::copy() is deprecated in drupal:10.3.0 and is removed from drupal:12.0.0. Use \\Drupal\\Core\\File\\FileExists enum instead. See https://www.drupal.org/node/3426517');
    $this->fileSystem
      ->copy($uri, $destination, \PHP_INT_MIN);
  }

}

Members

Title Sort descending Deprecated Modifiers Object type Summary
ExtensionListTestTrait::getModulePath protected function Gets the path for the specified module.
ExtensionListTestTrait::getThemePath protected function Gets the path for the specified theme.
LegacyFileSystemTest::$fileSystem protected property The file system under test.
LegacyFileSystemTest::setUp protected function
LegacyFileSystemTest::testCopyWithDeprecatedFileExists public function @covers ::copy[[api-linebreak]]
LegacyFileSystemTest::testCopyWithOutOfBoundsIntNegative public function @covers ::copy[[api-linebreak]]
LegacyFileSystemTest::testCopyWithOutOfBoundsIntPositive public function @covers ::copy[[api-linebreak]]
LegacyFileSystemTest::testGetDestinationFilenameWithDeprecatedFileExists public function @covers ::getDestinationFilename[[api-linebreak]]
LegacyFileSystemTest::testMoveWithDeprecatedFileExists public function @covers ::move[[api-linebreak]]
LegacyFileSystemTest::testSaveDataWithDeprecatedFileExists public function @covers ::saveData[[api-linebreak]]
RandomGeneratorTrait::getRandomGenerator protected function Gets the random generator for the utility methods.
RandomGeneratorTrait::randomMachineName protected function Generates a unique random string containing letters and numbers.
RandomGeneratorTrait::randomObject public function Generates a random PHP object.
RandomGeneratorTrait::randomString public function Generates a pseudo-random string of ASCII characters of codes 32 to 126.
RandomGeneratorTrait::randomStringValidate Deprecated public function Callback for random string validation.
StorageCopyTrait::replaceStorageContents protected static function Copy the configuration from one storage to another and remove stale items.
TestRequirementsTrait::checkModuleRequirements Deprecated private function Checks missing module requirements.
TestRequirementsTrait::checkRequirements Deprecated protected function Check module requirements for the Drupal use case.
TestRequirementsTrait::getDrupalRoot protected static function Returns the Drupal root directory.

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.