FileCopyTest.php

Same filename in this branch
  1. 11.x core/modules/migrate/tests/src/Kernel/process/FileCopyTest.php
  2. 11.x core/tests/Drupal/KernelTests/Core/File/FileCopyTest.php
Same filename and directory in other branches
  1. 9 core/modules/migrate/tests/src/Unit/process/FileCopyTest.php
  2. 9 core/modules/migrate/tests/src/Kernel/process/FileCopyTest.php
  3. 9 core/tests/Drupal/KernelTests/Core/File/FileCopyTest.php
  4. 8.9.x core/modules/migrate/tests/src/Unit/process/FileCopyTest.php
  5. 8.9.x core/modules/migrate/tests/src/Kernel/process/FileCopyTest.php
  6. 8.9.x core/tests/Drupal/KernelTests/Core/File/FileCopyTest.php
  7. 10 core/modules/migrate/tests/src/Unit/process/FileCopyTest.php
  8. 10 core/modules/migrate/tests/src/Kernel/process/FileCopyTest.php
  9. 10 core/tests/Drupal/KernelTests/Core/File/FileCopyTest.php

Namespace

Drupal\Tests\migrate\Unit\process

File

core/modules/migrate/tests/src/Unit/process/FileCopyTest.php

View source
<?php

declare (strict_types=1);
namespace Drupal\Tests\migrate\Unit\process;

use Drupal\Core\File\FileExists;
use Drupal\Core\File\FileSystemInterface;
use Drupal\Core\StreamWrapper\StreamWrapperManagerInterface;
use Drupal\migrate\Plugin\migrate\process\FileCopy;
use Drupal\migrate\Plugin\MigrateProcessInterface;

/**
 * Tests the file copy process plugin.
 *
 * @group migrate
 *
 * @coversDefaultClass \Drupal\migrate\Plugin\migrate\process\FileCopy
 */
class FileCopyTest extends MigrateProcessTestCase {
    
    /**
     * Tests that the plugin constructor correctly sets the configuration.
     *
     * @dataProvider providerFileProcessBaseConstructor
     *
     * @param array $configuration
     *   The plugin configuration.
     * @param $expected
     *   The expected value of the plugin configuration.
     */
    public function testFileProcessBaseConstructor($configuration, $expected) : void {
        $this->assertPlugin($configuration, $expected);
    }
    
    /**
     * Data provider for testFileProcessBaseConstructor.
     */
    public static function providerFileProcessBaseConstructor() {
        return [
            [
                [
                    'file_exists' => 'replace',
                ],
                FileExists::Replace,
            ],
            [
                [
                    'file_exists' => 'rename',
                ],
                FileExists::Rename,
            ],
            [
                [
                    'file_exists' => 'use existing',
                ],
                FileExists::Error,
            ],
            [
                [
                    'file_exists' => 'foobar',
                ],
                FileExists::Replace,
            ],
            [
                [],
                FileExists::Replace,
            ],
        ];
    }
    
    /**
     * Creates a TestFileCopy process plugin.
     *
     * @param array $configuration
     *   The plugin configuration.
     * @param \Drupal\Core\File\FileExists $expected
     *   The expected value of the plugin configuration.
     *
     * @internal
     */
    protected function assertPlugin(array $configuration, FileExists $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 for testing FileCopy.
 */
class TestFileCopy extends FileCopy {
    
    /**
     * Gets this plugin's configuration.
     *
     * @return array
     *   An array of this plugin's configuration.
     */
    public function getConfiguration() {
        return $this->configuration;
    }

}

Classes

Title Deprecated Summary
FileCopyTest Tests the file copy process plugin.
TestFileCopy Class for testing FileCopy.

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