Make sure that testDeleteShare() has some shares to delete

This commit is contained in:
Bjoern Schiessle 2013-09-30 12:23:44 +02:00
commit 9a2e82c3c5
2 changed files with 39 additions and 15 deletions

View file

@ -86,7 +86,7 @@ class Api {
}
if ($shares === null || empty($shares)) {
return new \OC_OCS_Result(null, 404, 'share doesn\'t exists');
return new \OC_OCS_Result(null, 404, 'share doesn\'t exist');
} else {
return new \OC_OCS_Result($shares);
}
@ -451,17 +451,15 @@ class Api {
$query = \OCP\DB::prepare($sql);
$result = $query->execute($args);
$share = Null;
if (\OCP\DB::isError($result)) {
\OCP\Util::writeLog('files_sharing', \OC_DB::getErrorMessage($result), \OCP\Util::ERROR);
} else {
if ($result->numRows() > 0) {
$share = $result->fetchRow();
}
return null;
}
if ($share = $result->fetchRow()) {
return $share;
}
return $share;
return null;
}

View file

@ -221,7 +221,7 @@ class Test_Files_Sharing_Api extends \PHPUnit_Framework_TestCase {
$fileInfo = $this->view->getFileInfo($this->filename);
$result = \OCP\Share::shareItem('file', $fileInfo['fileid'], \OCP\Share::SHARE_TYPE_USER,
\Test_Files_Sharing_Api::TEST_FILES_SHARING_API_USER2, 31);
\Test_Files_Sharing_Api::TEST_FILES_SHARING_API_USER2, 31);
// share was successful?
$this->assertTrue($result);
@ -229,7 +229,7 @@ class Test_Files_Sharing_Api extends \PHPUnit_Framework_TestCase {
// get item to determine share ID
$result = \OCP\Share::getItemShared('file', $fileInfo['fileid']);
$this->assertEquals(count($result), 1);
$this->assertEquals(1, count($result));
// get first element
$share = reset($result);
@ -240,11 +240,25 @@ class Test_Files_Sharing_Api extends \PHPUnit_Framework_TestCase {
$this->assertTrue($result->succeeded());
// test should return one share
$this->assertEquals(count($result->getData()), 1);
// test should return one share created from testCreateShare()
$this->assertEquals(1, count($result->getData()));
\OCP\Share::unshare('file', $fileInfo['fileid'], \OCP\Share::SHARE_TYPE_USER,
\Test_Files_Sharing_Api::TEST_FILES_SHARING_API_USER2);
\Test_Files_Sharing_Api::TEST_FILES_SHARING_API_USER2);
}
/**
* @medium
*/
function testGetShareFromUnknownId() {
$params = array('id' => 0);
$result = Share\Api::getShare($params);
$this->assertEquals(404, $result->getStatusCode());
$this->assertEquals('share doesn\'t exist', $result->getMeta()['message']);
}
@ -291,7 +305,7 @@ class Test_Files_Sharing_Api extends \PHPUnit_Framework_TestCase {
// update permissions
$this->assertEquals($userShare['permissions'], '31');
$this->assertEquals('31', $userShare['permissions']);
$params = array();
$params['id'] = $userShare['id'];
@ -314,7 +328,7 @@ class Test_Files_Sharing_Api extends \PHPUnit_Framework_TestCase {
$this->assertTrue(is_array($newUserShare));
$this->assertEquals($newUserShare['permissions'], '1');
$this->assertEquals('1', $newUserShare['permissions']);
// update password for link share
@ -354,8 +368,19 @@ class Test_Files_Sharing_Api extends \PHPUnit_Framework_TestCase {
* @depends testCreateShare
*/
function testDeleteShare() {
$fileInfo = $this->view->getFileInfo($this->filename);
\OCP\Share::shareItem('file', $fileInfo['fileid'], \OCP\Share::SHARE_TYPE_USER,
\Test_Files_Sharing_Api::TEST_FILES_SHARING_API_USER2, 31);
\OCP\Share::shareItem('file', $fileInfo['fileid'], \OCP\Share::SHARE_TYPE_LINK,
null, 1);
$items = \OCP\Share::getItemShared('file', null);
$this->assertEquals(2, count($items));
foreach ($items as $item) {
$result = Share\Api::deleteShare(array('id' => $item['id']));
@ -365,6 +390,7 @@ class Test_Files_Sharing_Api extends \PHPUnit_Framework_TestCase {
$itemsAfterDelete = \OCP\Share::getItemShared('file', null);
$this->assertTrue(empty($itemsAfterDelete));
}
/**