RoundCube Webmail
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.

94 lines
2.7 KiB

  1. <?php
  2. namespace Roundcube\Tests;
  3. /*
  4. +-----------------------------------------------------------------------+
  5. | This file is part of the Roundcube Webmail client |
  6. | |
  7. | Copyright (C) The Roundcube Dev Team |
  8. | |
  9. | Licensed under the GNU General Public License version 3 or |
  10. | any later version with exceptions for skins & plugins. |
  11. | See the README file for a full license statement. |
  12. | |
  13. | PURPOSE: |
  14. | A class for easier testing of code utilizing rcube_storage |
  15. +-----------------------------------------------------------------------+
  16. | Author: Aleksander Machniak <alec@alec.pl> |
  17. +-----------------------------------------------------------------------+
  18. */
  19. /**
  20. * A class for easier testing of code utilizing rcube_storage
  21. */
  22. class StorageMock
  23. {
  24. public $methodCalls = [];
  25. protected $mocks = [];
  26. public function registerFunction($name, $result = null)
  27. {
  28. $this->mocks[] = [$name, $result];
  29. return $this;
  30. }
  31. public function __call($name, $arguments)
  32. {
  33. foreach ($this->mocks as $idx => $mock) {
  34. if ($mock[0] == $name) {
  35. $result = $mock[1];
  36. $this->methodCalls[] = ['name' => $name, 'args' => $arguments];
  37. unset($this->mocks[$idx]);
  38. return $result;
  39. }
  40. }
  41. throw new \Exception("Unhandled function call for '{$name}'");
  42. }
  43. /**
  44. * Close connection. Usually done on script shutdown
  45. */
  46. public function close()
  47. {
  48. // do nothing
  49. }
  50. public function get_hierarchy_delimiter()
  51. {
  52. return '/';
  53. }
  54. public function get_namespace()
  55. {
  56. return null;
  57. }
  58. /**
  59. * Check if specified folder is a special folder
  60. */
  61. public function is_special_folder($name)
  62. {
  63. return $name == 'INBOX' || in_array($name, $this->get_special_folders());
  64. }
  65. /**
  66. * Return configured special folders
  67. */
  68. public function get_special_folders($forced = false)
  69. {
  70. $rcube = \rcube::get_instance();
  71. $folders = [];
  72. foreach (\rcube_storage::$folder_types as $type) {
  73. if ($folder = $rcube->config->get($type . '_mbox')) {
  74. $folders[$type] = $folder;
  75. }
  76. }
  77. return $folders;
  78. }
  79. }