From ad68b06dcccac031319e38265b7a32f3d77fdf28 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=B4me=20Chilliet?= Date: Thu, 22 Feb 2024 10:09:03 +0100 Subject: [PATCH] feat(tests): Add test for moveFromStorage MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Côme Chilliet --- tests/lib/Files/Storage/Storage.php | 38 +++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/tests/lib/Files/Storage/Storage.php b/tests/lib/Files/Storage/Storage.php index 82a31c28ccb..345964e9444 100644 --- a/tests/lib/Files/Storage/Storage.php +++ b/tests/lib/Files/Storage/Storage.php @@ -698,4 +698,42 @@ abstract class Storage extends \Test\TestCase { $this->assertEquals($size, $pos); } + + public function testMoveFromStorage() { + $source = 'foo.txt'; + $target = 'bar.txt'; + + $instance = $this->createMock(\OCP\Files\Storage\IStorage::class); + $mTime = time() - 400; + + $instance->method('copyFromStorage') + ->willThrowException(new \Exception('copy')); + $instance->expects(static::once()) + ->method('isDeletable') + ->with($source) + ->willReturn(true); + $instance->expects(static::atLeastOnce()) + ->method('is_dir') + ->with($source) + ->willReturn(false); + $instance->expects(static::once()) + ->method('fopen') + ->willReturnCallback(function ($path, $mode) { + $temp = \OCP\Server::get(\OCP\ITempManager::class); + return fopen($temp->getTemporaryFile(), $mode); + }); + $instance->expects(static::once()) + ->method('unlink') + ->with($source) + ->willReturn(true); + $instance->expects(static::atLeastOnce()) + ->method('filemtime') + ->with($source) + ->willReturn($mTime); + + $this->assertFalse($this->instance->file_exists($target)); + $this->instance->moveFromStorage($instance, $source, $target); + $this->assertTrue($this->instance->file_exists($target)); + $this->assertEquals($mTime, $this->instance->filemtime($target), 'mtime was not preserved by move'); + } }