backend.php 3.7 KB

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