diff options
Diffstat (limited to 'apps/files_versions/tests/Controller/PreviewControllerTest.php')
-rw-r--r-- | apps/files_versions/tests/Controller/PreviewControllerTest.php | 55 |
1 files changed, 37 insertions, 18 deletions
diff --git a/apps/files_versions/tests/Controller/PreviewControllerTest.php b/apps/files_versions/tests/Controller/PreviewControllerTest.php index 384f43cf495..7c248b36349 100644 --- a/apps/files_versions/tests/Controller/PreviewControllerTest.php +++ b/apps/files_versions/tests/Controller/PreviewControllerTest.php @@ -20,9 +20,12 @@ * along with this program. If not, see <http://www.gnu.org/licenses/>. * */ + namespace OCA\Files_Versions\Tests\Controller; +use OC\User\User; use OCA\Files_Versions\Controller\PreviewController; +use OCA\Files_Versions\Versions\IVersionManager; use OCP\AppFramework\Http; use OCP\AppFramework\Http\DataResponse; use OCP\AppFramework\Http\FileDisplayResponse; @@ -34,6 +37,8 @@ use OCP\Files\NotFoundException; use OCP\Files\SimpleFS\ISimpleFile; use OCP\IPreview; use OCP\IRequest; +use OCP\IUser; +use OCP\IUserSession; use Test\TestCase; class PreviewControllerTest extends TestCase { @@ -50,23 +55,39 @@ class PreviewControllerTest extends TestCase { /** @var IPreview|\PHPUnit_Framework_MockObject_MockObject */ private $previewManager; - /** @var PreviewController */ + /** @var PreviewController|\PHPUnit_Framework_MockObject_MockObject */ private $controller; + /** @var IUserSession|\PHPUnit_Framework_MockObject_MockObject */ + private $userSession; + + /** @var IVersionManager|\PHPUnit_Framework_MockObject_MockObject */ + private $versionManager; + public function setUp() { parent::setUp(); $this->rootFolder = $this->createMock(IRootFolder::class); $this->userId = 'user'; + $user = $this->createMock(IUser::class); + $user->expects($this->any()) + ->method('getUID') + ->willReturn($this->userId); $this->mimeTypeDetector = $this->createMock(IMimeTypeDetector::class); $this->previewManager = $this->createMock(IPreview::class); + $this->userSession = $this->createMock(IUserSession::class); + $this->userSession->expects($this->any()) + ->method('getUser') + ->willReturn($user); + $this->versionManager = $this->createMock(IVersionManager::class); $this->controller = new PreviewController( 'files_versions', $this->createMock(IRequest::class), $this->rootFolder, - $this->userId, + $this->userSession, $this->mimeTypeDetector, + $this->versionManager, $this->previewManager ); } @@ -102,24 +123,23 @@ class PreviewControllerTest extends TestCase { public function testValidPreview() { $userFolder = $this->createMock(Folder::class); $userRoot = $this->createMock(Folder::class); - $versions = $this->createMock(Folder::class); $this->rootFolder->method('getUserFolder') ->with($this->userId) ->willReturn($userFolder); $userFolder->method('getParent') ->willReturn($userRoot); - $userRoot->method('get') - ->with('files_versions') - ->willReturn($versions); - $this->mimeTypeDetector->method('detectPath') - ->with($this->equalTo('file')) - ->willReturn('myMime'); + $sourceFile = $this->createMock(File::class); + $userFolder->method('get') + ->with('file') + ->willReturn($sourceFile); $file = $this->createMock(File::class); - $versions->method('get') - ->with($this->equalTo('file.v42')) + $file->method('getMimetype') + ->willReturn('myMime'); + + $this->versionManager->method('getVersionFile') ->willReturn($file); $preview = $this->createMock(ISimpleFile::class); @@ -138,24 +158,23 @@ class PreviewControllerTest extends TestCase { public function testVersionNotFound() { $userFolder = $this->createMock(Folder::class); $userRoot = $this->createMock(Folder::class); - $versions = $this->createMock(Folder::class); $this->rootFolder->method('getUserFolder') ->with($this->userId) ->willReturn($userFolder); $userFolder->method('getParent') ->willReturn($userRoot); - $userRoot->method('get') - ->with('files_versions') - ->willReturn($versions); + + $sourceFile = $this->createMock(File::class); + $userFolder->method('get') + ->with('file') + ->willReturn($sourceFile); $this->mimeTypeDetector->method('detectPath') ->with($this->equalTo('file')) ->willReturn('myMime'); - $file = $this->createMock(File::class); - $versions->method('get') - ->with($this->equalTo('file.v42')) + $this->versionManager->method('getVersionFile') ->willThrowException(new NotFoundException()); $res = $this->controller->getPreview('file', 10, 10, '42'); |