View source
<?php
namespace Drupal\Tests\file\Kernel\Plugin\migrate\source\d7;
use Drupal\Tests\migrate\Kernel\MigrateSqlSourceTestBase;
class FileTest extends MigrateSqlSourceTestBase {
protected static $modules = [
'file',
'migrate_drupal',
];
public function providerSource() {
$tests = [];
$tests[0]['source_data']['file_managed'] = [
[
'fid' => '1',
'uid' => '1',
'filename' => 'cube.jpeg',
'uri' => 'public://cube.jpeg',
'filemime' => 'image/jpeg',
'filesize' => '3620',
'status' => '1',
'timestamp' => '1421727515',
],
[
'fid' => '1',
'uid' => '1',
'filename' => 'cube.jpeg',
'uri' => 'private://cube.jpeg',
'filemime' => 'image/jpeg',
'filesize' => '3620',
'status' => '1',
'timestamp' => '1421727515',
],
[
'fid' => '1',
'uid' => '1',
'filename' => 'cube.jpeg',
'uri' => 'temporary://cube.jpeg',
'filemime' => 'image/jpeg',
'filesize' => '3620',
'status' => '1',
'timestamp' => '1421727515',
],
[
'fid' => '1',
'uid' => '1',
'filename' => 'cube.jpeg',
'uri' => 'null://cube.jpeg',
'filemime' => 'image/jpeg',
'filesize' => '3620',
'status' => '1',
'timestamp' => '1421727515',
],
];
$tests[0]['source_data']['variable'] = [
[
'name' => 'file_public_path',
'value' => serialize('sites/default/files'),
],
[
'name' => 'file_private_path',
'value' => serialize('/path/to/private/files'),
],
[
'name' => 'file_temporary_path',
'value' => serialize('/tmp'),
],
];
$tests[0]['expected_data'] = array_slice($tests[0]['source_data']['file_managed'], 0, 2);
$tests[0]['expected_data'][0]['filepath'] = 'sites/default/files/cube.jpeg';
$tests[0]['expected_data'][1]['filepath'] = '/path/to/private/files/cube.jpeg';
$tests[0]['expected_count'] = NULL;
$tests[0]['configuration'] = [
'constants' => [
'source_base_path' => '/path/to/files',
],
'scheme' => [
'public',
'private',
'temporary',
],
];
$tests[1]['source_data'] = $tests[0]['source_data'];
$tests[1]['expected_data'] = [
[
'fid' => '1',
'uid' => '1',
'filename' => 'cube.jpeg',
'uri' => 'public://cube.jpeg',
'filemime' => 'image/jpeg',
'filesize' => '3620',
'status' => '1',
'timestamp' => '1421727515',
'filepath' => 'sites/default/files/cube.jpeg',
],
];
$tests[1]['expected_count'] = NULL;
$tests[1]['configuration'] = [
'constants' => [
'source_base_path' => '/path/to/files',
],
'scheme' => [
'public',
],
];
$tests[2]['source_data'] = $tests[0]['source_data'];
$tests[2]['expected_data'] = [
[
'fid' => '1',
'uid' => '1',
'filename' => 'cube.jpeg',
'uri' => 'public://cube.jpeg',
'filemime' => 'image/jpeg',
'filesize' => '3620',
'status' => '1',
'timestamp' => '1421727515',
'filepath' => 'sites/default/files/cube.jpeg',
],
];
$tests[2]['expected_count'] = NULL;
$tests[2]['configuration'] = [
'constants' => [
'source_base_path' => '/path/to/files',
],
'scheme' => 'public',
];
$tests[3]['source_data'] = $tests[0]['source_data'];
$tests[3]['source_data']['variable'][1] = [
'name' => 'file_private_path',
'value' => serialize('/home/lillian/subdomains/u2/u2-private-files'),
];
$tests[3]['expected_data'] = [
[
'fid' => '1',
'uid' => '1',
'filename' => 'cube.jpeg',
'uri' => 'private://cube.jpeg',
'filemime' => 'image/jpeg',
'filesize' => '3620',
'status' => '1',
'timestamp' => '1421727515',
'filepath' => 'home/lillian/subdomains/u2/u2-private-files/cube.jpeg',
],
];
$tests[3]['expected_count'] = NULL;
$tests[3]['configuration'] = [
'constants' => [
'source_base_path' => '/',
],
'scheme' => 'private',
];
return $tests;
}
}