public function MediaMigrationDatabaseTraitTest::providerTest in Media Migration 8
Data provider for the tests.
File
- tests/
src/ Kernel/ Plugin/ migrate/ source/ d7/ MediaMigrationDatabaseTraitTest.php, line 71
Class
- MediaMigrationDatabaseTraitTest
- @coversDefaultClass \Drupal\media_migration\Plugin\migrate\source\d7\MediaMigrationDatabaseTrait
Namespace
Drupal\Tests\media_migration\Kernel\Plugin\migrate\source\d7Code
public function providerTest() {
$blue_png = [
'fid' => 1,
'filename' => 'blue.png',
'scheme' => 'public',
'mime' => 'image',
];
$blue_png_fe = [
'fid' => 1,
'filename' => 'blue.png',
'scheme' => 'public',
'type' => 'image',
];
$green_jpg = [
'fid' => 2,
'filename' => 'green.jpg',
'scheme' => 'public',
'mime' => 'image',
];
$green_jpg_fe = [
'fid' => 2,
'filename' => 'green.jpg',
'scheme' => 'public',
'type' => 'image',
];
$licence_txt = [
'fid' => 3,
'filename' => 'LICENSE.txt',
'scheme' => 'public',
'mime' => 'text',
];
$licence_txt_fe = [
'fid' => 3,
'filename' => 'LICENSE.txt',
'scheme' => 'public',
'type' => 'document',
];
$test_cases = [
'No webform or user file usage' => [
'DB records' => [
'file_usage' => [
[
'fid' => 1,
'module' => 'file',
'type' => 'node',
'id' => 1,
'count' => 1,
],
[
'fid' => 2,
'module' => 'file',
'type' => 'node',
'id' => 2,
'count' => 1,
],
[
'fid' => 3,
'module' => 'file',
'type' => 'node',
'id' => 3,
'count' => 1,
],
],
],
'Expected results' => [
'Plain file' => [
$blue_png,
$green_jpg,
$licence_txt,
],
'File entity' => [
$blue_png_fe,
$green_jpg_fe,
$licence_txt_fe,
],
],
],
'Single user image usage with count 1, no webform submission file usage' => [
'DB records' => [
'users' => [
[
'uid' => 1,
'name' => 'admin',
'pass' => 'pass',
'status' => 1,
'picture' => 1,
],
],
'file_usage' => [
[
'fid' => 1,
'module' => 'file',
'type' => 'user',
'id' => 1,
'count' => 1,
],
[
'fid' => 2,
'module' => 'file',
'type' => 'submission',
'id' => 2314,
'count' => 1,
],
[
'fid' => 2,
'module' => 'webform',
'type' => 'not_a_submission',
'id' => 34,
'count' => 1,
],
],
],
'Expected results' => [
'Plain file' => [
$green_jpg,
$licence_txt,
],
'File entity' => [
$green_jpg_fe,
$licence_txt_fe,
],
],
],
'Two webform submission file usage with count 1, no user pictures' => [
'DB records' => [
'file_usage' => [
[
'fid' => 1,
'module' => 'webform',
'type' => 'submission',
'id' => 1,
'count' => 1,
],
[
'fid' => 2,
'module' => 'file',
'type' => 'submission',
'id' => 2314,
'count' => 1,
],
[
'fid' => 3,
'module' => 'webform',
'type' => 'not_a_submission',
'id' => 34,
'count' => 1,
],
],
],
'Expected results' => [
'Plain file' => [
$licence_txt,
],
'File entity' => [
$licence_txt_fe,
],
],
],
'A user file is used somewhere else as well' => [
'DB records' => [
'users' => [
[
'uid' => 1,
'name' => 'admin',
'pass' => 'pass',
'status' => 1,
'picture' => 1,
],
],
'file_usage' => [
[
'fid' => 1,
'module' => 'file',
'type' => 'node',
'id' => 1,
'count' => 1,
],
[
'fid' => 1,
'module' => 'file',
'type' => 'user',
'id' => 1,
'count' => 1,
],
],
],
'Expected results' => [
'Plain file' => [
$blue_png,
$green_jpg,
$licence_txt,
],
'File entity' => [
$blue_png_fe,
$green_jpg_fe,
$licence_txt_fe,
],
],
],
'A webform submission file is used somewhere' => [
'DB records' => [
'file_usage' => [
[
'fid' => 3,
'module' => 'webform',
'type' => 'submission',
'id' => 1,
'count' => 1,
],
[
'fid' => 3,
'module' => 'file',
'type' => 'node',
'id' => 1,
'count' => 1,
],
],
],
'Expected results' => [
'Plain file' => [
$blue_png,
$green_jpg,
$licence_txt,
],
'File entity' => [
$blue_png_fe,
$green_jpg_fe,
$licence_txt_fe,
],
],
],
'A webform submission file is used as user picture' => [
'DB records' => [
'users' => [
[
'uid' => 1,
'name' => 'admin',
'pass' => 'pass',
'status' => 1,
'picture' => 1,
],
],
'file_usage' => [
[
'fid' => 1,
'module' => 'webform',
'type' => 'submission',
'id' => 1,
'count' => 1,
],
[
'fid' => 1,
'module' => 'file',
'type' => 'user',
'id' => 1,
'count' => 2,
],
],
],
'Expected results' => [
'Plain file' => [
$green_jpg,
$licence_txt,
],
'File entity' => [
$green_jpg_fe,
$licence_txt_fe,
],
],
],
'A webform submission file is used as user picture AND somewhere else' => [
'DB records' => [
'users' => [
[
'uid' => 1,
'name' => 'admin',
'pass' => 'pass',
'status' => 1,
'picture' => 1,
],
],
'file_usage' => [
[
'fid' => 1,
'module' => 'webform',
'type' => 'submission',
'id' => 1,
'count' => 1,
],
[
'fid' => 1,
'module' => 'file',
'type' => 'user',
'id' => 1,
'count' => 1,
],
[
'fid' => 1,
'module' => 'file',
'type' => 'node',
'id' => 1,
'count' => 1,
],
],
],
'Expected results' => [
'Plain file' => [
$blue_png,
$green_jpg,
$licence_txt,
],
'File entity' => [
$blue_png_fe,
$green_jpg_fe,
$licence_txt_fe,
],
],
],
];
return $test_cases;
}