class StorageTest extends TestCase {
+ /** @var Storage */
+ protected $storage;
+
/** @var \PHPUnit_Framework_MockObject_MockObject */
protected $util;
->disableOriginalConstructor()
->getMock();
+ $this->storage = new Storage('encModule', $this->view, $this->util);
+
}
public function testSetFileKey() {
$this->equalTo('key'))
->willReturn(strlen('key'));
- $storage = new Storage('encModule', $this->view, $this->util);
-
$this->assertTrue(
- $storage->setFileKey('user1/files/foo.txt', 'fileKey', 'key')
+ $this->storage->setFileKey('user1/files/foo.txt', 'fileKey', 'key')
);
}
->with($this->equalTo('/user1/files_encryption/keys/files/foo.txt/encModule/fileKey'))
->willReturn(true);
- $storage = new Storage('encModule', $this->view, $this->util);
-
$this->assertSame('key',
- $storage->getFileKey('user1/files/foo.txt', 'fileKey')
+ $this->storage->getFileKey('user1/files/foo.txt', 'fileKey')
);
}
$this->equalTo('key'))
->willReturn(strlen('key'));
- $storage = new Storage('encModule', $this->view, $this->util);
-
$this->assertTrue(
- $storage->setFileKey('user1/files/foo.txt', 'fileKey', 'key')
+ $this->storage->setFileKey('user1/files/foo.txt', 'fileKey', 'key')
);
}
->with($this->equalTo('/files_encryption/keys/files/foo.txt/encModule/fileKey'))
->willReturn(true);
- $storage = new Storage('encModule', $this->view, $this->util);
-
$this->assertSame('key',
- $storage->getFileKey('user1/files/foo.txt', 'fileKey')
+ $this->storage->getFileKey('user1/files/foo.txt', 'fileKey')
);
}
$this->equalTo('key'))
->willReturn(strlen('key'));
- $storage = new Storage('encModule', $this->view, $this->util);
-
$this->assertTrue(
- $storage->setSystemUserKey('shareKey_56884', 'key')
+ $this->storage->setSystemUserKey('shareKey_56884', 'key')
);
}
$this->equalTo('key'))
->willReturn(strlen('key'));
- $storage = new Storage('encModule', $this->view, $this->util);
-
$this->assertTrue(
- $storage->setUserKey('user1', 'publicKey', 'key')
+ $this->storage->setUserKey('user1', 'publicKey', 'key')
);
}
->with($this->equalTo('/files_encryption/encModule/shareKey_56884'))
->willReturn(true);
- $storage = new Storage('encModule', $this->view, $this->util);
-
$this->assertSame('key',
- $storage->getSystemUserKey('shareKey_56884')
+ $this->storage->getSystemUserKey('shareKey_56884')
);
}
->with($this->equalTo('/user1/files_encryption/encModule/user1.publicKey'))
->willReturn(true);
- $storage = new Storage('encModule', $this->view, $this->util);
-
$this->assertSame('key',
- $storage->getUserKey('user1', 'publicKey')
+ $this->storage->getUserKey('user1', 'publicKey')
);
}
->with($this->equalTo('/user1/files_encryption/encModule/user1.publicKey'))
->willReturn(true);
- $storage = new Storage('encModule', $this->view, $this->util);
-
$this->assertTrue(
- $storage->deleteUserKey('user1', 'publicKey')
+ $this->storage->deleteUserKey('user1', 'publicKey')
);
}
->with($this->equalTo('/files_encryption/encModule/shareKey_56884'))
->willReturn(true);
- $storage = new Storage('encModule', $this->view, $this->util);
-
$this->assertTrue(
- $storage->deleteSystemUserKey('shareKey_56884')
+ $this->storage->deleteSystemUserKey('shareKey_56884')
);
}
->with($this->equalTo('/files_encryption/keys/files/foo.txt/encModule/fileKey'))
->willReturn(true);
- $storage = new Storage('encModule', $this->view, $this->util);
-
$this->assertTrue(
- $storage->deleteFileKey('user1/files/foo.txt', 'fileKey')
+ $this->storage->deleteFileKey('user1/files/foo.txt', 'fileKey')
);
}
->with($this->equalTo('/user1/files_encryption/keys/files/foo.txt/encModule/fileKey'))
->willReturn(true);
- $storage = new Storage('encModule', $this->view, $this->util);
-
$this->assertTrue(
- $storage->deleteFileKey('user1/files/foo.txt', 'fileKey')
+ $this->storage->deleteFileKey('user1/files/foo.txt', 'fileKey')
);
}
->method('isSystemWideMountPoint')
->willReturn($systemWideMount);
- $storage = new Storage('encModule', $this->view, $this->util);
- $storage->renameKeys($source, $target);
+ $this->storage->renameKeys($source, $target);
}
/**
->method('isSystemWideMountPoint')
->willReturn($systemWideMount);
- $storage = new Storage('encModule', $this->view, $this->util);
- $storage->copyKeys($source, $target);
+ $this->storage->copyKeys($source, $target);
}
public function getUidAndFilenameCallback() {
);
}
+ public function testKeySetPreparation() {
+ $this->view->expects($this->any())
+ ->method('file_exists')
+ ->willReturn(false);
+ $this->view->expects($this->any())
+ ->method('is_dir')
+ ->willReturn(false);
+ $this->view->expects($this->any())
+ ->method('mkdir')
+ ->will($this->returnCallback(array($this, 'mkdirCallback')));
+
+ $this->mkdirStack = array(
+ '/user1/files_encryption/keys/foo',
+ '/user1/files_encryption/keys',
+ '/user1/files_encryption',
+ '/user1');
+
+ \Test_Helper::invokePrivate($this->storage, 'keySetPreparation', array('/user1/files_encryption/keys/foo'));
+ }
+
+ public function mkdirCallback() {
+ $args = func_get_args();
+ $expected = array_pop($this->mkdirStack);
+ $this->assertSame($expected, $args[0]);
+ }
+
}