1
0

PropagationTestCase.php 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. <?php
  2. /**
  3. * @copyright Copyright (c) 2016, ownCloud, Inc.
  4. *
  5. * @author Joas Schilling <coding@schilljs.com>
  6. * @author Robin Appelman <robin@icewind.nl>
  7. *
  8. * @license AGPL-3.0
  9. *
  10. * This code is free software: you can redistribute it and/or modify
  11. * it under the terms of the GNU Affero General Public License, version 3,
  12. * as published by the Free Software Foundation.
  13. *
  14. * This program is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. * GNU Affero General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU Affero General Public License, version 3,
  20. * along with this program. If not, see <http://www.gnu.org/licenses/>
  21. *
  22. */
  23. namespace OCA\Files_Sharing\Tests;
  24. abstract class PropagationTestCase extends TestCase {
  25. /**
  26. * @var \OC\Files\View
  27. */
  28. protected $rootView;
  29. protected $fileIds = []; // [$user=>[$path=>$id]]
  30. protected $fileEtags = []; // [$id=>$etag]
  31. public static function setUpBeforeClass() {
  32. parent::setUpBeforeClass();
  33. \OCA\Files_Sharing\Helper::registerHooks();
  34. }
  35. protected function setUp() {
  36. parent::setUp();
  37. $this->setUpShares();
  38. }
  39. protected function tearDown() {
  40. \OC_Hook::clear('OC_Filesystem', 'post_write');
  41. \OC_Hook::clear('OC_Filesystem', 'post_delete');
  42. \OC_Hook::clear('OC_Filesystem', 'post_rename');
  43. \OC_Hook::clear('OCP\Share', 'post_update_permissions');
  44. parent::tearDown();
  45. }
  46. abstract protected function setUpShares();
  47. /**
  48. * @param string[] $users
  49. * @param string $subPath
  50. */
  51. protected function assertEtagsChanged($users, $subPath = '') {
  52. $oldUser = \OC::$server->getUserSession()->getUser();
  53. foreach ($users as $user) {
  54. $this->loginAsUser($user);
  55. $id = $this->fileIds[$user][$subPath];
  56. $path = $this->rootView->getPath($id);
  57. $etag = $this->rootView->getFileInfo($path)->getEtag();
  58. $this->assertNotEquals($this->fileEtags[$id], $etag, 'Failed asserting that the etag for "' . $subPath . '" of user ' . $user . ' has changed');
  59. $this->fileEtags[$id] = $etag;
  60. }
  61. $this->loginAsUser($oldUser->getUID());
  62. }
  63. /**
  64. * @param string[] $users
  65. * @param string $subPath
  66. */
  67. protected function assertEtagsNotChanged($users, $subPath = '') {
  68. $oldUser = \OC::$server->getUserSession()->getUser();
  69. foreach ($users as $user) {
  70. $this->loginAsUser($user);
  71. $id = $this->fileIds[$user][$subPath];
  72. $path = $this->rootView->getPath($id);
  73. $etag = $this->rootView->getFileInfo($path)->getEtag();
  74. $this->assertEquals($this->fileEtags[$id], $etag, 'Failed asserting that the etag for "' . $subPath . '" of user ' . $user . ' has not changed');
  75. $this->fileEtags[$id] = $etag;
  76. }
  77. $this->loginAsUser($oldUser->getUID());
  78. }
  79. /**
  80. * Assert that the etags for the root, /sub1 and /sub1/sub2 have changed
  81. *
  82. * @param string[] $users
  83. */
  84. protected function assertEtagsForFoldersChanged($users) {
  85. $this->assertEtagsChanged($users);
  86. $this->assertEtagsChanged($users, 'sub1');
  87. $this->assertEtagsChanged($users, 'sub1/sub2');
  88. }
  89. protected function assertAllUnchanged() {
  90. $users = [self::TEST_FILES_SHARING_API_USER1, self::TEST_FILES_SHARING_API_USER2,
  91. self::TEST_FILES_SHARING_API_USER3, self::TEST_FILES_SHARING_API_USER4];
  92. $this->assertEtagsNotChanged($users);
  93. }
  94. }