@@ -10,98 +10,98 @@ |
||
10 | 10 | use OCA\Files_External\Lib\StorageConfig; |
11 | 11 | |
12 | 12 | class FrontendDefinitionTraitTest extends \Test\TestCase { |
13 | - public function testJsonSerialization(): void { |
|
14 | - $param = $this->getMockBuilder(DefinitionParameter::class) |
|
15 | - ->disableOriginalConstructor() |
|
16 | - ->getMock(); |
|
17 | - $param->method('getName')->willReturn('foo'); |
|
13 | + public function testJsonSerialization(): void { |
|
14 | + $param = $this->getMockBuilder(DefinitionParameter::class) |
|
15 | + ->disableOriginalConstructor() |
|
16 | + ->getMock(); |
|
17 | + $param->method('getName')->willReturn('foo'); |
|
18 | 18 | |
19 | - $trait = $this->getMockForTrait(\OCA\Files_External\Lib\FrontendDefinitionTrait::class); |
|
20 | - $trait->setText('test'); |
|
21 | - $trait->addParameters([$param]); |
|
22 | - $trait->addCustomJs('foo/bar.js'); |
|
23 | - $trait->addCustomJs('bar/foo.js'); |
|
19 | + $trait = $this->getMockForTrait(\OCA\Files_External\Lib\FrontendDefinitionTrait::class); |
|
20 | + $trait->setText('test'); |
|
21 | + $trait->addParameters([$param]); |
|
22 | + $trait->addCustomJs('foo/bar.js'); |
|
23 | + $trait->addCustomJs('bar/foo.js'); |
|
24 | 24 | |
25 | - $json = $trait->jsonSerializeDefinition(); |
|
25 | + $json = $trait->jsonSerializeDefinition(); |
|
26 | 26 | |
27 | - $this->assertEquals('test', $json['name']); |
|
28 | - $this->assertContains('foo/bar.js', $json['custom']); |
|
29 | - $this->assertContains('bar/foo.js', $json['custom']); |
|
27 | + $this->assertEquals('test', $json['name']); |
|
28 | + $this->assertContains('foo/bar.js', $json['custom']); |
|
29 | + $this->assertContains('bar/foo.js', $json['custom']); |
|
30 | 30 | |
31 | - $configuration = $json['configuration']; |
|
32 | - $this->assertArrayHasKey('foo', $configuration); |
|
33 | - } |
|
31 | + $configuration = $json['configuration']; |
|
32 | + $this->assertArrayHasKey('foo', $configuration); |
|
33 | + } |
|
34 | 34 | |
35 | - public static function validateStorageProvider(): array { |
|
36 | - return [ |
|
37 | - [true, ['foo' => true, 'bar' => true, 'baz' => true]], |
|
38 | - [false, ['foo' => true, 'bar' => false]] |
|
39 | - ]; |
|
40 | - } |
|
35 | + public static function validateStorageProvider(): array { |
|
36 | + return [ |
|
37 | + [true, ['foo' => true, 'bar' => true, 'baz' => true]], |
|
38 | + [false, ['foo' => true, 'bar' => false]] |
|
39 | + ]; |
|
40 | + } |
|
41 | 41 | |
42 | - /** |
|
43 | - * @dataProvider validateStorageProvider |
|
44 | - */ |
|
45 | - public function testValidateStorage(bool $expectedSuccess, array $params): void { |
|
46 | - $backendParams = []; |
|
47 | - foreach ($params as $name => $valid) { |
|
48 | - $param = $this->getMockBuilder(DefinitionParameter::class) |
|
49 | - ->disableOriginalConstructor() |
|
50 | - ->getMock(); |
|
51 | - $param->method('getName') |
|
52 | - ->willReturn($name); |
|
53 | - $param->method('isOptional') |
|
54 | - ->willReturn(false); |
|
55 | - $param->expects($this->once()) |
|
56 | - ->method('validateValue') |
|
57 | - ->willReturn($valid); |
|
58 | - $backendParams[] = $param; |
|
59 | - } |
|
42 | + /** |
|
43 | + * @dataProvider validateStorageProvider |
|
44 | + */ |
|
45 | + public function testValidateStorage(bool $expectedSuccess, array $params): void { |
|
46 | + $backendParams = []; |
|
47 | + foreach ($params as $name => $valid) { |
|
48 | + $param = $this->getMockBuilder(DefinitionParameter::class) |
|
49 | + ->disableOriginalConstructor() |
|
50 | + ->getMock(); |
|
51 | + $param->method('getName') |
|
52 | + ->willReturn($name); |
|
53 | + $param->method('isOptional') |
|
54 | + ->willReturn(false); |
|
55 | + $param->expects($this->once()) |
|
56 | + ->method('validateValue') |
|
57 | + ->willReturn($valid); |
|
58 | + $backendParams[] = $param; |
|
59 | + } |
|
60 | 60 | |
61 | - $storageConfig = $this->getMockBuilder(StorageConfig::class) |
|
62 | - ->disableOriginalConstructor() |
|
63 | - ->getMock(); |
|
64 | - $storageConfig->expects($this->any()) |
|
65 | - ->method('getBackendOption') |
|
66 | - ->willReturn(null); |
|
67 | - $storageConfig->expects($this->any()) |
|
68 | - ->method('setBackendOption'); |
|
61 | + $storageConfig = $this->getMockBuilder(StorageConfig::class) |
|
62 | + ->disableOriginalConstructor() |
|
63 | + ->getMock(); |
|
64 | + $storageConfig->expects($this->any()) |
|
65 | + ->method('getBackendOption') |
|
66 | + ->willReturn(null); |
|
67 | + $storageConfig->expects($this->any()) |
|
68 | + ->method('setBackendOption'); |
|
69 | 69 | |
70 | - $trait = $this->getMockForTrait(\OCA\Files_External\Lib\FrontendDefinitionTrait::class); |
|
71 | - $trait->setText('test'); |
|
72 | - $trait->addParameters($backendParams); |
|
70 | + $trait = $this->getMockForTrait(\OCA\Files_External\Lib\FrontendDefinitionTrait::class); |
|
71 | + $trait->setText('test'); |
|
72 | + $trait->addParameters($backendParams); |
|
73 | 73 | |
74 | - $this->assertEquals($expectedSuccess, $trait->validateStorageDefinition($storageConfig)); |
|
75 | - } |
|
74 | + $this->assertEquals($expectedSuccess, $trait->validateStorageDefinition($storageConfig)); |
|
75 | + } |
|
76 | 76 | |
77 | - public function testValidateStorageSet(): void { |
|
78 | - $param = $this->getMockBuilder(DefinitionParameter::class) |
|
79 | - ->disableOriginalConstructor() |
|
80 | - ->getMock(); |
|
81 | - $param->method('getName') |
|
82 | - ->willReturn('param'); |
|
83 | - $param->expects($this->once()) |
|
84 | - ->method('validateValue') |
|
85 | - ->willReturnCallback(function (&$value) { |
|
86 | - $value = 'foobar'; |
|
87 | - return true; |
|
88 | - }); |
|
77 | + public function testValidateStorageSet(): void { |
|
78 | + $param = $this->getMockBuilder(DefinitionParameter::class) |
|
79 | + ->disableOriginalConstructor() |
|
80 | + ->getMock(); |
|
81 | + $param->method('getName') |
|
82 | + ->willReturn('param'); |
|
83 | + $param->expects($this->once()) |
|
84 | + ->method('validateValue') |
|
85 | + ->willReturnCallback(function (&$value) { |
|
86 | + $value = 'foobar'; |
|
87 | + return true; |
|
88 | + }); |
|
89 | 89 | |
90 | - $storageConfig = $this->getMockBuilder(StorageConfig::class) |
|
91 | - ->disableOriginalConstructor() |
|
92 | - ->getMock(); |
|
93 | - $storageConfig->expects($this->once()) |
|
94 | - ->method('getBackendOption') |
|
95 | - ->with('param') |
|
96 | - ->willReturn('barfoo'); |
|
97 | - $storageConfig->expects($this->once()) |
|
98 | - ->method('setBackendOption') |
|
99 | - ->with('param', 'foobar'); |
|
90 | + $storageConfig = $this->getMockBuilder(StorageConfig::class) |
|
91 | + ->disableOriginalConstructor() |
|
92 | + ->getMock(); |
|
93 | + $storageConfig->expects($this->once()) |
|
94 | + ->method('getBackendOption') |
|
95 | + ->with('param') |
|
96 | + ->willReturn('barfoo'); |
|
97 | + $storageConfig->expects($this->once()) |
|
98 | + ->method('setBackendOption') |
|
99 | + ->with('param', 'foobar'); |
|
100 | 100 | |
101 | - $trait = $this->getMockForTrait(\OCA\Files_External\Lib\FrontendDefinitionTrait::class); |
|
102 | - $trait->setText('test'); |
|
103 | - $trait->addParameter($param); |
|
101 | + $trait = $this->getMockForTrait(\OCA\Files_External\Lib\FrontendDefinitionTrait::class); |
|
102 | + $trait->setText('test'); |
|
103 | + $trait->addParameter($param); |
|
104 | 104 | |
105 | - $this->assertEquals(true, $trait->validateStorageDefinition($storageConfig)); |
|
106 | - } |
|
105 | + $this->assertEquals(true, $trait->validateStorageDefinition($storageConfig)); |
|
106 | + } |
|
107 | 107 | } |
@@ -13,53 +13,53 @@ |
||
13 | 13 | use OCA\Files_External\Lib\StorageConfig; |
14 | 14 | |
15 | 15 | class AuthMechanismTest extends \Test\TestCase { |
16 | - public function testJsonSerialization(): void { |
|
17 | - $mechanism = $this->getMockBuilder(AuthMechanism::class) |
|
18 | - ->onlyMethods(['jsonSerializeDefinition']) |
|
19 | - ->getMock(); |
|
20 | - $mechanism->expects($this->once()) |
|
21 | - ->method('jsonSerializeDefinition') |
|
22 | - ->willReturn(['foo' => 'bar']); |
|
16 | + public function testJsonSerialization(): void { |
|
17 | + $mechanism = $this->getMockBuilder(AuthMechanism::class) |
|
18 | + ->onlyMethods(['jsonSerializeDefinition']) |
|
19 | + ->getMock(); |
|
20 | + $mechanism->expects($this->once()) |
|
21 | + ->method('jsonSerializeDefinition') |
|
22 | + ->willReturn(['foo' => 'bar']); |
|
23 | 23 | |
24 | - $mechanism->setScheme('scheme'); |
|
24 | + $mechanism->setScheme('scheme'); |
|
25 | 25 | |
26 | - $json = $mechanism->jsonSerialize(); |
|
27 | - $this->assertEquals('bar', $json['foo']); |
|
28 | - $this->assertEquals('scheme', $json['scheme']); |
|
29 | - } |
|
26 | + $json = $mechanism->jsonSerialize(); |
|
27 | + $this->assertEquals('bar', $json['foo']); |
|
28 | + $this->assertEquals('scheme', $json['scheme']); |
|
29 | + } |
|
30 | 30 | |
31 | - public static function validateStorageProvider(): array { |
|
32 | - return [ |
|
33 | - [true, 'scheme', true], |
|
34 | - [false, 'scheme', false], |
|
35 | - [true, 'foobar', true], |
|
36 | - [false, 'barfoo', true], |
|
37 | - ]; |
|
38 | - } |
|
31 | + public static function validateStorageProvider(): array { |
|
32 | + return [ |
|
33 | + [true, 'scheme', true], |
|
34 | + [false, 'scheme', false], |
|
35 | + [true, 'foobar', true], |
|
36 | + [false, 'barfoo', true], |
|
37 | + ]; |
|
38 | + } |
|
39 | 39 | |
40 | - /** |
|
41 | - * @dataProvider validateStorageProvider |
|
42 | - */ |
|
43 | - public function testValidateStorage(bool $expectedSuccess, string $scheme, bool $definitionSuccess): void { |
|
44 | - $mechanism = $this->getMockBuilder(AuthMechanism::class) |
|
45 | - ->onlyMethods(['validateStorageDefinition']) |
|
46 | - ->getMock(); |
|
47 | - $mechanism->expects($this->atMost(1)) |
|
48 | - ->method('validateStorageDefinition') |
|
49 | - ->willReturn($definitionSuccess); |
|
40 | + /** |
|
41 | + * @dataProvider validateStorageProvider |
|
42 | + */ |
|
43 | + public function testValidateStorage(bool $expectedSuccess, string $scheme, bool $definitionSuccess): void { |
|
44 | + $mechanism = $this->getMockBuilder(AuthMechanism::class) |
|
45 | + ->onlyMethods(['validateStorageDefinition']) |
|
46 | + ->getMock(); |
|
47 | + $mechanism->expects($this->atMost(1)) |
|
48 | + ->method('validateStorageDefinition') |
|
49 | + ->willReturn($definitionSuccess); |
|
50 | 50 | |
51 | - $mechanism->setScheme($scheme); |
|
51 | + $mechanism->setScheme($scheme); |
|
52 | 52 | |
53 | - $backend = $this->createMock(Backend::class); |
|
54 | - $backend->expects($this->once()) |
|
55 | - ->method('getAuthSchemes') |
|
56 | - ->willReturn(['scheme' => true, 'foobar' => true]); |
|
53 | + $backend = $this->createMock(Backend::class); |
|
54 | + $backend->expects($this->once()) |
|
55 | + ->method('getAuthSchemes') |
|
56 | + ->willReturn(['scheme' => true, 'foobar' => true]); |
|
57 | 57 | |
58 | - $storageConfig = $this->createMock(StorageConfig::class); |
|
59 | - $storageConfig->expects($this->once()) |
|
60 | - ->method('getBackend') |
|
61 | - ->willReturn($backend); |
|
58 | + $storageConfig = $this->createMock(StorageConfig::class); |
|
59 | + $storageConfig->expects($this->once()) |
|
60 | + ->method('getBackend') |
|
61 | + ->willReturn($backend); |
|
62 | 62 | |
63 | - $this->assertEquals($expectedSuccess, $mechanism->validateStorage($storageConfig)); |
|
64 | - } |
|
63 | + $this->assertEquals($expectedSuccess, $mechanism->validateStorage($storageConfig)); |
|
64 | + } |
|
65 | 65 | } |
@@ -14,46 +14,46 @@ |
||
14 | 14 | use OCA\Files_External\Lib\StorageConfig; |
15 | 15 | |
16 | 16 | class StorageConfigTest extends \Test\TestCase { |
17 | - public function testJsonSerialization(): void { |
|
18 | - $backend = $this->createMock(Backend::class); |
|
19 | - $parameter = $this->createMock(DefinitionParameter::class); |
|
20 | - $parameter |
|
21 | - ->expects($this->once()) |
|
22 | - ->method('getType') |
|
23 | - ->willReturn(1); |
|
24 | - $backend |
|
25 | - ->expects($this->once()) |
|
26 | - ->method('getParameters') |
|
27 | - ->willReturn(['secure' => $parameter]); |
|
28 | - $backend->method('getIdentifier') |
|
29 | - ->willReturn('storage::identifier'); |
|
17 | + public function testJsonSerialization(): void { |
|
18 | + $backend = $this->createMock(Backend::class); |
|
19 | + $parameter = $this->createMock(DefinitionParameter::class); |
|
20 | + $parameter |
|
21 | + ->expects($this->once()) |
|
22 | + ->method('getType') |
|
23 | + ->willReturn(1); |
|
24 | + $backend |
|
25 | + ->expects($this->once()) |
|
26 | + ->method('getParameters') |
|
27 | + ->willReturn(['secure' => $parameter]); |
|
28 | + $backend->method('getIdentifier') |
|
29 | + ->willReturn('storage::identifier'); |
|
30 | 30 | |
31 | - $authMech = $this->createMock(AuthMechanism::class); |
|
32 | - $authMech->method('getIdentifier') |
|
33 | - ->willReturn('auth::identifier'); |
|
31 | + $authMech = $this->createMock(AuthMechanism::class); |
|
32 | + $authMech->method('getIdentifier') |
|
33 | + ->willReturn('auth::identifier'); |
|
34 | 34 | |
35 | - $storageConfig = new StorageConfig(1); |
|
36 | - $storageConfig->setMountPoint('test'); |
|
37 | - $storageConfig->setBackend($backend); |
|
38 | - $storageConfig->setAuthMechanism($authMech); |
|
39 | - $storageConfig->setBackendOptions(['user' => 'test', 'password' => 'password123', 'secure' => '1']); |
|
40 | - $storageConfig->setPriority(128); |
|
41 | - $storageConfig->setApplicableUsers(['user1', 'user2']); |
|
42 | - $storageConfig->setApplicableGroups(['group1', 'group2']); |
|
43 | - $storageConfig->setMountOptions(['preview' => false]); |
|
35 | + $storageConfig = new StorageConfig(1); |
|
36 | + $storageConfig->setMountPoint('test'); |
|
37 | + $storageConfig->setBackend($backend); |
|
38 | + $storageConfig->setAuthMechanism($authMech); |
|
39 | + $storageConfig->setBackendOptions(['user' => 'test', 'password' => 'password123', 'secure' => '1']); |
|
40 | + $storageConfig->setPriority(128); |
|
41 | + $storageConfig->setApplicableUsers(['user1', 'user2']); |
|
42 | + $storageConfig->setApplicableGroups(['group1', 'group2']); |
|
43 | + $storageConfig->setMountOptions(['preview' => false]); |
|
44 | 44 | |
45 | - $json = $storageConfig->jsonSerialize(); |
|
45 | + $json = $storageConfig->jsonSerialize(); |
|
46 | 46 | |
47 | - $this->assertSame(1, $json['id']); |
|
48 | - $this->assertSame('/test', $json['mountPoint']); |
|
49 | - $this->assertSame('storage::identifier', $json['backend']); |
|
50 | - $this->assertSame('auth::identifier', $json['authMechanism']); |
|
51 | - $this->assertSame('test', $json['backendOptions']['user']); |
|
52 | - $this->assertSame('password123', $json['backendOptions']['password']); |
|
53 | - $this->assertSame(true, $json['backendOptions']['secure']); |
|
54 | - $this->assertSame(128, $json['priority']); |
|
55 | - $this->assertSame(['user1', 'user2'], $json['applicableUsers']); |
|
56 | - $this->assertSame(['group1', 'group2'], $json['applicableGroups']); |
|
57 | - $this->assertSame(['preview' => false], $json['mountOptions']); |
|
58 | - } |
|
47 | + $this->assertSame(1, $json['id']); |
|
48 | + $this->assertSame('/test', $json['mountPoint']); |
|
49 | + $this->assertSame('storage::identifier', $json['backend']); |
|
50 | + $this->assertSame('auth::identifier', $json['authMechanism']); |
|
51 | + $this->assertSame('test', $json['backendOptions']['user']); |
|
52 | + $this->assertSame('password123', $json['backendOptions']['password']); |
|
53 | + $this->assertSame(true, $json['backendOptions']['secure']); |
|
54 | + $this->assertSame(128, $json['priority']); |
|
55 | + $this->assertSame(['user1', 'user2'], $json['applicableUsers']); |
|
56 | + $this->assertSame(['group1', 'group2'], $json['applicableGroups']); |
|
57 | + $this->assertSame(['preview' => false], $json['mountOptions']); |
|
58 | + } |
|
59 | 59 | } |
@@ -18,73 +18,73 @@ |
||
18 | 18 | * @package OCA\Files_External\Tests\Storage |
19 | 19 | */ |
20 | 20 | class FtpTest extends \Test\Files\Storage\Storage { |
21 | - private $config; |
|
22 | - |
|
23 | - protected function setUp(): void { |
|
24 | - parent::setUp(); |
|
25 | - |
|
26 | - $id = $this->getUniqueID(); |
|
27 | - $this->config = include('files_external/tests/config.ftp.php'); |
|
28 | - if (! is_array($this->config) or ! $this->config['run']) { |
|
29 | - $this->markTestSkipped('FTP backend not configured'); |
|
30 | - } |
|
31 | - $rootInstance = new FTP($this->config); |
|
32 | - $rootInstance->mkdir($id); |
|
33 | - |
|
34 | - $this->config['root'] .= '/' . $id; //make sure we have an new empty folder to work in |
|
35 | - $this->instance = new FTP($this->config); |
|
36 | - } |
|
37 | - |
|
38 | - protected function tearDown(): void { |
|
39 | - if ($this->instance) { |
|
40 | - $this->instance->rmdir(''); |
|
41 | - } |
|
42 | - $this->instance = null; |
|
43 | - |
|
44 | - parent::tearDown(); |
|
45 | - } |
|
46 | - |
|
47 | - /** |
|
48 | - * ftp has no proper way to handle spaces at the end of file names |
|
49 | - */ |
|
50 | - public static function directoryProvider(): array { |
|
51 | - return array_filter(parent::directoryProvider(), function ($item) { |
|
52 | - return substr($item[0], -1) !== ' '; |
|
53 | - }); |
|
54 | - } |
|
55 | - |
|
56 | - |
|
57 | - /** |
|
58 | - * mtime for folders is only with a minute resolution |
|
59 | - */ |
|
60 | - public function testStat(): void { |
|
61 | - $textFile = \OC::$SERVERROOT . '/tests/data/lorem.txt'; |
|
62 | - $ctimeStart = time(); |
|
63 | - $this->instance->file_put_contents('/lorem.txt', file_get_contents($textFile)); |
|
64 | - $this->assertTrue($this->instance->isReadable('/lorem.txt')); |
|
65 | - $ctimeEnd = time(); |
|
66 | - $mTime = $this->instance->filemtime('/lorem.txt'); |
|
67 | - $this->assertTrue($this->instance->hasUpdated('/lorem.txt', $ctimeStart - 5)); |
|
68 | - $this->assertTrue($this->instance->hasUpdated('/', $ctimeStart - 61)); |
|
69 | - |
|
70 | - // check that ($ctimeStart - 5) <= $mTime <= ($ctimeEnd + 1) |
|
71 | - $this->assertGreaterThanOrEqual(($ctimeStart - 5), $mTime); |
|
72 | - $this->assertLessThanOrEqual(($ctimeEnd + 1), $mTime); |
|
73 | - $this->assertEquals(filesize($textFile), $this->instance->filesize('/lorem.txt')); |
|
74 | - |
|
75 | - $stat = $this->instance->stat('/lorem.txt'); |
|
76 | - //only size and mtime are required in the result |
|
77 | - $this->assertEquals($stat['size'], $this->instance->filesize('/lorem.txt')); |
|
78 | - $this->assertEquals($stat['mtime'], $mTime); |
|
79 | - |
|
80 | - if ($this->instance->touch('/lorem.txt', 100) !== false) { |
|
81 | - $mTime = $this->instance->filemtime('/lorem.txt'); |
|
82 | - $this->assertEquals($mTime, 100); |
|
83 | - } |
|
84 | - |
|
85 | - $mtimeStart = time(); |
|
86 | - |
|
87 | - $this->instance->unlink('/lorem.txt'); |
|
88 | - $this->assertTrue($this->instance->hasUpdated('/', $mtimeStart - 61)); |
|
89 | - } |
|
21 | + private $config; |
|
22 | + |
|
23 | + protected function setUp(): void { |
|
24 | + parent::setUp(); |
|
25 | + |
|
26 | + $id = $this->getUniqueID(); |
|
27 | + $this->config = include('files_external/tests/config.ftp.php'); |
|
28 | + if (! is_array($this->config) or ! $this->config['run']) { |
|
29 | + $this->markTestSkipped('FTP backend not configured'); |
|
30 | + } |
|
31 | + $rootInstance = new FTP($this->config); |
|
32 | + $rootInstance->mkdir($id); |
|
33 | + |
|
34 | + $this->config['root'] .= '/' . $id; //make sure we have an new empty folder to work in |
|
35 | + $this->instance = new FTP($this->config); |
|
36 | + } |
|
37 | + |
|
38 | + protected function tearDown(): void { |
|
39 | + if ($this->instance) { |
|
40 | + $this->instance->rmdir(''); |
|
41 | + } |
|
42 | + $this->instance = null; |
|
43 | + |
|
44 | + parent::tearDown(); |
|
45 | + } |
|
46 | + |
|
47 | + /** |
|
48 | + * ftp has no proper way to handle spaces at the end of file names |
|
49 | + */ |
|
50 | + public static function directoryProvider(): array { |
|
51 | + return array_filter(parent::directoryProvider(), function ($item) { |
|
52 | + return substr($item[0], -1) !== ' '; |
|
53 | + }); |
|
54 | + } |
|
55 | + |
|
56 | + |
|
57 | + /** |
|
58 | + * mtime for folders is only with a minute resolution |
|
59 | + */ |
|
60 | + public function testStat(): void { |
|
61 | + $textFile = \OC::$SERVERROOT . '/tests/data/lorem.txt'; |
|
62 | + $ctimeStart = time(); |
|
63 | + $this->instance->file_put_contents('/lorem.txt', file_get_contents($textFile)); |
|
64 | + $this->assertTrue($this->instance->isReadable('/lorem.txt')); |
|
65 | + $ctimeEnd = time(); |
|
66 | + $mTime = $this->instance->filemtime('/lorem.txt'); |
|
67 | + $this->assertTrue($this->instance->hasUpdated('/lorem.txt', $ctimeStart - 5)); |
|
68 | + $this->assertTrue($this->instance->hasUpdated('/', $ctimeStart - 61)); |
|
69 | + |
|
70 | + // check that ($ctimeStart - 5) <= $mTime <= ($ctimeEnd + 1) |
|
71 | + $this->assertGreaterThanOrEqual(($ctimeStart - 5), $mTime); |
|
72 | + $this->assertLessThanOrEqual(($ctimeEnd + 1), $mTime); |
|
73 | + $this->assertEquals(filesize($textFile), $this->instance->filesize('/lorem.txt')); |
|
74 | + |
|
75 | + $stat = $this->instance->stat('/lorem.txt'); |
|
76 | + //only size and mtime are required in the result |
|
77 | + $this->assertEquals($stat['size'], $this->instance->filesize('/lorem.txt')); |
|
78 | + $this->assertEquals($stat['mtime'], $mTime); |
|
79 | + |
|
80 | + if ($this->instance->touch('/lorem.txt', 100) !== false) { |
|
81 | + $mTime = $this->instance->filemtime('/lorem.txt'); |
|
82 | + $this->assertEquals($mTime, 100); |
|
83 | + } |
|
84 | + |
|
85 | + $mtimeStart = time(); |
|
86 | + |
|
87 | + $this->instance->unlink('/lorem.txt'); |
|
88 | + $this->assertTrue($this->instance->hasUpdated('/', $mtimeStart - 61)); |
|
89 | + } |
|
90 | 90 | } |
@@ -18,121 +18,121 @@ |
||
18 | 18 | * @package OCA\Files_External\Tests\Storage |
19 | 19 | */ |
20 | 20 | class SftpTest extends \Test\Files\Storage\Storage { |
21 | - /** |
|
22 | - * @var SFTP instance |
|
23 | - */ |
|
24 | - protected $instance; |
|
21 | + /** |
|
22 | + * @var SFTP instance |
|
23 | + */ |
|
24 | + protected $instance; |
|
25 | 25 | |
26 | - private $config; |
|
26 | + private $config; |
|
27 | 27 | |
28 | - protected function setUp(): void { |
|
29 | - parent::setUp(); |
|
28 | + protected function setUp(): void { |
|
29 | + parent::setUp(); |
|
30 | 30 | |
31 | - $id = $this->getUniqueID(); |
|
32 | - $this->config = include('files_external/tests/config.sftp.php'); |
|
33 | - if (!is_array($this->config) or !$this->config['run']) { |
|
34 | - $this->markTestSkipped('SFTP backend not configured'); |
|
35 | - } |
|
36 | - $this->config['root'] .= '/' . $id; //make sure we have an new empty folder to work in |
|
37 | - $this->instance = new SFTP($this->config); |
|
38 | - $this->instance->mkdir('/'); |
|
39 | - } |
|
31 | + $id = $this->getUniqueID(); |
|
32 | + $this->config = include('files_external/tests/config.sftp.php'); |
|
33 | + if (!is_array($this->config) or !$this->config['run']) { |
|
34 | + $this->markTestSkipped('SFTP backend not configured'); |
|
35 | + } |
|
36 | + $this->config['root'] .= '/' . $id; //make sure we have an new empty folder to work in |
|
37 | + $this->instance = new SFTP($this->config); |
|
38 | + $this->instance->mkdir('/'); |
|
39 | + } |
|
40 | 40 | |
41 | - protected function tearDown(): void { |
|
42 | - if ($this->instance) { |
|
43 | - $this->instance->rmdir('/'); |
|
44 | - } |
|
41 | + protected function tearDown(): void { |
|
42 | + if ($this->instance) { |
|
43 | + $this->instance->rmdir('/'); |
|
44 | + } |
|
45 | 45 | |
46 | - parent::tearDown(); |
|
47 | - } |
|
46 | + parent::tearDown(); |
|
47 | + } |
|
48 | 48 | |
49 | - /** |
|
50 | - * @dataProvider configProvider |
|
51 | - */ |
|
52 | - public function testStorageId($config, $expectedStorageId): void { |
|
53 | - $instance = new SFTP($config); |
|
54 | - $this->assertEquals($expectedStorageId, $instance->getId()); |
|
55 | - } |
|
49 | + /** |
|
50 | + * @dataProvider configProvider |
|
51 | + */ |
|
52 | + public function testStorageId($config, $expectedStorageId): void { |
|
53 | + $instance = new SFTP($config); |
|
54 | + $this->assertEquals($expectedStorageId, $instance->getId()); |
|
55 | + } |
|
56 | 56 | |
57 | - public static function configProvider(): array { |
|
58 | - return [ |
|
59 | - [ |
|
60 | - // no root path |
|
61 | - [ |
|
62 | - 'run' => true, |
|
63 | - 'host' => 'somehost', |
|
64 | - 'user' => 'someuser', |
|
65 | - 'password' => 'somepassword', |
|
66 | - 'root' => '', |
|
67 | - ], |
|
68 | - 'sftp::someuser@somehost//', |
|
69 | - ], |
|
70 | - [ |
|
71 | - // without leading nor trailing slash |
|
72 | - [ |
|
73 | - 'run' => true, |
|
74 | - 'host' => 'somehost', |
|
75 | - 'user' => 'someuser', |
|
76 | - 'password' => 'somepassword', |
|
77 | - 'root' => 'remotedir/subdir', |
|
78 | - ], |
|
79 | - 'sftp::someuser@somehost//remotedir/subdir/', |
|
80 | - ], |
|
81 | - [ |
|
82 | - // regular path |
|
83 | - [ |
|
84 | - 'run' => true, |
|
85 | - 'host' => 'somehost', |
|
86 | - 'user' => 'someuser', |
|
87 | - 'password' => 'somepassword', |
|
88 | - 'root' => '/remotedir/subdir/', |
|
89 | - ], |
|
90 | - 'sftp::someuser@somehost//remotedir/subdir/', |
|
91 | - ], |
|
92 | - [ |
|
93 | - // different port |
|
94 | - [ |
|
95 | - 'run' => true, |
|
96 | - 'host' => 'somehost:8822', |
|
97 | - 'user' => 'someuser', |
|
98 | - 'password' => 'somepassword', |
|
99 | - 'root' => 'remotedir/subdir/', |
|
100 | - ], |
|
101 | - 'sftp::someuser@somehost:8822//remotedir/subdir/', |
|
102 | - ], |
|
103 | - [ |
|
104 | - // ipv6 with port |
|
105 | - [ |
|
106 | - 'run' => true, |
|
107 | - 'host' => 'FE80:0000:0000:0000:0202:B3FF:FE1E:8329', |
|
108 | - 'user' => 'someuser', |
|
109 | - 'password' => 'somepassword', |
|
110 | - 'root' => 'remotedir/subdir/', |
|
111 | - ], |
|
112 | - 'sftp::someuser@FE80:0000:0000:0000:0202:B3FF:FE1E:8329//remotedir/subdir/', |
|
113 | - ], |
|
114 | - [ |
|
115 | - // ipv6 without port |
|
116 | - [ |
|
117 | - 'run' => true, |
|
118 | - 'host' => 'FE80:0000:0000:0000:0202:B3FF:FE1E:8329:8822', |
|
119 | - 'user' => 'someuser', |
|
120 | - 'password' => 'somepassword', |
|
121 | - 'root' => 'remotedir/subdir/', |
|
122 | - ], |
|
123 | - 'sftp::someuser@FE80:0000:0000:0000:0202:B3FF:FE1E:8329:8822//remotedir/subdir/', |
|
124 | - ], |
|
125 | - [ |
|
126 | - // collapsed ipv6 with port |
|
127 | - [ |
|
128 | - 'run' => true, |
|
129 | - 'host' => 'FE80::0202:B3FF:FE1E:8329:8822', |
|
130 | - 'user' => 'someuser', |
|
131 | - 'password' => 'somepassword', |
|
132 | - 'root' => 'remotedir/subdir/', |
|
133 | - ], |
|
134 | - 'sftp::someuser@FE80::0202:B3FF:FE1E:8329:8822//remotedir/subdir/', |
|
135 | - ], |
|
136 | - ]; |
|
137 | - } |
|
57 | + public static function configProvider(): array { |
|
58 | + return [ |
|
59 | + [ |
|
60 | + // no root path |
|
61 | + [ |
|
62 | + 'run' => true, |
|
63 | + 'host' => 'somehost', |
|
64 | + 'user' => 'someuser', |
|
65 | + 'password' => 'somepassword', |
|
66 | + 'root' => '', |
|
67 | + ], |
|
68 | + 'sftp::someuser@somehost//', |
|
69 | + ], |
|
70 | + [ |
|
71 | + // without leading nor trailing slash |
|
72 | + [ |
|
73 | + 'run' => true, |
|
74 | + 'host' => 'somehost', |
|
75 | + 'user' => 'someuser', |
|
76 | + 'password' => 'somepassword', |
|
77 | + 'root' => 'remotedir/subdir', |
|
78 | + ], |
|
79 | + 'sftp::someuser@somehost//remotedir/subdir/', |
|
80 | + ], |
|
81 | + [ |
|
82 | + // regular path |
|
83 | + [ |
|
84 | + 'run' => true, |
|
85 | + 'host' => 'somehost', |
|
86 | + 'user' => 'someuser', |
|
87 | + 'password' => 'somepassword', |
|
88 | + 'root' => '/remotedir/subdir/', |
|
89 | + ], |
|
90 | + 'sftp::someuser@somehost//remotedir/subdir/', |
|
91 | + ], |
|
92 | + [ |
|
93 | + // different port |
|
94 | + [ |
|
95 | + 'run' => true, |
|
96 | + 'host' => 'somehost:8822', |
|
97 | + 'user' => 'someuser', |
|
98 | + 'password' => 'somepassword', |
|
99 | + 'root' => 'remotedir/subdir/', |
|
100 | + ], |
|
101 | + 'sftp::someuser@somehost:8822//remotedir/subdir/', |
|
102 | + ], |
|
103 | + [ |
|
104 | + // ipv6 with port |
|
105 | + [ |
|
106 | + 'run' => true, |
|
107 | + 'host' => 'FE80:0000:0000:0000:0202:B3FF:FE1E:8329', |
|
108 | + 'user' => 'someuser', |
|
109 | + 'password' => 'somepassword', |
|
110 | + 'root' => 'remotedir/subdir/', |
|
111 | + ], |
|
112 | + 'sftp::someuser@FE80:0000:0000:0000:0202:B3FF:FE1E:8329//remotedir/subdir/', |
|
113 | + ], |
|
114 | + [ |
|
115 | + // ipv6 without port |
|
116 | + [ |
|
117 | + 'run' => true, |
|
118 | + 'host' => 'FE80:0000:0000:0000:0202:B3FF:FE1E:8329:8822', |
|
119 | + 'user' => 'someuser', |
|
120 | + 'password' => 'somepassword', |
|
121 | + 'root' => 'remotedir/subdir/', |
|
122 | + ], |
|
123 | + 'sftp::someuser@FE80:0000:0000:0000:0202:B3FF:FE1E:8329:8822//remotedir/subdir/', |
|
124 | + ], |
|
125 | + [ |
|
126 | + // collapsed ipv6 with port |
|
127 | + [ |
|
128 | + 'run' => true, |
|
129 | + 'host' => 'FE80::0202:B3FF:FE1E:8329:8822', |
|
130 | + 'user' => 'someuser', |
|
131 | + 'password' => 'somepassword', |
|
132 | + 'root' => 'remotedir/subdir/', |
|
133 | + ], |
|
134 | + 'sftp::someuser@FE80::0202:B3FF:FE1E:8329:8822//remotedir/subdir/', |
|
135 | + ], |
|
136 | + ]; |
|
137 | + } |
|
138 | 138 | } |
@@ -14,145 +14,145 @@ |
||
14 | 14 | use PHPUnit\Framework\MockObject\MockObject; |
15 | 15 | |
16 | 16 | class ApplicableTest extends CommandTestCase { |
17 | - private function getInstance($storageService): Applicable { |
|
18 | - /** @var IUserManager&MockObject $userManager */ |
|
19 | - $userManager = $this->createMock(IUserManager::class); |
|
20 | - /** @var IGroupManager&MockObject $groupManager */ |
|
21 | - $groupManager = $this->createMock(IGroupManager::class); |
|
17 | + private function getInstance($storageService): Applicable { |
|
18 | + /** @var IUserManager&MockObject $userManager */ |
|
19 | + $userManager = $this->createMock(IUserManager::class); |
|
20 | + /** @var IGroupManager&MockObject $groupManager */ |
|
21 | + $groupManager = $this->createMock(IGroupManager::class); |
|
22 | 22 | |
23 | - $userManager->expects($this->any()) |
|
24 | - ->method('userExists') |
|
25 | - ->willReturn(true); |
|
23 | + $userManager->expects($this->any()) |
|
24 | + ->method('userExists') |
|
25 | + ->willReturn(true); |
|
26 | 26 | |
27 | - $groupManager->expects($this->any()) |
|
28 | - ->method('groupExists') |
|
29 | - ->willReturn(true); |
|
27 | + $groupManager->expects($this->any()) |
|
28 | + ->method('groupExists') |
|
29 | + ->willReturn(true); |
|
30 | 30 | |
31 | - return new Applicable($storageService, $userManager, $groupManager); |
|
32 | - } |
|
31 | + return new Applicable($storageService, $userManager, $groupManager); |
|
32 | + } |
|
33 | 33 | |
34 | - public function testListEmpty(): void { |
|
35 | - $mount = $this->getMount(1, '', ''); |
|
34 | + public function testListEmpty(): void { |
|
35 | + $mount = $this->getMount(1, '', ''); |
|
36 | 36 | |
37 | - $storageService = $this->getGlobalStorageService([$mount]); |
|
38 | - $command = $this->getInstance($storageService); |
|
37 | + $storageService = $this->getGlobalStorageService([$mount]); |
|
38 | + $command = $this->getInstance($storageService); |
|
39 | 39 | |
40 | - $input = $this->getInput($command, [ |
|
41 | - 'mount_id' => 1 |
|
42 | - ], [ |
|
43 | - 'output' => 'json' |
|
44 | - ]); |
|
40 | + $input = $this->getInput($command, [ |
|
41 | + 'mount_id' => 1 |
|
42 | + ], [ |
|
43 | + 'output' => 'json' |
|
44 | + ]); |
|
45 | 45 | |
46 | - $result = json_decode($this->executeCommand($command, $input), true); |
|
46 | + $result = json_decode($this->executeCommand($command, $input), true); |
|
47 | 47 | |
48 | - $this->assertEquals(['users' => [], 'groups' => []], $result); |
|
49 | - } |
|
48 | + $this->assertEquals(['users' => [], 'groups' => []], $result); |
|
49 | + } |
|
50 | 50 | |
51 | - public function testList(): void { |
|
52 | - $mount = $this->getMount(1, '', '', '', [], [], ['test', 'asd']); |
|
51 | + public function testList(): void { |
|
52 | + $mount = $this->getMount(1, '', '', '', [], [], ['test', 'asd']); |
|
53 | 53 | |
54 | - $storageService = $this->getGlobalStorageService([$mount]); |
|
55 | - $command = $this->getInstance($storageService); |
|
54 | + $storageService = $this->getGlobalStorageService([$mount]); |
|
55 | + $command = $this->getInstance($storageService); |
|
56 | 56 | |
57 | - $input = $this->getInput($command, [ |
|
58 | - 'mount_id' => 1 |
|
59 | - ], [ |
|
60 | - 'output' => 'json' |
|
61 | - ]); |
|
57 | + $input = $this->getInput($command, [ |
|
58 | + 'mount_id' => 1 |
|
59 | + ], [ |
|
60 | + 'output' => 'json' |
|
61 | + ]); |
|
62 | 62 | |
63 | - $result = json_decode($this->executeCommand($command, $input), true); |
|
63 | + $result = json_decode($this->executeCommand($command, $input), true); |
|
64 | 64 | |
65 | - $this->assertEquals(['users' => ['test', 'asd'], 'groups' => []], $result); |
|
66 | - } |
|
65 | + $this->assertEquals(['users' => ['test', 'asd'], 'groups' => []], $result); |
|
66 | + } |
|
67 | 67 | |
68 | - public function testAddSingle(): void { |
|
69 | - $mount = $this->getMount(1, '', '', '', [], [], []); |
|
68 | + public function testAddSingle(): void { |
|
69 | + $mount = $this->getMount(1, '', '', '', [], [], []); |
|
70 | 70 | |
71 | - $storageService = $this->getGlobalStorageService([$mount]); |
|
72 | - $command = $this->getInstance($storageService); |
|
71 | + $storageService = $this->getGlobalStorageService([$mount]); |
|
72 | + $command = $this->getInstance($storageService); |
|
73 | 73 | |
74 | - $input = $this->getInput($command, [ |
|
75 | - 'mount_id' => 1 |
|
76 | - ], [ |
|
77 | - 'output' => 'json', |
|
78 | - 'add-user' => ['foo'] |
|
79 | - ]); |
|
74 | + $input = $this->getInput($command, [ |
|
75 | + 'mount_id' => 1 |
|
76 | + ], [ |
|
77 | + 'output' => 'json', |
|
78 | + 'add-user' => ['foo'] |
|
79 | + ]); |
|
80 | 80 | |
81 | - $this->executeCommand($command, $input); |
|
81 | + $this->executeCommand($command, $input); |
|
82 | 82 | |
83 | - $this->assertEquals(['foo'], $mount->getApplicableUsers()); |
|
84 | - } |
|
83 | + $this->assertEquals(['foo'], $mount->getApplicableUsers()); |
|
84 | + } |
|
85 | 85 | |
86 | - public function testAddDuplicate(): void { |
|
87 | - $mount = $this->getMount(1, '', '', '', [], [], ['foo']); |
|
86 | + public function testAddDuplicate(): void { |
|
87 | + $mount = $this->getMount(1, '', '', '', [], [], ['foo']); |
|
88 | 88 | |
89 | - $storageService = $this->getGlobalStorageService([$mount]); |
|
90 | - $command = $this->getInstance($storageService); |
|
89 | + $storageService = $this->getGlobalStorageService([$mount]); |
|
90 | + $command = $this->getInstance($storageService); |
|
91 | 91 | |
92 | - $input = $this->getInput($command, [ |
|
93 | - 'mount_id' => 1 |
|
94 | - ], [ |
|
95 | - 'output' => 'json', |
|
96 | - 'add-user' => ['foo', 'bar'] |
|
97 | - ]); |
|
92 | + $input = $this->getInput($command, [ |
|
93 | + 'mount_id' => 1 |
|
94 | + ], [ |
|
95 | + 'output' => 'json', |
|
96 | + 'add-user' => ['foo', 'bar'] |
|
97 | + ]); |
|
98 | 98 | |
99 | - $this->executeCommand($command, $input); |
|
99 | + $this->executeCommand($command, $input); |
|
100 | 100 | |
101 | - $this->assertEquals(['foo', 'bar'], $mount->getApplicableUsers()); |
|
102 | - } |
|
101 | + $this->assertEquals(['foo', 'bar'], $mount->getApplicableUsers()); |
|
102 | + } |
|
103 | 103 | |
104 | - public function testRemoveSingle(): void { |
|
105 | - $mount = $this->getMount(1, '', '', '', [], [], ['foo', 'bar']); |
|
104 | + public function testRemoveSingle(): void { |
|
105 | + $mount = $this->getMount(1, '', '', '', [], [], ['foo', 'bar']); |
|
106 | 106 | |
107 | - $storageService = $this->getGlobalStorageService([$mount]); |
|
108 | - $command = $this->getInstance($storageService); |
|
107 | + $storageService = $this->getGlobalStorageService([$mount]); |
|
108 | + $command = $this->getInstance($storageService); |
|
109 | 109 | |
110 | - $input = $this->getInput($command, [ |
|
111 | - 'mount_id' => 1 |
|
112 | - ], [ |
|
113 | - 'output' => 'json', |
|
114 | - 'remove-user' => ['bar'] |
|
115 | - ]); |
|
110 | + $input = $this->getInput($command, [ |
|
111 | + 'mount_id' => 1 |
|
112 | + ], [ |
|
113 | + 'output' => 'json', |
|
114 | + 'remove-user' => ['bar'] |
|
115 | + ]); |
|
116 | 116 | |
117 | - $this->executeCommand($command, $input); |
|
117 | + $this->executeCommand($command, $input); |
|
118 | 118 | |
119 | - $this->assertEquals(['foo'], $mount->getApplicableUsers()); |
|
120 | - } |
|
119 | + $this->assertEquals(['foo'], $mount->getApplicableUsers()); |
|
120 | + } |
|
121 | 121 | |
122 | - public function testRemoveNonExisting(): void { |
|
123 | - $mount = $this->getMount(1, '', '', '', [], [], ['foo', 'bar']); |
|
122 | + public function testRemoveNonExisting(): void { |
|
123 | + $mount = $this->getMount(1, '', '', '', [], [], ['foo', 'bar']); |
|
124 | 124 | |
125 | - $storageService = $this->getGlobalStorageService([$mount]); |
|
126 | - $command = $this->getInstance($storageService); |
|
125 | + $storageService = $this->getGlobalStorageService([$mount]); |
|
126 | + $command = $this->getInstance($storageService); |
|
127 | 127 | |
128 | - $input = $this->getInput($command, [ |
|
129 | - 'mount_id' => 1 |
|
130 | - ], [ |
|
131 | - 'output' => 'json', |
|
132 | - 'remove-user' => ['bar', 'asd'] |
|
133 | - ]); |
|
128 | + $input = $this->getInput($command, [ |
|
129 | + 'mount_id' => 1 |
|
130 | + ], [ |
|
131 | + 'output' => 'json', |
|
132 | + 'remove-user' => ['bar', 'asd'] |
|
133 | + ]); |
|
134 | 134 | |
135 | - $this->executeCommand($command, $input); |
|
135 | + $this->executeCommand($command, $input); |
|
136 | 136 | |
137 | - $this->assertEquals(['foo'], $mount->getApplicableUsers()); |
|
138 | - } |
|
137 | + $this->assertEquals(['foo'], $mount->getApplicableUsers()); |
|
138 | + } |
|
139 | 139 | |
140 | - public function testRemoveAddRemove(): void { |
|
141 | - $mount = $this->getMount(1, '', '', '', [], [], ['foo', 'bar']); |
|
140 | + public function testRemoveAddRemove(): void { |
|
141 | + $mount = $this->getMount(1, '', '', '', [], [], ['foo', 'bar']); |
|
142 | 142 | |
143 | - $storageService = $this->getGlobalStorageService([$mount]); |
|
144 | - $command = $this->getInstance($storageService); |
|
143 | + $storageService = $this->getGlobalStorageService([$mount]); |
|
144 | + $command = $this->getInstance($storageService); |
|
145 | 145 | |
146 | - $input = $this->getInput($command, [ |
|
147 | - 'mount_id' => 1 |
|
148 | - ], [ |
|
149 | - 'output' => 'json', |
|
150 | - 'remove-user' => ['bar', 'asd'], |
|
151 | - 'add-user' => ['test'] |
|
152 | - ]); |
|
146 | + $input = $this->getInput($command, [ |
|
147 | + 'mount_id' => 1 |
|
148 | + ], [ |
|
149 | + 'output' => 'json', |
|
150 | + 'remove-user' => ['bar', 'asd'], |
|
151 | + 'add-user' => ['test'] |
|
152 | + ]); |
|
153 | 153 | |
154 | - $this->executeCommand($command, $input); |
|
154 | + $this->executeCommand($command, $input); |
|
155 | 155 | |
156 | - $this->assertEquals(['foo', 'test'], $mount->getApplicableUsers()); |
|
157 | - } |
|
156 | + $this->assertEquals(['foo', 'test'], $mount->getApplicableUsers()); |
|
157 | + } |
|
158 | 158 | } |
@@ -24,37 +24,37 @@ |
||
24 | 24 | use Symfony\Component\Console\Output\BufferedOutput; |
25 | 25 | |
26 | 26 | class ListCommandTest extends CommandTestCase { |
27 | - private function getInstance(): ListCommand { |
|
28 | - /** @var GlobalStoragesService&MockObject $globalService */ |
|
29 | - $globalService = $this->createMock(GlobalStoragesService::class); |
|
30 | - /** @var UserStoragesService&MockObject $userService */ |
|
31 | - $userService = $this->createMock(UserStoragesService::class); |
|
32 | - /** @var IUserManager&MockObject $userManager */ |
|
33 | - $userManager = $this->createMock(IUserManager::class); |
|
34 | - /** @var IUserSession&MockObject $userSession */ |
|
35 | - $userSession = $this->createMock(IUserSession::class); |
|
27 | + private function getInstance(): ListCommand { |
|
28 | + /** @var GlobalStoragesService&MockObject $globalService */ |
|
29 | + $globalService = $this->createMock(GlobalStoragesService::class); |
|
30 | + /** @var UserStoragesService&MockObject $userService */ |
|
31 | + $userService = $this->createMock(UserStoragesService::class); |
|
32 | + /** @var IUserManager&MockObject $userManager */ |
|
33 | + $userManager = $this->createMock(IUserManager::class); |
|
34 | + /** @var IUserSession&MockObject $userSession */ |
|
35 | + $userSession = $this->createMock(IUserSession::class); |
|
36 | 36 | |
37 | - return new ListCommand($globalService, $userService, $userSession, $userManager); |
|
38 | - } |
|
37 | + return new ListCommand($globalService, $userService, $userSession, $userManager); |
|
38 | + } |
|
39 | 39 | |
40 | - public function testListAuthIdentifier(): void { |
|
41 | - $l10n = $this->createMock(IL10N::class); |
|
42 | - $instance = $this->getInstance(); |
|
43 | - $mount1 = new StorageConfig(); |
|
44 | - $mount1->setAuthMechanism(new Password($l10n)); |
|
45 | - $mount1->setBackend(new Local($l10n, new NullMechanism($l10n))); |
|
46 | - $mount2 = new StorageConfig(); |
|
47 | - $credentialStore = $this->createMock(IStore::class); |
|
48 | - $mount2->setAuthMechanism(new SessionCredentials($l10n, $credentialStore)); |
|
49 | - $mount2->setBackend(new Local($l10n, new NullMechanism($l10n))); |
|
50 | - $input = $this->getInput($instance, [], [ |
|
51 | - 'output' => 'json' |
|
52 | - ]); |
|
53 | - $output = new BufferedOutput(); |
|
40 | + public function testListAuthIdentifier(): void { |
|
41 | + $l10n = $this->createMock(IL10N::class); |
|
42 | + $instance = $this->getInstance(); |
|
43 | + $mount1 = new StorageConfig(); |
|
44 | + $mount1->setAuthMechanism(new Password($l10n)); |
|
45 | + $mount1->setBackend(new Local($l10n, new NullMechanism($l10n))); |
|
46 | + $mount2 = new StorageConfig(); |
|
47 | + $credentialStore = $this->createMock(IStore::class); |
|
48 | + $mount2->setAuthMechanism(new SessionCredentials($l10n, $credentialStore)); |
|
49 | + $mount2->setBackend(new Local($l10n, new NullMechanism($l10n))); |
|
50 | + $input = $this->getInput($instance, [], [ |
|
51 | + 'output' => 'json' |
|
52 | + ]); |
|
53 | + $output = new BufferedOutput(); |
|
54 | 54 | |
55 | - $instance->listMounts('', [$mount1, $mount2], $input, $output); |
|
56 | - $output = json_decode($output->fetch(), true); |
|
55 | + $instance->listMounts('', [$mount1, $mount2], $input, $output); |
|
56 | + $output = json_decode($output->fetch(), true); |
|
57 | 57 | |
58 | - $this->assertNotEquals($output[0]['authentication_type'], $output[1]['authentication_type']); |
|
59 | - } |
|
58 | + $this->assertNotEquals($output[0]['authentication_type'], $output[1]['authentication_type']); |
|
59 | + } |
|
60 | 60 | } |
@@ -17,57 +17,57 @@ |
||
17 | 17 | use PHPUnit\Framework\MockObject\MockObject; |
18 | 18 | |
19 | 19 | class UserPlaceholderHandlerTest extends \Test\TestCase { |
20 | - protected IUser&MockObject $user; |
|
21 | - protected IUserSession&MockObject $session; |
|
22 | - protected IManager&MockObject $shareManager; |
|
23 | - protected IRequest&MockObject $request; |
|
24 | - protected IUserManager&MockObject $userManager; |
|
25 | - protected UserPlaceholderHandler $handler; |
|
20 | + protected IUser&MockObject $user; |
|
21 | + protected IUserSession&MockObject $session; |
|
22 | + protected IManager&MockObject $shareManager; |
|
23 | + protected IRequest&MockObject $request; |
|
24 | + protected IUserManager&MockObject $userManager; |
|
25 | + protected UserPlaceholderHandler $handler; |
|
26 | 26 | |
27 | - protected function setUp(): void { |
|
28 | - parent::setUp(); |
|
27 | + protected function setUp(): void { |
|
28 | + parent::setUp(); |
|
29 | 29 | |
30 | - $this->user = $this->createMock(IUser::class); |
|
31 | - $this->user->expects($this->any()) |
|
32 | - ->method('getUid') |
|
33 | - ->willReturn('alice'); |
|
34 | - $this->session = $this->createMock(IUserSession::class); |
|
35 | - $this->shareManager = $this->createMock(IManager::class); |
|
36 | - $this->request = $this->createMock(IRequest::class); |
|
37 | - $this->userManager = $this->createMock(IUserManager::class); |
|
30 | + $this->user = $this->createMock(IUser::class); |
|
31 | + $this->user->expects($this->any()) |
|
32 | + ->method('getUid') |
|
33 | + ->willReturn('alice'); |
|
34 | + $this->session = $this->createMock(IUserSession::class); |
|
35 | + $this->shareManager = $this->createMock(IManager::class); |
|
36 | + $this->request = $this->createMock(IRequest::class); |
|
37 | + $this->userManager = $this->createMock(IUserManager::class); |
|
38 | 38 | |
39 | - $this->handler = new UserPlaceholderHandler($this->session, $this->shareManager, $this->request, $this->userManager); |
|
40 | - } |
|
39 | + $this->handler = new UserPlaceholderHandler($this->session, $this->shareManager, $this->request, $this->userManager); |
|
40 | + } |
|
41 | 41 | |
42 | - protected function setUser(): void { |
|
43 | - $this->session->expects($this->any()) |
|
44 | - ->method('getUser') |
|
45 | - ->willReturn($this->user); |
|
46 | - } |
|
42 | + protected function setUser(): void { |
|
43 | + $this->session->expects($this->any()) |
|
44 | + ->method('getUser') |
|
45 | + ->willReturn($this->user); |
|
46 | + } |
|
47 | 47 | |
48 | - public static function optionProvider(): array { |
|
49 | - return [ |
|
50 | - ['/foo/bar/$user/foobar', '/foo/bar/alice/foobar'], |
|
51 | - [['/foo/bar/$user/foobar'], ['/foo/bar/alice/foobar']], |
|
52 | - [['/FOO/BAR/$USER/FOOBAR'], ['/FOO/BAR/alice/FOOBAR']], |
|
53 | - ]; |
|
54 | - } |
|
48 | + public static function optionProvider(): array { |
|
49 | + return [ |
|
50 | + ['/foo/bar/$user/foobar', '/foo/bar/alice/foobar'], |
|
51 | + [['/foo/bar/$user/foobar'], ['/foo/bar/alice/foobar']], |
|
52 | + [['/FOO/BAR/$USER/FOOBAR'], ['/FOO/BAR/alice/FOOBAR']], |
|
53 | + ]; |
|
54 | + } |
|
55 | 55 | |
56 | - /** |
|
57 | - * @dataProvider optionProvider |
|
58 | - */ |
|
59 | - public function testHandle(string|array $option, string|array $expected): void { |
|
60 | - $this->setUser(); |
|
61 | - $this->assertSame($expected, $this->handler->handle($option)); |
|
62 | - } |
|
56 | + /** |
|
57 | + * @dataProvider optionProvider |
|
58 | + */ |
|
59 | + public function testHandle(string|array $option, string|array $expected): void { |
|
60 | + $this->setUser(); |
|
61 | + $this->assertSame($expected, $this->handler->handle($option)); |
|
62 | + } |
|
63 | 63 | |
64 | - /** |
|
65 | - * @dataProvider optionProvider |
|
66 | - */ |
|
67 | - public function testHandleNoUser(string|array $option): void { |
|
68 | - $this->shareManager->expects($this->once()) |
|
69 | - ->method('getShareByToken') |
|
70 | - ->willThrowException(new ShareNotFound()); |
|
71 | - $this->assertSame($option, $this->handler->handle($option)); |
|
72 | - } |
|
64 | + /** |
|
65 | + * @dataProvider optionProvider |
|
66 | + */ |
|
67 | + public function testHandleNoUser(string|array $option): void { |
|
68 | + $this->shareManager->expects($this->once()) |
|
69 | + ->method('getShareByToken') |
|
70 | + ->willThrowException(new ShareNotFound()); |
|
71 | + $this->assertSame($option, $this->handler->handle($option)); |
|
72 | + } |
|
73 | 73 | } |
@@ -56,7 +56,7 @@ discard block |
||
56 | 56 | /** |
57 | 57 | * @dataProvider optionProvider |
58 | 58 | */ |
59 | - public function testHandle(string|array $option, string|array $expected): void { |
|
59 | + public function testHandle(string | array $option, string | array $expected): void { |
|
60 | 60 | $this->setUser(); |
61 | 61 | $this->assertSame($expected, $this->handler->handle($option)); |
62 | 62 | } |
@@ -64,7 +64,7 @@ discard block |
||
64 | 64 | /** |
65 | 65 | * @dataProvider optionProvider |
66 | 66 | */ |
67 | - public function testHandleNoUser(string|array $option): void { |
|
67 | + public function testHandleNoUser(string | array $option): void { |
|
68 | 68 | $this->shareManager->expects($this->once()) |
69 | 69 | ->method('getShareByToken') |
70 | 70 | ->willThrowException(new ShareNotFound()); |
@@ -17,22 +17,22 @@ |
||
17 | 17 | use Test\TestCase; |
18 | 18 | |
19 | 19 | class PersonalMountTest extends TestCase { |
20 | - public function testFindByStorageId(): void { |
|
21 | - $storageConfig = $this->createMock(StorageConfig::class); |
|
22 | - /** @var UserStoragesService $storageService */ |
|
23 | - $storageService = $this->createMock(UserStoragesService::class); |
|
20 | + public function testFindByStorageId(): void { |
|
21 | + $storageConfig = $this->createMock(StorageConfig::class); |
|
22 | + /** @var UserStoragesService $storageService */ |
|
23 | + $storageService = $this->createMock(UserStoragesService::class); |
|
24 | 24 | |
25 | - $storage = $this->createMock(Storage::class); |
|
25 | + $storage = $this->createMock(Storage::class); |
|
26 | 26 | |
27 | - $storage->expects($this->any()) |
|
28 | - ->method('getId') |
|
29 | - ->willReturn('dummy'); |
|
27 | + $storage->expects($this->any()) |
|
28 | + ->method('getId') |
|
29 | + ->willReturn('dummy'); |
|
30 | 30 | |
31 | - $mount = new PersonalMount($storageService, $storageConfig, 10, $storage, '/foo'); |
|
31 | + $mount = new PersonalMount($storageService, $storageConfig, 10, $storage, '/foo'); |
|
32 | 32 | |
33 | - $mountManager = new Manager($this->createMock(SetupManagerFactory::class)); |
|
34 | - $mountManager->addMount($mount); |
|
33 | + $mountManager = new Manager($this->createMock(SetupManagerFactory::class)); |
|
34 | + $mountManager->addMount($mount); |
|
35 | 35 | |
36 | - $this->assertEquals([$mount], $mountManager->findByStorageId('dummy')); |
|
37 | - } |
|
36 | + $this->assertEquals([$mount], $mountManager->findByStorageId('dummy')); |
|
37 | + } |
|
38 | 38 | } |