Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
update unittest to match the changes
  • Loading branch information
jvillafanez committed Aug 8, 2017
commit 5872861d9d8bffdf2f31e4a9d23df66cc093e90b
60 changes: 55 additions & 5 deletions apps/dav/tests/unit/Connector/Sabre/FileTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -351,15 +351,15 @@ private function supportsNegativeMtime() {

public function legalMtimeProvider() {
return [
"string" => [
"string" => [
'HTTP_X_OC_MTIME' => "string",
'expected result' => 0
],
"castable string (int)" => [
'HTTP_X_OC_MTIME' => "34",
'expected result' => 34
],
"castable string (float)" => [
"castable string (float)" => [
'HTTP_X_OC_MTIME' => "34.56",
'expected result' => 34
],
Expand Down Expand Up @@ -1079,7 +1079,7 @@ private function listPartFiles(View $userView = null, $path = '') {

/**
* returns an array of file information filesize, mtime, filetype, mimetype
*
*
* @param string $path
* @param View $userView
* @return array
Expand All @@ -1101,11 +1101,14 @@ private function getFileInfos($path = '', View $userView = null) {
*/
public function testGetFopenFails() {
$view = $this->getMockBuilder(View::class)
->setMethods(['fopen'])
->setMethods(['fopen', 'file_exists'])
->getMock();
$view->expects($this->atLeastOnce())
->method('fopen')
->will($this->returnValue(false));
$view->expects($this->atLeastOnce())
->method('file_exists')
->will($this->returnValue(true));

$info = new FileInfo('/test.txt', $this->getMockStorage(), null, [
'permissions' => Constants::PERMISSION_ALL
Expand All @@ -1121,11 +1124,14 @@ public function testGetFopenFails() {
*/
public function testGetFopenThrows() {
$view = $this->getMockBuilder(View::class)
->setMethods(['fopen'])
->setMethods(['fopen', 'file_exists'])
->getMock();
$view->expects($this->atLeastOnce())
->method('fopen')
->willThrowException(new ForbiddenException('', true));
$view->expects($this->atLeastOnce())
->method('file_exists')
->will($this->returnValue(true));

$info = new FileInfo('/test.txt', $this->getMockStorage(), null, [
'permissions' => Constants::PERMISSION_ALL
Expand Down Expand Up @@ -1154,4 +1160,48 @@ public function testGetThrowsIfNoPermission() {

$file->get();
}

/**
* @expectedException \Sabre\DAV\Exception\NotFound
*/
public function testGetThrowsIfFileNotExists() {
$view = $this->getMockBuilder(View::class)
->setMethods(['fopen', 'file_exists'])
->getMock();
$view->expects($this->never())
->method('fopen');
$view->expects($this->atLeastOnce())
->method('file_exists')
->will($this->returnValue(false));

$info = new FileInfo('/test.txt', $this->getMockStorage(), null, [
'permissions' => Constants::PERMISSION_ALL
], null);

$file = new File($view, $info);

$file->get();
}

/**
* @expectedException \Sabre\DAV\Exception\NotFound
*/
public function testGetThrowsIfNoPermissionsAndFileNotExists() {
$view = $this->getMockBuilder(View::class)
->setMethods(['fopen', 'file_exists'])
->getMock();
$view->expects($this->never())
->method('fopen');
$view->expects($this->any())
->method('file_exists')
->will($this->returnValue(false));

$info = new FileInfo('/test.txt', $this->getMockStorage(), null, [
'permissions' => Constants::PERMISSION_CREATE
], null);

$file = new File($view, $info);

$file->get();
}
}