home.php 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  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. class Home extends Storage {
  43. /**
  44. * @var string tmpDir
  45. */
  46. private $tmpDir;
  47. private $userId;
  48. /**
  49. * @var \OC\User\User $user
  50. */
  51. private $user;
  52. protected function setUp() {
  53. parent::setUp();
  54. $this->tmpDir = \OC_Helper::tmpFolder();
  55. $this->userId = $this->getUniqueID('user_');
  56. $this->user = new DummyUser($this->userId, $this->tmpDir);
  57. $this->instance = new \OC\Files\Storage\Home(array('user' => $this->user));
  58. }
  59. protected function tearDown() {
  60. \OC_Helper::rmdirr($this->tmpDir);
  61. parent::tearDown();
  62. }
  63. /**
  64. * Tests that the root path matches the data dir
  65. */
  66. public function testRoot() {
  67. if (\OC_Util::runningOnWindows()) {
  68. // Windows removes trailing slashes when returning paths
  69. $this->assertEquals(rtrim($this->tmpDir, '/'), $this->instance->getLocalFolder(''));
  70. } else {
  71. $this->assertEquals($this->tmpDir, $this->instance->getLocalFolder(''));
  72. }
  73. }
  74. /**
  75. * Tests that the home id is in the format home::user1
  76. */
  77. public function testId() {
  78. $this->assertEquals('home::' . $this->userId, $this->instance->getId());
  79. }
  80. /**
  81. * Tests that the legacy home id is in the format local::/path/to/datadir/user1/
  82. */
  83. public function testLegacyId() {
  84. $this->instance = new \OC\Files\Storage\Home(array('user' => $this->user, 'legacy' => true));
  85. $this->assertEquals('local::' . $this->tmpDir . '/', $this->instance->getId());
  86. }
  87. /**
  88. * Tests that getCache() returns an instance of HomeCache
  89. */
  90. public function testGetCacheReturnsHomeCache() {
  91. $this->assertInstanceOf('\OC\Files\Cache\HomeCache', $this->instance->getCache());
  92. }
  93. public function testGetOwner() {
  94. $this->assertEquals($this->userId, $this->instance->getOwner(''));
  95. }
  96. }