integration.php 3.8 KB

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