diff options
author | Florin Peter <github@florin-peter.de> | 2013-05-16 02:36:40 +0400 |
---|---|---|
committer | Florin Peter <github@florin-peter.de> | 2013-05-16 02:36:40 +0400 |
commit | 0fca2f8f319d77b056516216ade0a931d21a2a69 (patch) | |
tree | f44ad2271af91aaf2420ebfd1068fda47e179337 /apps/files_encryption/tests/crypt.php | |
parent | c651950a17cf1381a832e172191e4f4cc172569b (diff) |
added tests for put content, get content, touch and fopen
Diffstat (limited to 'apps/files_encryption/tests/crypt.php')
-rwxr-xr-x | apps/files_encryption/tests/crypt.php | 75 |
1 files changed, 74 insertions, 1 deletions
diff --git a/apps/files_encryption/tests/crypt.php b/apps/files_encryption/tests/crypt.php index 6168f69415e..3916b0e15e0 100755 --- a/apps/files_encryption/tests/crypt.php +++ b/apps/files_encryption/tests/crypt.php @@ -77,7 +77,7 @@ class Test_Crypt extends \PHPUnit_Framework_TestCase { } function tearDown() { - + \OC_FileProxy::clearProxies(); } function testGenerateKey() { @@ -756,6 +756,79 @@ class Test_Crypt extends \PHPUnit_Framework_TestCase { $view = new \OC\Files\View('/' . $this->userId . '/files'); $view->unlink( $filename ); } + + function testViewFilePutAndGetContents() { + + $filename = '/tmp-'.time(); + $view = new \OC\Files\View('/' . $this->userId . '/files'); + + // Save short data as encrypted file using stream wrapper + $cryptedFile = $view->file_put_contents( $filename, $this->dataShort ); + + // Test that data was successfully written + $this->assertTrue( is_int( $cryptedFile ) ); + + // Get file decrypted contents + $decrypt = $view->file_get_contents( $filename ); + + $this->assertEquals( $this->dataShort, $decrypt ); + + // Save long data as encrypted file using stream wrapper + $cryptedFileLong = $view->file_put_contents( $filename, $this->dataLong ); + + // Test that data was successfully written + $this->assertTrue( is_int( $cryptedFileLong ) ); + + // Get file decrypted contents + $decryptLong = $view->file_get_contents( $filename ); + + $this->assertEquals( $this->dataLong, $decryptLong ); + + // tear down + $view->unlink( $filename ); + } + + function testTouchFile() { + $filename = '/tmp-'.time(); + $view = new \OC\Files\View('/' . $this->userId . '/files'); + + // Save short data as encrypted file using stream wrapper + $cryptedFile = $view->file_put_contents( $filename, $this->dataShort ); + + // Test that data was successfully written + $this->assertTrue( is_int( $cryptedFile ) ); + + $view->touch($filename); + + // Get file decrypted contents + $decrypt = $view->file_get_contents( $filename ); + + $this->assertEquals( $this->dataShort, $decrypt ); + + // tear down + $view->unlink( $filename ); + } + + function testFopenFile() { + $filename = '/tmp-'.time(); + $view = new \OC\Files\View('/' . $this->userId . '/files'); + + // Save short data as encrypted file using stream wrapper + $cryptedFile = $view->file_put_contents( $filename, $this->dataShort ); + + // Test that data was successfully written + $this->assertTrue( is_int( $cryptedFile ) ); + + $handle = $view->fopen($filename, 'r'); + + // Get file decrypted contents + $decrypt = fgets($handle); + + $this->assertEquals( $this->dataShort, $decrypt ); + + // tear down + $view->unlink( $filename ); + } // function testEncryption(){ // // $key=uniqid(); |