update tests

This commit is contained in:
Robin Appelman 2015-04-09 14:46:25 +02:00
parent 6a59502759
commit cbcee34eb0
2 changed files with 45 additions and 26 deletions

View File

@ -71,7 +71,7 @@ class File extends Node implements IFile {
* different object on a subsequent GET you are strongly recommended to not * different object on a subsequent GET you are strongly recommended to not
* return an ETag, and just return null. * return an ETag, and just return null.
* *
* @param resource $data * @param resource|string $data
* *
* @throws Forbidden * @throws Forbidden
* @throws UnsupportedMediaType * @throws UnsupportedMediaType
@ -82,6 +82,11 @@ class File extends Node implements IFile {
* @return string|null * @return string|null
*/ */
public function put($data) { public function put($data) {
if (is_string($data)) {
$stream = fopen('php://temp', 'r+');
fwrite($stream, $data);
$data = $stream;
};
try { try {
$exists = $this->fileView->file_exists($this->path); $exists = $this->fileView->file_exists($this->path);
if ($this->info && $exists && !$this->info->isUpdateable()) { if ($this->info && $exists && !$this->info->isUpdateable()) {
@ -178,7 +183,9 @@ class File extends Node implements IFile {
// since we skipped the view we need to scan and emit the hooks ourselves // since we skipped the view we need to scan and emit the hooks ourselves
$storage->getScanner()->scanFile($internalPath); $storage->getScanner()->scanFile($internalPath);
$hookPath = \OC\Files\Filesystem::getView()->getRelativePath($this->fileView->getAbsolutePath($this->path)); $view = \OC\Files\Filesystem::getView();
if ($view) {
$hookPath = $view->getRelativePath($this->fileView->getAbsolutePath($this->path));
if (!$exists) { if (!$exists) {
\OC_Hook::emit(\OC\Files\Filesystem::CLASSNAME, \OC\Files\Filesystem::signal_post_create, array( \OC_Hook::emit(\OC\Files\Filesystem::CLASSNAME, \OC\Files\Filesystem::signal_post_create, array(
\OC\Files\Filesystem::signal_param_path => $hookPath \OC\Files\Filesystem::signal_param_path => $hookPath
@ -191,6 +198,7 @@ class File extends Node implements IFile {
\OC_Hook::emit(\OC\Files\Filesystem::CLASSNAME, \OC\Files\Filesystem::signal_post_write, array( \OC_Hook::emit(\OC\Files\Filesystem::CLASSNAME, \OC\Files\Filesystem::signal_post_write, array(
\OC\Files\Filesystem::signal_param_path => $hookPath \OC\Files\Filesystem::signal_param_path => $hookPath
)); ));
}
// allow sync clients to send the mtime along in a header // allow sync clients to send the mtime along in a header
$request = \OC::$server->getRequest(); $request = \OC::$server->getRequest();
@ -209,6 +217,7 @@ class File extends Node implements IFile {
/** /**
* Returns the data * Returns the data
*
* @return string|resource * @return string|resource
* @throws Forbidden * @throws Forbidden
* @throws ServiceUnavailable * @throws ServiceUnavailable
@ -228,6 +237,7 @@ class File extends Node implements IFile {
/** /**
* Delete the current file * Delete the current file
*
* @throws Forbidden * @throws Forbidden
* @throws ServiceUnavailable * @throws ServiceUnavailable
*/ */
@ -358,6 +368,7 @@ class File extends Node implements IFile {
* Returns whether a part file is needed for the given storage * Returns whether a part file is needed for the given storage
* or whether the file can be assembled/uploaded directly on the * or whether the file can be assembled/uploaded directly on the
* target storage. * target storage.
*
* @param \OCP\Files\Storage $storage * @param \OCP\Files\Storage $storage
* @return bool true if the storage needs part file handling * @return bool true if the storage needs part file handling
*/ */

View File

@ -15,9 +15,13 @@ class File extends \Test\TestCase {
*/ */
public function testSimplePutFails() { public function testSimplePutFails() {
// setup // setup
$view = $this->getMock('\OC\Files\View', array('file_put_contents', 'getRelativePath'), array()); $storage = $this->getMock('\OC\Files\Storage\Local', ['fopen'], [['datadir' => \OC::$server->getTempManager()->getTemporaryFolder()]]);
$view = $this->getMock('\OC\Files\View', array('file_put_contents', 'getRelativePath', 'resolvePath'), array());
$view->expects($this->any()) $view->expects($this->any())
->method('file_put_contents') ->method('resolvePath')
->will($this->returnValue(array($storage, '')));
$storage->expects($this->once())
->method('fopen')
->will($this->returnValue(false)); ->will($this->returnValue(false));
$view->expects($this->any()) $view->expects($this->any())
@ -36,8 +40,9 @@ class File extends \Test\TestCase {
public function testPutSingleFileShare() { public function testPutSingleFileShare() {
// setup // setup
$storage = $this->getMock('\OCP\Files\Storage'); $stream = fopen('php://temp', 'w+');
$view = $this->getMock('\OC\Files\View', array('file_put_contents', 'getRelativePath'), array()); $storage = $this->getMock('\OC\Files\Storage\Local', ['fopen'], [['datadir' => \OC::$server->getTempManager()->getTemporaryFolder()]]);
$view = $this->getMock('\OC\Files\View', array('file_put_contents', 'getRelativePath', 'resolvePath'), array());
$view->expects($this->any()) $view->expects($this->any())
->method('resolvePath') ->method('resolvePath')
->with('') ->with('')
@ -49,6 +54,9 @@ class File extends \Test\TestCase {
->method('file_put_contents') ->method('file_put_contents')
->with('') ->with('')
->will($this->returnValue(true)); ->will($this->returnValue(true));
$storage->expects($this->once())
->method('fopen')
->will($this->returnValue($stream));
$info = new \OC\Files\FileInfo('/foo.txt', null, null, array( $info = new \OC\Files\FileInfo('/foo.txt', null, null, array(
'permissions' => \OCP\Constants::PERMISSION_ALL 'permissions' => \OCP\Constants::PERMISSION_ALL