1
0

IntegrationTest.php 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. <?php
  2. /**
  3. * Copyright (c) 2013 Robin Appelman <icewind@owncloud.com>
  4. * This file is licensed under the Affero General Public License version 3 or
  5. * later.
  6. * See the COPYING-README file.
  7. */
  8. namespace Test\Files\Node;
  9. use OC\Files\Node\Root;
  10. use OC\Files\Storage\Temporary;
  11. use OC\Files\View;
  12. use OC\User\User;
  13. use OCP\ILogger;
  14. use OCP\IUserManager;
  15. /**
  16. * Class IntegrationTest
  17. *
  18. * @group DB
  19. *
  20. * @package Test\Files\Node
  21. */
  22. class IntegrationTest extends \Test\TestCase {
  23. /**
  24. * @var \OC\Files\Node\Root $root
  25. */
  26. private $root;
  27. /**
  28. * @var \OC\Files\Storage\Storage[]
  29. */
  30. private $storages;
  31. /**
  32. * @var \OC\Files\View $view
  33. */
  34. private $view;
  35. protected function setUp() {
  36. parent::setUp();
  37. $manager = \OC\Files\Filesystem::getMountManager();
  38. \OC_Hook::clear('OC_Filesystem');
  39. $user = new User($this->getUniqueID('user'), new \Test\Util\User\Dummy);
  40. $this->loginAsUser($user->getUID());
  41. $this->view = new View();
  42. $this->root = new Root(
  43. $manager,
  44. $this->view,
  45. $user,
  46. \OC::$server->getUserMountCache(),
  47. $this->createMock(ILogger::class),
  48. $this->createMock(IUserManager::class)
  49. );
  50. $storage = new Temporary(array());
  51. $subStorage = new Temporary(array());
  52. $this->storages[] = $storage;
  53. $this->storages[] = $subStorage;
  54. $this->root->mount($storage, '/');
  55. $this->root->mount($subStorage, '/substorage/');
  56. }
  57. protected function tearDown() {
  58. foreach ($this->storages as $storage) {
  59. $storage->getCache()->clear();
  60. }
  61. $this->logout();
  62. parent::tearDown();
  63. }
  64. public function testBasicFile() {
  65. $file = $this->root->newFile('/foo.txt');
  66. $this->assertCount(2, $this->root->getDirectoryListing());
  67. $this->assertTrue($this->root->nodeExists('/foo.txt'));
  68. $id = $file->getId();
  69. $this->assertInstanceOf('\OC\Files\Node\File', $file);
  70. $file->putContent('qwerty');
  71. $this->assertEquals('text/plain', $file->getMimeType());
  72. $this->assertEquals('qwerty', $file->getContent());
  73. $this->assertFalse($this->root->nodeExists('/bar.txt'));
  74. $target = $file->move('/bar.txt');
  75. $this->assertEquals($id, $target->getId());
  76. $this->assertEquals($id, $file->getId());
  77. $this->assertFalse($this->root->nodeExists('/foo.txt'));
  78. $this->assertTrue($this->root->nodeExists('/bar.txt'));
  79. $this->assertEquals('bar.txt', $file->getName());
  80. $this->assertEquals('bar.txt', $file->getInternalPath());
  81. $file->move('/substorage/bar.txt');
  82. $this->assertEquals($id, $file->getId());
  83. $this->assertEquals('qwerty', $file->getContent());
  84. }
  85. public function testBasicFolder() {
  86. $folder = $this->root->newFolder('/foo');
  87. $this->assertTrue($this->root->nodeExists('/foo'));
  88. $file = $folder->newFile('/bar');
  89. $this->assertTrue($this->root->nodeExists('/foo/bar'));
  90. $file->putContent('qwerty');
  91. $listing = $folder->getDirectoryListing();
  92. $this->assertEquals(1, count($listing));
  93. $this->assertEquals($file->getId(), $listing[0]->getId());
  94. $this->assertEquals($file->getStorage(), $listing[0]->getStorage());
  95. $rootListing = $this->root->getDirectoryListing();
  96. $this->assertEquals(2, count($rootListing));
  97. $folder->move('/asd');
  98. /**
  99. * @var \OC\Files\Node\File $file
  100. */
  101. $file = $folder->get('/bar');
  102. $this->assertInstanceOf('\OC\Files\Node\File', $file);
  103. $this->assertFalse($this->root->nodeExists('/foo/bar'));
  104. $this->assertTrue($this->root->nodeExists('/asd/bar'));
  105. $this->assertEquals('qwerty', $file->getContent());
  106. $folder->move('/substorage/foo');
  107. /**
  108. * @var \OC\Files\Node\File $file
  109. */
  110. $file = $folder->get('/bar');
  111. $this->assertInstanceOf('\OC\Files\Node\File', $file);
  112. $this->assertTrue($this->root->nodeExists('/substorage/foo/bar'));
  113. $this->assertEquals('qwerty', $file->getContent());
  114. }
  115. }