NullCacheTest.php 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  1. <?php
  2. /**
  3. * @copyright 2016, Roeland Jago Douma <roeland@famdouma.nl>
  4. *
  5. * @author Roeland Jago Douma <roeland@famdouma.nl>
  6. *
  7. * @license GNU AGPL version 3 or any later version
  8. *
  9. * This program is free software: you can redistribute it and/or modify
  10. * it under the terms of the GNU Affero General Public License as
  11. * published by the Free Software Foundation, either version 3 of the
  12. * License, or (at your option) any later version.
  13. *
  14. * This program is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. * GNU Affero General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU Affero General Public License
  20. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  21. *
  22. */
  23. namespace Test\Lockdown\Filesystem;
  24. use OC\ForbiddenException;
  25. use OC\Lockdown\Filesystem\NullCache;
  26. use OCP\Constants;
  27. use OCP\Files\Cache\ICache;
  28. use OCP\Files\FileInfo;
  29. class NulLCacheTest extends \Test\TestCase {
  30. /** @var NullCache */
  31. private $cache;
  32. public function setUp() {
  33. parent::setUp();
  34. $this->cache = new NullCache();
  35. }
  36. public function testGetNumericStorageId() {
  37. $this->assertSame(-1, $this->cache->getNumericStorageId());
  38. }
  39. public function testGetEmpty() {
  40. $this->assertNull($this->cache->get('foo'));
  41. }
  42. public function testGet() {
  43. $data = $this->cache->get('');
  44. $this->assertEquals(-1, $data['fileid']);
  45. $this->assertEquals(-1, $data['parent']);
  46. $this->assertEquals('', $data['name']);
  47. $this->assertEquals('', $data['path']);
  48. $this->assertEquals('0', $data['size']);
  49. $this->assertEquals('', $data['etag']);
  50. $this->assertEquals(FileInfo::MIMETYPE_FOLDER, $data['mimetype']);
  51. $this->assertEquals('httpd', $data['mimepart']);
  52. $this->assertEquals(Constants::PERMISSION_READ, $data['permissions']);
  53. }
  54. public function testGetFolderContents() {
  55. $this->assertSame([], $this->cache->getFolderContents('foo'));
  56. }
  57. public function testGetFolderContentsById() {
  58. $this->assertSame([], $this->cache->getFolderContentsById(42));
  59. }
  60. public function testPut() {
  61. $this->expectException(ForbiddenException::class);
  62. $this->expectExceptionMessage('This request is not allowed to access the filesystem');
  63. $this->cache->put('foo', ['size' => 100]);
  64. }
  65. public function testInsert() {
  66. $this->expectException(ForbiddenException::class);
  67. $this->expectExceptionMessage('This request is not allowed to access the filesystem');
  68. $this->cache->insert('foo', ['size' => 100]);
  69. }
  70. public function testUpdate() {
  71. $this->expectException(ForbiddenException::class);
  72. $this->expectExceptionMessage('This request is not allowed to access the filesystem');
  73. $this->cache->update('foo', ['size' => 100]);
  74. }
  75. public function testGetId() {
  76. $this->assertSame(-1, $this->cache->getId('foo'));
  77. }
  78. public function testGetParentId() {
  79. $this->assertSame(-1, $this->cache->getParentId('foo'));
  80. }
  81. public function testInCache() {
  82. $this->assertTrue($this->cache->inCache(''));
  83. $this->assertFalse($this->cache->inCache('foo'));
  84. }
  85. public function testRemove() {
  86. $this->expectException(ForbiddenException::class);
  87. $this->expectExceptionMessage('This request is not allowed to access the filesystem');
  88. $this->cache->remove('foo');
  89. }
  90. public function testMove() {
  91. $this->expectException(ForbiddenException::class);
  92. $this->expectExceptionMessage('This request is not allowed to access the filesystem');
  93. $this->cache->move('foo', 'bar');
  94. }
  95. public function testMoveFromCache() {
  96. $sourceCache = $this->createMock(ICache::class);
  97. $this->expectException(ForbiddenException::class);
  98. $this->expectExceptionMessage('This request is not allowed to access the filesystem');
  99. $this->cache->moveFromCache($sourceCache, 'foo', 'bar');
  100. }
  101. public function testGetStatus() {
  102. $this->assertSame(ICache::COMPLETE, $this->cache->getStatus('foo'));
  103. }
  104. public function testSearch() {
  105. $this->assertSame([], $this->cache->search('foo'));
  106. }
  107. public function testSearchByMime() {
  108. $this->assertSame([], $this->cache->searchByMime('foo'));
  109. }
  110. public function testGetIncomplete() {
  111. $this->assertSame([], $this->cache->getIncomplete());
  112. }
  113. public function testGetPathById() {
  114. $this->assertSame('', $this->cache->getPathById(42));
  115. }
  116. public function testNormalize() {
  117. $this->assertSame('foo/ bar /', $this->cache->normalize('foo/ bar /'));
  118. }
  119. }