editor = new Editor(); $this->random = $this->createMock(ISecureRandom::class); $this->connection = \OC::$server->getDatabaseConnection(); $this->userSession = $this->createMock(IUserSession::class); $this->rootFolder = $this->createMock(IRootFolder::class); $this->userFolder = $this->createMock(Folder::class); $this->l10n = $this->createMock(IL10N::class); $l10nFactory = $this->createMock(IFactory::class); $l10nFactory->expects($this->once()) ->method('get') ->willReturn($this->l10n); $this->rootFolder->expects($this->any()) ->method('getUserFolder') ->willReturn($this->userFolder); $this->manager = new Manager( $this->random, $this->connection, $this->userSession, $this->rootFolder, $l10nFactory ); $this->manager->registerDirectEditor($this->editor); } public function testEditorRegistration() { $this->assertEquals($this->manager->getEditors(), ['testeditor' => $this->editor]); } public function testCreateToken() { $expectedToken = 'TOKEN' . time(); $file = $this->createMock(File::class); $file->expects($this->any()) ->method('getId') ->willReturn(123); $this->random->expects($this->once()) ->method('generate') ->willReturn($expectedToken); $this->userFolder ->method('nodeExists') ->with('/File.txt') ->willReturn(false); $this->userFolder->expects($this->once()) ->method('newFile') ->willReturn($file); $token = $this->manager->create('/File.txt', 'testeditor', 'createEmpty'); $this->assertEquals($token, $expectedToken); } public function testCreateTokenAccess() { $expectedToken = 'TOKEN' . time(); $file = $this->createMock(File::class); $file->expects($this->any()) ->method('getId') ->willReturn(123); $this->random->expects($this->once()) ->method('generate') ->willReturn($expectedToken); $this->userFolder ->method('nodeExists') ->with('/File.txt') ->willReturn(false); $this->userFolder->expects($this->once()) ->method('newFile') ->willReturn($file); $this->manager->create('/File.txt', 'testeditor', 'createEmpty'); $firstResult = $this->manager->edit($expectedToken); $secondResult = $this->manager->edit($expectedToken); $this->assertInstanceOf(DataResponse::class, $firstResult); $this->assertInstanceOf(NotFoundResponse::class, $secondResult); } public function testCreateFileAlreadyExists() { $this->expectException(\RuntimeException::class); $this->userFolder ->method('nodeExists') ->with('/File.txt') ->willReturn(true); $this->manager->create('/File.txt', 'testeditor', 'createEmpty'); } }