root.php 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  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 OCP\Files\NotPermittedException;
  11. use OC\Files\Mount\Manager;
  12. class Root extends \PHPUnit_Framework_TestCase {
  13. private $user;
  14. public function setUp() {
  15. $this->user = new \OC\User\User('', new \OC_User_Dummy);
  16. }
  17. public function testGet() {
  18. $manager = new Manager();
  19. /**
  20. * @var \OC\Files\Storage\Storage $storage
  21. */
  22. $storage = $this->getMock('\OC\Files\Storage\Storage');
  23. /**
  24. * @var \OC\Files\View | \PHPUnit_Framework_MockObject_MockObject $view
  25. */
  26. $view = $this->getMock('\OC\Files\View');
  27. $root = new \OC\Files\Node\Root($manager, $view, $this->user);
  28. $view->expects($this->once())
  29. ->method('getFileInfo')
  30. ->with('/bar/foo')
  31. ->will($this->returnValue(array('fileid' => 10, 'path' => 'bar/foo', 'name', 'mimetype' => 'text/plain')));
  32. $view->expects($this->once())
  33. ->method('is_dir')
  34. ->with('/bar/foo')
  35. ->will($this->returnValue(false));
  36. $view->expects($this->once())
  37. ->method('file_exists')
  38. ->with('/bar/foo')
  39. ->will($this->returnValue(true));
  40. $root->mount($storage, '');
  41. $node = $root->get('/bar/foo');
  42. $this->assertEquals(10, $node->getId());
  43. $this->assertInstanceOf('\OC\Files\Node\File', $node);
  44. }
  45. /**
  46. * @expectedException \OCP\Files\NotFoundException
  47. */
  48. public function testGetNotFound() {
  49. $manager = new Manager();
  50. /**
  51. * @var \OC\Files\Storage\Storage $storage
  52. */
  53. $storage = $this->getMock('\OC\Files\Storage\Storage');
  54. /**
  55. * @var \OC\Files\View | \PHPUnit_Framework_MockObject_MockObject $view
  56. */
  57. $view = $this->getMock('\OC\Files\View');
  58. $root = new \OC\Files\Node\Root($manager, $view, $this->user);
  59. $view->expects($this->once())
  60. ->method('file_exists')
  61. ->with('/bar/foo')
  62. ->will($this->returnValue(false));
  63. $root->mount($storage, '');
  64. $root->get('/bar/foo');
  65. }
  66. /**
  67. * @expectedException \OCP\Files\NotPermittedException
  68. */
  69. public function testGetInvalidPath() {
  70. $manager = new Manager();
  71. /**
  72. * @var \OC\Files\View | \PHPUnit_Framework_MockObject_MockObject $view
  73. */
  74. $view = $this->getMock('\OC\Files\View');
  75. $root = new \OC\Files\Node\Root($manager, $view, $this->user);
  76. $root->get('/../foo');
  77. }
  78. /**
  79. * @expectedException \OCP\Files\NotFoundException
  80. */
  81. public function testGetNoStorages() {
  82. $manager = new Manager();
  83. /**
  84. * @var \OC\Files\View | \PHPUnit_Framework_MockObject_MockObject $view
  85. */
  86. $view = $this->getMock('\OC\Files\View');
  87. $root = new \OC\Files\Node\Root($manager, $view, $this->user);
  88. $root->get('/bar/foo');
  89. }
  90. }