Version 1
[yaffs-website] / web / core / modules / file / tests / src / Unit / Plugin / migrate / process / d6 / FileUriTest.php
1 <?php
2
3 namespace Drupal\Tests\file\Unit\Plugin\migrate\process\d6;
4
5 use Drupal\file\Plugin\migrate\process\d6\FileUri;
6 use Drupal\migrate\MigrateExecutable;
7 use Drupal\migrate\MigrateMessage;
8 use Drupal\migrate\Row;
9 use Drupal\Tests\migrate\Unit\MigrateTestCase;
10
11 /**
12  * @coversDefaultClass \Drupal\file\Plugin\migrate\process\d6\FileUri
13  * @group file
14  */
15 class FileUriTest extends MigrateTestCase {
16
17   protected $migrationConfiguration = [
18     'id' => 'test',
19   ];
20
21   public function testPublic() {
22     $value = [
23       'sites/default/files/foo.jpg',
24       'sites/default/files',
25       '/tmp',
26       TRUE,
27     ];
28     $this->assertEquals('public://foo.jpg', $this->doTransform($value));
29   }
30
31   public function testPublicUnknownBasePath() {
32     $value = [
33       '/path/to/public/files/foo.jpg',
34       'sites/default/files',
35       '/tmp',
36       TRUE,
37     ];
38     $this->assertEquals('public://path/to/public/files/foo.jpg', $this->doTransform($value));
39   }
40
41   public function testPrivate() {
42     $value = [
43       'sites/default/files/baz.gif',
44       'sites/default/files',
45       '/tmp',
46       FALSE,
47     ];
48     $this->assertEquals('private://baz.gif', $this->doTransform($value));
49   }
50
51   public function testPrivateUnknownBasePath() {
52     $value = [
53       '/path/to/private/files/baz.gif',
54       'sites/default/files',
55       '/tmp',
56       FALSE,
57     ];
58     $this->assertEquals('private://path/to/private/files/baz.gif', $this->doTransform($value));
59   }
60
61   public function testTemporary() {
62     $value = [
63       '/tmp/bar.png',
64       'sites/default/files',
65       '/tmp',
66       TRUE,
67     ];
68     $this->assertEquals('temporary://bar.png', $this->doTransform($value));
69   }
70
71   protected function doTransform(array $value) {
72     $executable = new MigrateExecutable($this->getMigration(), new MigrateMessage());
73     $row = new Row();
74
75     return (new FileUri([], 'file_uri', []))
76       ->transform($value, $executable, $row, 'foobaz');
77   }
78
79 }