diff options
author | Marcel Klehr <mklehr@gmx.net> | 2024-05-10 06:51:41 +0200 |
---|---|---|
committer | Marcel Klehr <mklehr@gmx.net> | 2024-05-14 11:38:41 +0200 |
commit | 19a0aaeb5e71a2431d347dc54b28aeaad4254c2c (patch) | |
tree | fb10b99e8bb57882f09aaf58b736c302424eed4d /tests | |
parent | ec94a672d72720530ffcfce92f9695d8b9a09e27 (diff) | |
download | nextcloud-server-19a0aaeb5e71a2431d347dc54b28aeaad4254c2c.tar.gz nextcloud-server-19a0aaeb5e71a2431d347dc54b28aeaad4254c2c.zip |
fix(TextToImage): Allow leaving the resources open
Signed-off-by: Marcel Klehr <mklehr@gmx.net>
Diffstat (limited to 'tests')
-rw-r--r-- | tests/lib/TaskProcessing/TaskProcessingTest.php | 17 |
1 files changed, 9 insertions, 8 deletions
diff --git a/tests/lib/TaskProcessing/TaskProcessingTest.php b/tests/lib/TaskProcessing/TaskProcessingTest.php index 846644ab6c3..ac220ad7c63 100644 --- a/tests/lib/TaskProcessing/TaskProcessingTest.php +++ b/tests/lib/TaskProcessing/TaskProcessingTest.php @@ -256,7 +256,6 @@ class SuccessfulTextToImageProvider implements \OCP\TextToImage\IProvider { $this->ran = true; foreach($resources as $resource) { fwrite($resource, 'test'); - fclose($resource); } } @@ -299,8 +298,8 @@ class TaskProcessingTest extends \Test\TestCase { private TaskMapper $taskMapper; private IJobList $jobList; private IAppData $appData; - private \OCP\Share\IManager $shareManager; + private IRootFolder $rootFolder; protected function setUp(): void { parent::setUp(); @@ -332,6 +331,8 @@ class TaskProcessingTest extends \Test\TestCase { $this->coordinator = $this->createMock(Coordinator::class); $this->coordinator->expects($this->any())->method('getRegistrationContext')->willReturn($this->registrationContext); + $this->rootFolder = \OCP\Server::get(IRootFolder::class); + $this->taskMapper = \OCP\Server::get(TaskMapper::class); $this->jobList = $this->createPartialMock(DummyJobList::class, ['add']); @@ -383,8 +384,6 @@ class TaskProcessingTest extends \Test\TestCase { } private function getFile(string $name, string $content): \OCP\Files\File { - /** @var IRootFolder $rootFolder */ - $rootFolder = \OC::$server->get(IRootFolder::class); $this->appData = \OC::$server->get(IAppDataFactory::class)->get('core'); try { $folder = $this->appData->getFolder('test'); @@ -392,7 +391,7 @@ class TaskProcessingTest extends \Test\TestCase { $folder = $this->appData->newFolder('test'); } $file = $folder->newFile($name, $content); - $inputFile = current($rootFolder->getByIdInPath($file->getId(), '/' . $rootFolder->getAppDataDirectoryName() . '/')); + $inputFile = current($this->rootFolder->getByIdInPath($file->getId(), '/' . $this->rootFolder->getAppDataDirectoryName() . '/')); if (!$inputFile instanceof \OCP\Files\File) { throw new \Exception('PEBCAK'); } @@ -581,12 +580,10 @@ class TaskProcessingTest extends \Test\TestCase { self::assertEquals(Task::STATUS_SUCCESSFUL, $task->getStatus()); self::assertEquals(1, $task->getProgress()); self::assertTrue(isset($task->getOutput()['spectrogram'])); - $root = \OCP\Server::get(IRootFolder::class); - $node = $root->getFirstNodeByIdInPath($task->getOutput()['spectrogram'], '/' . $root->getAppDataDirectoryName() . '/'); + $node = $this->rootFolder->getFirstNodeByIdInPath($task->getOutput()['spectrogram'], '/' . $this->rootFolder->getAppDataDirectoryName() . '/'); self::assertNotNull($node); self::assertInstanceOf(\OCP\Files\File::class, $node); self::assertEquals('World', $node->getContent()); - } public function testNonexistentTask() { @@ -731,6 +728,10 @@ class TaskProcessingTest extends \Test\TestCase { self::assertIsArray($task->getOutput()['images']); self::assertCount(3, $task->getOutput()['images']); self::assertTrue($this->providers[SuccessfulTextToImageProvider::class]->ran); + $node = $this->rootFolder->getFirstNodeByIdInPath($task->getOutput()['images'][0], '/' . $this->rootFolder->getAppDataDirectoryName() . '/'); + self::assertNotNull($node); + self::assertInstanceOf(\OCP\Files\File::class, $node); + self::assertEquals('test', $node->getContent()); } public function testShouldTransparentlyHandleFailingText2ImageProviders() { |