@@ -24,9 +24,9 @@ class DirectoryResolverTest extends \PHPUnit\Framework\TestCase
24
24
private $ directoryResolver ;
25
25
26
26
/**
27
- * @var \Magento\Framework\Filesystem\Directory\WriteInterface
27
+ * @var \Magento\Framework\Filesystem
28
28
*/
29
- private $ directory ;
29
+ private $ filesystem ;
30
30
31
31
/**
32
32
* @inheritdoc
@@ -36,22 +36,23 @@ protected function setUp()
36
36
$ this ->objectManager = Bootstrap::getObjectManager ();
37
37
$ this ->directoryResolver = $ this ->objectManager
38
38
->create (\Magento \Framework \App \Filesystem \DirectoryResolver::class);
39
- /** @var \Magento\Framework\Filesystem $filesystem */
40
- $ filesystem = $ this ->objectManager ->create (\Magento \Framework \Filesystem::class);
41
- $ this ->directory = $ filesystem ->getDirectoryWrite (\Magento \Framework \App \Filesystem \DirectoryList::MEDIA );
39
+ $ this ->filesystem = $ this ->objectManager ->create (\Magento \Framework \Filesystem::class);
42
40
}
43
41
44
42
/**
45
43
* @param string $path
46
44
* @param string $directoryConfig
47
45
* @param bool $expectation
48
46
* @dataProvider validatePathDataProvider
47
+ * @throws \Magento\Framework\Exception\FileSystemException
49
48
* @magentoAppIsolation enabled
50
49
* @return void
51
50
*/
52
51
public function testValidatePath ($ path , $ directoryConfig , $ expectation )
53
52
{
54
- $ path = $ this ->directory ->getAbsolutePath ($ path );
53
+ $ directory = $ this ->filesystem
54
+ ->getDirectoryWrite (\Magento \Framework \App \Filesystem \DirectoryList::MEDIA );
55
+ $ path = $ directory ->getAbsolutePath ($ path );
55
56
$ this ->assertEquals ($ expectation , $ this ->directoryResolver ->validatePath ($ path , $ directoryConfig ));
56
57
}
57
58
@@ -62,10 +63,45 @@ public function testValidatePath($path, $directoryConfig, $expectation)
62
63
*/
63
64
public function testValidatePathWithException ()
64
65
{
65
- $ path = $ this ->directory ->getAbsolutePath ();
66
+ $ directory = $ this ->filesystem
67
+ ->getDirectoryWrite (\Magento \Framework \App \Filesystem \DirectoryList::MEDIA );
68
+ $ path = $ directory ->getAbsolutePath ();
66
69
$ this ->directoryResolver ->validatePath ($ path , 'wrong_dir ' );
67
70
}
68
71
72
+ /**
73
+ * @param string $path
74
+ * @param string $directoryConfig
75
+ * @param bool $expectation
76
+ * @dataProvider validatePathDataProvider
77
+ * @throws \Magento\Framework\Exception\FileSystemException
78
+ * @magentoAppIsolation enabled
79
+ * @return void
80
+ */
81
+ public function testValidatePathWithSymlink ($ path , $ directoryConfig , $ expectation )
82
+ {
83
+ $ directory = $ this ->filesystem
84
+ ->getDirectoryWrite (\Magento \Framework \App \Filesystem \DirectoryList::PUB );
85
+ $ driver = $ directory ->getDriver ();
86
+
87
+ $ mediaPath = $ directory ->getAbsolutePath ('media ' );
88
+ $ mediaMovedPath = $ directory ->getAbsolutePath ('moved-media ' );
89
+
90
+ try {
91
+ $ driver ->rename ($ mediaPath , $ mediaMovedPath );
92
+ $ driver ->symlink ($ mediaMovedPath , $ mediaPath );
93
+ $ this ->testValidatePath ($ path , $ directoryConfig , $ expectation );
94
+ } finally {
95
+ // be defensive in case some operations failed
96
+ if ($ driver ->isExists ($ mediaPath ) && $ driver ->isExists ($ mediaMovedPath )) {
97
+ $ driver ->deleteFile ($ mediaPath );
98
+ $ driver ->rename ($ mediaMovedPath , $ mediaPath );
99
+ } elseif ($ driver ->isExists ($ mediaMovedPath )) {
100
+ $ driver ->rename ($ mediaMovedPath , $ mediaPath );
101
+ }
102
+ }
103
+ }
104
+
69
105
/**
70
106
* @return array
71
107
*/
0 commit comments