file.php 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670
  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\NotFoundException;
  11. use OCP\Files\NotPermittedException;
  12. use OC\Files\View;
  13. class File extends \Test\TestCase {
  14. private $user;
  15. protected function setUp() {
  16. parent::setUp();
  17. $this->user = new \OC\User\User('', new \OC_User_Dummy);
  18. }
  19. protected function getFileInfo($data) {
  20. return new FileInfo('', null, '', $data, null);
  21. }
  22. public function testDelete() {
  23. $manager = $this->getMock('\OC\Files\Mount\Manager');
  24. /**
  25. * @var \OC\Files\View | \PHPUnit_Framework_MockObject_MockObject $view
  26. */
  27. $view = $this->getMock('\OC\Files\View');
  28. $root = $this->getMock('\OC\Files\Node\Root', array(), array($manager, $view, $this->user));
  29. $root->expects($this->exactly(2))
  30. ->method('emit')
  31. ->will($this->returnValue(true));
  32. $root->expects($this->any())
  33. ->method('getUser')
  34. ->will($this->returnValue($this->user));
  35. $view->expects($this->once())
  36. ->method('getFileInfo')
  37. ->with('/bar/foo')
  38. ->will($this->returnValue($this->getFileInfo(array('permissions' => \OCP\Constants::PERMISSION_ALL))));
  39. $view->expects($this->once())
  40. ->method('unlink')
  41. ->with('/bar/foo')
  42. ->will($this->returnValue(true));
  43. $node = new \OC\Files\Node\File($root, $view, '/bar/foo');
  44. $node->delete();
  45. }
  46. public function testDeleteHooks() {
  47. $test = $this;
  48. $hooksRun = 0;
  49. /**
  50. * @param \OC\Files\Node\File $node
  51. */
  52. $preListener = function ($node) use (&$test, &$hooksRun) {
  53. $test->assertInstanceOf('\OC\Files\Node\File', $node);
  54. $test->assertEquals('foo', $node->getInternalPath());
  55. $test->assertEquals('/bar/foo', $node->getPath());
  56. $test->assertEquals(1, $node->getId());
  57. $hooksRun++;
  58. };
  59. /**
  60. * @param \OC\Files\Node\File $node
  61. */
  62. $postListener = function ($node) use (&$test, &$hooksRun) {
  63. $test->assertInstanceOf('\OC\Files\Node\NonExistingFile', $node);
  64. $test->assertEquals('foo', $node->getInternalPath());
  65. $test->assertEquals('/bar/foo', $node->getPath());
  66. $hooksRun++;
  67. };
  68. /**
  69. * @var \OC\Files\Mount\Manager $manager
  70. */
  71. $manager = $this->getMock('\OC\Files\Mount\Manager');
  72. /**
  73. * @var \OC\Files\View | \PHPUnit_Framework_MockObject_MockObject $view
  74. */
  75. $view = $this->getMock('\OC\Files\View');
  76. $root = new \OC\Files\Node\Root($manager, $view, $this->user);
  77. $root->listen('\OC\Files', 'preDelete', $preListener);
  78. $root->listen('\OC\Files', 'postDelete', $postListener);
  79. $view->expects($this->any())
  80. ->method('getFileInfo')
  81. ->with('/bar/foo')
  82. ->will($this->returnValue($this->getFileInfo(array('permissions' => \OCP\Constants::PERMISSION_ALL, 'fileid' => 1))));
  83. $view->expects($this->once())
  84. ->method('unlink')
  85. ->with('/bar/foo')
  86. ->will($this->returnValue(true));
  87. $view->expects($this->any())
  88. ->method('resolvePath')
  89. ->with('/bar/foo')
  90. ->will($this->returnValue(array(null, 'foo')));
  91. $node = new \OC\Files\Node\File($root, $view, '/bar/foo');
  92. $node->delete();
  93. $this->assertEquals(2, $hooksRun);
  94. }
  95. /**
  96. * @expectedException \OCP\Files\NotPermittedException
  97. */
  98. public function testDeleteNotPermitted() {
  99. $manager = $this->getMock('\OC\Files\Mount\Manager');
  100. /**
  101. * @var \OC\Files\View | \PHPUnit_Framework_MockObject_MockObject $view
  102. */
  103. $view = $this->getMock('\OC\Files\View');
  104. $root = $this->getMock('\OC\Files\Node\Root', array(), array($manager, $view, $this->user));
  105. $root->expects($this->any())
  106. ->method('getUser')
  107. ->will($this->returnValue($this->user));
  108. $view->expects($this->once())
  109. ->method('getFileInfo')
  110. ->with('/bar/foo')
  111. ->will($this->returnValue($this->getFileInfo(array('permissions' => \OCP\Constants::PERMISSION_READ))));
  112. $node = new \OC\Files\Node\File($root, $view, '/bar/foo');
  113. $node->delete();
  114. }
  115. public function testGetContent() {
  116. /**
  117. * @var \OC\Files\Mount\Manager $manager
  118. */
  119. $manager = $this->getMock('\OC\Files\Mount\Manager');
  120. /**
  121. * @var \OC\Files\View | \PHPUnit_Framework_MockObject_MockObject $view
  122. */
  123. $view = $this->getMock('\OC\Files\View');
  124. $root = new \OC\Files\Node\Root($manager, $view, $this->user);
  125. $hook = function ($file) {
  126. throw new \Exception('Hooks are not supposed to be called');
  127. };
  128. $root->listen('\OC\Files', 'preWrite', $hook);
  129. $root->listen('\OC\Files', 'postWrite', $hook);
  130. $view->expects($this->once())
  131. ->method('file_get_contents')
  132. ->with('/bar/foo')
  133. ->will($this->returnValue('bar'));
  134. $view->expects($this->once())
  135. ->method('getFileInfo')
  136. ->with('/bar/foo')
  137. ->will($this->returnValue($this->getFileInfo(array('permissions' => \OCP\Constants::PERMISSION_READ))));
  138. $node = new \OC\Files\Node\File($root, $view, '/bar/foo');
  139. $this->assertEquals('bar', $node->getContent());
  140. }
  141. /**
  142. * @expectedException \OCP\Files\NotPermittedException
  143. */
  144. public function testGetContentNotPermitted() {
  145. $manager = $this->getMock('\OC\Files\Mount\Manager');
  146. /**
  147. * @var \OC\Files\View | \PHPUnit_Framework_MockObject_MockObject $view
  148. */
  149. $view = $this->getMock('\OC\Files\View');
  150. $root = $this->getMock('\OC\Files\Node\Root', array(), array($manager, $view, $this->user));
  151. $root->expects($this->any())
  152. ->method('getUser')
  153. ->will($this->returnValue($this->user));
  154. $view->expects($this->once())
  155. ->method('getFileInfo')
  156. ->with('/bar/foo')
  157. ->will($this->returnValue($this->getFileInfo(array('permissions' => 0))));
  158. $node = new \OC\Files\Node\File($root, $view, '/bar/foo');
  159. $node->getContent();
  160. }
  161. public function testPutContent() {
  162. $manager = $this->getMock('\OC\Files\Mount\Manager');
  163. /**
  164. * @var \OC\Files\View | \PHPUnit_Framework_MockObject_MockObject $view
  165. */
  166. $view = $this->getMock('\OC\Files\View');
  167. $root = $this->getMock('\OC\Files\Node\Root', array(), array($manager, $view, $this->user));
  168. $root->expects($this->any())
  169. ->method('getUser')
  170. ->will($this->returnValue($this->user));
  171. $view->expects($this->once())
  172. ->method('getFileInfo')
  173. ->with('/bar/foo')
  174. ->will($this->returnValue($this->getFileInfo(array('permissions' => \OCP\Constants::PERMISSION_ALL))));
  175. $view->expects($this->once())
  176. ->method('file_put_contents')
  177. ->with('/bar/foo', 'bar')
  178. ->will($this->returnValue(true));
  179. $node = new \OC\Files\Node\File($root, $view, '/bar/foo');
  180. $node->putContent('bar');
  181. }
  182. /**
  183. * @expectedException \OCP\Files\NotPermittedException
  184. */
  185. public function testPutContentNotPermitted() {
  186. $manager = $this->getMock('\OC\Files\Mount\Manager');
  187. /**
  188. * @var \OC\Files\View | \PHPUnit_Framework_MockObject_MockObject $view
  189. */
  190. $view = $this->getMock('\OC\Files\View');
  191. $root = $this->getMock('\OC\Files\Node\Root', array(), array($manager, $view, $this->user));
  192. $view->expects($this->once())
  193. ->method('getFileInfo')
  194. ->with('/bar/foo')
  195. ->will($this->returnValue($this->getFileInfo(array('permissions' => \OCP\Constants::PERMISSION_READ))));
  196. $node = new \OC\Files\Node\File($root, $view, '/bar/foo');
  197. $node->putContent('bar');
  198. }
  199. public function testGetMimeType() {
  200. $manager = $this->getMock('\OC\Files\Mount\Manager');
  201. /**
  202. * @var \OC\Files\View | \PHPUnit_Framework_MockObject_MockObject $view
  203. */
  204. $view = $this->getMock('\OC\Files\View');
  205. $root = $this->getMock('\OC\Files\Node\Root', array(), array($manager, $view, $this->user));
  206. $view->expects($this->once())
  207. ->method('getFileInfo')
  208. ->with('/bar/foo')
  209. ->will($this->returnValue($this->getFileInfo(array('mimetype' => 'text/plain'))));
  210. $node = new \OC\Files\Node\File($root, $view, '/bar/foo');
  211. $this->assertEquals('text/plain', $node->getMimeType());
  212. }
  213. public function testFOpenRead() {
  214. $stream = fopen('php://memory', 'w+');
  215. fwrite($stream, 'bar');
  216. rewind($stream);
  217. /**
  218. * @var \OC\Files\Mount\Manager $manager
  219. */
  220. $manager = $this->getMock('\OC\Files\Mount\Manager');
  221. /**
  222. * @var \OC\Files\View | \PHPUnit_Framework_MockObject_MockObject $view
  223. */
  224. $view = $this->getMock('\OC\Files\View');
  225. $root = new \OC\Files\Node\Root($manager, $view, $this->user);
  226. $hook = function ($file) {
  227. throw new \Exception('Hooks are not supposed to be called');
  228. };
  229. $root->listen('\OC\Files', 'preWrite', $hook);
  230. $root->listen('\OC\Files', 'postWrite', $hook);
  231. $view->expects($this->once())
  232. ->method('fopen')
  233. ->with('/bar/foo', 'r')
  234. ->will($this->returnValue($stream));
  235. $view->expects($this->once())
  236. ->method('getFileInfo')
  237. ->with('/bar/foo')
  238. ->will($this->returnValue($this->getFileInfo(array('permissions' => \OCP\Constants::PERMISSION_ALL))));
  239. $node = new \OC\Files\Node\File($root, $view, '/bar/foo');
  240. $fh = $node->fopen('r');
  241. $this->assertEquals($stream, $fh);
  242. $this->assertEquals('bar', fread($fh, 3));
  243. }
  244. public function testFOpenWrite() {
  245. $stream = fopen('php://memory', 'w+');
  246. /**
  247. * @var \OC\Files\Mount\Manager $manager
  248. */
  249. $manager = $this->getMock('\OC\Files\Mount\Manager');
  250. /**
  251. * @var \OC\Files\View | \PHPUnit_Framework_MockObject_MockObject $view
  252. */
  253. $view = $this->getMock('\OC\Files\View');
  254. $root = new \OC\Files\Node\Root($manager, new $view, $this->user);
  255. $hooksCalled = 0;
  256. $hook = function ($file) use (&$hooksCalled) {
  257. $hooksCalled++;
  258. };
  259. $root->listen('\OC\Files', 'preWrite', $hook);
  260. $root->listen('\OC\Files', 'postWrite', $hook);
  261. $view->expects($this->once())
  262. ->method('fopen')
  263. ->with('/bar/foo', 'w')
  264. ->will($this->returnValue($stream));
  265. $view->expects($this->once())
  266. ->method('getFileInfo')
  267. ->with('/bar/foo')
  268. ->will($this->returnValue($this->getFileInfo(array('permissions' => \OCP\Constants::PERMISSION_ALL))));
  269. $node = new \OC\Files\Node\File($root, $view, '/bar/foo');
  270. $fh = $node->fopen('w');
  271. $this->assertEquals($stream, $fh);
  272. fwrite($fh, 'bar');
  273. rewind($fh);
  274. $this->assertEquals('bar', fread($stream, 3));
  275. $this->assertEquals(2, $hooksCalled);
  276. }
  277. /**
  278. * @expectedException \OCP\Files\NotPermittedException
  279. */
  280. public function testFOpenReadNotPermitted() {
  281. /**
  282. * @var \OC\Files\Mount\Manager $manager
  283. */
  284. $manager = $this->getMock('\OC\Files\Mount\Manager');
  285. /**
  286. * @var \OC\Files\View | \PHPUnit_Framework_MockObject_MockObject $view
  287. */
  288. $view = $this->getMock('\OC\Files\View');
  289. $root = new \OC\Files\Node\Root($manager, $view, $this->user);
  290. $hook = function ($file) {
  291. throw new \Exception('Hooks are not supposed to be called');
  292. };
  293. $view->expects($this->once())
  294. ->method('getFileInfo')
  295. ->with('/bar/foo')
  296. ->will($this->returnValue($this->getFileInfo(array('permissions' => 0))));
  297. $node = new \OC\Files\Node\File($root, $view, '/bar/foo');
  298. $node->fopen('r');
  299. }
  300. /**
  301. * @expectedException \OCP\Files\NotPermittedException
  302. */
  303. public function testFOpenReadWriteNoReadPermissions() {
  304. /**
  305. * @var \OC\Files\Mount\Manager $manager
  306. */
  307. $manager = $this->getMock('\OC\Files\Mount\Manager');
  308. /**
  309. * @var \OC\Files\View | \PHPUnit_Framework_MockObject_MockObject $view
  310. */
  311. $view = $this->getMock('\OC\Files\View');
  312. $root = new \OC\Files\Node\Root($manager, $view, $this->user);
  313. $hook = function () {
  314. throw new \Exception('Hooks are not supposed to be called');
  315. };
  316. $view->expects($this->once())
  317. ->method('getFileInfo')
  318. ->with('/bar/foo')
  319. ->will($this->returnValue($this->getFileInfo(array('permissions' => \OCP\Constants::PERMISSION_UPDATE))));
  320. $node = new \OC\Files\Node\File($root, $view, '/bar/foo');
  321. $node->fopen('w');
  322. }
  323. /**
  324. * @expectedException \OCP\Files\NotPermittedException
  325. */
  326. public function testFOpenReadWriteNoWritePermissions() {
  327. /**
  328. * @var \OC\Files\Mount\Manager $manager
  329. */
  330. $manager = $this->getMock('\OC\Files\Mount\Manager');
  331. /**
  332. * @var \OC\Files\View | \PHPUnit_Framework_MockObject_MockObject $view
  333. */
  334. $view = $this->getMock('\OC\Files\View');
  335. $root = new \OC\Files\Node\Root($manager, new $view, $this->user);
  336. $hook = function () {
  337. throw new \Exception('Hooks are not supposed to be called');
  338. };
  339. $view->expects($this->once())
  340. ->method('getFileInfo')
  341. ->with('/bar/foo')
  342. ->will($this->returnValue($this->getFileInfo(array('permissions' => \OCP\Constants::PERMISSION_READ))));
  343. $node = new \OC\Files\Node\File($root, $view, '/bar/foo');
  344. $node->fopen('w');
  345. }
  346. public function testCopySameStorage() {
  347. /**
  348. * @var \OC\Files\Mount\Manager $manager
  349. */
  350. $manager = $this->getMock('\OC\Files\Mount\Manager');
  351. /**
  352. * @var \OC\Files\View | \PHPUnit_Framework_MockObject_MockObject $view
  353. */
  354. $view = $this->getMock('\OC\Files\View');
  355. $root = $this->getMock('\OC\Files\Node\Root', array(), array($manager, $view, $this->user));
  356. $view->expects($this->any())
  357. ->method('copy')
  358. ->with('/bar/foo', '/bar/asd');
  359. $view->expects($this->any())
  360. ->method('getFileInfo')
  361. ->will($this->returnValue($this->getFileInfo(array('permissions' => \OCP\Constants::PERMISSION_ALL, 'fileid' => 3))));
  362. $node = new \OC\Files\Node\File($root, $view, '/bar/foo');
  363. $parentNode = new \OC\Files\Node\Folder($root, $view, '/bar');
  364. $newNode = new \OC\Files\Node\File($root, $view, '/bar/asd');
  365. $root->expects($this->exactly(2))
  366. ->method('get')
  367. ->will($this->returnValueMap(array(
  368. array('/bar/asd', $newNode),
  369. array('/bar', $parentNode)
  370. )));
  371. $target = $node->copy('/bar/asd');
  372. $this->assertInstanceOf('\OC\Files\Node\File', $target);
  373. $this->assertEquals(3, $target->getId());
  374. }
  375. /**
  376. * @expectedException \OCP\Files\NotPermittedException
  377. */
  378. public function testCopyNotPermitted() {
  379. /**
  380. * @var \OC\Files\Mount\Manager $manager
  381. */
  382. $manager = $this->getMock('\OC\Files\Mount\Manager');
  383. /**
  384. * @var \OC\Files\View | \PHPUnit_Framework_MockObject_MockObject $view
  385. */
  386. $view = $this->getMock('\OC\Files\View');
  387. $root = $this->getMock('\OC\Files\Node\Root', array(), array($manager, $view, $this->user));
  388. /**
  389. * @var \OC\Files\Storage\Storage | \PHPUnit_Framework_MockObject_MockObject $storage
  390. */
  391. $storage = $this->getMock('\OC\Files\Storage\Storage');
  392. $root->expects($this->never())
  393. ->method('getMount');
  394. $storage->expects($this->never())
  395. ->method('copy');
  396. $view->expects($this->any())
  397. ->method('getFileInfo')
  398. ->will($this->returnValue($this->getFileInfo(array('permissions' => \OCP\Constants::PERMISSION_READ, 'fileid' => 3))));
  399. $node = new \OC\Files\Node\File($root, $view, '/bar/foo');
  400. $parentNode = new \OC\Files\Node\Folder($root, $view, '/bar');
  401. $root->expects($this->once())
  402. ->method('get')
  403. ->will($this->returnValueMap(array(
  404. array('/bar', $parentNode)
  405. )));
  406. $node->copy('/bar/asd');
  407. }
  408. /**
  409. * @expectedException \OCP\Files\NotFoundException
  410. */
  411. public function testCopyNoParent() {
  412. /**
  413. * @var \OC\Files\Mount\Manager $manager
  414. */
  415. $manager = $this->getMock('\OC\Files\Mount\Manager');
  416. /**
  417. * @var \OC\Files\View | \PHPUnit_Framework_MockObject_MockObject $view
  418. */
  419. $view = $this->getMock('\OC\Files\View');
  420. $root = $this->getMock('\OC\Files\Node\Root', array(), array($manager, $view, $this->user));
  421. $view->expects($this->never())
  422. ->method('copy');
  423. $node = new \OC\Files\Node\File($root, $view, '/bar/foo');
  424. $root->expects($this->once())
  425. ->method('get')
  426. ->with('/bar/asd')
  427. ->will($this->throwException(new NotFoundException()));
  428. $node->copy('/bar/asd/foo');
  429. }
  430. /**
  431. * @expectedException \OCP\Files\NotPermittedException
  432. */
  433. public function testCopyParentIsFile() {
  434. /**
  435. * @var \OC\Files\Mount\Manager $manager
  436. */
  437. $manager = $this->getMock('\OC\Files\Mount\Manager');
  438. /**
  439. * @var \OC\Files\View | \PHPUnit_Framework_MockObject_MockObject $view
  440. */
  441. $view = $this->getMock('\OC\Files\View');
  442. $root = $this->getMock('\OC\Files\Node\Root', array(), array($manager, $view, $this->user));
  443. $view->expects($this->never())
  444. ->method('copy');
  445. $node = new \OC\Files\Node\File($root, $view, '/bar/foo');
  446. $parentNode = new \OC\Files\Node\File($root, $view, '/bar');
  447. $root->expects($this->once())
  448. ->method('get')
  449. ->will($this->returnValueMap(array(
  450. array('/bar', $parentNode)
  451. )));
  452. $node->copy('/bar/asd');
  453. }
  454. public function testMoveSameStorage() {
  455. /**
  456. * @var \OC\Files\Mount\Manager $manager
  457. */
  458. $manager = $this->getMock('\OC\Files\Mount\Manager');
  459. /**
  460. * @var \OC\Files\View | \PHPUnit_Framework_MockObject_MockObject $view
  461. */
  462. $view = $this->getMock('\OC\Files\View');
  463. $root = $this->getMock('\OC\Files\Node\Root', array(), array($manager, $view, $this->user));
  464. $view->expects($this->any())
  465. ->method('rename')
  466. ->with('/bar/foo', '/bar/asd');
  467. $view->expects($this->any())
  468. ->method('getFileInfo')
  469. ->will($this->returnValue($this->getFileInfo(array('permissions' => \OCP\Constants::PERMISSION_ALL, 'fileid' => 1))));
  470. $node = new \OC\Files\Node\File($root, $view, '/bar/foo');
  471. $parentNode = new \OC\Files\Node\Folder($root, $view, '/bar');
  472. $root->expects($this->any())
  473. ->method('get')
  474. ->will($this->returnValueMap(array(array('/bar', $parentNode), array('/bar/asd', $node))));
  475. $target = $node->move('/bar/asd');
  476. $this->assertInstanceOf('\OC\Files\Node\File', $target);
  477. $this->assertEquals(1, $target->getId());
  478. $this->assertEquals('/bar/asd', $node->getPath());
  479. }
  480. /**
  481. * @expectedException \OCP\Files\NotPermittedException
  482. */
  483. public function testMoveNotPermitted() {
  484. /**
  485. * @var \OC\Files\Mount\Manager $manager
  486. */
  487. $manager = $this->getMock('\OC\Files\Mount\Manager');
  488. /**
  489. * @var \OC\Files\View | \PHPUnit_Framework_MockObject_MockObject $view
  490. */
  491. $view = $this->getMock('\OC\Files\View');
  492. $root = $this->getMock('\OC\Files\Node\Root', array(), array($manager, $view, $this->user));
  493. $view->expects($this->any())
  494. ->method('getFileInfo')
  495. ->will($this->returnValue($this->getFileInfo(array('permissions' => \OCP\Constants::PERMISSION_READ))));
  496. $view->expects($this->never())
  497. ->method('rename');
  498. $node = new \OC\Files\Node\File($root, $view, '/bar/foo');
  499. $parentNode = new \OC\Files\Node\Folder($root, $view, '/bar');
  500. $root->expects($this->once())
  501. ->method('get')
  502. ->with('/bar')
  503. ->will($this->returnValue($parentNode));
  504. $node->move('/bar/asd');
  505. }
  506. /**
  507. * @expectedException \OCP\Files\NotFoundException
  508. */
  509. public function testMoveNoParent() {
  510. /**
  511. * @var \OC\Files\Mount\Manager $manager
  512. */
  513. $manager = $this->getMock('\OC\Files\Mount\Manager');
  514. /**
  515. * @var \OC\Files\View | \PHPUnit_Framework_MockObject_MockObject $view
  516. */
  517. $view = $this->getMock('\OC\Files\View');
  518. $root = $this->getMock('\OC\Files\Node\Root', array(), array($manager, $view, $this->user));
  519. /**
  520. * @var \OC\Files\Storage\Storage | \PHPUnit_Framework_MockObject_MockObject $storage
  521. */
  522. $storage = $this->getMock('\OC\Files\Storage\Storage');
  523. $storage->expects($this->never())
  524. ->method('rename');
  525. $node = new \OC\Files\Node\File($root, $view, '/bar/foo');
  526. $parentNode = new \OC\Files\Node\Folder($root, $view, '/bar');
  527. $root->expects($this->once())
  528. ->method('get')
  529. ->with('/bar')
  530. ->will($this->throwException(new NotFoundException()));
  531. $node->move('/bar/asd');
  532. }
  533. /**
  534. * @expectedException \OCP\Files\NotPermittedException
  535. */
  536. public function testMoveParentIsFile() {
  537. /**
  538. * @var \OC\Files\Mount\Manager $manager
  539. */
  540. $manager = $this->getMock('\OC\Files\Mount\Manager');
  541. /**
  542. * @var \OC\Files\View | \PHPUnit_Framework_MockObject_MockObject $view
  543. */
  544. $view = $this->getMock('\OC\Files\View');
  545. $root = $this->getMock('\OC\Files\Node\Root', array(), array($manager, $view, $this->user));
  546. $view->expects($this->never())
  547. ->method('rename');
  548. $node = new \OC\Files\Node\File($root, $view, '/bar/foo');
  549. $parentNode = new \OC\Files\Node\File($root, $view, '/bar');
  550. $root->expects($this->once())
  551. ->method('get')
  552. ->with('/bar')
  553. ->will($this->returnValue($parentNode));
  554. $node->move('/bar/asd');
  555. }
  556. }