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