View source
<?php
namespace Drupal\Tests\migrate\Unit\process;
use Drupal\Core\File\FileSystemInterface;
use Drupal\Core\StreamWrapper\StreamWrapperManagerInterface;
use Drupal\migrate\Plugin\migrate\process\FileCopy;
use Drupal\migrate\Plugin\MigrateProcessInterface;
class FileCopyTest extends MigrateProcessTestCase {
public function testFileProcessBaseConstructor($configuration, $expected) {
$this
->assertPlugin($configuration, $expected);
}
public function providerFileProcessBaseConstructor() {
return [
[
[
'file_exists' => 'replace',
],
FileSystemInterface::EXISTS_REPLACE,
],
[
[
'file_exists' => 'rename',
],
FileSystemInterface::EXISTS_RENAME,
],
[
[
'file_exists' => 'use existing',
],
FileSystemInterface::EXISTS_ERROR,
],
[
[
'file_exists' => 'foobar',
],
FileSystemInterface::EXISTS_REPLACE,
],
[
[],
FileSystemInterface::EXISTS_REPLACE,
],
];
}
protected function assertPlugin(array $configuration, int $expected) : void {
$stream_wrapper_manager = $this
->prophesize(StreamWrapperManagerInterface::class)
->reveal();
$file_system = $this
->prophesize(FileSystemInterface::class)
->reveal();
$download_plugin = $this
->prophesize(MigrateProcessInterface::class)
->reveal();
$this->plugin = new TestFileCopy($configuration, 'test', [], $stream_wrapper_manager, $file_system, $download_plugin);
$plugin_config = $this->plugin
->getConfiguration();
$this
->assertArrayHasKey('file_exists', $plugin_config);
$this
->assertSame($expected, $plugin_config['file_exists']);
}
}
class TestFileCopy extends FileCopy {
public function getConfiguration() {
return $this->configuration;
}
}