1
0

HomeTest.php 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. <?php
  2. /**
  3. * ownCloud
  4. *
  5. * @author Robin Appelman
  6. * @copyright 2012 Robin Appelman icewind@owncloud.com
  7. *
  8. * This library is free software; you can redistribute it and/or
  9. * modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE
  10. * License as published by the Free Software Foundation; either
  11. * version 3 of the License, or any later version.
  12. *
  13. * This library is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU AFFERO GENERAL PUBLIC LICENSE for more details.
  17. *
  18. * You should have received a copy of the GNU Affero General Public
  19. * License along with this library. If not, see <http://www.gnu.org/licenses/>.
  20. *
  21. */
  22. namespace Test\Files\Storage;
  23. use OC\User\User;
  24. class DummyUser extends User {
  25. private $home;
  26. private $uid;
  27. /**
  28. * @param string $uid
  29. * @param string $home
  30. */
  31. public function __construct($uid, $home) {
  32. $this->uid = $uid;
  33. $this->home = $home;
  34. }
  35. public function getHome() {
  36. return $this->home;
  37. }
  38. public function getUID() {
  39. return $this->uid;
  40. }
  41. }
  42. /**
  43. * Class Home
  44. *
  45. * @group DB
  46. *
  47. * @package Test\Files\Storage
  48. */
  49. class HomeTest extends Storage {
  50. /**
  51. * @var string tmpDir
  52. */
  53. private $tmpDir;
  54. private $userId;
  55. /**
  56. * @var \OC\User\User $user
  57. */
  58. private $user;
  59. protected function setUp(): void {
  60. parent::setUp();
  61. $this->tmpDir = \OC::$server->getTempManager()->getTemporaryFolder();
  62. $this->userId = $this->getUniqueID('user_');
  63. $this->user = new DummyUser($this->userId, $this->tmpDir);
  64. $this->instance = new \OC\Files\Storage\Home(['user' => $this->user]);
  65. }
  66. protected function tearDown(): void {
  67. \OC_Helper::rmdirr($this->tmpDir);
  68. parent::tearDown();
  69. }
  70. /**
  71. * Tests that the home id is in the format home::user1
  72. */
  73. public function testId() {
  74. $this->assertEquals('home::' . $this->userId, $this->instance->getId());
  75. }
  76. /**
  77. * Tests that getCache() returns an instance of HomeCache
  78. */
  79. public function testGetCacheReturnsHomeCache() {
  80. $this->assertInstanceOf('\OC\Files\Cache\HomeCache', $this->instance->getCache());
  81. }
  82. public function testGetOwner() {
  83. $this->assertEquals($this->userId, $this->instance->getOwner(''));
  84. }
  85. }