PropagationTestCase.php 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  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. * @author Roeland Jago Douma <roeland@famdouma.nl>
  8. *
  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. namespace OCA\Files_Sharing\Tests;
  25. abstract class PropagationTestCase extends TestCase {
  26. /**
  27. * @var \OC\Files\View
  28. */
  29. protected $rootView;
  30. protected $fileIds = []; // [$user=>[$path=>$id]]
  31. protected $fileEtags = []; // [$id=>$etag]
  32. public static function setUpBeforeClass(): void {
  33. parent::setUpBeforeClass();
  34. \OCA\Files_Sharing\Helper::registerHooks();
  35. }
  36. protected function setUp(): void {
  37. parent::setUp();
  38. $this->setUpShares();
  39. }
  40. protected function tearDown(): void {
  41. \OC_Hook::clear('OC_Filesystem', 'post_write');
  42. \OC_Hook::clear('OC_Filesystem', 'post_delete');
  43. \OC_Hook::clear('OC_Filesystem', 'post_rename');
  44. \OC_Hook::clear('OCP\Share', 'post_update_permissions');
  45. parent::tearDown();
  46. }
  47. abstract protected function setUpShares();
  48. /**
  49. * @param string[] $users
  50. * @param string $subPath
  51. */
  52. protected function assertEtagsChanged($users, $subPath = '') {
  53. $oldUser = \OC::$server->getUserSession()->getUser();
  54. foreach ($users as $user) {
  55. $this->loginAsUser($user);
  56. $id = $this->fileIds[$user][$subPath];
  57. $path = $this->rootView->getPath($id);
  58. $etag = $this->rootView->getFileInfo($path)->getEtag();
  59. $this->assertNotEquals($this->fileEtags[$id], $etag, 'Failed asserting that the etag for "' . $subPath . '" of user ' . $user . ' has changed');
  60. $this->fileEtags[$id] = $etag;
  61. }
  62. $this->loginAsUser($oldUser->getUID());
  63. }
  64. /**
  65. * @param string[] $users
  66. * @param string $subPath
  67. */
  68. protected function assertEtagsNotChanged($users, $subPath = '') {
  69. $oldUser = \OC::$server->getUserSession()->getUser();
  70. foreach ($users as $user) {
  71. $this->loginAsUser($user);
  72. $id = $this->fileIds[$user][$subPath];
  73. $path = $this->rootView->getPath($id);
  74. $etag = $this->rootView->getFileInfo($path)->getEtag();
  75. $this->assertEquals($this->fileEtags[$id], $etag, 'Failed asserting that the etag for "' . $subPath . '" of user ' . $user . ' has not changed');
  76. $this->fileEtags[$id] = $etag;
  77. }
  78. $this->loginAsUser($oldUser->getUID());
  79. }
  80. /**
  81. * Assert that the etags for the root, /sub1 and /sub1/sub2 have changed
  82. *
  83. * @param string[] $users
  84. */
  85. protected function assertEtagsForFoldersChanged($users) {
  86. $this->assertEtagsChanged($users);
  87. $this->assertEtagsChanged($users, 'sub1');
  88. $this->assertEtagsChanged($users, 'sub1/sub2');
  89. }
  90. protected function assertAllUnchanged() {
  91. $users = [self::TEST_FILES_SHARING_API_USER1, self::TEST_FILES_SHARING_API_USER2,
  92. self::TEST_FILES_SHARING_API_USER3, self::TEST_FILES_SHARING_API_USER4];
  93. $this->assertEtagsNotChanged($users);
  94. }
  95. }