|
| 1 | +<?php |
| 2 | +/** |
| 3 | + * Copyright © Magento, Inc. All rights reserved. |
| 4 | + * See COPYING.txt for license details. |
| 5 | + */ |
| 6 | +declare(strict_types=1); |
| 7 | + |
| 8 | +namespace Magento\ImportExport\Controller\Adminhtml\Export\File; |
| 9 | + |
| 10 | +use Magento\Framework\App\Filesystem\DirectoryList; |
| 11 | + |
| 12 | +/** |
| 13 | + * Test for \Magento\ImportExport\Controller\Adminhtml\Export\File\Delete class. |
| 14 | + */ |
| 15 | +class DeleteTest extends \PHPUnit\Framework\TestCase |
| 16 | +{ |
| 17 | + /** |
| 18 | + * @var \Magento\ImportExport\Controller\Adminhtml\Export\File\Delete |
| 19 | + */ |
| 20 | + private $model; |
| 21 | + |
| 22 | + /** |
| 23 | + * @var \Magento\Framework\Filesystem\Directory\WriteInterface |
| 24 | + */ |
| 25 | + private $varDirectory; |
| 26 | + |
| 27 | + /** |
| 28 | + * @var string |
| 29 | + */ |
| 30 | + private $fullDirectoryPath; |
| 31 | + |
| 32 | + /** |
| 33 | + * @var string |
| 34 | + */ |
| 35 | + private $fileName = 'catalog_product.csv'; |
| 36 | + |
| 37 | + /** |
| 38 | + * @var \Magento\Framework\Filesystem |
| 39 | + */ |
| 40 | + private $filesystem; |
| 41 | + |
| 42 | + /** |
| 43 | + * @var \Magento\Framework\ObjectManagerInterface |
| 44 | + */ |
| 45 | + private $objectManager; |
| 46 | + |
| 47 | + /** |
| 48 | + * @inheritdoc |
| 49 | + */ |
| 50 | + protected function setUp() |
| 51 | + { |
| 52 | + $this->objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager(); |
| 53 | + $this->filesystem = $this->objectManager->get(\Magento\Framework\Filesystem::class); |
| 54 | + $this->varDirectory = $this->filesystem->getDirectoryWrite(DirectoryList::VAR_DIR); |
| 55 | + $this->varDirectory->create($this->varDirectory->getRelativePath('export')); |
| 56 | + $this->fullDirectoryPath = $this->varDirectory->getAbsolutePath('export'); |
| 57 | + $filePath = $this->fullDirectoryPath . DIRECTORY_SEPARATOR . $this->fileName; |
| 58 | + $fixtureDir = realpath(__DIR__ . '/../../Import/_files'); |
| 59 | + copy($fixtureDir . '/' . $this->fileName, $filePath); |
| 60 | + $this->model = $this->objectManager->get(\Magento\ImportExport\Controller\Adminhtml\Export\File\Delete::class); |
| 61 | + } |
| 62 | + |
| 63 | + /** |
| 64 | + * Check that file can be removed under var/export directory. |
| 65 | + * |
| 66 | + * @return void |
| 67 | + */ |
| 68 | + public function testExecute() |
| 69 | + { |
| 70 | + $this->model->getRequest()->setMethod('GET')->setParams(['filename' => 'catalog_product.csv']); |
| 71 | + $this->model->execute(); |
| 72 | + |
| 73 | + $this->assertFalse( |
| 74 | + $this->varDirectory->isExist( |
| 75 | + $this->varDirectory->getRelativePath( 'export/' . $this->fileName) |
| 76 | + ) |
| 77 | + ); |
| 78 | + } |
| 79 | + |
| 80 | + /** |
| 81 | + * @inheritdoc |
| 82 | + */ |
| 83 | + public static function tearDownAfterClass() |
| 84 | + { |
| 85 | + $filesystem = \Magento\TestFramework\Helper\Bootstrap::getObjectManager() |
| 86 | + ->get(\Magento\Framework\Filesystem::class); |
| 87 | + /** @var \Magento\Framework\Filesystem\Directory\WriteInterface $directory */ |
| 88 | + $directory = $filesystem->getDirectoryWrite(DirectoryList::VAR_DIR); |
| 89 | + if ($directory->isExist('export')) { |
| 90 | + $directory->delete('export'); |
| 91 | + } |
| 92 | + } |
| 93 | +} |
0 commit comments