Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
NewFolderTest.php
Go to the documentation of this file.
1 <?php
8 
10 
14 class NewFolderTest extends \PHPUnit\Framework\TestCase
15 {
19  private $model;
20 
24  private $mediaDirectory;
25 
29  private $fullDirectoryPath;
30 
34  private $dirName= 'NewDirectory';
35 
39  private $filesystem;
40 
44  private $imagesHelper;
45 
49  protected function setUp()
50  {
52  $this->filesystem = $objectManager->get(\Magento\Framework\Filesystem::class);
54  $this->imagesHelper = $objectManager->get(\Magento\Cms\Helper\Wysiwyg\Images::class);
55  $this->mediaDirectory = $this->filesystem->getDirectoryWrite(DirectoryList::MEDIA);
56  $this->fullDirectoryPath = $this->imagesHelper->getStorageRoot();
57  $this->model = $objectManager->get(\Magento\Cms\Controller\Adminhtml\Wysiwyg\Images\NewFolder::class);
58  }
59 
65  public function testExecute()
66  {
67  $this->model->getRequest()->setMethod('POST')
68  ->setPostValue('name', $this->dirName);
69  $this->model->getStorage()->getSession()->setCurrentPath($this->fullDirectoryPath);
70  $this->model->execute();
71 
72  $this->assertTrue(
73  $this->mediaDirectory->isExist(
74  $this->mediaDirectory->getRelativePath(
75  $this->fullDirectoryPath . DIRECTORY_SEPARATOR . $this->dirName
76  )
77  )
78  );
79  }
80 
86  public function testExecuteWithLinkedMedia()
87  {
88  $linkedDirectoryPath = $this->filesystem->getDirectoryRead(DirectoryList::PUB)
89  ->getAbsolutePath() . 'linked_media';
90  $this->model->getRequest()->setMethod('POST')
91  ->setPostValue('name', $this->dirName);
92  $this->model->getStorage()
93  ->getSession()
94  ->setCurrentPath($this->fullDirectoryPath . DIRECTORY_SEPARATOR . 'wysiwyg');
95  $this->model->execute();
96 
97  $this->assertTrue(is_dir($linkedDirectoryPath . DIRECTORY_SEPARATOR . $this->dirName));
98  }
99 
106  public function testExecuteWithWrongPath()
107  {
108  $dirPath = '/../../../';
109  $this->model->getRequest()->setMethod('POST')
110  ->setPostValue('name', $this->dirName);
111  $this->model->getStorage()->getSession()->setCurrentPath($this->fullDirectoryPath . $dirPath);
112  $this->model->execute();
113 
114  $this->assertFileNotExists(
115  $this->fullDirectoryPath . $dirPath . $this->dirName
116  );
117  }
118 
122  public static function tearDownAfterClass()
123  {
125  ->get(\Magento\Framework\Filesystem::class);
127  $directory = $filesystem->getDirectoryWrite(DirectoryList::MEDIA);
128  if ($directory->isExist('wysiwyg')) {
129  $directory->delete('wysiwyg');
130  }
131  }
132 }
$objectManager
Definition: bootstrap.php:17