image_test.module 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. <?php
  2. /**
  3. * @file
  4. * Helper module for the image tests.
  5. */
  6. /**
  7. * Implements hook_image_toolkits().
  8. */
  9. function image_test_image_toolkits() {
  10. return array(
  11. 'test' => array(
  12. 'title' => t('A dummy toolkit that works'),
  13. 'available' => TRUE,
  14. ),
  15. 'broken' => array(
  16. 'title' => t('A dummy toolkit that is "broken"'),
  17. 'available' => FALSE,
  18. ),
  19. );
  20. }
  21. /**
  22. * Reset/initialize the history of calls to the toolkit functions.
  23. *
  24. * @see image_test_get_all_calls()
  25. */
  26. function image_test_reset() {
  27. // Keep track of calls to these operations
  28. $results = array(
  29. 'load' => array(),
  30. 'save' => array(),
  31. 'settings' => array(),
  32. 'resize' => array(),
  33. 'rotate' => array(),
  34. 'crop' => array(),
  35. 'desaturate' => array(),
  36. );
  37. variable_set('image_test_results', $results);
  38. }
  39. /**
  40. * Get an array with the all the calls to the toolkits since image_test_reset()
  41. * was called.
  42. *
  43. * @return
  44. * An array keyed by operation name ('load', 'save', 'settings', 'resize',
  45. * 'rotate', 'crop', 'desaturate') with values being arrays of parameters
  46. * passed to each call.
  47. */
  48. function image_test_get_all_calls() {
  49. return variable_get('image_test_results', array());
  50. }
  51. /**
  52. * Store the values passed to a toolkit call.
  53. *
  54. * @param $op
  55. * One of the image toolkit operations: 'get_info', 'load', 'save',
  56. * 'settings', 'resize', 'rotate', 'crop', 'desaturate'.
  57. * @param $args
  58. * Values passed to hook.
  59. *
  60. * @see image_test_get_all_calls()
  61. * @see image_test_reset()
  62. */
  63. function _image_test_log_call($op, $args) {
  64. $results = variable_get('image_test_results', array());
  65. $results[$op][] = $args;
  66. variable_set('image_test_results', $results);
  67. }
  68. /**
  69. * Image tookit's settings operation.
  70. */
  71. function image_test_settings() {
  72. _image_test_log_call('settings', array());
  73. return array();
  74. }
  75. /**
  76. * Image toolkit's get_info operation.
  77. */
  78. function image_test_get_info(stdClass $image) {
  79. _image_test_log_call('get_info', array($image));
  80. return array();
  81. }
  82. /**
  83. * Image tookit's load operation.
  84. */
  85. function image_test_load(stdClass $image) {
  86. _image_test_log_call('load', array($image));
  87. return $image;
  88. }
  89. /**
  90. * Image tookit's save operation.
  91. */
  92. function image_test_save(stdClass $image, $destination) {
  93. _image_test_log_call('save', array($image, $destination));
  94. // Return false so that image_save() doesn't try to chmod the destination
  95. // file that we didn't bother to create.
  96. return FALSE;
  97. }
  98. /**
  99. * Image tookit's crop operation.
  100. */
  101. function image_test_crop(stdClass $image, $x, $y, $width, $height) {
  102. _image_test_log_call('crop', array($image, $x, $y, $width, $height));
  103. return TRUE;
  104. }
  105. /**
  106. * Image tookit's resize operation.
  107. */
  108. function image_test_resize(stdClass $image, $width, $height) {
  109. _image_test_log_call('resize', array($image, $width, $height));
  110. return TRUE;
  111. }
  112. /**
  113. * Image tookit's rotate operation.
  114. */
  115. function image_test_rotate(stdClass $image, $degrees, $background = NULL) {
  116. _image_test_log_call('rotate', array($image, $degrees, $background));
  117. return TRUE;
  118. }
  119. /**
  120. * Image tookit's desaturate operation.
  121. */
  122. function image_test_desaturate(stdClass $image) {
  123. _image_test_log_call('desaturate', array($image));
  124. return TRUE;
  125. }