function FilePathTest::makeFiles

Same name in other branches
  1. 10 core/modules/migrate_drupal_ui/tests/src/Functional/d7/FilePathTest.php \Drupal\Tests\migrate_drupal_ui\Functional\d7\FilePathTest::makeFiles()
  2. 11.x core/modules/migrate_drupal_ui/tests/src/Functional/d7/FilePathTest.php \Drupal\Tests\migrate_drupal_ui\Functional\d7\FilePathTest::makeFiles()

Creates files for the test.

The source files are written to a subdirectory of the temporary files directory of the test sites. The subdirectory path always ends with the path to the relevant scheme as set in the source variable table.

For example: The source site files_managed table. uri: public://foo.txt filename: foo.txt The source site variable table. file_public_path: sites/default/files Local directory /bar

The resulting directory is /bar/sites/default/files/foo.txt.

1 call to FilePathTest::makeFiles()
FilePathTest::testFilePath in core/modules/migrate_drupal_ui/tests/src/Functional/d7/FilePathTest.php
Executes all steps of migrations upgrade.

File

core/modules/migrate_drupal_ui/tests/src/Functional/d7/FilePathTest.php, line 222

Class

FilePathTest
Tests the Drupal 7 public and private file migrations.

Namespace

Drupal\Tests\migrate_drupal_ui\Functional\d7

Code

protected function makeFiles() {
    // Get file information from the source database.
    foreach ($this->getManagedFiles() as $file) {
        $this->assertSame(1, preg_match('/^(private|public|temporary):/', $file['uri'], $matches));
        $scheme = $matches[1];
        $path = $this->sourceFileScheme[$scheme] ?? '';
        $filepath = implode('/', [
            $this->getSourcePath($scheme),
            $path,
            $file['filename'],
        ]);
        // Create the file.
        $source_file = @fopen($filepath, 'w');
        if (!$source_file) {
            // If fopen didn't work, make sure there's a writable directory in
            // place.
            $dir = $this->fs
                ->dirname($filepath);
            $this->fs
                ->prepareDirectory($dir, FileSystemInterface::CREATE_DIRECTORY | FileSystemInterface::MODIFY_PERMISSIONS);
            // Let's try that fopen again.
            $source_file = @fopen($filepath, 'w');
        }
        fwrite($source_file, '42');
    }
}

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