HomeTest.php 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. <?php
  2. /**
  3. * SPDX-FileCopyrightText: 2016-2024 Nextcloud GmbH and Nextcloud contributors
  4. * SPDX-FileCopyrightText: 2016 ownCloud, Inc.
  5. * SPDX-License-Identifier: AGPL-3.0-or-later
  6. */
  7. namespace Test\Files\Storage;
  8. use OC\User\User;
  9. class DummyUser extends User {
  10. private $home;
  11. private $uid;
  12. /**
  13. * @param string $uid
  14. * @param string $home
  15. */
  16. public function __construct($uid, $home) {
  17. $this->uid = $uid;
  18. $this->home = $home;
  19. }
  20. public function getHome() {
  21. return $this->home;
  22. }
  23. public function getUID() {
  24. return $this->uid;
  25. }
  26. }
  27. /**
  28. * Class Home
  29. *
  30. * @group DB
  31. *
  32. * @package Test\Files\Storage
  33. */
  34. class HomeTest extends Storage {
  35. /**
  36. * @var string tmpDir
  37. */
  38. private $tmpDir;
  39. private $userId;
  40. /**
  41. * @var \OC\User\User $user
  42. */
  43. private $user;
  44. protected function setUp(): void {
  45. parent::setUp();
  46. $this->tmpDir = \OC::$server->getTempManager()->getTemporaryFolder();
  47. $this->userId = $this->getUniqueID('user_');
  48. $this->user = new DummyUser($this->userId, $this->tmpDir);
  49. $this->instance = new \OC\Files\Storage\Home(['user' => $this->user]);
  50. }
  51. protected function tearDown(): void {
  52. \OC_Helper::rmdirr($this->tmpDir);
  53. parent::tearDown();
  54. }
  55. /**
  56. * Tests that the home id is in the format home::user1
  57. */
  58. public function testId() {
  59. $this->assertEquals('home::' . $this->userId, $this->instance->getId());
  60. }
  61. /**
  62. * Tests that getCache() returns an instance of HomeCache
  63. */
  64. public function testGetCacheReturnsHomeCache() {
  65. $this->assertInstanceOf('\OC\Files\Cache\HomeCache', $this->instance->getCache());
  66. }
  67. public function testGetOwner() {
  68. $this->assertEquals($this->userId, $this->instance->getOwner(''));
  69. }
  70. }