|
9 | 9 |
|
10 | 10 | use Magento\Customer\Model\FileProcessor;
|
11 | 11 | use Magento\Framework\App\Filesystem\DirectoryList;
|
| 12 | +use Magento\Framework\Filesystem\Driver\File; |
12 | 13 |
|
13 | 14 | /**
|
14 | 15 | * Test for \Magento\MediaStorage\Model\File\Uploader
|
@@ -89,6 +90,41 @@ public function testUploadFileWithExcessiveFolderName(): void
|
89 | 90 | $uploader->save($longDirectoryFolderName);
|
90 | 91 | }
|
91 | 92 |
|
| 93 | + /** |
| 94 | + * Upload file test to 'var' directory |
| 95 | + * |
| 96 | + * @magentoConfigFixture system/media_gallery/enabled 1 |
| 97 | + * @magentoAppArea adminhtml |
| 98 | + * |
| 99 | + * @return void |
| 100 | + */ |
| 101 | + public function testUploadFileToVar(): void |
| 102 | + { |
| 103 | + $destinationDirectory = $this->filesystem->getDirectoryWrite(DirectoryList::VAR_DIR); |
| 104 | + $tmpDirectory = $this->filesystem->getDirectoryWrite(DirectoryList::SYS_TMP); |
| 105 | + |
| 106 | + $fileName = 'file.txt'; |
| 107 | + $destinationDir = 'tmp'; |
| 108 | + $filePath = $tmpDirectory->getAbsolutePath($fileName); |
| 109 | + |
| 110 | + $tmpDirectory->writeFile($fileName, 'some data'); |
| 111 | + |
| 112 | + $type = [ |
| 113 | + 'tmp_name' => $filePath, |
| 114 | + 'name' => $fileName, |
| 115 | + ]; |
| 116 | + |
| 117 | + $uploader = $this->uploaderFactory->create(['fileId' => $type]); |
| 118 | + $uploader->save($destinationDirectory->getAbsolutePath($destinationDir)); |
| 119 | + |
| 120 | + // Uploader doesn't save file to local var if remote storage is configured |
| 121 | + if ($this->filesystem->getDirectoryWrite(DirectoryList::MEDIA)->getDriver() instanceof File) { |
| 122 | + $this->assertTrue($destinationDirectory->isFile($destinationDir . DIRECTORY_SEPARATOR . $fileName)); |
| 123 | + } else { |
| 124 | + $this->assertFalse($destinationDirectory->isFile($destinationDir . DIRECTORY_SEPARATOR . $fileName)); |
| 125 | + } |
| 126 | + } |
| 127 | + |
92 | 128 | /**
|
93 | 129 | * Upload file test when `Old Media Gallery` is disabled
|
94 | 130 | *
|
@@ -130,7 +166,7 @@ public function dirCodeDataProvider(): array
|
130 | 166 | {
|
131 | 167 | return [
|
132 | 168 | 'media destination' => [DirectoryList::MEDIA],
|
133 |
| - 'non-media destination' => [DirectoryList::VAR_DIR], |
| 169 | + 'non-media destination' => [DirectoryList::VAR_IMPORT_EXPORT], |
134 | 170 | ];
|
135 | 171 | }
|
136 | 172 |
|
|
0 commit comments