CacheTest.php 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. <?php
  2. /**
  3. * @copyright Copyright (c) 2016, ownCloud, Inc.
  4. *
  5. * @author Joas Schilling <coding@schilljs.com>
  6. * @author Robin Appelman <robin@icewind.nl>
  7. * @author Thomas Müller <thomas.mueller@tmit.eu>
  8. * @author Vincent Petry <pvince81@owncloud.com>
  9. *
  10. * @license AGPL-3.0
  11. *
  12. * This code is free software: you can redistribute it and/or modify
  13. * it under the terms of the GNU Affero General Public License, version 3,
  14. * as published by the Free Software Foundation.
  15. *
  16. * This program is distributed in the hope that it will be useful,
  17. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  18. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  19. * GNU Affero General Public License for more details.
  20. *
  21. * You should have received a copy of the GNU Affero General Public License, version 3,
  22. * along with this program. If not, see <http://www.gnu.org/licenses/>
  23. *
  24. */
  25. namespace OCA\Files_Sharing\Tests\External;
  26. use OC\Federation\CloudIdManager;
  27. use OCA\Files_Sharing\Tests\TestCase;
  28. use OCP\Federation\ICloudIdManager;
  29. /**
  30. * Class Cache
  31. *
  32. * @group DB
  33. *
  34. * @package OCA\Files_Sharing\Tests\External
  35. */
  36. class CacheTest extends TestCase {
  37. /**
  38. * @var \OC\Files\Storage\Storage
  39. **/
  40. private $storage;
  41. /**
  42. * @var \OCA\Files_Sharing\External\Cache
  43. */
  44. private $cache;
  45. /**
  46. * @var string
  47. */
  48. private $remoteUser;
  49. /** @var ICloudIdManager */
  50. private $cloudIdManager;
  51. protected function setUp() {
  52. parent::setUp();
  53. $this->cloudIdManager = new CloudIdManager();
  54. $this->remoteUser = $this->getUniqueID('remoteuser');
  55. $this->storage = $this->getMockBuilder('\OCA\Files_Sharing\External\Storage')
  56. ->disableOriginalConstructor()
  57. ->getMock();
  58. $this->storage
  59. ->expects($this->any())
  60. ->method('getId')
  61. ->will($this->returnValue('dummystorage::'));
  62. $this->cache = new \OCA\Files_Sharing\External\Cache(
  63. $this->storage,
  64. $this->cloudIdManager->getCloudId($this->remoteUser, 'http://example.com/owncloud')
  65. );
  66. $this->cache->put(
  67. 'test.txt',
  68. array(
  69. 'mimetype' => 'text/plain',
  70. 'size' => 5,
  71. 'mtime' => 123,
  72. )
  73. );
  74. }
  75. protected function tearDown() {
  76. if ($this->cache) {
  77. $this->cache->clear();
  78. }
  79. parent::tearDown();
  80. }
  81. public function testGetInjectsOwnerDisplayName() {
  82. $info = $this->cache->get('test.txt');
  83. $this->assertEquals(
  84. $this->remoteUser . '@example.com/owncloud',
  85. $info['displayname_owner']
  86. );
  87. }
  88. public function testGetReturnsFalseIfNotFound() {
  89. $info = $this->cache->get('unexisting-entry.txt');
  90. $this->assertFalse($info);
  91. }
  92. public function testGetFolderPopulatesOwner() {
  93. $dirId = $this->cache->put(
  94. 'subdir',
  95. array(
  96. 'mimetype' => 'httpd/unix-directory',
  97. 'size' => 5,
  98. 'mtime' => 123,
  99. )
  100. );
  101. $this->cache->put(
  102. 'subdir/contents.txt',
  103. array(
  104. 'mimetype' => 'text/plain',
  105. 'size' => 5,
  106. 'mtime' => 123,
  107. )
  108. );
  109. $results = $this->cache->getFolderContentsById($dirId);
  110. $this->assertEquals(1, count($results));
  111. $this->assertEquals(
  112. $this->remoteUser . '@example.com/owncloud',
  113. $results[0]['displayname_owner']
  114. );
  115. }
  116. }