diff options
Diffstat (limited to 'tests/lib/Files/ViewTest.php')
-rw-r--r-- | tests/lib/Files/ViewTest.php | 93 |
1 files changed, 55 insertions, 38 deletions
diff --git a/tests/lib/Files/ViewTest.php b/tests/lib/Files/ViewTest.php index 57050059375..9dbe2a4e10e 100644 --- a/tests/lib/Files/ViewTest.php +++ b/tests/lib/Files/ViewTest.php @@ -15,6 +15,7 @@ use OC\Files\Storage\Common; use OC\Files\Storage\Temporary; use OC\Files\Stream\Quota; use OC\Files\View; +use OCP\Constants; use OCP\Files\Config\IMountProvider; use OCP\Files\FileInfo; use OCP\Files\Storage\IStorage; @@ -803,7 +804,6 @@ class ViewTest extends \Test\TestCase { } public function xtestLongPath() { - $storage = new Temporary([]); Filesystem::mount($storage, [], '/'); @@ -1169,11 +1169,11 @@ class ViewTest extends \Test\TestCase { $storage2->expects($this->any()) ->method('fopen') - ->will($this->returnCallback(function ($path, $mode) use ($storage2) { + ->willReturnCallback(function ($path, $mode) use ($storage2) { /** @var \PHPUnit_Framework_MockObject_MockObject | \OC\Files\Storage\Temporary $storage2 */ $source = fopen($storage2->getSourcePath($path), $mode); return Quota::wrap($source, 9); - })); + }); $storage1->mkdir('sub'); $storage1->file_put_contents('foo.txt', '0123456789ABCDEFGH'); @@ -1209,7 +1209,6 @@ class ViewTest extends \Test\TestCase { // second file not moved/copied $this->assertFalse($storage2->file_exists('dirtomove/indir2.txt')); $this->assertFalse($storage2->getCache()->get('dirtomove/indir2.txt')); - } public function testDeleteFailKeepCache() { @@ -1220,7 +1219,7 @@ class ViewTest extends \Test\TestCase { ->getMock(); $storage->expects($this->once()) ->method('unlink') - ->will($this->returnValue(false)); + ->willReturn(false); $scanner = $storage->getScanner(); $cache = $storage->getCache(); $storage->file_put_contents('foo.txt', 'asd'); @@ -1540,7 +1539,6 @@ class ViewTest extends \Test\TestCase { $this->assertFalse($this->isFileLocked($view, '/test//sub', ILockingProvider::LOCK_SHARED)); $this->assertFalse($this->isFileLocked($view, '/test//sub', ILockingProvider::LOCK_EXCLUSIVE)); - } public function hookPathProvider() { @@ -1597,7 +1595,7 @@ class ViewTest extends \Test\TestCase { $mountProvider = $this->createMock(IMountProvider::class); $mountProvider->expects($this->any()) ->method('getMountsForUser') - ->will($this->returnValue($mounts)); + ->willReturn($mounts); $mountProviderCollection = \OC::$server->getMountProviderCollection(); $mountProviderCollection->registerProvider($mountProvider); @@ -1611,17 +1609,17 @@ class ViewTest extends \Test\TestCase { public function testMountPointMove() { self::loginAsUser($this->user); - list($mount1, $mount2) = $this->createTestMovableMountPoints([ + [$mount1, $mount2] = $this->createTestMovableMountPoints([ $this->user . '/files/mount1', $this->user . '/files/mount2', ]); $mount1->expects($this->once()) ->method('moveMount') - ->will($this->returnValue(true)); + ->willReturn(true); $mount2->expects($this->once()) ->method('moveMount') - ->will($this->returnValue(true)); + ->willReturn(true); $view = new View('/' . $this->user . '/files/'); $view->mkdir('sub'); @@ -1636,7 +1634,7 @@ class ViewTest extends \Test\TestCase { public function testMoveMountPointIntoAnother() { self::loginAsUser($this->user); - list($mount1, $mount2) = $this->createTestMovableMountPoints([ + [$mount1, $mount2] = $this->createTestMovableMountPoints([ $this->user . '/files/mount1', $this->user . '/files/mount2', ]); @@ -1659,7 +1657,7 @@ class ViewTest extends \Test\TestCase { public function testMoveMountPointIntoSharedFolder() { self::loginAsUser($this->user); - list($mount1) = $this->createTestMovableMountPoints([ + [$mount1] = $this->createTestMovableMountPoints([ $this->user . '/files/mount1', ]); @@ -1846,13 +1844,13 @@ class ViewTest extends \Test\TestCase { $storage->expects($this->once()) ->method($operation) - ->will($this->returnCallback( + ->willReturnCallback( function () use ($view, $lockedPath, &$lockTypeDuring) { $lockTypeDuring = $this->getFileLockType($view, $lockedPath); return true; } - )); + ); $this->assertNull($this->getFileLockType($view, $lockedPath), 'File not locked before operation'); @@ -1890,13 +1888,13 @@ class ViewTest extends \Test\TestCase { $storage->expects($this->once()) ->method('fopen') - ->will($this->returnCallback( + ->willReturnCallback( function () use ($view, $path, &$lockTypeDuring) { $lockTypeDuring = $this->getFileLockType($view, $path); return fopen('php://temp', 'r+'); } - )); + ); $this->connectMockHooks('write', $view, $path, $lockTypePre, $lockTypePost); @@ -1929,13 +1927,13 @@ class ViewTest extends \Test\TestCase { $storage->expects($this->once()) ->method('fopen') - ->will($this->returnCallback( + ->willReturnCallback( function () use ($view, $path, &$lockTypeDuring) { $lockTypeDuring = $this->getFileLockType($view, $path); return fopen('php://temp', 'r+'); } - )); + ); $this->connectMockHooks('write', $view, $path, $lockTypePre, $lockTypePost); @@ -1990,11 +1988,11 @@ class ViewTest extends \Test\TestCase { $storage->expects($this->once()) ->method($operation) - ->will($this->returnCallback( + ->willReturnCallback( function () { throw new \Exception('Simulated exception'); } - )); + ); $thrown = false; try { @@ -2097,12 +2095,21 @@ class ViewTest extends \Test\TestCase { /** @var Temporary|\PHPUnit_Framework_MockObject_MockObject $storage */ $storage = $this->getMockBuilder(Temporary::class) - ->setMethods([$operation, 'filemtime']) + ->setMethods([$operation, 'getMetaData', 'filemtime']) ->getMock(); $storage->expects($this->any()) + ->method('getMetaData') + ->will($this->returnValue([ + 'mtime' => 1885434487, + 'etag' => '', + 'mimetype' => 'text/plain', + 'permissions' => Constants::PERMISSION_ALL, + 'size' => 3 + ])); + $storage->expects($this->any()) ->method('filemtime') - ->will($this->returnValue(123456789)); + ->willReturn(123456789); $sourcePath = 'original.txt'; $targetPath = 'target.txt'; @@ -2113,14 +2120,14 @@ class ViewTest extends \Test\TestCase { $storage->expects($this->once()) ->method($operation) - ->will($this->returnCallback( + ->willReturnCallback( function () use ($view, $sourcePath, $targetPath, &$lockTypeSourceDuring, &$lockTypeTargetDuring) { $lockTypeSourceDuring = $this->getFileLockType($view, $sourcePath); $lockTypeTargetDuring = $this->getFileLockType($view, $targetPath); return true; } - )); + ); $this->connectMockHooks($operation, $view, $sourcePath, $lockTypeSourcePre, $lockTypeSourcePost); $this->connectMockHooks($operation, $view, $targetPath, $lockTypeTargetPre, $lockTypeTargetPost); @@ -2166,11 +2173,11 @@ class ViewTest extends \Test\TestCase { $storage->expects($this->once()) ->method('copy') - ->will($this->returnCallback( + ->willReturnCallback( function () { throw new \Exception(); } - )); + ); $this->connectMockHooks('copy', $view, $sourcePath, $lockTypeSourcePre, $lockTypeSourcePost); $this->connectMockHooks('copy', $view, $targetPath, $lockTypeTargetPre, $lockTypeTargetPost); @@ -2277,12 +2284,21 @@ class ViewTest extends \Test\TestCase { ->getMock(); /** @var Temporary|\PHPUnit_Framework_MockObject_MockObject $storage2 */ $storage2 = $this->getMockBuilder(Temporary::class) - ->setMethods([$storageOperation, 'filemtime']) + ->setMethods([$storageOperation, 'getMetaData', 'filemtime']) ->getMock(); $storage2->expects($this->any()) + ->method('getMetaData') + ->will($this->returnValue([ + 'mtime' => 1885434487, + 'etag' => '', + 'mimetype' => 'text/plain', + 'permissions' => Constants::PERMISSION_ALL, + 'size' => 3 + ])); + $storage2->expects($this->any()) ->method('filemtime') - ->will($this->returnValue(123456789)); + ->willReturn(123456789); $sourcePath = 'original.txt'; $targetPath = 'substorage/target.txt'; @@ -2296,14 +2312,14 @@ class ViewTest extends \Test\TestCase { ->method($storageOperation); $storage2->expects($this->once()) ->method($storageOperation) - ->will($this->returnCallback( + ->willReturnCallback( function () use ($view, $sourcePath, $targetPath, &$lockTypeSourceDuring, &$lockTypeTargetDuring) { $lockTypeSourceDuring = $this->getFileLockType($view, $sourcePath); $lockTypeTargetDuring = $this->getFileLockType($view, $targetPath); return true; } - )); + ); $this->connectMockHooks($viewOperation, $view, $sourcePath, $lockTypeSourcePre, $lockTypeSourcePost); $this->connectMockHooks($viewOperation, $view, $targetPath, $lockTypeTargetPre, $lockTypeTargetPost); @@ -2331,7 +2347,7 @@ class ViewTest extends \Test\TestCase { public function testLockMoveMountPoint() { self::loginAsUser('test'); - list($mount) = $this->createTestMovableMountPoints([ + [$mount] = $this->createTestMovableMountPoints([ $this->user . '/files/substorage', ]); @@ -2343,7 +2359,7 @@ class ViewTest extends \Test\TestCase { $mount->expects($this->once()) ->method('moveMount') - ->will($this->returnCallback( + ->willReturnCallback( function ($target) use ($mount, $view, $sourcePath, $targetPath, &$lockTypeSourceDuring, &$lockTypeTargetDuring, &$lockTypeSharedRootDuring) { $lockTypeSourceDuring = $this->getFileLockType($view, $sourcePath, true); $lockTypeTargetDuring = $this->getFileLockType($view, $targetPath, true); @@ -2354,7 +2370,7 @@ class ViewTest extends \Test\TestCase { return true; } - )); + ); $this->connectMockHooks('rename', $view, $sourcePath, $lockTypeSourcePre, $lockTypeSourcePost, true); $this->connectMockHooks('rename', $view, $targetPath, $lockTypeTargetPre, $lockTypeTargetPost, true); @@ -2408,18 +2424,18 @@ class ViewTest extends \Test\TestCase { $eventHandler->expects($this->any()) ->method('preCallback') - ->will($this->returnCallback( + ->willReturnCallback( function () use ($view, $path, $onMountPoint, &$lockTypePre) { $lockTypePre = $this->getFileLockType($view, $path, $onMountPoint); } - )); + ); $eventHandler->expects($this->any()) ->method('postCallback') - ->will($this->returnCallback( + ->willReturnCallback( function () use ($view, $path, $onMountPoint, &$lockTypePost) { $lockTypePost = $this->getFileLockType($view, $path, $onMountPoint); } - )); + ); if ($hookType !== null) { Util::connectHook( @@ -2450,7 +2466,7 @@ class ViewTest extends \Test\TestCase { private function getFileLockType(View $view, $path, $onMountPoint = false) { if ($this->isFileLocked($view, $path, ILockingProvider::LOCK_EXCLUSIVE, $onMountPoint)) { return ILockingProvider::LOCK_EXCLUSIVE; - } else if ($this->isFileLocked($view, $path, ILockingProvider::LOCK_SHARED, $onMountPoint)) { + } elseif ($this->isFileLocked($view, $path, ILockingProvider::LOCK_SHARED, $onMountPoint)) { return ILockingProvider::LOCK_SHARED; } return null; @@ -2553,6 +2569,7 @@ class ViewTest extends \Test\TestCase { $fh = tmpfile(); fwrite($fh, 'fooo'); rewind($fh); + clearstatcache(); $view->file_put_contents('', $fh); $this->assertEquals('fooo', $view->file_get_contents('')); $data = $view->getFileInfo('.'); |