diff options
author | Thomas Müller <thomas.mueller@tmit.eu> | 2015-04-02 11:07:07 +0200 |
---|---|---|
committer | Thomas Müller <thomas.mueller@tmit.eu> | 2015-04-07 13:30:30 +0200 |
commit | 8ffa6db110007dc053db0073e14c9374b75a4c16 (patch) | |
tree | 996c96888d9f7ffe72c49fe2a2f980d2ad3f55cb /tests/lib/files | |
parent | 391fab35f078bd37d7b432eaf6a1c6fab701dff4 (diff) | |
download | nextcloud-server-8ffa6db110007dc053db0073e14c9374b75a4c16.tar.gz nextcloud-server-8ffa6db110007dc053db0073e14c9374b75a4c16.zip |
fixing unit tests for stream wrapper
Diffstat (limited to 'tests/lib/files')
-rw-r--r-- | tests/lib/files/stream/encryption.php | 52 |
1 files changed, 42 insertions, 10 deletions
diff --git a/tests/lib/files/stream/encryption.php b/tests/lib/files/stream/encryption.php index 1c5e5cf7a49..3a5a2d4899e 100644 --- a/tests/lib/files/stream/encryption.php +++ b/tests/lib/files/stream/encryption.php @@ -11,14 +11,14 @@ class Encryption extends \Test\TestCase { * @param string $mode * @param integer $limit */ - protected function getStream($mode) { + protected function getStream($fileName, $mode) { - $source = fopen('php://temp', $mode); - $internalPath = ''; - $fullPath = ''; + $source = fopen($fileName, $mode); + $internalPath = $fileName; + $fullPath = $fileName; $header = []; $uid = ''; - $encryptionModule = new DummyModule(); + $encryptionModule = $this->buildMockModule(); $storage = $this->getMockBuilder('\OC\Files\Storage\Storage') ->disableOriginalConstructor()->getMock(); $encStorage = $this->getMockBuilder('\OC\Files\Storage\Wrapper\Encryption') @@ -26,19 +26,51 @@ class Encryption extends \Test\TestCase { $config = $this->getMockBuilder('\OCP\IConfig') ->disableOriginalConstructor() ->getMock(); - $util = new \OC\Encryption\Util(new View(), new \OC\User\Manager(), $config); + $file = $this->getMockBuilder('\OC\Encryption\File') + ->disableOriginalConstructor() + ->getMock(); + $util = $this->getMock('\OC\Encryption\Util', ['getUidAndFilename'], [new View(), new \OC\User\Manager(), $config]); + $util->expects($this->any()) + ->method('getUidAndFilename') + ->willReturn(['user1', $internalPath]); $size = 12; $unencryptedSize = 8000; return \OC\Files\Stream\Encryption::wrap($source, $internalPath, $fullPath, $header, $uid, $encryptionModule, $storage, $encStorage, - $util, $mode, $size, $unencryptedSize); + $util, $file, $mode, $size, $unencryptedSize); } - public function testWriteEnoughSpace() { - $stream = $this->getStream('w+'); + public function testWriteRead() { + $fileName = tempnam("/tmp", "FOO"); + $stream = $this->getStream($fileName, 'w+'); $this->assertEquals(6, fwrite($stream, 'foobar')); - rewind($stream); + fclose($stream); + + $stream = $this->getStream($fileName, 'r'); $this->assertEquals('foobar', fread($stream, 100)); + fclose($stream); + } + + /** + * @return \PHPUnit_Framework_MockObject_MockObject + */ + protected function buildMockModule() { + $encryptionModule = $this->getMockBuilder('\OCP\Encryption\IEncryptionModule') + ->disableOriginalConstructor() + ->setMethods(['getId', 'getDisplayName', 'begin', 'end', 'encrypt', 'decrypt', 'update', 'shouldEncrypt', 'calculateUnencryptedSize', 'getUnencryptedBlockSize']) + ->getMock(); + + $encryptionModule->expects($this->any())->method('getId')->willReturn('UNIT_TEST_MODULE'); + $encryptionModule->expects($this->any())->method('getDisplayName')->willReturn('Unit test module'); + $encryptionModule->expects($this->any())->method('begin')->willReturn([]); + $encryptionModule->expects($this->any())->method('end')->willReturn(''); + $encryptionModule->expects($this->any())->method('encrypt')->willReturnArgument(0); + $encryptionModule->expects($this->any())->method('decrypt')->willReturnArgument(0); + $encryptionModule->expects($this->any())->method('update')->willReturn(true); + $encryptionModule->expects($this->any())->method('shouldEncrypt')->willReturn(true); + $encryptionModule->expects($this->any())->method('calculateUnencryptedSize')->willReturn(42); + $encryptionModule->expects($this->any())->method('getUnencryptedBlockSize')->willReturn(6126); + return $encryptionModule; } } |