mock-image-editor.php 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. <?php
  2. if ( class_exists( 'WP_Image_Editor' ) ) :
  3. class WP_Image_Editor_Mock extends WP_Image_Editor {
  4. public static $load_return = true;
  5. public static $test_return = true;
  6. public static $save_return = array();
  7. public static $spy = array();
  8. public static $edit_return = array();
  9. public static $size_return = null;
  10. // Allow testing of jpeg_quality filter.
  11. public function set_mime_type( $mime_type = null ) {
  12. $this->mime_type = $mime_type;
  13. }
  14. public function load() {
  15. return self::$load_return;
  16. }
  17. public static function test( $args = array() ) {
  18. return self::$test_return;
  19. }
  20. public static function supports_mime_type( $mime_type ) {
  21. return true;
  22. }
  23. public function resize( $max_w, $max_h, $crop = false ) {
  24. self::$spy[ __FUNCTION__ ][] = func_get_args();
  25. if ( isset( self::$edit_return[ __FUNCTION__ ] ) ) {
  26. return self::$edit_return[ __FUNCTION__ ];
  27. }
  28. }
  29. public function multi_resize( $sizes ) {
  30. self::$spy[ __FUNCTION__ ][] = func_get_args();
  31. if ( isset( self::$edit_return[ __FUNCTION__ ] ) ) {
  32. return self::$edit_return[ __FUNCTION__ ];
  33. }
  34. }
  35. public function crop( $src_x, $src_y, $src_w, $src_h, $dst_w = null, $dst_h = null, $src_abs = false ) {
  36. self::$spy[ __FUNCTION__ ][] = func_get_args();
  37. if ( isset( self::$edit_return[ __FUNCTION__ ] ) ) {
  38. return self::$edit_return[ __FUNCTION__ ];
  39. }
  40. }
  41. public function rotate( $angle ) {
  42. self::$spy[ __FUNCTION__ ][] = func_get_args();
  43. if ( isset( self::$edit_return[ __FUNCTION__ ] ) ) {
  44. return self::$edit_return[ __FUNCTION__ ];
  45. }
  46. }
  47. public function flip( $horz, $vert ) {
  48. self::$spy[ __FUNCTION__ ][] = func_get_args();
  49. if ( isset( self::$edit_return[ __FUNCTION__ ] ) ) {
  50. return self::$edit_return[ __FUNCTION__ ];
  51. }
  52. }
  53. public function save( $destfilename = null, $mime_type = null ) {
  54. return self::$save_return;
  55. }
  56. public function stream( $mime_type = null ) {
  57. }
  58. public function get_size() {
  59. if ( self::$size_return ) {
  60. return self::$size_return;
  61. }
  62. return parent::get_size();
  63. }
  64. }
  65. endif;