diff --git a/core/modules/migrate/tests/src/Kernel/process/CopyFileTest.php b/core/modules/migrate/tests/src/Kernel/process/CopyFileTest.php index 427d413bc62898b1c5c9188972bb68b9b8f200a4..ecd1bb14d4557b6fd1929e6a3895fd199300c4cb 100644 --- a/core/modules/migrate/tests/src/Kernel/process/CopyFileTest.php +++ b/core/modules/migrate/tests/src/Kernel/process/CopyFileTest.php @@ -3,7 +3,7 @@ namespace Drupal\Tests\migrate\Kernel\process; use Drupal\Core\StreamWrapper\StreamWrapperInterface; -use Drupal\KernelTests\Core\File\FileTestBase; +use Drupal\KernelTests\KernelTestBase; use Drupal\migrate\MigrateExecutableInterface; use Drupal\migrate\Plugin\migrate\process\FileCopy; use Drupal\migrate\Row; @@ -13,7 +13,7 @@ * * @group migrate */ -class CopyFileTest extends FileTestBase { +class CopyFileTest extends KernelTestBase { /** * {@inheritdoc} @@ -180,4 +180,39 @@ protected function doImport($source_path, $destination_path, $configuration = [] return $result; } + /** + * Create a file and return the URI of it. + * + * @param $filepath + * Optional string specifying the file path. If none is provided then a + * randomly named file will be created in the site's files directory. + * @param $contents + * Optional contents to save into the file. If a NULL value is provided an + * arbitrary string will be used. + * @param $scheme + * Optional string indicating the stream scheme to use. Drupal core includes + * public, private, and temporary. The public wrapper is the default. + * @return + * File URI. + */ + protected function createUri($filepath = NULL, $contents = NULL, $scheme = NULL) { + if (!isset($filepath)) { + // Prefix with non-latin characters to ensure that all file-related + // tests work with international filenames. + $filepath = 'Файл для тестирования ' . $this->randomMachineName(); + } + if (empty($scheme)) { + $scheme = file_default_scheme(); + } + $filepath = $scheme . '://' . $filepath; + + if (empty($contents)) { + $contents = "file_put_contents() doesn't seem to appreciate empty strings so let's put in some data."; + } + + file_put_contents($filepath, $contents); + $this->assertFileExists($filepath, t('The test file exists on the disk.')); + return $filepath; + } + }