-
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
/
Copy pathTemporaryFileTest.php
84 lines (62 loc) · 3.12 KB
/
TemporaryFileTest.php
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
83
84
<?php
namespace Maatwebsite\Excel\Tests;
use Maatwebsite\Excel\Files\TemporaryFileFactory;
use Maatwebsite\Excel\Tests\Helpers\FileHelper;
class TemporaryFileTest extends TestCase
{
private $defaultDirectoryPermissions;
private $defaultFilePermissions;
/**
* Setup the test environment.
*/
protected function setUp(): void
{
parent::setUp();
$path = FileHelper::absolutePath('rights-test-permissions', 'local');
mkdir($path);
$this->defaultDirectoryPermissions = substr(sprintf('%o', fileperms($path)), -4);
$filePath = $path . DIRECTORY_SEPARATOR . 'file-permissions';
touch($filePath);
$this->defaultFilePermissions = substr(sprintf('%o', fileperms($filePath)), -4);
@unlink($filePath);
@rmdir($path);
}
public function test_can_use_default_rights()
{
$path = FileHelper::absolutePath('rights-test', 'local');
FileHelper::recursiveDelete($path);
config()->set('excel.temporary_files.local_path', $path);
$temporaryFileFactory = app(TemporaryFileFactory::class);
$temporaryFile = $temporaryFileFactory->makeLocal(null, 'txt');
$temporaryFile->put('data-set');
$this->assertFileExists($temporaryFile->getLocalPath());
$this->assertEquals($this->defaultDirectoryPermissions, substr(sprintf('%o', fileperms(dirname($temporaryFile->getLocalPath()))), -4));
$this->assertEquals($this->defaultFilePermissions, substr(sprintf('%o', fileperms($temporaryFile->getLocalPath())), -4));
}
public function test_can_use_dir_rights()
{
$path = FileHelper::absolutePath('rights-test', 'local');
FileHelper::recursiveDelete($path);
config()->set('excel.temporary_files.local_path', $path);
config()->set('excel.temporary_files.local_permissions.dir', 0700);
$temporaryFileFactory = app(TemporaryFileFactory::class);
$temporaryFile = $temporaryFileFactory->makeLocal(null, 'txt');
$temporaryFile->put('data-set');
$this->assertFileExists($temporaryFile->getLocalPath());
$this->assertEquals('0700', substr(sprintf('%o', fileperms(dirname($temporaryFile->getLocalPath()))), -4));
$this->assertEquals($this->defaultFilePermissions, substr(sprintf('%o', fileperms($temporaryFile->getLocalPath())), -4));
}
public function test_can_use_file_rights()
{
$path = FileHelper::absolutePath('rights-test', 'local');
FileHelper::recursiveDelete($path);
config()->set('excel.temporary_files.local_path', $path);
config()->set('excel.temporary_files.local_permissions.file', 0600);
$temporaryFileFactory = app(TemporaryFileFactory::class);
$temporaryFile = $temporaryFileFactory->makeLocal(null, 'txt');
$temporaryFile->put('data-set');
$this->assertFileExists($temporaryFile->getLocalPath());
$this->assertEquals($this->defaultDirectoryPermissions, substr(sprintf('%o', fileperms(dirname($temporaryFile->getLocalPath()))), -4));
$this->assertEquals('0600', substr(sprintf('%o', fileperms($temporaryFile->getLocalPath())), -4));
}
}