backend.php 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. <?php
  2. /**
  3. * ownCloud
  4. *
  5. * @author Bjoern Schiessle
  6. * @copyright 2014 Bjoern Schiessle <schiessle@owncloud.com>
  7. *
  8. * This library is free software; you can redistribute it and/or
  9. * modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE
  10. * License as published by the Free Software Foundation; either
  11. * version 3 of the License, or any later version.
  12. *
  13. * This library is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU AFFERO GENERAL PUBLIC LICENSE for more details.
  17. *
  18. * You should have received a copy of the GNU Affero General Public
  19. * License along with this library. If not, see <http://www.gnu.org/licenses/>.
  20. *
  21. */
  22. use OCA\Files\Share;
  23. use OCA\Files_sharing\Tests\TestCase;
  24. /**
  25. * Class Test_Files_Sharing
  26. */
  27. class Test_Files_Sharing_Backend extends TestCase {
  28. const TEST_FOLDER_NAME = '/folder_share_api_test';
  29. public $folder;
  30. public $subfolder;
  31. public $subsubfolder;
  32. protected function setUp() {
  33. parent::setUp();
  34. $this->folder = self::TEST_FOLDER_NAME;
  35. $this->subfolder = '/subfolder_share_backend_test';
  36. $this->subsubfolder = '/subsubfolder_share_backend_test';
  37. $this->filename = '/share-backend-test.txt';
  38. // save file with content
  39. $this->view->file_put_contents($this->filename, $this->data);
  40. $this->view->mkdir($this->folder);
  41. $this->view->mkdir($this->folder . $this->subfolder);
  42. $this->view->mkdir($this->folder . $this->subfolder . $this->subsubfolder);
  43. $this->view->file_put_contents($this->folder.$this->filename, $this->data);
  44. $this->view->file_put_contents($this->folder . $this->subfolder . $this->filename, $this->data);
  45. $this->view->file_put_contents($this->folder . $this->subfolder . $this->subsubfolder . $this->filename, $this->data);
  46. }
  47. protected function tearDown() {
  48. $this->view->unlink($this->filename);
  49. $this->view->deleteAll($this->folder);
  50. parent::tearDown();
  51. }
  52. function testGetParents() {
  53. $fileinfo1 = $this->view->getFileInfo($this->folder);
  54. $fileinfo2 = $this->view->getFileInfo($this->folder . $this->subfolder . $this->subsubfolder);
  55. $fileinfo3 = $this->view->getFileInfo($this->folder . $this->subfolder . $this->subsubfolder . $this->filename);
  56. $this->assertTrue(\OCP\Share::shareItem('folder', $fileinfo1['fileid'], \OCP\Share::SHARE_TYPE_USER,
  57. self::TEST_FILES_SHARING_API_USER2, 31));
  58. $this->assertTrue(\OCP\Share::shareItem('folder', $fileinfo2['fileid'], \OCP\Share::SHARE_TYPE_USER,
  59. self::TEST_FILES_SHARING_API_USER3, 31));
  60. $backend = new \OC_Share_Backend_Folder();
  61. $result = $backend->getParents($fileinfo3['fileid']);
  62. $this->assertSame(2, count($result));
  63. $count1 = 0;
  64. $count2 = 0;
  65. foreach($result as $r) {
  66. if ($r['path'] === 'files' . $this->folder) {
  67. $this->assertSame(ltrim($this->folder, '/'), $r['collection']['path']);
  68. $count1++;
  69. } elseif ($r['path'] === 'files' . $this->folder . $this->subfolder . $this->subsubfolder) {
  70. $this->assertSame(ltrim($this->subsubfolder, '/'), $r['collection']['path']);
  71. $count2++;
  72. } else {
  73. $this->assertTrue(false, 'unexpected result');
  74. }
  75. }
  76. $this->assertSame(1, $count1);
  77. $this->assertSame(1, $count2);
  78. $result1 = $backend->getParents($fileinfo3['fileid'], self::TEST_FILES_SHARING_API_USER3);
  79. $this->assertSame(1, count($result1));
  80. $elemet = reset($result1);
  81. $this->assertSame('files' . $this->folder . $this->subfolder . $this->subsubfolder ,$elemet['path']);
  82. $this->assertSame(ltrim($this->subsubfolder, '/') ,$elemet['collection']['path']);
  83. }
  84. }