1
0

integration.php 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  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\Cache\Cache;
  10. use OC\Files\Node\Root;
  11. use OC\Files\Storage\Temporary;
  12. use OC\Files\View;
  13. use OC\User\User;
  14. class IntegrationTests extends \Test\TestCase {
  15. /**
  16. * @var \OC\Files\Node\Root $root
  17. */
  18. private $root;
  19. /**
  20. * @var \OC\Files\Storage\Storage[]
  21. */
  22. private $storages;
  23. /**
  24. * @var \OC\Files\View $view
  25. */
  26. private $view;
  27. protected function setUp() {
  28. parent::setUp();
  29. $manager = \OC\Files\Filesystem::getMountManager();
  30. \OC_Hook::clear('OC_Filesystem');
  31. \OC_Hook::connect('OC_Filesystem', 'post_write', '\OC\Files\Cache\Updater', 'writeHook');
  32. \OC_Hook::connect('OC_Filesystem', 'post_delete', '\OC\Files\Cache\Updater', 'deleteHook');
  33. \OC_Hook::connect('OC_Filesystem', 'post_rename', '\OC\Files\Cache\Updater', 'renameHook');
  34. \OC_Hook::connect('OC_Filesystem', 'post_touch', '\OC\Files\Cache\Updater', 'touchHook');
  35. $user = new User($this->getUniqueID('user'), new \OC_User_Dummy);
  36. $this->loginAsUser($user->getUID());
  37. $this->view = new View();
  38. $this->root = new Root($manager, $this->view, $user);
  39. $storage = new Temporary(array());
  40. $subStorage = new Temporary(array());
  41. $this->storages[] = $storage;
  42. $this->storages[] = $subStorage;
  43. $this->root->mount($storage, '/');
  44. $this->root->mount($subStorage, '/substorage/');
  45. }
  46. protected function tearDown() {
  47. foreach ($this->storages as $storage) {
  48. $storage->getCache()->clear();
  49. }
  50. $this->logout();
  51. parent::tearDown();
  52. }
  53. public function testBasicFile() {
  54. $file = $this->root->newFile('/foo.txt');
  55. $this->assertCount(2, $this->root->getDirectoryListing());
  56. $this->assertTrue($this->root->nodeExists('/foo.txt'));
  57. $id = $file->getId();
  58. $this->assertInstanceOf('\OC\Files\Node\File', $file);
  59. $file->putContent('qwerty');
  60. $this->assertEquals('text/plain', $file->getMimeType());
  61. $this->assertEquals('qwerty', $file->getContent());
  62. $this->assertFalse($this->root->nodeExists('/bar.txt'));
  63. $target = $file->move('/bar.txt');
  64. $this->assertEquals($id, $target->getId());
  65. $this->assertEquals($id, $file->getId());
  66. $this->assertFalse($this->root->nodeExists('/foo.txt'));
  67. $this->assertTrue($this->root->nodeExists('/bar.txt'));
  68. $this->assertEquals('bar.txt', $file->getName());
  69. $this->assertEquals('bar.txt', $file->getInternalPath());
  70. $file->move('/substorage/bar.txt');
  71. $this->assertNotEquals($id, $file->getId());
  72. $this->assertEquals('qwerty', $file->getContent());
  73. }
  74. public function testBasicFolder() {
  75. $folder = $this->root->newFolder('/foo');
  76. $this->assertTrue($this->root->nodeExists('/foo'));
  77. $file = $folder->newFile('/bar');
  78. $this->assertTrue($this->root->nodeExists('/foo/bar'));
  79. $file->putContent('qwerty');
  80. $listing = $folder->getDirectoryListing();
  81. $this->assertEquals(1, count($listing));
  82. $this->assertEquals($file->getId(), $listing[0]->getId());
  83. $this->assertEquals($file->getStorage(), $listing[0]->getStorage());
  84. $rootListing = $this->root->getDirectoryListing();
  85. $this->assertEquals(2, count($rootListing));
  86. $folder->move('/asd');
  87. /**
  88. * @var \OC\Files\Node\File $file
  89. */
  90. $file = $folder->get('/bar');
  91. $this->assertInstanceOf('\OC\Files\Node\File', $file);
  92. $this->assertFalse($this->root->nodeExists('/foo/bar'));
  93. $this->assertTrue($this->root->nodeExists('/asd/bar'));
  94. $this->assertEquals('qwerty', $file->getContent());
  95. $folder->move('/substorage/foo');
  96. /**
  97. * @var \OC\Files\Node\File $file
  98. */
  99. $file = $folder->get('/bar');
  100. $this->assertInstanceOf('\OC\Files\Node\File', $file);
  101. $this->assertTrue($this->root->nodeExists('/substorage/foo/bar'));
  102. $this->assertEquals('qwerty', $file->getContent());
  103. }
  104. }