1
0

NullCacheTest.php 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. <?php
  2. /**
  3. * SPDX-FileCopyrightText: 2016 Nextcloud GmbH and Nextcloud contributors
  4. * SPDX-License-Identifier: AGPL-3.0-or-later
  5. */
  6. namespace Test\Lockdown\Filesystem;
  7. use OC\ForbiddenException;
  8. use OC\Lockdown\Filesystem\NullCache;
  9. use OCP\Constants;
  10. use OCP\Files\Cache\ICache;
  11. use OCP\Files\FileInfo;
  12. class NulLCacheTest extends \Test\TestCase {
  13. /** @var NullCache */
  14. private $cache;
  15. protected function setUp(): void {
  16. parent::setUp();
  17. $this->cache = new NullCache();
  18. }
  19. public function testGetNumericStorageId() {
  20. $this->assertSame(-1, $this->cache->getNumericStorageId());
  21. }
  22. public function testGetEmpty() {
  23. $this->assertNull($this->cache->get('foo'));
  24. }
  25. public function testGet() {
  26. $data = $this->cache->get('');
  27. $this->assertEquals(-1, $data['fileid']);
  28. $this->assertEquals(-1, $data['parent']);
  29. $this->assertEquals('', $data['name']);
  30. $this->assertEquals('', $data['path']);
  31. $this->assertEquals('0', $data['size']);
  32. $this->assertEquals('', $data['etag']);
  33. $this->assertEquals(FileInfo::MIMETYPE_FOLDER, $data['mimetype']);
  34. $this->assertEquals('httpd', $data['mimepart']);
  35. $this->assertEquals(Constants::PERMISSION_READ, $data['permissions']);
  36. }
  37. public function testGetFolderContents() {
  38. $this->assertSame([], $this->cache->getFolderContents('foo'));
  39. }
  40. public function testGetFolderContentsById() {
  41. $this->assertSame([], $this->cache->getFolderContentsById(42));
  42. }
  43. public function testPut() {
  44. $this->expectException(ForbiddenException::class);
  45. $this->expectExceptionMessage('This request is not allowed to access the filesystem');
  46. $this->cache->put('foo', ['size' => 100]);
  47. }
  48. public function testInsert() {
  49. $this->expectException(ForbiddenException::class);
  50. $this->expectExceptionMessage('This request is not allowed to access the filesystem');
  51. $this->cache->insert('foo', ['size' => 100]);
  52. }
  53. public function testUpdate() {
  54. $this->expectException(ForbiddenException::class);
  55. $this->expectExceptionMessage('This request is not allowed to access the filesystem');
  56. $this->cache->update('foo', ['size' => 100]);
  57. }
  58. public function testGetId() {
  59. $this->assertSame(-1, $this->cache->getId('foo'));
  60. }
  61. public function testGetParentId() {
  62. $this->assertSame(-1, $this->cache->getParentId('foo'));
  63. }
  64. public function testInCache() {
  65. $this->assertTrue($this->cache->inCache(''));
  66. $this->assertFalse($this->cache->inCache('foo'));
  67. }
  68. public function testRemove() {
  69. $this->expectException(ForbiddenException::class);
  70. $this->expectExceptionMessage('This request is not allowed to access the filesystem');
  71. $this->cache->remove('foo');
  72. }
  73. public function testMove() {
  74. $this->expectException(ForbiddenException::class);
  75. $this->expectExceptionMessage('This request is not allowed to access the filesystem');
  76. $this->cache->move('foo', 'bar');
  77. }
  78. public function testMoveFromCache() {
  79. $sourceCache = $this->createMock(ICache::class);
  80. $this->expectException(ForbiddenException::class);
  81. $this->expectExceptionMessage('This request is not allowed to access the filesystem');
  82. $this->cache->moveFromCache($sourceCache, 'foo', 'bar');
  83. }
  84. public function testGetStatus() {
  85. $this->assertSame(ICache::COMPLETE, $this->cache->getStatus('foo'));
  86. }
  87. public function testSearch() {
  88. $this->assertSame([], $this->cache->search('foo'));
  89. }
  90. public function testSearchByMime() {
  91. $this->assertSame([], $this->cache->searchByMime('foo'));
  92. }
  93. public function testGetIncomplete() {
  94. $this->assertSame([], $this->cache->getIncomplete());
  95. }
  96. public function testGetPathById() {
  97. $this->assertSame('', $this->cache->getPathById(42));
  98. }
  99. public function testNormalize() {
  100. $this->assertSame('foo/ bar /', $this->cache->normalize('foo/ bar /'));
  101. }
  102. }