-
-
Notifications
You must be signed in to change notification settings - Fork 5.3k
Expand file tree
/
Copy pathFileInfoTest.php
More file actions
84 lines (71 loc) · 2.23 KB
/
Copy pathFileInfoTest.php
File metadata and controls
84 lines (71 loc) · 2.23 KB
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
/**
* SPDX-FileCopyrightText: 2016 Nextcloud GmbH and Nextcloud contributors
* SPDX-License-Identifier: AGPL-3.0-or-later
*/
namespace Test\Files;
use OC\Files\FileInfo;
use OC\Files\Mount\HomeMountPoint;
use OC\Files\Mount\MountPoint;
use OC\Files\Storage\Home;
use OC\Files\Storage\Temporary;
use OCP\IConfig;
use OCP\IUser;
use Test\TestCase;
use Test\Traits\UserTrait;
class FileInfoTest extends TestCase {
use UserTrait;
private $config;
protected function setUp(): void {
parent::setUp();
$this->createUser('foo', 'foo');
$this->config = $this->getMockBuilder(IConfig::class)->getMock();
}
private function makeFileInfo(array $data): FileInfo {
$storage = new Temporary();
return new FileInfo('', $storage, '', $data, new MountPoint($storage, '/foo/files'));
}
public function testGetSizeEncryptedZeroByte(): void {
$info = $this->makeFileInfo(['encrypted' => true, 'size' => 8192, 'unencrypted_size' => 0]);
// Both paths must report the true plaintext size (0), not the on-disk encrypted size (8192)
$this->assertSame(0, $info->getSize(true));
$this->assertSame(0, $info->getSize(false));
}
public function testGetSizeEncryptedNonZero(): void {
$info = $this->makeFileInfo(['encrypted' => true, 'size' => 16384, 'unencrypted_size' => 5000]);
$this->assertSame(5000, $info->getSize(true));
$this->assertSame(5000, $info->getSize(false));
}
public function testGetSizeNonEncrypted(): void {
$info = $this->makeFileInfo(['encrypted' => false, 'size' => 100]);
$this->assertSame(100, $info->getSize(true));
$this->assertSame(100, $info->getSize(false));
}
public function testIsMountedHomeStorage(): void {
$user = $this->createMock(IUser::class);
$user->method('getUID')
->willReturn('foo');
$user->method('getHome')
->willReturn('foo');
$storage = new Home(['user' => $user]);
$fileInfo = new FileInfo(
'',
$storage,
'',
[],
new HomeMountPoint($user, $storage, '/foo/files')
);
$this->assertFalse($fileInfo->isMounted());
}
public function testIsMountedNonHomeStorage(): void {
$storage = new Temporary();
$fileInfo = new FileInfo(
'',
$storage,
'',
[],
new MountPoint($storage, '/foo/files/bar')
);
$this->assertTrue($fileInfo->isMounted());
}
}