8ae0ec41fa16257c0c684b4aa43f217199304309
[yaffs-website] / web / core / modules / file / tests / src / Kernel / Plugin / migrate / source / d7 / FileTest.php
1 <?php
2
3 namespace Drupal\Tests\file\Kernel\Plugin\migrate\source\d7;
4
5 use Drupal\Tests\migrate\Kernel\MigrateSqlSourceTestBase;
6
7 /**
8  * Tests D7 file source plugin.
9  *
10  * @covers \Drupal\file\Plugin\migrate\source\d7\File
11  * @group file
12  */
13 class FileTest extends MigrateSqlSourceTestBase {
14
15   /**
16    * {@inheritdoc}
17    */
18   public static $modules = ['file', 'migrate_drupal'];
19
20   /**
21    * {@inheritdoc}
22    */
23   public function providerSource() {
24     $tests = [];
25
26     $tests[0]['source_data']['file_managed'] = [
27       // A public file.
28       [
29         'fid' => '1',
30         'uid' => '1',
31         'filename' => 'cube.jpeg',
32         'uri' => 'public://cube.jpeg',
33         'filemime' => 'image/jpeg',
34         'filesize' => '3620',
35         'status' => '1',
36         'timestamp' => '1421727515',
37       ],
38       // A private file.
39       [
40         'fid' => '1',
41         'uid' => '1',
42         'filename' => 'cube.jpeg',
43         'uri' => 'private://cube.jpeg',
44         'filemime' => 'image/jpeg',
45         'filesize' => '3620',
46         'status' => '1',
47         'timestamp' => '1421727515',
48       ],
49       // A temporary file.
50       [
51         'fid' => '1',
52         'uid' => '1',
53         'filename' => 'cube.jpeg',
54         'uri' => 'temporary://cube.jpeg',
55         'filemime' => 'image/jpeg',
56         'filesize' => '3620',
57         'status' => '1',
58         'timestamp' => '1421727515',
59       ],
60       // A file with a URI scheme that will be filtered out.
61       [
62         'fid' => '1',
63         'uid' => '1',
64         'filename' => 'cube.jpeg',
65         'uri' => 'null://cube.jpeg',
66         'filemime' => 'image/jpeg',
67         'filesize' => '3620',
68         'status' => '1',
69         'timestamp' => '1421727515',
70       ],
71     ];
72     $tests[0]['source_data']['variable'] = [
73       [
74         'name' => 'file_public_path',
75         'value' => serialize('sites/default/files'),
76       ],
77       [
78         'name' => 'file_private_path',
79         'value' => serialize('/path/to/private/files'),
80       ],
81       [
82         'name' => 'file_temporary_path',
83         'value' => serialize('/tmp'),
84       ],
85     ];
86
87     // The expected results will include only the first three files, since we
88     // are configuring the plugin to filter out the file with the null URI
89     // scheme.
90     $tests[0]['expected_data'] = array_slice($tests[0]['source_data']['file_managed'], 0, 3);
91
92     // The filepath property will vary by URI scheme.
93     $tests[0]['expected_data'][0]['filepath'] = 'sites/default/files/cube.jpeg';
94     $tests[0]['expected_data'][1]['filepath'] = '/path/to/private/files/cube.jpeg';
95     $tests[0]['expected_data'][2]['filepath'] = '/tmp/cube.jpeg';
96
97     // Do an automatic count.
98     $tests[0]['expected_count'] = NULL;
99
100     // Set up plugin configuration.
101     $tests[0]['configuration'] = [
102       'constants' => [
103         'source_base_path' => '/path/to/files',
104       ],
105       // Only return files which use one of these URI schemes.
106       'scheme' => ['public', 'private', 'temporary'],
107     ];
108
109     return $tests;
110   }
111
112 }