aboutsummaryrefslogtreecommitdiffstats
path: root/tests/lib/files/stream/encryption.php
blob: 1c5e5cf7a49ff2683a527187dfdc5a98e68f50dc (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
<?php

namespace Test\Files\Stream;

use OC\Files\View;
use OCA\Encryption_Dummy\DummyModule;

class Encryption extends \Test\TestCase {

	/**
	 * @param string $mode
	 * @param integer $limit
	 */
	protected function getStream($mode) {

		$source = fopen('php://temp', $mode);
		$internalPath = '';
		$fullPath = '';
		$header = [];
		$uid = '';
		$encryptionModule = new DummyModule();
		$storage = $this->getMockBuilder('\OC\Files\Storage\Storage')
			->disableOriginalConstructor()->getMock();
		$encStorage = $this->getMockBuilder('\OC\Files\Storage\Wrapper\Encryption')
			->disableOriginalConstructor()->getMock();
		$config = $this->getMockBuilder('\OCP\IConfig')
			->disableOriginalConstructor()
			->getMock();
		$util = new \OC\Encryption\Util(new View(), new \OC\User\Manager(), $config);
		$size = 12;
		$unencryptedSize = 8000;

		return \OC\Files\Stream\Encryption::wrap($source, $internalPath,
			$fullPath, $header, $uid, $encryptionModule, $storage, $encStorage,
			$util, $mode, $size, $unencryptedSize);
	}

	public function testWriteEnoughSpace() {
		$stream = $this->getStream('w+');
		$this->assertEquals(6, fwrite($stream, 'foobar'));
		rewind($stream);
		$this->assertEquals('foobar', fread($stream, 100));
	}
}