Completed
Push — master ( 158b3e...c62fa5 )
by Joas
29:53 queued 14s
created
tests/lib/OCS/DiscoveryServiceTest.php 1 patch
Indentation   +55 added lines, -55 removed lines patch added patch discarded remove patch
@@ -13,68 +13,68 @@
 block discarded – undo
13 13
 use Test\TestCase;
14 14
 
15 15
 class DiscoveryServiceTest extends TestCase {
16
-	/** @var \PHPUnit\Framework\MockObject\MockObject | ICacheFactory */
17
-	private $cacheFactory;
16
+    /** @var \PHPUnit\Framework\MockObject\MockObject | ICacheFactory */
17
+    private $cacheFactory;
18 18
 
19
-	/** @var \PHPUnit\Framework\MockObject\MockObject | IClientService */
20
-	private $clientService;
19
+    /** @var \PHPUnit\Framework\MockObject\MockObject | IClientService */
20
+    private $clientService;
21 21
 
22
-	/** @var IDiscoveryService */
23
-	private $discoveryService;
22
+    /** @var IDiscoveryService */
23
+    private $discoveryService;
24 24
 
25
-	protected function setUp(): void {
26
-		parent::setUp();
25
+    protected function setUp(): void {
26
+        parent::setUp();
27 27
 
28
-		$this->cacheFactory = $this->getMockBuilder(ICacheFactory::class)->getMock();
29
-		$this->clientService = $this->getMockBuilder(IClientService::class)->getMock();
28
+        $this->cacheFactory = $this->getMockBuilder(ICacheFactory::class)->getMock();
29
+        $this->clientService = $this->getMockBuilder(IClientService::class)->getMock();
30 30
 
31
-		$this->discoveryService = new DiscoveryService(
32
-			$this->cacheFactory,
33
-			$this->clientService
34
-		);
35
-	}
31
+        $this->discoveryService = new DiscoveryService(
32
+            $this->cacheFactory,
33
+            $this->clientService
34
+        );
35
+    }
36 36
 
37
-	/**
38
-	 * @dataProvider dataTestIsSafeUrl
39
-	 *
40
-	 * @param string $url
41
-	 * @param bool $expected
42
-	 */
43
-	public function testIsSafeUrl($url, $expected): void {
44
-		$result = $this->invokePrivate($this->discoveryService, 'isSafeUrl', [$url]);
45
-		$this->assertSame($expected, $result);
46
-	}
37
+    /**
38
+     * @dataProvider dataTestIsSafeUrl
39
+     *
40
+     * @param string $url
41
+     * @param bool $expected
42
+     */
43
+    public function testIsSafeUrl($url, $expected): void {
44
+        $result = $this->invokePrivate($this->discoveryService, 'isSafeUrl', [$url]);
45
+        $this->assertSame($expected, $result);
46
+    }
47 47
 
48
-	public static function dataTestIsSafeUrl(): array {
49
-		return [
50
-			['api/ocs/v1.php/foo', true],
51
-			['/api/ocs/v1.php/foo', true],
52
-			['api/ocs/v1.php/foo/', true],
53
-			['api/ocs/v1.php/foo-bar/', true],
54
-			['api/ocs/v1:php/foo', false],
55
-			['api/ocs/<v1.php/foo', false],
56
-			['api/ocs/v1.php>/foo', false],
57
-		];
58
-	}
48
+    public static function dataTestIsSafeUrl(): array {
49
+        return [
50
+            ['api/ocs/v1.php/foo', true],
51
+            ['/api/ocs/v1.php/foo', true],
52
+            ['api/ocs/v1.php/foo/', true],
53
+            ['api/ocs/v1.php/foo-bar/', true],
54
+            ['api/ocs/v1:php/foo', false],
55
+            ['api/ocs/<v1.php/foo', false],
56
+            ['api/ocs/v1.php>/foo', false],
57
+        ];
58
+    }
59 59
 
60
-	/**
61
-	 * @dataProvider dataTestGetEndpoints
62
-	 *
63
-	 * @param array $decodedServices
64
-	 * @param string $service
65
-	 * @param array $expected
66
-	 */
67
-	public function testGetEndpoints($decodedServices, $service, $expected): void {
68
-		$result = $this->invokePrivate($this->discoveryService, 'getEndpoints', [$decodedServices, $service]);
69
-		$this->assertSame($expected, $result);
70
-	}
60
+    /**
61
+     * @dataProvider dataTestGetEndpoints
62
+     *
63
+     * @param array $decodedServices
64
+     * @param string $service
65
+     * @param array $expected
66
+     */
67
+    public function testGetEndpoints($decodedServices, $service, $expected): void {
68
+        $result = $this->invokePrivate($this->discoveryService, 'getEndpoints', [$decodedServices, $service]);
69
+        $this->assertSame($expected, $result);
70
+    }
71 71
 
72
-	public static function dataTestGetEndpoints(): array {
73
-		return [
74
-			[['services' => ['myService' => ['endpoints' => []]]], 'myService', []],
75
-			[['services' => ['myService' => ['endpoints' => ['foo' => '/bar']]]], 'myService', ['foo' => '/bar']],
76
-			[['services' => ['myService' => ['endpoints' => ['foo' => '/bar']]]], 'anotherService', []],
77
-			[['services' => ['myService' => ['endpoints' => ['foo' => '/bar</foo']]]], 'myService', []],
78
-		];
79
-	}
72
+    public static function dataTestGetEndpoints(): array {
73
+        return [
74
+            [['services' => ['myService' => ['endpoints' => []]]], 'myService', []],
75
+            [['services' => ['myService' => ['endpoints' => ['foo' => '/bar']]]], 'myService', ['foo' => '/bar']],
76
+            [['services' => ['myService' => ['endpoints' => ['foo' => '/bar']]]], 'anotherService', []],
77
+            [['services' => ['myService' => ['endpoints' => ['foo' => '/bar</foo']]]], 'myService', []],
78
+        ];
79
+    }
80 80
 }
Please login to merge, or discard this patch.
tests/lib/OCS/ApiHelperTest.php 1 patch
Indentation   +34 added lines, -34 removed lines patch added patch discarded remove patch
@@ -14,38 +14,38 @@
 block discarded – undo
14 14
 use OCP\IRequest;
15 15
 
16 16
 class ApiHelperTest extends \Test\TestCase {
17
-	public static function versionDataScriptNameProvider(): array {
18
-		return [
19
-			// Valid script name
20
-			[
21
-				'/master/ocs/v2.php', true,
22
-			],
23
-
24
-			// Invalid script names
25
-			[
26
-				'/master/ocs/v2.php/someInvalidPathName', false,
27
-			],
28
-			[
29
-				'/master/ocs/v1.php', false,
30
-			],
31
-			[
32
-				'', false,
33
-			],
34
-		];
35
-	}
36
-
37
-	/**
38
-	 * @dataProvider versionDataScriptNameProvider
39
-	 */
40
-	public function testIsV2(string $scriptName, bool $expected): void {
41
-		$request = $this->getMockBuilder(IRequest::class)
42
-			->disableOriginalConstructor()
43
-			->getMock();
44
-		$request
45
-			->expects($this->once())
46
-			->method('getScriptName')
47
-			->willReturn($scriptName);
48
-
49
-		$this->assertEquals($expected, $this->invokePrivate(new ApiHelper, 'isV2', [$request]));
50
-	}
17
+    public static function versionDataScriptNameProvider(): array {
18
+        return [
19
+            // Valid script name
20
+            [
21
+                '/master/ocs/v2.php', true,
22
+            ],
23
+
24
+            // Invalid script names
25
+            [
26
+                '/master/ocs/v2.php/someInvalidPathName', false,
27
+            ],
28
+            [
29
+                '/master/ocs/v1.php', false,
30
+            ],
31
+            [
32
+                '', false,
33
+            ],
34
+        ];
35
+    }
36
+
37
+    /**
38
+     * @dataProvider versionDataScriptNameProvider
39
+     */
40
+    public function testIsV2(string $scriptName, bool $expected): void {
41
+        $request = $this->getMockBuilder(IRequest::class)
42
+            ->disableOriginalConstructor()
43
+            ->getMock();
44
+        $request
45
+            ->expects($this->once())
46
+            ->method('getScriptName')
47
+            ->willReturn($scriptName);
48
+
49
+        $this->assertEquals($expected, $this->invokePrivate(new ApiHelper, 'isV2', [$request]));
50
+    }
51 51
 }
Please login to merge, or discard this patch.
tests/lib/InfoXmlTest.php 1 patch
Indentation   +114 added lines, -114 removed lines patch added patch discarded remove patch
@@ -16,118 +16,118 @@
 block discarded – undo
16 16
  * @package Test
17 17
  */
18 18
 class InfoXmlTest extends TestCase {
19
-	private IAppManager $appManager;
20
-
21
-	protected function setUp(): void {
22
-		parent::setUp();
23
-		$this->appManager = Server::get(IAppManager::class);
24
-	}
25
-
26
-	public static function dataApps(): array {
27
-		return [
28
-			['admin_audit'],
29
-			['comments'],
30
-			['dav'],
31
-			['encryption'],
32
-			['federatedfilesharing'],
33
-			['federation'],
34
-			['files'],
35
-			['files_external'],
36
-			['files_sharing'],
37
-			['files_trashbin'],
38
-			['files_versions'],
39
-			['provisioning_api'],
40
-			['systemtags'],
41
-			['theming'],
42
-			['settings'],
43
-			['twofactor_backupcodes'],
44
-			['updatenotification'],
45
-			['user_ldap'],
46
-			['workflowengine'],
47
-		];
48
-	}
49
-
50
-	/**
51
-	 * @dataProvider dataApps
52
-	 *
53
-	 * @param string $app
54
-	 */
55
-	public function testClasses($app): void {
56
-		$appInfo = $this->appManager->getAppInfo($app);
57
-		$appPath = $this->appManager->getAppPath($app);
58
-		\OC_App::registerAutoloading($app, $appPath);
59
-
60
-		//Add the appcontainer
61
-		$applicationClassName = \OCP\AppFramework\App::buildAppNamespace($app) . '\\AppInfo\\Application';
62
-		if (class_exists($applicationClassName)) {
63
-			$application = new $applicationClassName();
64
-			$this->addToAssertionCount(1);
65
-		} else {
66
-			$application = new \OCP\AppFramework\App($app);
67
-			$this->addToAssertionCount(1);
68
-		}
69
-
70
-		if (isset($appInfo['background-jobs'])) {
71
-			foreach ($appInfo['background-jobs'] as $job) {
72
-				$this->assertTrue(class_exists($job), 'Asserting background job "' . $job . '" exists');
73
-				$this->assertInstanceOf($job, \OC::$server->query($job));
74
-			}
75
-		}
76
-
77
-		if (isset($appInfo['two-factor-providers'])) {
78
-			foreach ($appInfo['two-factor-providers'] as $provider) {
79
-				$this->assertTrue(class_exists($provider), 'Asserting two-factor providers "' . $provider . '" exists');
80
-				$this->assertInstanceOf($provider, \OC::$server->query($provider));
81
-			}
82
-		}
83
-
84
-		if (isset($appInfo['commands'])) {
85
-			foreach ($appInfo['commands'] as $command) {
86
-				$this->assertTrue(class_exists($command), 'Asserting command "' . $command . '" exists');
87
-				$this->assertInstanceOf($command, \OC::$server->query($command));
88
-			}
89
-		}
90
-
91
-		if (isset($appInfo['repair-steps']['pre-migration'])) {
92
-			foreach ($appInfo['repair-steps']['pre-migration'] as $migration) {
93
-				$this->assertTrue(class_exists($migration), 'Asserting pre-migration "' . $migration . '" exists');
94
-				$this->assertInstanceOf($migration, \OC::$server->query($migration));
95
-			}
96
-		}
97
-
98
-		if (isset($appInfo['repair-steps']['post-migration'])) {
99
-			foreach ($appInfo['repair-steps']['post-migration'] as $migration) {
100
-				$this->assertTrue(class_exists($migration), 'Asserting post-migration "' . $migration . '" exists');
101
-				$this->assertInstanceOf($migration, \OC::$server->query($migration));
102
-			}
103
-		}
104
-
105
-		if (isset($appInfo['repair-steps']['live-migration'])) {
106
-			foreach ($appInfo['repair-steps']['live-migration'] as $migration) {
107
-				$this->assertTrue(class_exists($migration), 'Asserting live-migration "' . $migration . '" exists');
108
-				$this->assertInstanceOf($migration, \OC::$server->query($migration));
109
-			}
110
-		}
111
-
112
-		if (isset($appInfo['repair-steps']['install'])) {
113
-			foreach ($appInfo['repair-steps']['install'] as $migration) {
114
-				$this->assertTrue(class_exists($migration), 'Asserting install-migration "' . $migration . '" exists');
115
-				$this->assertInstanceOf($migration, \OC::$server->query($migration));
116
-			}
117
-		}
118
-
119
-		if (isset($appInfo['repair-steps']['uninstall'])) {
120
-			foreach ($appInfo['repair-steps']['uninstall'] as $migration) {
121
-				$this->assertTrue(class_exists($migration), 'Asserting uninstall-migration "' . $migration . '" exists');
122
-				$this->assertInstanceOf($migration, \OC::$server->query($migration));
123
-			}
124
-		}
125
-
126
-		if (isset($appInfo['commands'])) {
127
-			foreach ($appInfo['commands'] as $command) {
128
-				$this->assertTrue(class_exists($command), 'Asserting command "' . $command . '"exists');
129
-				$this->assertInstanceOf($command, \OC::$server->query($command));
130
-			}
131
-		}
132
-	}
19
+    private IAppManager $appManager;
20
+
21
+    protected function setUp(): void {
22
+        parent::setUp();
23
+        $this->appManager = Server::get(IAppManager::class);
24
+    }
25
+
26
+    public static function dataApps(): array {
27
+        return [
28
+            ['admin_audit'],
29
+            ['comments'],
30
+            ['dav'],
31
+            ['encryption'],
32
+            ['federatedfilesharing'],
33
+            ['federation'],
34
+            ['files'],
35
+            ['files_external'],
36
+            ['files_sharing'],
37
+            ['files_trashbin'],
38
+            ['files_versions'],
39
+            ['provisioning_api'],
40
+            ['systemtags'],
41
+            ['theming'],
42
+            ['settings'],
43
+            ['twofactor_backupcodes'],
44
+            ['updatenotification'],
45
+            ['user_ldap'],
46
+            ['workflowengine'],
47
+        ];
48
+    }
49
+
50
+    /**
51
+     * @dataProvider dataApps
52
+     *
53
+     * @param string $app
54
+     */
55
+    public function testClasses($app): void {
56
+        $appInfo = $this->appManager->getAppInfo($app);
57
+        $appPath = $this->appManager->getAppPath($app);
58
+        \OC_App::registerAutoloading($app, $appPath);
59
+
60
+        //Add the appcontainer
61
+        $applicationClassName = \OCP\AppFramework\App::buildAppNamespace($app) . '\\AppInfo\\Application';
62
+        if (class_exists($applicationClassName)) {
63
+            $application = new $applicationClassName();
64
+            $this->addToAssertionCount(1);
65
+        } else {
66
+            $application = new \OCP\AppFramework\App($app);
67
+            $this->addToAssertionCount(1);
68
+        }
69
+
70
+        if (isset($appInfo['background-jobs'])) {
71
+            foreach ($appInfo['background-jobs'] as $job) {
72
+                $this->assertTrue(class_exists($job), 'Asserting background job "' . $job . '" exists');
73
+                $this->assertInstanceOf($job, \OC::$server->query($job));
74
+            }
75
+        }
76
+
77
+        if (isset($appInfo['two-factor-providers'])) {
78
+            foreach ($appInfo['two-factor-providers'] as $provider) {
79
+                $this->assertTrue(class_exists($provider), 'Asserting two-factor providers "' . $provider . '" exists');
80
+                $this->assertInstanceOf($provider, \OC::$server->query($provider));
81
+            }
82
+        }
83
+
84
+        if (isset($appInfo['commands'])) {
85
+            foreach ($appInfo['commands'] as $command) {
86
+                $this->assertTrue(class_exists($command), 'Asserting command "' . $command . '" exists');
87
+                $this->assertInstanceOf($command, \OC::$server->query($command));
88
+            }
89
+        }
90
+
91
+        if (isset($appInfo['repair-steps']['pre-migration'])) {
92
+            foreach ($appInfo['repair-steps']['pre-migration'] as $migration) {
93
+                $this->assertTrue(class_exists($migration), 'Asserting pre-migration "' . $migration . '" exists');
94
+                $this->assertInstanceOf($migration, \OC::$server->query($migration));
95
+            }
96
+        }
97
+
98
+        if (isset($appInfo['repair-steps']['post-migration'])) {
99
+            foreach ($appInfo['repair-steps']['post-migration'] as $migration) {
100
+                $this->assertTrue(class_exists($migration), 'Asserting post-migration "' . $migration . '" exists');
101
+                $this->assertInstanceOf($migration, \OC::$server->query($migration));
102
+            }
103
+        }
104
+
105
+        if (isset($appInfo['repair-steps']['live-migration'])) {
106
+            foreach ($appInfo['repair-steps']['live-migration'] as $migration) {
107
+                $this->assertTrue(class_exists($migration), 'Asserting live-migration "' . $migration . '" exists');
108
+                $this->assertInstanceOf($migration, \OC::$server->query($migration));
109
+            }
110
+        }
111
+
112
+        if (isset($appInfo['repair-steps']['install'])) {
113
+            foreach ($appInfo['repair-steps']['install'] as $migration) {
114
+                $this->assertTrue(class_exists($migration), 'Asserting install-migration "' . $migration . '" exists');
115
+                $this->assertInstanceOf($migration, \OC::$server->query($migration));
116
+            }
117
+        }
118
+
119
+        if (isset($appInfo['repair-steps']['uninstall'])) {
120
+            foreach ($appInfo['repair-steps']['uninstall'] as $migration) {
121
+                $this->assertTrue(class_exists($migration), 'Asserting uninstall-migration "' . $migration . '" exists');
122
+                $this->assertInstanceOf($migration, \OC::$server->query($migration));
123
+            }
124
+        }
125
+
126
+        if (isset($appInfo['commands'])) {
127
+            foreach ($appInfo['commands'] as $command) {
128
+                $this->assertTrue(class_exists($command), 'Asserting command "' . $command . '"exists');
129
+                $this->assertInstanceOf($command, \OC::$server->query($command));
130
+            }
131
+        }
132
+    }
133 133
 }
Please login to merge, or discard this patch.
tests/lib/LargeFileHelperGetFileSizeTest.php 2 patches
Indentation   +62 added lines, -62 removed lines patch added patch discarded remove patch
@@ -14,72 +14,72 @@
 block discarded – undo
14 14
  * Large files are not considered yet.
15 15
  */
16 16
 class LargeFileHelperGetFileSizeTest extends TestCase {
17
-	/** @var string */
18
-	protected $filename;
19
-	/** @var int */
20
-	protected $fileSize;
21
-	/** @var \OC\LargeFileHelper */
22
-	protected $helper;
17
+    /** @var string */
18
+    protected $filename;
19
+    /** @var int */
20
+    protected $fileSize;
21
+    /** @var \OC\LargeFileHelper */
22
+    protected $helper;
23 23
 
24
-	protected function setUp(): void {
25
-		parent::setUp();
26
-		$this->helper = new \OC\LargeFileHelper();
27
-	}
24
+    protected function setUp(): void {
25
+        parent::setUp();
26
+        $this->helper = new \OC\LargeFileHelper();
27
+    }
28 28
 
29
-	public static function dataFileNameProvider(): array {
30
-		$path = dirname(__DIR__) . DIRECTORY_SEPARATOR . 'data' . DIRECTORY_SEPARATOR;
29
+    public static function dataFileNameProvider(): array {
30
+        $path = dirname(__DIR__) . DIRECTORY_SEPARATOR . 'data' . DIRECTORY_SEPARATOR;
31 31
 
32
-		return [
33
-			[ $path . 'lorem.txt', 446 ],
34
-			[ $path . 'strängé filename (duplicate #2).txt', 446 ],
35
-		];
36
-	}
32
+        return [
33
+            [ $path . 'lorem.txt', 446 ],
34
+            [ $path . 'strängé filename (duplicate #2).txt', 446 ],
35
+        ];
36
+    }
37 37
 
38
-	/**
39
-	 * @dataProvider dataFileNameProvider
40
-	 */
41
-	public function XtestGetFileSizeViaCurl($filename, $fileSize) {
42
-		if (!extension_loaded('curl')) {
43
-			$this->markTestSkipped(
44
-				'The PHP curl extension is required for this test.'
45
-			);
46
-		}
47
-		if (\OC::$server->get(IniGetWrapper::class)->getString('open_basedir') !== '') {
48
-			$this->markTestSkipped(
49
-				'The PHP curl extension does not work with the file:// protocol when open_basedir is enabled.'
50
-			);
51
-		}
52
-		$this->assertSame(
53
-			$fileSize,
54
-			$this->helper->getFileSizeViaCurl($filename)
55
-		);
56
-	}
38
+    /**
39
+     * @dataProvider dataFileNameProvider
40
+     */
41
+    public function XtestGetFileSizeViaCurl($filename, $fileSize) {
42
+        if (!extension_loaded('curl')) {
43
+            $this->markTestSkipped(
44
+                'The PHP curl extension is required for this test.'
45
+            );
46
+        }
47
+        if (\OC::$server->get(IniGetWrapper::class)->getString('open_basedir') !== '') {
48
+            $this->markTestSkipped(
49
+                'The PHP curl extension does not work with the file:// protocol when open_basedir is enabled.'
50
+            );
51
+        }
52
+        $this->assertSame(
53
+            $fileSize,
54
+            $this->helper->getFileSizeViaCurl($filename)
55
+        );
56
+    }
57 57
 
58
-	/**
59
-	 * @dataProvider dataFileNameProvider
60
-	 */
61
-	public function testGetFileSizeViaExec($filename, $fileSize): void {
62
-		if (escapeshellarg('strängé') !== '\'strängé\'') {
63
-			$this->markTestSkipped('Your escapeshell args removes accents');
64
-		}
65
-		if (!\OCP\Util::isFunctionEnabled('exec')) {
66
-			$this->markTestSkipped(
67
-				'The exec() function needs to be enabled for this test.'
68
-			);
69
-		}
70
-		$this->assertSame(
71
-			$fileSize,
72
-			$this->helper->getFileSizeViaExec($filename)
73
-		);
74
-	}
58
+    /**
59
+     * @dataProvider dataFileNameProvider
60
+     */
61
+    public function testGetFileSizeViaExec($filename, $fileSize): void {
62
+        if (escapeshellarg('strängé') !== '\'strängé\'') {
63
+            $this->markTestSkipped('Your escapeshell args removes accents');
64
+        }
65
+        if (!\OCP\Util::isFunctionEnabled('exec')) {
66
+            $this->markTestSkipped(
67
+                'The exec() function needs to be enabled for this test.'
68
+            );
69
+        }
70
+        $this->assertSame(
71
+            $fileSize,
72
+            $this->helper->getFileSizeViaExec($filename)
73
+        );
74
+    }
75 75
 
76
-	/**
77
-	 * @dataProvider dataFileNameProvider
78
-	 */
79
-	public function testGetFileSizeNative($filename, $fileSize): void {
80
-		$this->assertSame(
81
-			$fileSize,
82
-			$this->helper->getFileSizeNative($filename)
83
-		);
84
-	}
76
+    /**
77
+     * @dataProvider dataFileNameProvider
78
+     */
79
+    public function testGetFileSizeNative($filename, $fileSize): void {
80
+        $this->assertSame(
81
+            $fileSize,
82
+            $this->helper->getFileSizeNative($filename)
83
+        );
84
+    }
85 85
 }
Please login to merge, or discard this patch.
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -27,11 +27,11 @@
 block discarded – undo
27 27
 	}
28 28
 
29 29
 	public static function dataFileNameProvider(): array {
30
-		$path = dirname(__DIR__) . DIRECTORY_SEPARATOR . 'data' . DIRECTORY_SEPARATOR;
30
+		$path = dirname(__DIR__).DIRECTORY_SEPARATOR.'data'.DIRECTORY_SEPARATOR;
31 31
 
32 32
 		return [
33
-			[ $path . 'lorem.txt', 446 ],
34
-			[ $path . 'strängé filename (duplicate #2).txt', 446 ],
33
+			[$path.'lorem.txt', 446],
34
+			[$path.'strängé filename (duplicate #2).txt', 446],
35 35
 		];
36 36
 	}
37 37
 
Please login to merge, or discard this patch.
tests/lib/Memcache/FactoryTest.php 1 patch
Indentation   +106 added lines, -106 removed lines patch added patch discarded remove patch
@@ -12,129 +12,129 @@
 block discarded – undo
12 12
 use Psr\Log\LoggerInterface;
13 13
 
14 14
 class Test_Factory_Available_Cache1 extends NullCache {
15
-	public function __construct($prefix = '') {
16
-	}
15
+    public function __construct($prefix = '') {
16
+    }
17 17
 
18
-	public static function isAvailable(): bool {
19
-		return true;
20
-	}
18
+    public static function isAvailable(): bool {
19
+        return true;
20
+    }
21 21
 }
22 22
 
23 23
 class Test_Factory_Available_Cache2 extends NullCache {
24
-	public function __construct($prefix = '') {
25
-	}
24
+    public function __construct($prefix = '') {
25
+    }
26 26
 
27
-	public static function isAvailable(): bool {
28
-		return true;
29
-	}
27
+    public static function isAvailable(): bool {
28
+        return true;
29
+    }
30 30
 }
31 31
 
32 32
 class Test_Factory_Unavailable_Cache1 extends NullCache {
33
-	public function __construct($prefix = '') {
34
-	}
33
+    public function __construct($prefix = '') {
34
+    }
35 35
 
36
-	public static function isAvailable(): bool {
37
-		return false;
38
-	}
36
+    public static function isAvailable(): bool {
37
+        return false;
38
+    }
39 39
 }
40 40
 
41 41
 class Test_Factory_Unavailable_Cache2 extends NullCache {
42
-	public function __construct($prefix = '') {
43
-	}
42
+    public function __construct($prefix = '') {
43
+    }
44 44
 
45
-	public static function isAvailable(): bool {
46
-		return false;
47
-	}
45
+    public static function isAvailable(): bool {
46
+        return false;
47
+    }
48 48
 }
49 49
 
50 50
 /**
51 51
  * @group Memcache
52 52
  */
53 53
 class FactoryTest extends \Test\TestCase {
54
-	public const AVAILABLE1 = '\\Test\\Memcache\\Test_Factory_Available_Cache1';
55
-	public const AVAILABLE2 = '\\Test\\Memcache\\Test_Factory_Available_Cache2';
56
-	public const UNAVAILABLE1 = '\\Test\\Memcache\\Test_Factory_Unavailable_Cache1';
57
-	public const UNAVAILABLE2 = '\\Test\\Memcache\\Test_Factory_Unavailable_Cache2';
58
-
59
-	public static function cacheAvailabilityProvider(): array {
60
-		return [
61
-			[
62
-				// local and distributed available
63
-				self::AVAILABLE1, self::AVAILABLE2, null,
64
-				self::AVAILABLE1, self::AVAILABLE2, \OC\Memcache\Factory::NULL_CACHE
65
-			],
66
-			[
67
-				// local and distributed null
68
-				null, null, null,
69
-				\OC\Memcache\Factory::NULL_CACHE, \OC\Memcache\Factory::NULL_CACHE, \OC\Memcache\Factory::NULL_CACHE
70
-			],
71
-			[
72
-				// local available, distributed null (most common scenario)
73
-				self::AVAILABLE1, null, null,
74
-				self::AVAILABLE1, self::AVAILABLE1, \OC\Memcache\Factory::NULL_CACHE
75
-			],
76
-			[
77
-				// locking cache available
78
-				null, null, self::AVAILABLE1,
79
-				\OC\Memcache\Factory::NULL_CACHE, \OC\Memcache\Factory::NULL_CACHE, self::AVAILABLE1
80
-			],
81
-			[
82
-				// locking cache unavailable: no exception here in the factory
83
-				null, null, self::UNAVAILABLE1,
84
-				\OC\Memcache\Factory::NULL_CACHE, \OC\Memcache\Factory::NULL_CACHE, \OC\Memcache\Factory::NULL_CACHE
85
-			]
86
-		];
87
-	}
88
-
89
-	public static function cacheUnavailableProvider(): array {
90
-		return [
91
-			[
92
-				// local available, distributed unavailable
93
-				self::AVAILABLE1, self::UNAVAILABLE1
94
-			],
95
-			[
96
-				// local unavailable, distributed available
97
-				self::UNAVAILABLE1, self::AVAILABLE1
98
-			],
99
-			[
100
-				// local and distributed unavailable
101
-				self::UNAVAILABLE1, self::UNAVAILABLE2
102
-			],
103
-		];
104
-	}
105
-
106
-	/**
107
-	 * @dataProvider cacheAvailabilityProvider
108
-	 */
109
-	public function testCacheAvailability($localCache, $distributedCache, $lockingCache,
110
-		$expectedLocalCache, $expectedDistributedCache, $expectedLockingCache): void {
111
-		$logger = $this->getMockBuilder(LoggerInterface::class)->getMock();
112
-		$profiler = $this->getMockBuilder(IProfiler::class)->getMock();
113
-		$factory = new \OC\Memcache\Factory(fn () => 'abc', $logger, $profiler, $localCache, $distributedCache, $lockingCache);
114
-		$this->assertTrue(is_a($factory->createLocal(), $expectedLocalCache));
115
-		$this->assertTrue(is_a($factory->createDistributed(), $expectedDistributedCache));
116
-		$this->assertTrue(is_a($factory->createLocking(), $expectedLockingCache));
117
-	}
118
-
119
-	/**
120
-	 * @dataProvider cacheUnavailableProvider
121
-	 */
122
-	public function testCacheNotAvailableException($localCache, $distributedCache): void {
123
-		$this->expectException(\OCP\HintException::class);
124
-
125
-		$logger = $this->getMockBuilder(LoggerInterface::class)->getMock();
126
-		$profiler = $this->getMockBuilder(IProfiler::class)->getMock();
127
-		new \OC\Memcache\Factory(fn () => 'abc', $logger, $profiler, $localCache, $distributedCache);
128
-	}
129
-
130
-	public function testCreateInMemory(): void {
131
-		$logger = $this->getMockBuilder(LoggerInterface::class)->getMock();
132
-		$profiler = $this->getMockBuilder(IProfiler::class)->getMock();
133
-		$factory = new \OC\Memcache\Factory(fn () => 'abc', $logger, $profiler, null, null, null);
134
-
135
-		$cache = $factory->createInMemory();
136
-		$cache->set('test', 48);
137
-
138
-		self::assertSame(48, $cache->get('test'));
139
-	}
54
+    public const AVAILABLE1 = '\\Test\\Memcache\\Test_Factory_Available_Cache1';
55
+    public const AVAILABLE2 = '\\Test\\Memcache\\Test_Factory_Available_Cache2';
56
+    public const UNAVAILABLE1 = '\\Test\\Memcache\\Test_Factory_Unavailable_Cache1';
57
+    public const UNAVAILABLE2 = '\\Test\\Memcache\\Test_Factory_Unavailable_Cache2';
58
+
59
+    public static function cacheAvailabilityProvider(): array {
60
+        return [
61
+            [
62
+                // local and distributed available
63
+                self::AVAILABLE1, self::AVAILABLE2, null,
64
+                self::AVAILABLE1, self::AVAILABLE2, \OC\Memcache\Factory::NULL_CACHE
65
+            ],
66
+            [
67
+                // local and distributed null
68
+                null, null, null,
69
+                \OC\Memcache\Factory::NULL_CACHE, \OC\Memcache\Factory::NULL_CACHE, \OC\Memcache\Factory::NULL_CACHE
70
+            ],
71
+            [
72
+                // local available, distributed null (most common scenario)
73
+                self::AVAILABLE1, null, null,
74
+                self::AVAILABLE1, self::AVAILABLE1, \OC\Memcache\Factory::NULL_CACHE
75
+            ],
76
+            [
77
+                // locking cache available
78
+                null, null, self::AVAILABLE1,
79
+                \OC\Memcache\Factory::NULL_CACHE, \OC\Memcache\Factory::NULL_CACHE, self::AVAILABLE1
80
+            ],
81
+            [
82
+                // locking cache unavailable: no exception here in the factory
83
+                null, null, self::UNAVAILABLE1,
84
+                \OC\Memcache\Factory::NULL_CACHE, \OC\Memcache\Factory::NULL_CACHE, \OC\Memcache\Factory::NULL_CACHE
85
+            ]
86
+        ];
87
+    }
88
+
89
+    public static function cacheUnavailableProvider(): array {
90
+        return [
91
+            [
92
+                // local available, distributed unavailable
93
+                self::AVAILABLE1, self::UNAVAILABLE1
94
+            ],
95
+            [
96
+                // local unavailable, distributed available
97
+                self::UNAVAILABLE1, self::AVAILABLE1
98
+            ],
99
+            [
100
+                // local and distributed unavailable
101
+                self::UNAVAILABLE1, self::UNAVAILABLE2
102
+            ],
103
+        ];
104
+    }
105
+
106
+    /**
107
+     * @dataProvider cacheAvailabilityProvider
108
+     */
109
+    public function testCacheAvailability($localCache, $distributedCache, $lockingCache,
110
+        $expectedLocalCache, $expectedDistributedCache, $expectedLockingCache): void {
111
+        $logger = $this->getMockBuilder(LoggerInterface::class)->getMock();
112
+        $profiler = $this->getMockBuilder(IProfiler::class)->getMock();
113
+        $factory = new \OC\Memcache\Factory(fn () => 'abc', $logger, $profiler, $localCache, $distributedCache, $lockingCache);
114
+        $this->assertTrue(is_a($factory->createLocal(), $expectedLocalCache));
115
+        $this->assertTrue(is_a($factory->createDistributed(), $expectedDistributedCache));
116
+        $this->assertTrue(is_a($factory->createLocking(), $expectedLockingCache));
117
+    }
118
+
119
+    /**
120
+     * @dataProvider cacheUnavailableProvider
121
+     */
122
+    public function testCacheNotAvailableException($localCache, $distributedCache): void {
123
+        $this->expectException(\OCP\HintException::class);
124
+
125
+        $logger = $this->getMockBuilder(LoggerInterface::class)->getMock();
126
+        $profiler = $this->getMockBuilder(IProfiler::class)->getMock();
127
+        new \OC\Memcache\Factory(fn () => 'abc', $logger, $profiler, $localCache, $distributedCache);
128
+    }
129
+
130
+    public function testCreateInMemory(): void {
131
+        $logger = $this->getMockBuilder(LoggerInterface::class)->getMock();
132
+        $profiler = $this->getMockBuilder(IProfiler::class)->getMock();
133
+        $factory = new \OC\Memcache\Factory(fn () => 'abc', $logger, $profiler, null, null, null);
134
+
135
+        $cache = $factory->createInMemory();
136
+        $cache->set('test', 48);
137
+
138
+        self::assertSame(48, $cache->get('test'));
139
+    }
140 140
 }
Please login to merge, or discard this patch.
tests/lib/Encryption/UtilTest.php 1 patch
Indentation   +238 added lines, -238 removed lines patch added patch discarded remove patch
@@ -15,242 +15,242 @@
 block discarded – undo
15 15
 use Test\TestCase;
16 16
 
17 17
 class UtilTest extends TestCase {
18
-	/**
19
-	 * block size will always be 8192 for a PHP stream
20
-	 *
21
-	 * @see https://bugs.php.net/bug.php?id=21641
22
-	 */
23
-	protected static int $headerSize = 8192;
24
-
25
-	/** @var \PHPUnit\Framework\MockObject\MockObject */
26
-	protected $view;
27
-
28
-	/** @var \PHPUnit\Framework\MockObject\MockObject|IUserManager */
29
-	protected $userManager;
30
-
31
-	/** @var \PHPUnit\Framework\MockObject\MockObject|IGroupManager */
32
-	protected $groupManager;
33
-
34
-	/** @var \PHPUnit\Framework\MockObject\MockObject|IConfig */
35
-	private $config;
36
-	private Util $util;
37
-
38
-	protected function setUp(): void {
39
-		parent::setUp();
40
-		$this->view = $this->getMockBuilder(View::class)
41
-			->disableOriginalConstructor()
42
-			->getMock();
43
-
44
-		$this->userManager = $this->createMock(IUserManager::class);
45
-		$this->groupManager = $this->createMock(IGroupManager::class);
46
-		$this->config = $this->createMock(IConfig::class);
47
-
48
-		$this->util = new Util(
49
-			$this->view,
50
-			$this->userManager,
51
-			$this->groupManager,
52
-			$this->config
53
-		);
54
-	}
55
-
56
-	/**
57
-	 * @dataProvider providesHeadersForEncryptionModule
58
-	 */
59
-	public function testGetEncryptionModuleId($expected, $header): void {
60
-		$id = $this->util->getEncryptionModuleId($header);
61
-		$this->assertEquals($expected, $id);
62
-	}
63
-
64
-	public static function providesHeadersForEncryptionModule(): array {
65
-		return [
66
-			['', []],
67
-			['', ['1']],
68
-			[2, ['oc_encryption_module' => 2]],
69
-		];
70
-	}
71
-
72
-	/**
73
-	 * @dataProvider providesHeaders
74
-	 */
75
-	public function testCreateHeader($expected, $header, $moduleId): void {
76
-		$em = $this->createMock(IEncryptionModule::class);
77
-		$em->expects($this->any())->method('getId')->willReturn($moduleId);
78
-
79
-		$result = $this->util->createHeader($header, $em);
80
-		$this->assertEquals($expected, $result);
81
-	}
82
-
83
-	public static function providesHeaders(): array {
84
-		return [
85
-			[str_pad('HBEGIN:oc_encryption_module:0:HEND', self::$headerSize, '-', STR_PAD_RIGHT)
86
-				, [], '0'],
87
-			[str_pad('HBEGIN:oc_encryption_module:0:custom_header:foo:HEND', self::$headerSize, '-', STR_PAD_RIGHT)
88
-				, ['custom_header' => 'foo'], '0'],
89
-		];
90
-	}
91
-
92
-
93
-	public function testCreateHeaderFailed(): void {
94
-		$this->expectException(\OC\Encryption\Exceptions\EncryptionHeaderKeyExistsException::class);
95
-
96
-
97
-		$header = ['header1' => 1, 'header2' => 2, 'oc_encryption_module' => 'foo'];
98
-
99
-		$em = $this->createMock(IEncryptionModule::class);
100
-		$em->expects($this->any())->method('getId')->willReturn('moduleId');
101
-
102
-		$this->util->createHeader($header, $em);
103
-	}
104
-
105
-	/**
106
-	 * @dataProvider providePathsForTestIsExcluded
107
-	 */
108
-	public function testIsExcluded($path, $keyStorageRoot, $expected): void {
109
-		$this->config->expects($this->once())
110
-			->method('getAppValue')
111
-			->with('core', 'encryption_key_storage_root', '')
112
-			->willReturn($keyStorageRoot);
113
-		$this->userManager
114
-			->expects($this->any())
115
-			->method('userExists')
116
-			->willReturnCallback([$this, 'isExcludedCallback']);
117
-
118
-		$this->assertSame($expected,
119
-			$this->util->isExcluded($path)
120
-		);
121
-	}
122
-
123
-	public static function providePathsForTestIsExcluded(): array {
124
-		return [
125
-			['/files_encryption', '', true],
126
-			['files_encryption/foo.txt', '', true],
127
-			['test/foo.txt', '', false],
128
-			['/user1/files_encryption/foo.txt', '', true],
129
-			['/user1/files/foo.txt', '', false],
130
-			['/keyStorage/user1/files/foo.txt', 'keyStorage', true],
131
-			['/keyStorage/files_encryption', '/keyStorage', true],
132
-			['keyStorage/user1/files_encryption', '/keyStorage/', true],
133
-
134
-		];
135
-	}
136
-
137
-	public function isExcludedCallback() {
138
-		$args = func_get_args();
139
-		if ($args[0] === 'user1') {
140
-			return true;
141
-		}
142
-
143
-		return false;
144
-	}
145
-
146
-	/**
147
-	 * @dataProvider dataTestIsFile
148
-	 */
149
-	public function testIsFile($path, $expected): void {
150
-		$this->assertSame($expected,
151
-			$this->util->isFile($path)
152
-		);
153
-	}
154
-
155
-	public static function dataTestIsFile(): array {
156
-		return [
157
-			['/user/files/test.txt', true],
158
-			['/user/files', true],
159
-			['/user/files_versions/test.txt', false],
160
-			['/user/foo/files/test.txt', false],
161
-			['/files/foo/files/test.txt', false],
162
-			['/user', false],
163
-			['/user/test.txt', false],
164
-		];
165
-	}
166
-
167
-	/**
168
-	 * @dataProvider dataTestStripPartialFileExtension
169
-	 *
170
-	 * @param string $path
171
-	 * @param string $expected
172
-	 */
173
-	public function testStripPartialFileExtension($path, $expected): void {
174
-		$this->assertSame($expected,
175
-			$this->util->stripPartialFileExtension($path));
176
-	}
177
-
178
-	public static function dataTestStripPartialFileExtension(): array {
179
-		return [
180
-			['/foo/test.txt', '/foo/test.txt'],
181
-			['/foo/test.txt.part', '/foo/test.txt'],
182
-			['/foo/test.txt.ocTransferId7567846853.part', '/foo/test.txt'],
183
-			['/foo/test.txt.ocTransferId7567.part', '/foo/test.txt'],
184
-		];
185
-	}
186
-
187
-	/**
188
-	 * @dataProvider dataTestParseRawHeader
189
-	 */
190
-	public function testParseRawHeader($rawHeader, $expected): void {
191
-		$result = $this->util->parseRawHeader($rawHeader);
192
-		$this->assertSameSize($expected, $result);
193
-		foreach ($result as $key => $value) {
194
-			$this->assertArrayHasKey($key, $expected);
195
-			$this->assertSame($expected[$key], $value);
196
-		}
197
-	}
198
-
199
-	public static function dataTestParseRawHeader(): array {
200
-		return [
201
-			[str_pad('HBEGIN:oc_encryption_module:0:HEND', self::$headerSize, '-', STR_PAD_RIGHT)
202
-				, [Util::HEADER_ENCRYPTION_MODULE_KEY => '0']],
203
-			[str_pad('HBEGIN:oc_encryption_module:0:custom_header:foo:HEND', self::$headerSize, '-', STR_PAD_RIGHT)
204
-				, ['custom_header' => 'foo', Util::HEADER_ENCRYPTION_MODULE_KEY => '0']],
205
-			[str_pad('HelloWorld', self::$headerSize, '-', STR_PAD_RIGHT), []],
206
-			['', []],
207
-			[str_pad('HBEGIN:oc_encryption_module:0', self::$headerSize, '-', STR_PAD_RIGHT)
208
-				, []],
209
-			[str_pad('oc_encryption_module:0:HEND', self::$headerSize, '-', STR_PAD_RIGHT)
210
-				, []],
211
-		];
212
-	}
213
-
214
-	/**
215
-	 * @dataProvider dataTestGetFileKeyDir
216
-	 *
217
-	 * @param bool $isSystemWideMountPoint
218
-	 * @param string $storageRoot
219
-	 * @param string $expected
220
-	 */
221
-	public function testGetFileKeyDir($isSystemWideMountPoint, $storageRoot, $expected): void {
222
-		$path = '/user1/files/foo/bar.txt';
223
-		$owner = 'user1';
224
-		$relativePath = '/foo/bar.txt';
225
-
226
-		$util = $this->getMockBuilder(Util::class)
227
-			->onlyMethods(['isSystemWideMountPoint', 'getUidAndFilename', 'getKeyStorageRoot'])
228
-			->setConstructorArgs([
229
-				$this->view,
230
-				$this->userManager,
231
-				$this->groupManager,
232
-				$this->config
233
-			])
234
-			->getMock();
235
-
236
-		$util->expects($this->once())->method('getKeyStorageRoot')
237
-			->willReturn($storageRoot);
238
-		$util->expects($this->once())->method('isSystemWideMountPoint')
239
-			->willReturn($isSystemWideMountPoint);
240
-		$util->expects($this->once())->method('getUidAndFilename')
241
-			->with($path)->willReturn([$owner, $relativePath]);
242
-
243
-		$this->assertSame($expected,
244
-			$util->getFileKeyDir('OC_DEFAULT_MODULE', $path)
245
-		);
246
-	}
247
-
248
-	public static function dataTestGetFileKeyDir(): array {
249
-		return [
250
-			[false, '', '/user1/files_encryption/keys/foo/bar.txt/OC_DEFAULT_MODULE/'],
251
-			[true, '', '/files_encryption/keys/foo/bar.txt/OC_DEFAULT_MODULE/'],
252
-			[false, 'newStorageRoot', '/newStorageRoot/user1/files_encryption/keys/foo/bar.txt/OC_DEFAULT_MODULE/'],
253
-			[true, 'newStorageRoot', '/newStorageRoot/files_encryption/keys/foo/bar.txt/OC_DEFAULT_MODULE/'],
254
-		];
255
-	}
18
+    /**
19
+     * block size will always be 8192 for a PHP stream
20
+     *
21
+     * @see https://bugs.php.net/bug.php?id=21641
22
+     */
23
+    protected static int $headerSize = 8192;
24
+
25
+    /** @var \PHPUnit\Framework\MockObject\MockObject */
26
+    protected $view;
27
+
28
+    /** @var \PHPUnit\Framework\MockObject\MockObject|IUserManager */
29
+    protected $userManager;
30
+
31
+    /** @var \PHPUnit\Framework\MockObject\MockObject|IGroupManager */
32
+    protected $groupManager;
33
+
34
+    /** @var \PHPUnit\Framework\MockObject\MockObject|IConfig */
35
+    private $config;
36
+    private Util $util;
37
+
38
+    protected function setUp(): void {
39
+        parent::setUp();
40
+        $this->view = $this->getMockBuilder(View::class)
41
+            ->disableOriginalConstructor()
42
+            ->getMock();
43
+
44
+        $this->userManager = $this->createMock(IUserManager::class);
45
+        $this->groupManager = $this->createMock(IGroupManager::class);
46
+        $this->config = $this->createMock(IConfig::class);
47
+
48
+        $this->util = new Util(
49
+            $this->view,
50
+            $this->userManager,
51
+            $this->groupManager,
52
+            $this->config
53
+        );
54
+    }
55
+
56
+    /**
57
+     * @dataProvider providesHeadersForEncryptionModule
58
+     */
59
+    public function testGetEncryptionModuleId($expected, $header): void {
60
+        $id = $this->util->getEncryptionModuleId($header);
61
+        $this->assertEquals($expected, $id);
62
+    }
63
+
64
+    public static function providesHeadersForEncryptionModule(): array {
65
+        return [
66
+            ['', []],
67
+            ['', ['1']],
68
+            [2, ['oc_encryption_module' => 2]],
69
+        ];
70
+    }
71
+
72
+    /**
73
+     * @dataProvider providesHeaders
74
+     */
75
+    public function testCreateHeader($expected, $header, $moduleId): void {
76
+        $em = $this->createMock(IEncryptionModule::class);
77
+        $em->expects($this->any())->method('getId')->willReturn($moduleId);
78
+
79
+        $result = $this->util->createHeader($header, $em);
80
+        $this->assertEquals($expected, $result);
81
+    }
82
+
83
+    public static function providesHeaders(): array {
84
+        return [
85
+            [str_pad('HBEGIN:oc_encryption_module:0:HEND', self::$headerSize, '-', STR_PAD_RIGHT)
86
+                , [], '0'],
87
+            [str_pad('HBEGIN:oc_encryption_module:0:custom_header:foo:HEND', self::$headerSize, '-', STR_PAD_RIGHT)
88
+                , ['custom_header' => 'foo'], '0'],
89
+        ];
90
+    }
91
+
92
+
93
+    public function testCreateHeaderFailed(): void {
94
+        $this->expectException(\OC\Encryption\Exceptions\EncryptionHeaderKeyExistsException::class);
95
+
96
+
97
+        $header = ['header1' => 1, 'header2' => 2, 'oc_encryption_module' => 'foo'];
98
+
99
+        $em = $this->createMock(IEncryptionModule::class);
100
+        $em->expects($this->any())->method('getId')->willReturn('moduleId');
101
+
102
+        $this->util->createHeader($header, $em);
103
+    }
104
+
105
+    /**
106
+     * @dataProvider providePathsForTestIsExcluded
107
+     */
108
+    public function testIsExcluded($path, $keyStorageRoot, $expected): void {
109
+        $this->config->expects($this->once())
110
+            ->method('getAppValue')
111
+            ->with('core', 'encryption_key_storage_root', '')
112
+            ->willReturn($keyStorageRoot);
113
+        $this->userManager
114
+            ->expects($this->any())
115
+            ->method('userExists')
116
+            ->willReturnCallback([$this, 'isExcludedCallback']);
117
+
118
+        $this->assertSame($expected,
119
+            $this->util->isExcluded($path)
120
+        );
121
+    }
122
+
123
+    public static function providePathsForTestIsExcluded(): array {
124
+        return [
125
+            ['/files_encryption', '', true],
126
+            ['files_encryption/foo.txt', '', true],
127
+            ['test/foo.txt', '', false],
128
+            ['/user1/files_encryption/foo.txt', '', true],
129
+            ['/user1/files/foo.txt', '', false],
130
+            ['/keyStorage/user1/files/foo.txt', 'keyStorage', true],
131
+            ['/keyStorage/files_encryption', '/keyStorage', true],
132
+            ['keyStorage/user1/files_encryption', '/keyStorage/', true],
133
+
134
+        ];
135
+    }
136
+
137
+    public function isExcludedCallback() {
138
+        $args = func_get_args();
139
+        if ($args[0] === 'user1') {
140
+            return true;
141
+        }
142
+
143
+        return false;
144
+    }
145
+
146
+    /**
147
+     * @dataProvider dataTestIsFile
148
+     */
149
+    public function testIsFile($path, $expected): void {
150
+        $this->assertSame($expected,
151
+            $this->util->isFile($path)
152
+        );
153
+    }
154
+
155
+    public static function dataTestIsFile(): array {
156
+        return [
157
+            ['/user/files/test.txt', true],
158
+            ['/user/files', true],
159
+            ['/user/files_versions/test.txt', false],
160
+            ['/user/foo/files/test.txt', false],
161
+            ['/files/foo/files/test.txt', false],
162
+            ['/user', false],
163
+            ['/user/test.txt', false],
164
+        ];
165
+    }
166
+
167
+    /**
168
+     * @dataProvider dataTestStripPartialFileExtension
169
+     *
170
+     * @param string $path
171
+     * @param string $expected
172
+     */
173
+    public function testStripPartialFileExtension($path, $expected): void {
174
+        $this->assertSame($expected,
175
+            $this->util->stripPartialFileExtension($path));
176
+    }
177
+
178
+    public static function dataTestStripPartialFileExtension(): array {
179
+        return [
180
+            ['/foo/test.txt', '/foo/test.txt'],
181
+            ['/foo/test.txt.part', '/foo/test.txt'],
182
+            ['/foo/test.txt.ocTransferId7567846853.part', '/foo/test.txt'],
183
+            ['/foo/test.txt.ocTransferId7567.part', '/foo/test.txt'],
184
+        ];
185
+    }
186
+
187
+    /**
188
+     * @dataProvider dataTestParseRawHeader
189
+     */
190
+    public function testParseRawHeader($rawHeader, $expected): void {
191
+        $result = $this->util->parseRawHeader($rawHeader);
192
+        $this->assertSameSize($expected, $result);
193
+        foreach ($result as $key => $value) {
194
+            $this->assertArrayHasKey($key, $expected);
195
+            $this->assertSame($expected[$key], $value);
196
+        }
197
+    }
198
+
199
+    public static function dataTestParseRawHeader(): array {
200
+        return [
201
+            [str_pad('HBEGIN:oc_encryption_module:0:HEND', self::$headerSize, '-', STR_PAD_RIGHT)
202
+                , [Util::HEADER_ENCRYPTION_MODULE_KEY => '0']],
203
+            [str_pad('HBEGIN:oc_encryption_module:0:custom_header:foo:HEND', self::$headerSize, '-', STR_PAD_RIGHT)
204
+                , ['custom_header' => 'foo', Util::HEADER_ENCRYPTION_MODULE_KEY => '0']],
205
+            [str_pad('HelloWorld', self::$headerSize, '-', STR_PAD_RIGHT), []],
206
+            ['', []],
207
+            [str_pad('HBEGIN:oc_encryption_module:0', self::$headerSize, '-', STR_PAD_RIGHT)
208
+                , []],
209
+            [str_pad('oc_encryption_module:0:HEND', self::$headerSize, '-', STR_PAD_RIGHT)
210
+                , []],
211
+        ];
212
+    }
213
+
214
+    /**
215
+     * @dataProvider dataTestGetFileKeyDir
216
+     *
217
+     * @param bool $isSystemWideMountPoint
218
+     * @param string $storageRoot
219
+     * @param string $expected
220
+     */
221
+    public function testGetFileKeyDir($isSystemWideMountPoint, $storageRoot, $expected): void {
222
+        $path = '/user1/files/foo/bar.txt';
223
+        $owner = 'user1';
224
+        $relativePath = '/foo/bar.txt';
225
+
226
+        $util = $this->getMockBuilder(Util::class)
227
+            ->onlyMethods(['isSystemWideMountPoint', 'getUidAndFilename', 'getKeyStorageRoot'])
228
+            ->setConstructorArgs([
229
+                $this->view,
230
+                $this->userManager,
231
+                $this->groupManager,
232
+                $this->config
233
+            ])
234
+            ->getMock();
235
+
236
+        $util->expects($this->once())->method('getKeyStorageRoot')
237
+            ->willReturn($storageRoot);
238
+        $util->expects($this->once())->method('isSystemWideMountPoint')
239
+            ->willReturn($isSystemWideMountPoint);
240
+        $util->expects($this->once())->method('getUidAndFilename')
241
+            ->with($path)->willReturn([$owner, $relativePath]);
242
+
243
+        $this->assertSame($expected,
244
+            $util->getFileKeyDir('OC_DEFAULT_MODULE', $path)
245
+        );
246
+    }
247
+
248
+    public static function dataTestGetFileKeyDir(): array {
249
+        return [
250
+            [false, '', '/user1/files_encryption/keys/foo/bar.txt/OC_DEFAULT_MODULE/'],
251
+            [true, '', '/files_encryption/keys/foo/bar.txt/OC_DEFAULT_MODULE/'],
252
+            [false, 'newStorageRoot', '/newStorageRoot/user1/files_encryption/keys/foo/bar.txt/OC_DEFAULT_MODULE/'],
253
+            [true, 'newStorageRoot', '/newStorageRoot/files_encryption/keys/foo/bar.txt/OC_DEFAULT_MODULE/'],
254
+        ];
255
+    }
256 256
 }
Please login to merge, or discard this patch.
tests/lib/Encryption/UpdateTest.php 1 patch
Indentation   +164 added lines, -164 removed lines patch added patch discarded remove patch
@@ -23,168 +23,168 @@
 block discarded – undo
23 23
 use Test\TestCase;
24 24
 
25 25
 class UpdateTest extends TestCase {
26
-	private string $uid;
27
-	private View&MockObject $view;
28
-	private Util&MockObject $util;
29
-	private \OC\Encryption\Manager&MockObject $encryptionManager;
30
-	private IEncryptionModule&MockObject $encryptionModule;
31
-	private File&MockObject $fileHelper;
32
-	private LoggerInterface&MockObject $logger;
33
-
34
-	protected function setUp(): void {
35
-		parent::setUp();
36
-
37
-		$this->view = $this->createMock(View::class);
38
-		$this->util = $this->createMock(Util::class);
39
-		$this->encryptionManager = $this->createMock(\OC\Encryption\Manager::class);
40
-		$this->fileHelper = $this->createMock(File::class);
41
-		$this->encryptionModule = $this->createMock(IEncryptionModule::class);
42
-		$this->logger = $this->createMock(LoggerInterface::class);
43
-
44
-		$this->uid = 'testUser1';
45
-	}
46
-
47
-	private function getUserMock(string $uid): IUser&MockObject {
48
-		$user = $this->createMock(IUser::class);
49
-		$user->expects(self::any())
50
-			->method('getUID')
51
-			->willReturn($uid);
52
-		return $user;
53
-	}
54
-
55
-	private function getFileMock(string $path, string $owner): OCPFile&MockObject {
56
-		$node = $this->createMock(OCPFile::class);
57
-		$node->expects(self::atLeastOnce())
58
-			->method('getPath')
59
-			->willReturn($path);
60
-		$node->expects(self::any())
61
-			->method('getOwner')
62
-			->willReturn($this->getUserMock($owner));
63
-
64
-		return $node;
65
-	}
66
-
67
-	private function getFolderMock(string $path, string $owner): Folder&MockObject {
68
-		$node = $this->createMock(Folder::class);
69
-		$node->expects(self::atLeastOnce())
70
-			->method('getPath')
71
-			->willReturn($path);
72
-		$node->expects(self::any())
73
-			->method('getOwner')
74
-			->willReturn($this->getUserMock($owner));
75
-
76
-		return $node;
77
-	}
78
-
79
-	/**
80
-	 * @dataProvider dataTestUpdate
81
-	 *
82
-	 * @param string $path
83
-	 * @param boolean $isDir
84
-	 * @param array $allFiles
85
-	 * @param integer $numberOfFiles
86
-	 */
87
-	public function testUpdate($path, $isDir, $allFiles, $numberOfFiles): void {
88
-		$updateMock = $this->getUpdateMock(['getOwnerPath']);
89
-		$updateMock->expects($this->once())->method('getOwnerPath')
90
-			->willReturnCallback(fn (OCPFile|Folder $node) => '/user/' . $node->getPath());
91
-
92
-		$this->encryptionManager->expects($this->once())
93
-			->method('getEncryptionModule')
94
-			->willReturn($this->encryptionModule);
95
-
96
-		if ($isDir) {
97
-			$this->util->expects($this->once())
98
-				->method('getAllFiles')
99
-				->willReturn($allFiles);
100
-			$node = $this->getFolderMock($path, 'user');
101
-		} else {
102
-			$node = $this->getFileMock($path, 'user');
103
-		}
104
-
105
-		$this->fileHelper->expects($this->exactly($numberOfFiles))
106
-			->method('getAccessList')
107
-			->willReturn(['users' => [], 'public' => false]);
108
-
109
-		$this->encryptionModule->expects($this->exactly($numberOfFiles))
110
-			->method('update')
111
-			->willReturn(true);
112
-
113
-		$updateMock->update($node);
114
-	}
115
-
116
-	public static function dataTestUpdate(): array {
117
-		return [
118
-			['/user/files/foo', true, ['/user/files/foo/file1.txt', '/user/files/foo/file1.txt'], 2],
119
-			['/user/files/test.txt', false, [], 1],
120
-		];
121
-	}
122
-
123
-	/**
124
-	 * @dataProvider dataTestPostRename
125
-	 *
126
-	 * @param string $source
127
-	 * @param string $target
128
-	 */
129
-	public function testPostRename($source, $target): void {
130
-		$updateMock = $this->getUpdateMock(['update','getOwnerPath']);
131
-
132
-		$sourceNode = $this->getFileMock($source, 'user');
133
-		$targetNode = $this->getFileMock($target, 'user');
134
-
135
-		if (dirname($source) === dirname($target)) {
136
-			$updateMock->expects($this->never())->method('getOwnerPath');
137
-			$updateMock->expects($this->never())->method('update');
138
-		} else {
139
-			$updateMock->expects($this->once())->method('update')
140
-				->willReturnCallback(fn (OCPFile|Folder $node) => $this->assertSame(
141
-					$target,
142
-					$node->getPath(),
143
-					'update needs to be executed for the target destination'
144
-				));
145
-		}
146
-
147
-		$updateMock->postRename($sourceNode, $targetNode);
148
-	}
149
-
150
-	public static function dataTestPostRename(): array {
151
-		return [
152
-			['/test.txt', '/testNew.txt'],
153
-			['/folder/test.txt', '/testNew.txt'],
154
-			['/test.txt', '/folder/testNew.txt'],
155
-		];
156
-	}
157
-
158
-	public function testPostRestore(): void {
159
-		$updateMock = $this->getUpdateMock(['update']);
160
-
161
-		$updateMock->expects($this->once())->method('update')
162
-			->willReturnCallback(fn (OCPFile|Folder $node) => $this->assertSame(
163
-				'/folder/test.txt',
164
-				$node->getPath(),
165
-				'update needs to be executed for the target destination'
166
-			));
167
-
168
-		$updateMock->postRestore($this->getFileMock('/folder/test.txt', 'user'));
169
-	}
170
-
171
-	/**
172
-	 * create mock of the update method
173
-	 *
174
-	 * @param array $methods methods which should be set
175
-	 */
176
-	protected function getUpdateMock(array $methods): Update&MockObject {
177
-		return  $this->getMockBuilder(Update::class)
178
-			->setConstructorArgs(
179
-				[
180
-					$this->util,
181
-					$this->encryptionManager,
182
-					$this->fileHelper,
183
-					$this->logger,
184
-					$this->uid
185
-				]
186
-			)
187
-			->onlyMethods($methods)
188
-			->getMock();
189
-	}
26
+    private string $uid;
27
+    private View&MockObject $view;
28
+    private Util&MockObject $util;
29
+    private \OC\Encryption\Manager&MockObject $encryptionManager;
30
+    private IEncryptionModule&MockObject $encryptionModule;
31
+    private File&MockObject $fileHelper;
32
+    private LoggerInterface&MockObject $logger;
33
+
34
+    protected function setUp(): void {
35
+        parent::setUp();
36
+
37
+        $this->view = $this->createMock(View::class);
38
+        $this->util = $this->createMock(Util::class);
39
+        $this->encryptionManager = $this->createMock(\OC\Encryption\Manager::class);
40
+        $this->fileHelper = $this->createMock(File::class);
41
+        $this->encryptionModule = $this->createMock(IEncryptionModule::class);
42
+        $this->logger = $this->createMock(LoggerInterface::class);
43
+
44
+        $this->uid = 'testUser1';
45
+    }
46
+
47
+    private function getUserMock(string $uid): IUser&MockObject {
48
+        $user = $this->createMock(IUser::class);
49
+        $user->expects(self::any())
50
+            ->method('getUID')
51
+            ->willReturn($uid);
52
+        return $user;
53
+    }
54
+
55
+    private function getFileMock(string $path, string $owner): OCPFile&MockObject {
56
+        $node = $this->createMock(OCPFile::class);
57
+        $node->expects(self::atLeastOnce())
58
+            ->method('getPath')
59
+            ->willReturn($path);
60
+        $node->expects(self::any())
61
+            ->method('getOwner')
62
+            ->willReturn($this->getUserMock($owner));
63
+
64
+        return $node;
65
+    }
66
+
67
+    private function getFolderMock(string $path, string $owner): Folder&MockObject {
68
+        $node = $this->createMock(Folder::class);
69
+        $node->expects(self::atLeastOnce())
70
+            ->method('getPath')
71
+            ->willReturn($path);
72
+        $node->expects(self::any())
73
+            ->method('getOwner')
74
+            ->willReturn($this->getUserMock($owner));
75
+
76
+        return $node;
77
+    }
78
+
79
+    /**
80
+     * @dataProvider dataTestUpdate
81
+     *
82
+     * @param string $path
83
+     * @param boolean $isDir
84
+     * @param array $allFiles
85
+     * @param integer $numberOfFiles
86
+     */
87
+    public function testUpdate($path, $isDir, $allFiles, $numberOfFiles): void {
88
+        $updateMock = $this->getUpdateMock(['getOwnerPath']);
89
+        $updateMock->expects($this->once())->method('getOwnerPath')
90
+            ->willReturnCallback(fn (OCPFile|Folder $node) => '/user/' . $node->getPath());
91
+
92
+        $this->encryptionManager->expects($this->once())
93
+            ->method('getEncryptionModule')
94
+            ->willReturn($this->encryptionModule);
95
+
96
+        if ($isDir) {
97
+            $this->util->expects($this->once())
98
+                ->method('getAllFiles')
99
+                ->willReturn($allFiles);
100
+            $node = $this->getFolderMock($path, 'user');
101
+        } else {
102
+            $node = $this->getFileMock($path, 'user');
103
+        }
104
+
105
+        $this->fileHelper->expects($this->exactly($numberOfFiles))
106
+            ->method('getAccessList')
107
+            ->willReturn(['users' => [], 'public' => false]);
108
+
109
+        $this->encryptionModule->expects($this->exactly($numberOfFiles))
110
+            ->method('update')
111
+            ->willReturn(true);
112
+
113
+        $updateMock->update($node);
114
+    }
115
+
116
+    public static function dataTestUpdate(): array {
117
+        return [
118
+            ['/user/files/foo', true, ['/user/files/foo/file1.txt', '/user/files/foo/file1.txt'], 2],
119
+            ['/user/files/test.txt', false, [], 1],
120
+        ];
121
+    }
122
+
123
+    /**
124
+     * @dataProvider dataTestPostRename
125
+     *
126
+     * @param string $source
127
+     * @param string $target
128
+     */
129
+    public function testPostRename($source, $target): void {
130
+        $updateMock = $this->getUpdateMock(['update','getOwnerPath']);
131
+
132
+        $sourceNode = $this->getFileMock($source, 'user');
133
+        $targetNode = $this->getFileMock($target, 'user');
134
+
135
+        if (dirname($source) === dirname($target)) {
136
+            $updateMock->expects($this->never())->method('getOwnerPath');
137
+            $updateMock->expects($this->never())->method('update');
138
+        } else {
139
+            $updateMock->expects($this->once())->method('update')
140
+                ->willReturnCallback(fn (OCPFile|Folder $node) => $this->assertSame(
141
+                    $target,
142
+                    $node->getPath(),
143
+                    'update needs to be executed for the target destination'
144
+                ));
145
+        }
146
+
147
+        $updateMock->postRename($sourceNode, $targetNode);
148
+    }
149
+
150
+    public static function dataTestPostRename(): array {
151
+        return [
152
+            ['/test.txt', '/testNew.txt'],
153
+            ['/folder/test.txt', '/testNew.txt'],
154
+            ['/test.txt', '/folder/testNew.txt'],
155
+        ];
156
+    }
157
+
158
+    public function testPostRestore(): void {
159
+        $updateMock = $this->getUpdateMock(['update']);
160
+
161
+        $updateMock->expects($this->once())->method('update')
162
+            ->willReturnCallback(fn (OCPFile|Folder $node) => $this->assertSame(
163
+                '/folder/test.txt',
164
+                $node->getPath(),
165
+                'update needs to be executed for the target destination'
166
+            ));
167
+
168
+        $updateMock->postRestore($this->getFileMock('/folder/test.txt', 'user'));
169
+    }
170
+
171
+    /**
172
+     * create mock of the update method
173
+     *
174
+     * @param array $methods methods which should be set
175
+     */
176
+    protected function getUpdateMock(array $methods): Update&MockObject {
177
+        return  $this->getMockBuilder(Update::class)
178
+            ->setConstructorArgs(
179
+                [
180
+                    $this->util,
181
+                    $this->encryptionManager,
182
+                    $this->fileHelper,
183
+                    $this->logger,
184
+                    $this->uid
185
+                ]
186
+            )
187
+            ->onlyMethods($methods)
188
+            ->getMock();
189
+    }
190 190
 }
Please login to merge, or discard this patch.
tests/lib/Encryption/EncryptionWrapperTest.php 1 patch
Indentation   +62 added lines, -62 removed lines patch added patch discarded remove patch
@@ -19,66 +19,66 @@
 block discarded – undo
19 19
 use Test\TestCase;
20 20
 
21 21
 class EncryptionWrapperTest extends TestCase {
22
-	/** @var EncryptionWrapper */
23
-	private $instance;
24
-
25
-	/** @var \PHPUnit\Framework\MockObject\MockObject | LoggerInterface */
26
-	private $logger;
27
-
28
-	/** @var \PHPUnit\Framework\MockObject\MockObject | \OC\Encryption\Manager */
29
-	private $manager;
30
-
31
-	/** @var \PHPUnit\Framework\MockObject\MockObject | \OC\Memcache\ArrayCache */
32
-	private $arrayCache;
33
-
34
-	protected function setUp(): void {
35
-		parent::setUp();
36
-
37
-		$this->arrayCache = $this->createMock(ArrayCache::class);
38
-		$this->manager = $this->createMock(Manager::class);
39
-		$this->logger = $this->createMock(LoggerInterface::class);
40
-
41
-		$this->instance = new EncryptionWrapper($this->arrayCache, $this->manager, $this->logger);
42
-	}
43
-
44
-
45
-	/**
46
-	 * @dataProvider provideWrapStorage
47
-	 */
48
-	public function testWrapStorage($expectedWrapped, $wrappedStorages): void {
49
-		$storage = $this->getMockBuilder(IStorage::class)
50
-			->disableOriginalConstructor()
51
-			->getMock();
52
-
53
-		foreach ($wrappedStorages as $wrapper) {
54
-			$storage->expects($this->any())
55
-				->method('instanceOfStorage')
56
-				->willReturnMap([
57
-					[$wrapper, true],
58
-				]);
59
-		}
60
-
61
-		$mount = $this->getMockBuilder(IMountPoint::class)
62
-			->disableOriginalConstructor()
63
-			->getMock();
64
-
65
-		$returnedStorage = $this->instance->wrapStorage('mountPoint', $storage, $mount);
66
-
67
-		$this->assertEquals(
68
-			$expectedWrapped,
69
-			$returnedStorage->instanceOfStorage(Encryption::class),
70
-			'Asserted that the storage is (not) wrapped with encryption'
71
-		);
72
-	}
73
-
74
-	public static function provideWrapStorage(): array {
75
-		return [
76
-			// Wrap when not wrapped or not wrapped with storage
77
-			[true, []],
78
-			[true, [Storage::class]],
79
-
80
-			// Do not wrap shared storages
81
-			[false, [IDisableEncryptionStorage::class]],
82
-		];
83
-	}
22
+    /** @var EncryptionWrapper */
23
+    private $instance;
24
+
25
+    /** @var \PHPUnit\Framework\MockObject\MockObject | LoggerInterface */
26
+    private $logger;
27
+
28
+    /** @var \PHPUnit\Framework\MockObject\MockObject | \OC\Encryption\Manager */
29
+    private $manager;
30
+
31
+    /** @var \PHPUnit\Framework\MockObject\MockObject | \OC\Memcache\ArrayCache */
32
+    private $arrayCache;
33
+
34
+    protected function setUp(): void {
35
+        parent::setUp();
36
+
37
+        $this->arrayCache = $this->createMock(ArrayCache::class);
38
+        $this->manager = $this->createMock(Manager::class);
39
+        $this->logger = $this->createMock(LoggerInterface::class);
40
+
41
+        $this->instance = new EncryptionWrapper($this->arrayCache, $this->manager, $this->logger);
42
+    }
43
+
44
+
45
+    /**
46
+     * @dataProvider provideWrapStorage
47
+     */
48
+    public function testWrapStorage($expectedWrapped, $wrappedStorages): void {
49
+        $storage = $this->getMockBuilder(IStorage::class)
50
+            ->disableOriginalConstructor()
51
+            ->getMock();
52
+
53
+        foreach ($wrappedStorages as $wrapper) {
54
+            $storage->expects($this->any())
55
+                ->method('instanceOfStorage')
56
+                ->willReturnMap([
57
+                    [$wrapper, true],
58
+                ]);
59
+        }
60
+
61
+        $mount = $this->getMockBuilder(IMountPoint::class)
62
+            ->disableOriginalConstructor()
63
+            ->getMock();
64
+
65
+        $returnedStorage = $this->instance->wrapStorage('mountPoint', $storage, $mount);
66
+
67
+        $this->assertEquals(
68
+            $expectedWrapped,
69
+            $returnedStorage->instanceOfStorage(Encryption::class),
70
+            'Asserted that the storage is (not) wrapped with encryption'
71
+        );
72
+    }
73
+
74
+    public static function provideWrapStorage(): array {
75
+        return [
76
+            // Wrap when not wrapped or not wrapped with storage
77
+            [true, []],
78
+            [true, [Storage::class]],
79
+
80
+            // Do not wrap shared storages
81
+            [false, [IDisableEncryptionStorage::class]],
82
+        ];
83
+    }
84 84
 }
Please login to merge, or discard this patch.
tests/lib/Cache/FileCacheTest.php 1 patch
Indentation   +134 added lines, -134 removed lines patch added patch discarded remove patch
@@ -19,138 +19,138 @@
 block discarded – undo
19 19
  * @package Test\Cache
20 20
  */
21 21
 class FileCacheTest extends TestCache {
22
-	use UserTrait;
23
-
24
-	/**
25
-	 * @var string
26
-	 * */
27
-	private $user;
28
-	/**
29
-	 * @var string
30
-	 * */
31
-	private $datadir;
32
-	/**
33
-	 * @var \OC\Files\Storage\Storage
34
-	 * */
35
-	private $storage;
36
-	/**
37
-	 * @var \OC\Files\View
38
-	 * */
39
-	private $rootView;
40
-
41
-	public function skip() {
42
-		//$this->skipUnless(OC_User::isLoggedIn());
43
-	}
44
-
45
-	protected function setUp(): void {
46
-		parent::setUp();
47
-
48
-		//login
49
-		$this->createUser('test', 'test');
50
-
51
-		$this->user = \OC_User::getUser();
52
-		\OC_User::setUserId('test');
53
-
54
-		//clear all proxies and hooks so we can do clean testing
55
-		\OC_Hook::clear('OC_Filesystem');
56
-
57
-		/** @var IMountManager $manager */
58
-		$manager = \OC::$server->get(IMountManager::class);
59
-		$manager->removeMount('/test');
60
-
61
-		$storage = new \OC\Files\Storage\Temporary([]);
62
-		\OC\Files\Filesystem::mount($storage, [], '/test/cache');
63
-
64
-		//set up the users dir
65
-		$this->rootView = new \OC\Files\View('');
66
-		$this->rootView->mkdir('/test');
67
-
68
-		$this->instance = new \OC\Cache\File();
69
-
70
-		// forces creation of cache folder for subsequent tests
71
-		$this->instance->set('hack', 'hack');
72
-	}
73
-
74
-	protected function tearDown(): void {
75
-		if ($this->instance) {
76
-			$this->instance->remove('hack', 'hack');
77
-		}
78
-
79
-		\OC_User::setUserId($this->user);
80
-
81
-		if ($this->instance) {
82
-			$this->instance->clear();
83
-			$this->instance = null;
84
-		}
85
-
86
-		parent::tearDown();
87
-	}
88
-
89
-	private function setupMockStorage() {
90
-		$mockStorage = $this->getMockBuilder(Local::class)
91
-			->onlyMethods(['filemtime', 'unlink'])
92
-			->setConstructorArgs([['datadir' => \OC::$server->getTempManager()->getTemporaryFolder()]])
93
-			->getMock();
94
-
95
-		\OC\Files\Filesystem::mount($mockStorage, [], '/test/cache');
96
-
97
-		return $mockStorage;
98
-	}
99
-
100
-	public function testGarbageCollectOldKeys(): void {
101
-		$mockStorage = $this->setupMockStorage();
102
-
103
-		$mockStorage->expects($this->atLeastOnce())
104
-			->method('filemtime')
105
-			->willReturn(100);
106
-		$mockStorage->expects($this->once())
107
-			->method('unlink')
108
-			->with('key1')
109
-			->willReturn(true);
110
-
111
-		$this->instance->set('key1', 'value1');
112
-		$this->instance->gc();
113
-	}
114
-
115
-	public function testGarbageCollectLeaveRecentKeys(): void {
116
-		$mockStorage = $this->setupMockStorage();
117
-
118
-		$mockStorage->expects($this->atLeastOnce())
119
-			->method('filemtime')
120
-			->willReturn(time() + 3600);
121
-		$mockStorage->expects($this->never())
122
-			->method('unlink')
123
-			->with('key1');
124
-		$this->instance->set('key1', 'value1');
125
-		$this->instance->gc();
126
-	}
127
-
128
-	public static function lockExceptionProvider(): array {
129
-		return [
130
-			[new \OCP\Lock\LockedException('key1')],
131
-			[new \OCP\Files\LockNotAcquiredException('key1', 1)],
132
-		];
133
-	}
134
-
135
-	/**
136
-	 * @dataProvider lockExceptionProvider
137
-	 */
138
-	public function testGarbageCollectIgnoreLockedKeys($testException): void {
139
-		$mockStorage = $this->setupMockStorage();
140
-
141
-		$mockStorage->expects($this->atLeastOnce())
142
-			->method('filemtime')
143
-			->willReturn(100);
144
-		$mockStorage->expects($this->atLeastOnce())
145
-			->method('unlink')
146
-			->will($this->onConsecutiveCalls(
147
-				$this->throwException($testException),
148
-				$this->returnValue(true)
149
-			));
150
-
151
-		$this->instance->set('key1', 'value1');
152
-		$this->instance->set('key2', 'value2');
153
-
154
-		$this->instance->gc();
155
-	}
22
+    use UserTrait;
23
+
24
+    /**
25
+     * @var string
26
+     * */
27
+    private $user;
28
+    /**
29
+     * @var string
30
+     * */
31
+    private $datadir;
32
+    /**
33
+     * @var \OC\Files\Storage\Storage
34
+     * */
35
+    private $storage;
36
+    /**
37
+     * @var \OC\Files\View
38
+     * */
39
+    private $rootView;
40
+
41
+    public function skip() {
42
+        //$this->skipUnless(OC_User::isLoggedIn());
43
+    }
44
+
45
+    protected function setUp(): void {
46
+        parent::setUp();
47
+
48
+        //login
49
+        $this->createUser('test', 'test');
50
+
51
+        $this->user = \OC_User::getUser();
52
+        \OC_User::setUserId('test');
53
+
54
+        //clear all proxies and hooks so we can do clean testing
55
+        \OC_Hook::clear('OC_Filesystem');
56
+
57
+        /** @var IMountManager $manager */
58
+        $manager = \OC::$server->get(IMountManager::class);
59
+        $manager->removeMount('/test');
60
+
61
+        $storage = new \OC\Files\Storage\Temporary([]);
62
+        \OC\Files\Filesystem::mount($storage, [], '/test/cache');
63
+
64
+        //set up the users dir
65
+        $this->rootView = new \OC\Files\View('');
66
+        $this->rootView->mkdir('/test');
67
+
68
+        $this->instance = new \OC\Cache\File();
69
+
70
+        // forces creation of cache folder for subsequent tests
71
+        $this->instance->set('hack', 'hack');
72
+    }
73
+
74
+    protected function tearDown(): void {
75
+        if ($this->instance) {
76
+            $this->instance->remove('hack', 'hack');
77
+        }
78
+
79
+        \OC_User::setUserId($this->user);
80
+
81
+        if ($this->instance) {
82
+            $this->instance->clear();
83
+            $this->instance = null;
84
+        }
85
+
86
+        parent::tearDown();
87
+    }
88
+
89
+    private function setupMockStorage() {
90
+        $mockStorage = $this->getMockBuilder(Local::class)
91
+            ->onlyMethods(['filemtime', 'unlink'])
92
+            ->setConstructorArgs([['datadir' => \OC::$server->getTempManager()->getTemporaryFolder()]])
93
+            ->getMock();
94
+
95
+        \OC\Files\Filesystem::mount($mockStorage, [], '/test/cache');
96
+
97
+        return $mockStorage;
98
+    }
99
+
100
+    public function testGarbageCollectOldKeys(): void {
101
+        $mockStorage = $this->setupMockStorage();
102
+
103
+        $mockStorage->expects($this->atLeastOnce())
104
+            ->method('filemtime')
105
+            ->willReturn(100);
106
+        $mockStorage->expects($this->once())
107
+            ->method('unlink')
108
+            ->with('key1')
109
+            ->willReturn(true);
110
+
111
+        $this->instance->set('key1', 'value1');
112
+        $this->instance->gc();
113
+    }
114
+
115
+    public function testGarbageCollectLeaveRecentKeys(): void {
116
+        $mockStorage = $this->setupMockStorage();
117
+
118
+        $mockStorage->expects($this->atLeastOnce())
119
+            ->method('filemtime')
120
+            ->willReturn(time() + 3600);
121
+        $mockStorage->expects($this->never())
122
+            ->method('unlink')
123
+            ->with('key1');
124
+        $this->instance->set('key1', 'value1');
125
+        $this->instance->gc();
126
+    }
127
+
128
+    public static function lockExceptionProvider(): array {
129
+        return [
130
+            [new \OCP\Lock\LockedException('key1')],
131
+            [new \OCP\Files\LockNotAcquiredException('key1', 1)],
132
+        ];
133
+    }
134
+
135
+    /**
136
+     * @dataProvider lockExceptionProvider
137
+     */
138
+    public function testGarbageCollectIgnoreLockedKeys($testException): void {
139
+        $mockStorage = $this->setupMockStorage();
140
+
141
+        $mockStorage->expects($this->atLeastOnce())
142
+            ->method('filemtime')
143
+            ->willReturn(100);
144
+        $mockStorage->expects($this->atLeastOnce())
145
+            ->method('unlink')
146
+            ->will($this->onConsecutiveCalls(
147
+                $this->throwException($testException),
148
+                $this->returnValue(true)
149
+            ));
150
+
151
+        $this->instance->set('key1', 'value1');
152
+        $this->instance->set('key2', 'value2');
153
+
154
+        $this->instance->gc();
155
+    }
156 156
 }
Please login to merge, or discard this patch.