summaryrefslogtreecommitdiffstatshomepage
path: root/tests/phpunit/includes/mock-image-editor.php
blob: ab2e7379fd4391dd57e3acfc9a3414992fde7e38 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
<?php

if ( class_exists( 'WP_Image_Editor' ) ) :

	class WP_Image_Editor_Mock extends WP_Image_Editor {

		public static $load_return = true;
		public static $test_return = true;
		public static $save_return = array();
		public static $spy         = array();
		public static $edit_return = array();
		public static $size_return = null;

		// Allow testing of jpeg_quality filter.
		public function set_mime_type( $mime_type = null ) {
			$this->mime_type = $mime_type;
		}

		public function load() {
			return self::$load_return;
		}
		public static function test( $args = array() ) {
			return self::$test_return;
		}
		public static function supports_mime_type( $mime_type ) {
			return true;
		}
		public function resize( $max_w, $max_h, $crop = false ) {
			self::$spy[ __FUNCTION__ ][] = func_get_args();
			if ( isset( self::$edit_return[ __FUNCTION__ ] ) ) {
				return self::$edit_return[ __FUNCTION__ ];
			}
		}
		public function multi_resize( $sizes ) {
			self::$spy[ __FUNCTION__ ][] = func_get_args();
			if ( isset( self::$edit_return[ __FUNCTION__ ] ) ) {
				return self::$edit_return[ __FUNCTION__ ];
			}
		}
		public function crop( $src_x, $src_y, $src_w, $src_h, $dst_w = null, $dst_h = null, $src_abs = false ) {
			self::$spy[ __FUNCTION__ ][] = func_get_args();
			if ( isset( self::$edit_return[ __FUNCTION__ ] ) ) {
				return self::$edit_return[ __FUNCTION__ ];
			}
		}
		public function rotate( $angle ) {
			self::$spy[ __FUNCTION__ ][] = func_get_args();
			if ( isset( self::$edit_return[ __FUNCTION__ ] ) ) {
				return self::$edit_return[ __FUNCTION__ ];
			}
		}
		public function flip( $horz, $vert ) {
			self::$spy[ __FUNCTION__ ][] = func_get_args();
			if ( isset( self::$edit_return[ __FUNCTION__ ] ) ) {
				return self::$edit_return[ __FUNCTION__ ];
			}
		}
		public function save( $destfilename = null, $mime_type = null ) {
			// Set new mime-type and quality if converting the image.
			$this->get_output_format( $destfilename, $mime_type );
			return self::$save_return;
		}
		public function stream( $mime_type = null ) {
		}

		public function get_size() {
			if ( self::$size_return ) {
				return self::$size_return;
			}

			return parent::get_size();
		}
	}

endif;