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