Advisor: mark that 'Rate of reading fixed position' may be wrong, requires further...
[phpmyadmin/thilanka.git] / test / libraries / rte / PMA_RTN_getQueryFromRequest_test.php
blobdb11ff4671b97d2b933a299b9301fa28b6def45a
1 <?php
2 /* vim: set expandtab sw=4 ts=4 sts=4: */
3 /**
4 * Test for generating CREATE [PROCEDURE|FUNCTION] query from HTTP request
6 * @package phpMyAdmin-test
7 */
9 /*
10 * Needed for PMA_backquote() and PMA_RTN_getQueryFromRequest()
12 require_once 'libraries/common.lib.php';
13 require_once 'libraries/php-gettext/gettext.inc';
16 * Include to test.
18 require_once 'libraries/rte/rte_routines.lib.php';
21 class PMA_RTN_getQueryFromRequest_test extends PHPUnit_Framework_TestCase
23 /**
24 * @dataProvider provider
26 public function testgetQueryFromRequest($request, $query, $num_err)
28 global $_REQUEST, $errors, $cfg;
30 $cfg['ShowFunctionFields'] = false;
32 require 'libraries/data_mysql.inc.php';
34 $errors = array();
35 PMA_RTN_setGlobals();
37 unset($_REQUEST);
38 $_REQUEST = $request;
39 $this->assertEquals($query, PMA_RTN_getQueryFromRequest());
40 $this->assertEquals($num_err, count($errors));
43 public function provider()
45 return array(
46 // Testing success
47 array(
48 array(
49 'item_name' => 'p r o c',
50 'item_returnlength' => '',
51 'item_returnopts_num' => '',
52 'item_returnopts_text' => '',
53 'item_definition' => 'SELECT 0;',
54 'item_comment' => 'foo',
55 'item_definer' => 'me@home',
56 'item_type' => 'PROCEDURE',
57 'item_num_params' => '0',
58 'item_param_dir' => '',
59 'item_param_name' => '',
60 'item_param_type' => '',
61 'item_param_length' => '',
62 'item_param_opts_num' => '',
63 'item_param_opts_text' => '',
64 'item_returntype' => '',
65 'item_isdeterministic' => '',
66 'item_securitytype' => 'INVOKER',
67 'item_sqldataaccess' => 'NO SQL'
69 'CREATE DEFINER=`me`@`home` PROCEDURE `p r o c`() COMMENT \'foo\' DETERMINISTIC NO SQL SQL SECURITY INVOKER SELECT 0;',
72 array(
73 array(
74 'item_name' => 'pr``oc',
75 'item_returnlength' => '',
76 'item_returnopts_num' => '',
77 'item_returnopts_text' => '',
78 'item_definition' => 'SELECT \'foobar\';',
79 'item_comment' => '',
80 'item_definer' => 'someuser@somehost',
81 'item_type' => 'PROCEDURE',
82 'item_num_params' => '2',
83 'item_param_dir' => array('IN', 'INOUT'),
84 'item_param_name' => array('pa`ram', 'par 2'),
85 'item_param_type' => array('INT', 'ENUM'),
86 'item_param_length' => array('10', '\'a\', \'b\''),
87 'item_param_opts_num' => array('ZEROFILL', ''),
88 'item_param_opts_text' => array('utf8', 'latin1'),
89 'item_returntype' => '',
90 'item_securitytype' => 'DEFINER',
91 'item_sqldataaccess' => 'foobar'
93 'CREATE DEFINER=`someuser`@`somehost` PROCEDURE `pr````oc`(IN `pa``ram` INT(10) ZEROFILL, INOUT `par 2` ENUM(\'a\', \'b\') CHARSET latin1) NOT DETERMINISTIC SQL SECURITY DEFINER SELECT \'foobar\';',
96 array(
97 array(
98 'item_name' => 'func\\',
99 'item_returnlength' => '5,5',
100 'item_returnopts_num' => 'UNSIGNED ZEROFILL',
101 'item_returnopts_text' => '',
102 'item_definition' => 'SELECT \'foobar\';',
103 'item_comment' => 'foo\'s bar',
104 'item_definer' => '',
105 'item_type' => 'FUNCTION',
106 'item_num_params' => '1',
107 'item_param_dir' => '',
108 'item_param_name' => array('pa`ram'),
109 'item_param_type' => array('VARCHAR'),
110 'item_param_length' => array('45'),
111 'item_param_opts_num' => array(''),
112 'item_param_opts_text' => array('latin1'),
113 'item_returntype' => 'DECIMAL',
114 'item_isdeterministic' => 'ON',
115 'item_securitytype' => 'DEFINER',
116 'item_sqldataaccess' => 'READ SQL DATA'
118 'CREATE FUNCTION `func\\`(`pa``ram` VARCHAR(45) CHARSET latin1) RETURNS DECIMAL(5,5) UNSIGNED ZEROFILL COMMENT \'foo\'\'s bar\' DETERMINISTIC SQL SECURITY DEFINER SELECT \'foobar\';',
121 array(
122 array(
123 'item_name' => 'func',
124 'item_returnlength' => '20',
125 'item_returnopts_num' => '',
126 'item_returnopts_text' => 'utf8',
127 'item_definition' => 'SELECT 0;',
128 'item_comment' => '',
129 'item_definer' => '',
130 'item_type' => 'FUNCTION',
131 'item_num_params' => '1',
132 'item_returntype' => 'VARCHAR',
133 'item_securitytype' => 'DEFINER',
134 'item_sqldataaccess' => 'READ SQL DATA'
136 'CREATE FUNCTION `func`() RETURNS VARCHAR(20) CHARSET utf8 NOT DETERMINISTIC SQL SECURITY DEFINER SELECT 0;',
139 // Testing failures
140 array(
141 array(
143 'CREATE () NOT DETERMINISTIC ', // invalid query
146 array(
147 array(
148 'item_name' => 'proc',
149 'item_returnlength' => '',
150 'item_returnopts_num' => '',
151 'item_returnopts_text' => '',
152 'item_definition' => 'SELECT 0;',
153 'item_comment' => 'foo',
154 'item_definer' => 'mehome', // invalid definer format
155 'item_type' => 'PROCEDURE',
156 'item_num_params' => '0',
157 'item_param_dir' => '',
158 'item_param_name' => '',
159 'item_param_type' => '',
160 'item_param_length' => '',
161 'item_param_opts_num' => '',
162 'item_param_opts_text' => '',
163 'item_returntype' => '',
164 'item_isdeterministic' => '',
165 'item_securitytype' => 'INVOKER',
166 'item_sqldataaccess' => 'NO SQL'
168 'CREATE PROCEDURE `proc`() COMMENT \'foo\' DETERMINISTIC NO SQL SQL SECURITY INVOKER SELECT 0;', // valid query
171 array(
172 array(
173 'item_name' => 'proc',
174 'item_returnlength' => '',
175 'item_returnopts_num' => '',
176 'item_returnopts_text' => '',
177 'item_definition' => 'SELECT 0;',
178 'item_comment' => '',
179 'item_definer' => '',
180 'item_type' => 'PROCEDURE',
181 'item_num_params' => '2',
182 'item_param_dir' => array('FAIL', 'INOUT'), // invalid direction
183 'item_param_name' => array('pa`ram', 'goo'),
184 'item_param_type' => array('INT', 'ENUM'),
185 'item_param_length' => array('10', ''), // missing ENUM values
186 'item_param_opts_num' => array('ZEROFILL', ''),
187 'item_param_opts_text' => array('utf8', 'latin1'),
188 'item_returntype' => '',
189 'item_securitytype' => 'DEFINER',
190 'item_sqldataaccess' => 'foobar' // invalid, will just be ignored withour throwing errors
192 'CREATE PROCEDURE `proc`((10) ZEROFILL, INOUT `goo` ENUM CHARSET latin1) NOT DETERMINISTIC SQL SECURITY DEFINER SELECT 0;', // invalid query
195 array(
196 array(
197 'item_name' => 'func',
198 'item_returnlength' => '', // missing length for VARCHAR
199 'item_returnopts_num' => '',
200 'item_returnopts_text' => 'utf8',
201 'item_definition' => 'SELECT 0;',
202 'item_comment' => '',
203 'item_definer' => '',
204 'item_type' => 'FUNCTION',
205 'item_num_params' => '2',
206 'item_param_dir' => array('IN'),
207 'item_param_name' => array(''), // missing name
208 'item_param_type' => array('INT'),
209 'item_param_length' => array('10'),
210 'item_param_opts_num' => array('ZEROFILL'),
211 'item_param_opts_text' => array('latin1'),
212 'item_returntype' => 'VARCHAR',
213 'item_securitytype' => 'DEFINER',
214 'item_sqldataaccess' => ''
216 'CREATE FUNCTION `func`() RETURNS VARCHAR CHARSET utf8 NOT DETERMINISTIC SQL SECURITY DEFINER SELECT 0;', // invalid query
219 array(
220 array(
221 'item_name' => 'func',
222 'item_returnlength' => '',
223 'item_returnopts_num' => '',
224 'item_returnopts_text' => '',
225 'item_definition' => 'SELECT 0;',
226 'item_comment' => '',
227 'item_definer' => '',
228 'item_type' => 'FUNCTION',
229 'item_num_params' => '0',
230 'item_returntype' => 'FAIL', // invalid return type
231 'item_securitytype' => 'DEFINER',
232 'item_sqldataaccess' => ''
234 'CREATE FUNCTION `func`() NOT DETERMINISTIC SQL SECURITY DEFINER SELECT 0;', // invalid query