base.php 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  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 static function setUpBeforeClass() {
  42. // reset backend
  43. \OC_User::clearBackends();
  44. \OC_User::useBackend('database');
  45. // clear share hooks
  46. \OC_Hook::clear('OCP\\Share');
  47. \OC::registerShareHooks();
  48. \OCP\Util::connectHook('OC_Filesystem', 'setup', '\OC\Files\Storage\Shared', 'setup');
  49. // create users
  50. self::loginHelper(self::TEST_FILES_SHARING_API_USER1, true);
  51. self::loginHelper(self::TEST_FILES_SHARING_API_USER2, true);
  52. self::loginHelper(self::TEST_FILES_SHARING_API_USER3, true);
  53. }
  54. function setUp() {
  55. //login as user1
  56. self::loginHelper(self::TEST_FILES_SHARING_API_USER1);
  57. $this->data = 'foobar';
  58. $this->view = new \OC_FilesystemView('/' . self::TEST_FILES_SHARING_API_USER1 . '/files');
  59. // remember files_encryption state
  60. $this->stateFilesEncryption = \OC_App::isEnabled('files_encryption');
  61. //we don't want to tests with app files_encryption enabled
  62. \OC_App::disable('files_encryption');
  63. $this->assertTrue(!\OC_App::isEnabled('files_encryption'));
  64. }
  65. function tearDown() {
  66. // reset app files_encryption
  67. if ($this->stateFilesEncryption) {
  68. \OC_App::enable('files_encryption');
  69. } else {
  70. \OC_App::disable('files_encryption');
  71. }
  72. }
  73. public static function tearDownAfterClass() {
  74. // cleanup users
  75. \OC_User::deleteUser(self::TEST_FILES_SHARING_API_USER1);
  76. \OC_User::deleteUser(self::TEST_FILES_SHARING_API_USER2);
  77. \OC_User::deleteUser(self::TEST_FILES_SHARING_API_USER3);
  78. }
  79. /**
  80. * @param $user
  81. * @param bool $create
  82. * @param bool $password
  83. */
  84. protected static function loginHelper($user, $create = false, $password = false) {
  85. if ($create) {
  86. \OC_User::createUser($user, $user);
  87. }
  88. if ($password === false) {
  89. $password = $user;
  90. }
  91. \OC_Util::tearDownFS();
  92. \OC_User::setUserId('');
  93. \OC\Files\Filesystem::tearDown();
  94. \OC_Util::setupFS($user);
  95. \OC_User::setUserId($user);
  96. $params['uid'] = $user;
  97. $params['password'] = $password;
  98. }
  99. /**
  100. * @brief get some information from a given share
  101. * @param int $shareID
  102. * @return array with: item_source, share_type, share_with, item_type, permissions
  103. */
  104. protected function getShareFromId($shareID) {
  105. $sql = 'SELECT `item_source`, `share_type`, `share_with`, `item_type`, `permissions` FROM `*PREFIX*share` WHERE `id` = ?';
  106. $args = array($shareID);
  107. $query = \OCP\DB::prepare($sql);
  108. $result = $query->execute($args);
  109. $share = Null;
  110. if ($result && $result->numRows() > 0) {
  111. $share = $result->fetchRow();
  112. }
  113. return $share;
  114. }
  115. }