summaryrefslogtreecommitdiff
path: root/modules/simpletest/tests/image_test.module
blob: de640f0ba24cc33b067375edd1394c4fcc2d45b6 (plain)
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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
<?php

/**
 * @file
 * Helper module for the image tests.
 */

/**
 * Implements hook_image_toolkits().
 */
function image_test_image_toolkits() {
  return array(
    'test' => array(
      'title' => t('A dummy toolkit that works'),
      'available' => TRUE,
    ),
    'broken' => array(
      'title' => t('A dummy toolkit that is "broken"'),
      'available' => FALSE,
    ),
  );
}

/**
 * Reset/initialize the history of calls to the toolkit functions.
 *
 * @see image_test_get_all_calls()
 */
function image_test_reset() {
  // Keep track of calls to these operations
  $results = array(
    'load' => array(),
    'save' => array(),
    'settings' => array(),
    'resize' => array(),
    'rotate' => array(),
    'crop' => array(),
    'desaturate' => array(),
  );
  variable_set('image_test_results', $results);
}

/**
 * Get an array with the all the calls to the toolkits since image_test_reset()
 * was called.
 *
 * @return
 *   An array keyed by operation name ('load', 'save', 'settings', 'resize',
 *   'rotate', 'crop', 'desaturate') with values being arrays of parameters
 *   passed to each call.
 */
function image_test_get_all_calls() {
  return variable_get('image_test_results', array());
}

/**
 * Store the values passed to a toolkit call.
 *
 * @param $op
 *   One of the image toolkit operations: 'get_info', 'load', 'save',
 *   'settings', 'resize', 'rotate', 'crop', 'desaturate'.
 * @param $args
 *   Values passed to hook.
 *
 * @see image_test_get_all_calls()
 * @see image_test_reset()
 */
function _image_test_log_call($op, $args) {
  $results = variable_get('image_test_results', array());
  $results[$op][] = $args;
  variable_set('image_test_results', $results);
}

/**
 * Image tookit's settings operation.
 */
function image_test_settings() {
  _image_test_log_call('settings', array());
  return array();
}

/**
 * Image toolkit's get_info operation.
 */
function image_test_get_info(stdClass $image) {
  _image_test_log_call('get_info', array($image));
  return array();
}

/**
 * Image tookit's load operation.
 */
function image_test_load(stdClass $image) {
  _image_test_log_call('load', array($image));
  return $image;
}

/**
 * Image tookit's save operation.
 */
function image_test_save(stdClass $image, $destination) {
  _image_test_log_call('save', array($image, $destination));
  // Return false so that image_save() doesn't try to chmod the destination
  // file that we didn't bother to create.
  return FALSE;
}

/**
 * Image tookit's crop operation.
 */
function image_test_crop(stdClass $image, $x, $y, $width, $height) {
  _image_test_log_call('crop', array($image, $x, $y, $width, $height));
  return TRUE;
}

/**
 * Image tookit's resize operation.
 */
function image_test_resize(stdClass $image, $width, $height) {
  _image_test_log_call('resize', array($image, $width, $height));
  return TRUE;
}

/**
 * Image tookit's rotate operation.
 */
function image_test_rotate(stdClass $image, $degrees, $background = NULL) {
  _image_test_log_call('rotate', array($image, $degrees, $background));
  return TRUE;
}

/**
 * Image tookit's desaturate operation.
 */
function image_test_desaturate(stdClass $image) {
  _image_test_log_call('desaturate', array($image));
  return TRUE;
}