1
0

HookHelper.php 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. <?php
  2. /**
  3. * SPDX-FileCopyrightText: 2016-2024 Nextcloud GmbH and Nextcloud contributors
  4. * SPDX-FileCopyrightText: 2016 ownCloud, Inc.
  5. * SPDX-License-Identifier: AGPL-3.0-or-later
  6. */
  7. namespace Test;
  8. use OC\Files\Filesystem;
  9. /**
  10. * Helper class to register hooks on
  11. */
  12. class HookHelper {
  13. public static $hookCalls;
  14. public static function setUpHooks() {
  15. self::clear();
  16. \OCP\Util::connectHook(
  17. Filesystem::CLASSNAME,
  18. Filesystem::signal_create,
  19. '\Test\HookHelper',
  20. 'createCallback'
  21. );
  22. \OCP\Util::connectHook(
  23. Filesystem::CLASSNAME,
  24. Filesystem::signal_update,
  25. '\Test\HookHelper',
  26. 'updateCallback'
  27. );
  28. \OCP\Util::connectHook(
  29. Filesystem::CLASSNAME,
  30. Filesystem::signal_write,
  31. '\Test\HookHelper',
  32. 'writeCallback'
  33. );
  34. \OCP\Util::connectHook(
  35. Filesystem::CLASSNAME,
  36. Filesystem::signal_post_create,
  37. '\Test\HookHelper',
  38. 'postCreateCallback'
  39. );
  40. \OCP\Util::connectHook(
  41. Filesystem::CLASSNAME,
  42. Filesystem::signal_post_update,
  43. '\Test\HookHelper',
  44. 'postUpdateCallback'
  45. );
  46. \OCP\Util::connectHook(
  47. Filesystem::CLASSNAME,
  48. Filesystem::signal_post_write,
  49. '\Test\HookHelper',
  50. 'postWriteCallback'
  51. );
  52. }
  53. public static function clear() {
  54. self::$hookCalls = [];
  55. }
  56. public static function createCallback($params) {
  57. self::$hookCalls[] = [
  58. 'signal' => Filesystem::signal_create,
  59. 'params' => $params
  60. ];
  61. }
  62. public static function updateCallback($params) {
  63. self::$hookCalls[] = [
  64. 'signal' => Filesystem::signal_update,
  65. 'params' => $params
  66. ];
  67. }
  68. public static function writeCallback($params) {
  69. self::$hookCalls[] = [
  70. 'signal' => Filesystem::signal_write,
  71. 'params' => $params
  72. ];
  73. }
  74. public static function postCreateCallback($params) {
  75. self::$hookCalls[] = [
  76. 'signal' => Filesystem::signal_post_create,
  77. 'params' => $params
  78. ];
  79. }
  80. public static function postUpdateCallback($params) {
  81. self::$hookCalls[] = [
  82. 'signal' => Filesystem::signal_post_update,
  83. 'params' => $params
  84. ];
  85. }
  86. public static function postWriteCallback($params) {
  87. self::$hookCalls[] = [
  88. 'signal' => Filesystem::signal_post_write,
  89. 'params' => $params
  90. ];
  91. }
  92. /**
  93. * Callback that sets the run parameter to false
  94. */
  95. public static function cancellingCallback($params) {
  96. $params[Filesystem::signal_param_run] = false;
  97. }
  98. }