You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

base.php 3.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  1. <?php
  2. /**
  3. * ownCloud
  4. *
  5. * @author Bjoern Schiessle
  6. * @copyright 2013 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. require_once __DIR__ . '/../../../lib/base.php';
  23. use OCA\Files\Share;
  24. /**
  25. * Class Test_Files_Sharing_Base
  26. *
  27. * Base class for sharing tests.
  28. */
  29. abstract class Test_Files_Sharing_Base extends \PHPUnit_Framework_TestCase {
  30. const TEST_FILES_SHARING_API_USER1 = "test-share-user1";
  31. const TEST_FILES_SHARING_API_USER2 = "test-share-user2";
  32. const TEST_FILES_SHARING_API_USER3 = "test-share-user3";
  33. public $stateFilesEncryption;
  34. public $filename;
  35. public $data;
  36. /**
  37. * @var OC_FilesystemView
  38. */
  39. public $view;
  40. public $folder;
  41. public $subfolder;
  42. public static function setUpBeforeClass() {
  43. // reset backend
  44. \OC_User::clearBackends();
  45. \OC_User::useBackend('database');
  46. // clear share hooks
  47. \OC_Hook::clear('OCP\\Share');
  48. \OC::registerShareHooks();
  49. \OCP\Util::connectHook('OC_Filesystem', 'setup', '\OC\Files\Storage\Shared', 'setup');
  50. // create users
  51. self::loginHelper(self::TEST_FILES_SHARING_API_USER1, true);
  52. self::loginHelper(self::TEST_FILES_SHARING_API_USER2, true);
  53. self::loginHelper(self::TEST_FILES_SHARING_API_USER3, true);
  54. }
  55. function setUp() {
  56. //login as user1
  57. self::loginHelper(self::TEST_FILES_SHARING_API_USER1);
  58. $this->data = 'foobar';
  59. $this->view = new \OC_FilesystemView('/' . self::TEST_FILES_SHARING_API_USER1 . '/files');
  60. // remember files_encryption state
  61. $this->stateFilesEncryption = \OC_App::isEnabled('files_encryption');
  62. //we don't want to tests with app files_encryption enabled
  63. \OC_App::disable('files_encryption');
  64. $this->assertTrue(!\OC_App::isEnabled('files_encryption'));
  65. }
  66. function tearDown() {
  67. // reset app files_encryption
  68. if ($this->stateFilesEncryption) {
  69. \OC_App::enable('files_encryption');
  70. } else {
  71. \OC_App::disable('files_encryption');
  72. }
  73. }
  74. public static function tearDownAfterClass() {
  75. // cleanup users
  76. \OC_User::deleteUser(self::TEST_FILES_SHARING_API_USER1);
  77. \OC_User::deleteUser(self::TEST_FILES_SHARING_API_USER2);
  78. \OC_User::deleteUser(self::TEST_FILES_SHARING_API_USER3);
  79. }
  80. /**
  81. * @param $user
  82. * @param bool $create
  83. * @param bool $password
  84. */
  85. protected static function loginHelper($user, $create = false, $password = false) {
  86. if ($password === false) {
  87. $password = $user;
  88. }
  89. if ($create) {
  90. \OC_User::createUser($user, $password);
  91. }
  92. \OC_Util::tearDownFS();
  93. \OC_User::setUserId('');
  94. \OC\Files\Filesystem::tearDown();
  95. \OC_User::setUserId($user);
  96. \OC_Util::setupFS($user);
  97. }
  98. /**
  99. * @brief get some information from a given share
  100. * @param int $shareID
  101. * @return array with: item_source, share_type, share_with, item_type, permissions
  102. */
  103. protected function getShareFromId($shareID) {
  104. $sql = 'SELECT `item_source`, `share_type`, `share_with`, `item_type`, `permissions` FROM `*PREFIX*share` WHERE `id` = ?';
  105. $args = array($shareID);
  106. $query = \OCP\DB::prepare($sql);
  107. $result = $query->execute($args);
  108. $share = Null;
  109. if ($result) {
  110. $share = $result->fetchRow();
  111. }
  112. return $share;
  113. }
  114. }