root.php 2.8 KB

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