|
| 1 | +<?php |
| 2 | +/** |
| 3 | + * Copyright © Magento, Inc. All rights reserved. |
| 4 | + * See COPYING.txt for license details. |
| 5 | + */ |
| 6 | +namespace Magento\Setup\Model; |
| 7 | + |
| 8 | +use Magento\Framework\Setup\FilePermissions; |
| 9 | +use Magento\Framework\Filesystem; |
| 10 | +use Magento\TestFramework\Helper\Bootstrap; |
| 11 | +use Magento\Framework\App\Filesystem\DirectoryList; |
| 12 | +use Magento\Framework\App\State; |
| 13 | +use Magento\Framework\Filesystem\Directory\WriteInterface; |
| 14 | + |
| 15 | +/** |
| 16 | + * @magentoAppIsolation enabled |
| 17 | + */ |
| 18 | +class FilePermissionsTest extends \PHPUnit_Framework_TestCase |
| 19 | +{ |
| 20 | + /** |
| 21 | + * @var FilePermissions |
| 22 | + */ |
| 23 | + private $filePermissions; |
| 24 | + |
| 25 | + /** |
| 26 | + * @var WriteInterface |
| 27 | + */ |
| 28 | + private $varDirectoryWriter; |
| 29 | + |
| 30 | + /** |
| 31 | + * @var string |
| 32 | + */ |
| 33 | + private $testDir = 'test'; |
| 34 | + |
| 35 | + /** |
| 36 | + * @inheritdoc |
| 37 | + */ |
| 38 | + protected function setUp() |
| 39 | + { |
| 40 | + $objectManager = Bootstrap::getObjectManager(); |
| 41 | + /** @var Filesystem $filesystem */ |
| 42 | + $filesystem = $objectManager->get(Filesystem::class); |
| 43 | + $this->varDirectoryWriter = $filesystem->getDirectoryWrite(DirectoryList::VAR_DIR); |
| 44 | + |
| 45 | + $this->filePermissions = $objectManager->create(FilePermissions::class, [ |
| 46 | + 'filesystem' => $filesystem, |
| 47 | + 'directoryList' => $objectManager->get(DirectoryList::class), |
| 48 | + 'state' => $objectManager->get(State::class), |
| 49 | + ]); |
| 50 | + } |
| 51 | + |
| 52 | + /** |
| 53 | + * Checks the depth of recursive check permissions |
| 54 | + */ |
| 55 | + public function testDeepOfRecursiveCheckPermissions() |
| 56 | + { |
| 57 | + $dirs = [ |
| 58 | + 'dir1', |
| 59 | + 'dir2/dir21', |
| 60 | + 'dir2/dir22/dir221', |
| 61 | + 'dir3/dir31/dir311/dir3111', |
| 62 | + ]; |
| 63 | + foreach ($dirs as $dir) { |
| 64 | + $pathToReadOnlyDir = $this->testDir . '/' . $dir; |
| 65 | + $this->varDirectoryWriter->create($pathToReadOnlyDir); |
| 66 | + $this->varDirectoryWriter->changePermissionsRecursively($pathToReadOnlyDir, 0555, 0444); |
| 67 | + } |
| 68 | + $missingWritablePathsForInstallation = $this->filePermissions->getMissingWritablePathsForInstallation(); |
| 69 | + $this->assertCount(1, $missingWritablePathsForInstallation); |
| 70 | + $this->assertEquals('dir1', basename($missingWritablePathsForInstallation[0])); |
| 71 | + } |
| 72 | + |
| 73 | + /** |
| 74 | + * @inheritdoc |
| 75 | + */ |
| 76 | + protected function tearDown() |
| 77 | + { |
| 78 | + if ($this->varDirectoryWriter->isExist($this->testDir)) { |
| 79 | + $this->varDirectoryWriter->delete($this->testDir); |
| 80 | + } |
| 81 | + } |
| 82 | +} |
0 commit comments