Fixed usage of some browser transformations
[phpmyadmin.git] / test / libraries / PMA_transformation_test.php
blob5e33e414a0941c55f375af7ebd9045c39eef9768
1 <?php
2 /* vim: set expandtab sw=4 ts=4 sts=4: */
3 /**
4 * tests for transformation wrappers
6 * @package PhpMyAdmin-test
7 */
9 use PMA\libraries\Theme;
12 * Include to test.
14 require_once 'libraries/transformations.lib.php';
15 require_once 'libraries/database_interface.inc.php';
16 require_once 'libraries/relation.lib.php';
18 /**
19 * tests for transformation wrappers
21 * @package PhpMyAdmin-test
23 class PMA_Transformation_Test extends PHPUnit_Framework_TestCase
26 /**
27 * Set up global environment.
29 * @return void
31 public function setup()
33 $GLOBALS['table'] = 'table';
34 $GLOBALS['db'] = 'db';
35 $GLOBALS['cfg'] = array(
36 'ServerDefault' => 1,
37 'ActionLinksMode' => 'icons',
39 $GLOBALS['server'] = 1;
40 $GLOBALS['cfg']['Server']['pmadb'] = 'pmadb';
41 $GLOBALS['cfg']['Server']['user'] = 'user';
42 $GLOBALS['cfg']['Server']['bookmarktable'] = '';
43 $GLOBALS['cfg']['Server']['relation'] = '';
44 $GLOBALS['cfg']['Server']['table_info'] = '';
45 $GLOBALS['cfg']['Server']['table_coords'] = '';
46 $GLOBALS['cfg']['Server']['column_info'] = 'column_info';
47 $GLOBALS['cfg']['DBG']['sql'] = false;
48 // need to clear relation test cache
49 unset($_SESSION['relation']);
52 /**
53 * Test for parsing options.
55 * @param string $input String to parse
56 * @param array $expected Expected result
58 * @return void
60 * @dataProvider getOptionsData
62 public function testGetOptions($input, $expected)
64 $this->assertEquals(
65 $expected,
66 PMA_Transformation_getOptions($input)
70 /**
71 * Data provided for parsing options
73 * @return array with test data
75 public function getOptionsData()
77 return array(
78 array("option1 , option2 ", array('option1 ', ' option2 ')),
79 array("'option1' ,' option2' ", array('option1', ' option2')),
80 array("'2,3' ,' ,, option ,,' ", array('2,3', ' ,, option ,,')),
81 array("'',,", array('', '', '')),
82 array('', array()),
86 /**
87 * Test for getting available types.
89 * @return void
91 public function testGetTypes()
93 $this->assertEquals(
94 array (
95 'mimetype' => array (
96 'Application/Octetstream' => 'Application/Octetstream',
97 'Image/JPEG' => 'Image/JPEG',
98 'Image/PNG' => 'Image/PNG',
99 'Text/Plain' => 'Text/Plain',
100 'Text/Octetstream' => 'Text/Octetstream'
102 'transformation' => array (
103 0 => 'Application/Octetstream: Download',
104 1 => 'Application/Octetstream: Hex',
105 2 => 'Image/JPEG: Inline',
106 3 => 'Image/JPEG: Link',
107 4 => 'Image/PNG: Inline',
108 5 => 'Text/Octetstream: Sql',
109 6 => 'Text/Plain: Binarytoip',
110 7 => 'Text/Plain: Bool2Text',
111 8 => 'Text/Plain: Dateformat',
112 9 => 'Text/Plain: External',
113 10 => 'Text/Plain: Formatted',
114 11 => 'Text/Plain: Imagelink',
115 12 => 'Text/Plain: Json',
116 13 => 'Text/Plain: Sql',
117 14 => 'Text/Plain: Xml',
118 15 => 'Text/Plain: Link',
119 16 => 'Text/Plain: Longtoipv4',
120 17 => 'Text/Plain: PreApPend',
121 18 => 'Text/Plain: Substring',
123 'transformation_file' => array (
124 0 => 'output/Application_Octetstream_Download.php',
125 1 => 'output/Application_Octetstream_Hex.php',
126 2 => 'output/Image_JPEG_Inline.php',
127 3 => 'output/Image_JPEG_Link.php',
128 4 => 'output/Image_PNG_Inline.php',
129 5 => 'output/Text_Octetstream_Sql.php',
130 6 => 'output/Text_Plain_Binarytoip.php',
131 7 => 'output/Text_Plain_Bool2Text.php',
132 8 => 'output/Text_Plain_Dateformat.php',
133 9 => 'output/Text_Plain_External.php',
134 10 => 'output/Text_Plain_Formatted.php',
135 11 => 'output/Text_Plain_Imagelink.php',
136 12 => 'output/Text_Plain_Json.php',
137 13 => 'output/Text_Plain_Sql.php',
138 14 => 'output/Text_Plain_Xml.php',
139 15 => 'Text_Plain_Link.php',
140 16 => 'Text_Plain_Longtoipv4.php',
141 17 => 'Text_Plain_PreApPend.php',
142 18 => 'Text_Plain_Substring.php',
144 'input_transformation' => array(
145 'Image/JPEG: Upload',
146 'Text/Plain: FileUpload',
147 'Text/Plain: Iptobinary',
148 'Text/Plain: JsonEditor',
149 'Text/Plain: RegexValidation',
150 'Text/Plain: SqlEditor',
151 'Text/Plain: XmlEditor',
152 'Text/Plain: Link',
153 'Text/Plain: Longtoipv4',
154 'Text/Plain: PreApPend',
155 'Text/Plain: Substring',
157 'input_transformation_file' => array(
158 'input/Image_JPEG_Upload.php',
159 'input/Text_Plain_FileUpload.php',
160 'input/Text_Plain_Iptobinary.php',
161 'input/Text_Plain_JsonEditor.php',
162 'input/Text_Plain_RegexValidation.php',
163 'input/Text_Plain_SqlEditor.php',
164 'input/Text_Plain_XmlEditor.php',
165 'Text_Plain_Link.php',
166 'Text_Plain_Longtoipv4.php',
167 'Text_Plain_PreApPend.php',
168 'Text_Plain_Substring.php',
171 PMA_getAvailableMIMEtypes()
176 * Tests getting mime types for table
178 * @return void
180 public function testGetMime()
182 $_SESSION['relation'][$GLOBALS['server']]['PMA_VERSION'] = PMA_VERSION;
183 $_SESSION['relation'][$GLOBALS['server']]['commwork'] = true;
184 $_SESSION['relation'][$GLOBALS['server']]['db'] = "pmadb";
185 $_SESSION['relation'][$GLOBALS['server']]['column_info'] = "column_info";
186 $_SESSION['relation'][$GLOBALS['server']]['trackingwork'] = false;
187 $this->assertEquals(
188 array(
189 'o' => array(
190 'column_name' => 'o',
191 'mimetype' => 'Text/plain',
192 'transformation' => 'Sql',
193 'transformation_options' => '',
194 'input_transformation' => 'regex',
195 'input_transformation_options' => '/pma/i',
197 'col' => array(
198 'column_name' => 'col',
199 'mimetype' => 'T',
200 'transformation' => 'o/P',
201 'transformation_options' => '',
202 'input_transformation' => 'i/p',
203 'input_transformation_options' => '',
206 PMA_getMIME('pma_test', 'table1')
211 * Test for PMA_clearTransformations
213 * @return void
215 public function testClearTransformations()
217 // Mock dbi
218 $dbi = $this->getMockBuilder('PMA\libraries\DatabaseInterface')
219 ->disableOriginalConstructor()
220 ->getMock();
221 $dbi->expects($this->any())
222 ->method('tryQuery')
223 ->will($this->returnValue(true));
224 $GLOBALS['dbi'] = $dbi;
226 // Case 1 : no configuration storage
227 $actual = PMA_clearTransformations('db');
228 $this->assertEquals(
229 false,
230 $actual
233 $_SESSION['relation'][$GLOBALS['server']]['PMA_VERSION'] = PMA_VERSION;
234 $_SESSION['relation'][$GLOBALS['server']]['column_info'] = "column_info";
235 $_SESSION['relation'][$GLOBALS['server']]['db'] = "pmadb";
237 // Case 2 : database delete
238 $actual = PMA_clearTransformations('db');
239 $this->assertEquals(
240 true,
241 $actual
244 // Case 3 : table delete
245 $actual = PMA_clearTransformations('db', 'table');
246 $this->assertEquals(
247 true,
248 $actual
251 // Case 4 : column delete
252 $actual = PMA_clearTransformations('db', 'table', 'col');
253 $this->assertEquals(
254 true,
255 $actual
260 * @dataProvider fixupData
262 public function testFixup($value, $expected)
264 $this->assertEquals(
265 $expected,
266 PMA_fixupMIME($value)
270 public function fixupData()
272 return array(
273 array(
274 'text_plain_bool2text.php',
275 'Text_Plain_Bool2Text.php'
277 array(
278 'application_octetstream_download.php',
279 'Application_Octetstream_Download.php'
281 array(
282 'text_plain_json.php',
283 'Text_Plain_Json.php'
285 array(
286 'image_jpeg_link.php',
287 'Image_JPEG_Link.php'