2 /* vim: set expandtab sw=4 ts=4 sts=4: */
4 * Test for generating routine editor
6 * @package phpMyAdmin-test
8 require_once 'libraries/common.lib.php';
9 require_once 'libraries/php-gettext/gettext.inc';
10 require_once 'libraries/url_generating.lib.php';
14 require_once 'libraries/rte/rte_routines.lib.php';
16 class PMA_RTN_getEditorForm_test
extends PHPUnit_Framework_TestCase
18 public function setUp()
22 $cfg['ShowFunctionFields'] = false;
23 require 'libraries/data_mysql.inc.php';
25 if (! function_exists('PMA_generateCharsetDropdownBox')) {
26 function PMA_generateCharsetDropdownBox() {}
28 if (! defined('PMA_CSDROPDOWN_CHARSET')) {
29 define('PMA_CSDROPDOWN_CHARSET', '');
31 if (! function_exists('PMA_DBI_get_tables')) {
32 function PMA_DBI_get_tables($db)
34 return array('table1', 'table`2');
37 $GLOBALS['tear_down']['token'] = false;
38 $GLOBALS['tear_down']['server'] = false;
39 if (! isset($_SESSION[' PMA_token '])) {
40 $_SESSION[' PMA_token '] = '';
41 $GLOBALS['tear_down']['token'] = true;
43 if (! isset($GLOBALS['cfg']['ServerDefault'])) {
44 $GLOBALS['cfg']['ServerDefault'] = '';
45 $GLOBALS['tear_down']['server'] = true;
49 public function tearDown()
51 if ($GLOBALS['tear_down']['token']) {
52 unset($_SESSION[' PMA_token ']);
54 if ($GLOBALS['tear_down']['server']) {
55 unset($GLOBALS['cfg']['ServerDefault']);
57 unset($GLOBALS['tear_down']);
60 public function testgetParameterRow_empty()
62 $GLOBALS['is_ajax_request'] = false;
64 $this->assertEquals('', PMA_RTN_getParameterRow(array(), 0));
68 * @depends testgetParameterRow_empty
69 * @dataProvider provider_row
71 public function testgetParameterRow($data, $index, $matcher)
73 $GLOBALS['is_ajax_request'] = false;
75 $this->assertTag($matcher, PMA_RTN_getParameterRow($data, $index), false);
78 public function provider_row()
82 'item_original_name' => '',
83 'item_returnlength' => '',
84 'item_returnopts_num' => '',
85 'item_returnopts_text' => '',
86 'item_definition' => '',
89 'item_type' => 'PROCEDURE',
90 'item_type_toggle' => 'FUNCTION',
91 'item_original_type' => 'PROCEDURE',
92 'item_num_params' => 1,
93 'item_param_dir' => array(0 => 'IN'),
94 'item_param_name' => array(0 => 'foo'),
95 'item_param_type' => array(0 => 'INT'),
96 'item_param_length' => array(0 => ''),
97 'item_param_opts_num' => array(0 => 'UNSIGNED'),
98 'item_param_opts_text' => array(0 => ''),
99 'item_returntype' => '',
100 'item_isdeterministic' => '',
101 'item_securitytype_definer' => '',
102 'item_securitytype_invoker' => '',
103 'item_sqldataaccess' => ''
112 'attributes' => array(
113 'name' => 'item_param_dir[0]'
122 'attributes' => array(
123 'name' => 'item_param_name[0]'
132 'attributes' => array(
133 'name' => 'item_param_type[0]'
142 'attributes' => array(
143 'name' => 'item_param_length[0]'
152 'attributes' => array(
153 'name' => 'item_param_opts_num[0]'
162 'attributes' => array(
163 'class' => 'routine_param_remove_anchor'
171 * @depends testgetParameterRow
172 * @dataProvider provider_row_ajax
174 public function testgetParameterRow_ajax($data, $matcher)
176 $GLOBALS['is_ajax_request'] = false;
177 PMA_RTN_setGlobals();
178 $this->assertTag($matcher, PMA_RTN_getParameterRow($data), false);
181 public function provider_row_ajax()
185 'item_original_name' => '',
186 'item_returnlength' => '',
187 'item_returnopts_num' => '',
188 'item_returnopts_text' => '',
189 'item_definition' => '',
190 'item_comment' => '',
191 'item_definer' => '',
192 'item_type' => 'PROCEDURE',
193 'item_type_toggle' => 'FUNCTION',
194 'item_original_type' => 'PROCEDURE',
195 'item_num_params' => 1,
196 'item_param_dir' => array(0 => 'IN'),
197 'item_param_name' => array(0 => 'foo'),
198 'item_param_type' => array(0 => 'INT'),
199 'item_param_length' => array(0 => ''),
200 'item_param_opts_num' => array(0 => 'UNSIGNED'),
201 'item_param_opts_text' => array(0 => ''),
202 'item_returntype' => '',
203 'item_isdeterministic' => '',
204 'item_securitytype_definer' => '',
205 'item_securitytype_invoker' => '',
206 'item_sqldataaccess' => ''
214 'attributes' => array(
215 'name' => 'item_param_dir[%s]'
223 'attributes' => array(
224 'name' => 'item_param_name[%s]'
232 'attributes' => array(
233 'name' => 'item_param_type[%s]'
241 'attributes' => array(
242 'name' => 'item_param_length[%s]'
250 'attributes' => array(
251 'name' => 'item_param_opts_num[%s]'
259 'attributes' => array(
260 'class' => 'routine_param_remove_anchor'
268 * @depends testgetParameterRow_ajax
269 * @dataProvider provider_editor_1
271 public function testgetEditorForm_1($data, $matcher)
273 $GLOBALS['is_ajax_request'] = false;
274 PMA_RTN_setGlobals();
275 $this->assertTag($matcher, PMA_RTN_getEditorForm('add', '', $data), false);
278 public function provider_editor_1()
282 'item_original_name' => '',
283 'item_returnlength' => '',
284 'item_returnopts_num' => '',
285 'item_returnopts_text' => '',
286 'item_definition' => '',
287 'item_comment' => '',
288 'item_definer' => '',
289 'item_type' => 'PROCEDURE',
290 'item_type_toggle' => 'FUNCTION',
291 'item_original_type' => 'PROCEDURE',
292 'item_num_params' => 0,
293 'item_param_dir' => array(),
294 'item_param_name' => array(),
295 'item_param_type' => array(),
296 'item_param_length' => array(),
297 'item_param_opts_num' => array(),
298 'item_param_opts_text' => array(),
299 'item_returntype' => '',
300 'item_isdeterministic' => '',
301 'item_securitytype_definer' => '',
302 'item_securitytype_invoker' => '',
303 'item_sqldataaccess' => ''
311 'attributes' => array(
320 'attributes' => array(
321 'name' => 'item_name'
329 'attributes' => array(
330 'name' => 'item_type'
338 'attributes' => array(
339 'name' => 'routine_changetype'
349 'attributes' => array(
350 'name' => 'routine_addparameter'
358 'attributes' => array(
359 'name' => 'routine_removeparameter'
367 'attributes' => array(
368 'name' => 'item_returntype'
376 'attributes' => array(
377 'name' => 'item_returnlength'
385 'attributes' => array(
386 'name' => 'item_returnopts_num'
394 'attributes' => array(
395 'name' => 'item_definition'
403 'attributes' => array(
404 'name' => 'item_isdeterministic'
412 'attributes' => array(
413 'name' => 'item_definer'
421 'attributes' => array(
422 'name' => 'item_securitytype'
430 'attributes' => array(
431 'name' => 'item_sqldataaccess'
439 'attributes' => array(
440 'name' => 'item_comment'
448 'attributes' => array(
449 'name' => 'editor_process_add'
458 * @depends testgetParameterRow_ajax
459 * @dataProvider provider_editor_2
461 public function testgetEditorForm_2($data, $matcher)
463 $GLOBALS['is_ajax_request'] = false;
464 PMA_RTN_setGlobals();
465 $this->assertTag($matcher, PMA_RTN_getEditorForm('edit', 'change', $data), false);
468 public function provider_editor_2()
471 'item_name' => 'foo',
472 'item_original_name' => 'bar',
473 'item_returnlength' => '',
474 'item_returnopts_num' => '',
475 'item_returnopts_text' => '',
476 'item_definition' => 'SELECT 1',
477 'item_comment' => '',
478 'item_definer' => '',
479 'item_type' => 'PROCEDURE',
480 'item_type_toggle' => 'FUNCTION',
481 'item_original_type' => 'PROCEDURE',
482 'item_num_params' => 1,
483 'item_param_dir' => array(0 => 'IN'),
484 'item_param_name' => array(0 => 'baz'),
485 'item_param_type' => array(0 => 'INT'),
486 'item_param_length' => array(0 => '20'),
487 'item_param_opts_num' => array(0 => 'UNSIGNED'),
488 'item_param_opts_text' => array(0 => ''),
489 'item_returntype' => '',
490 'item_isdeterministic' => '',
491 'item_securitytype_definer' => '',
492 'item_securitytype_invoker' => '',
493 'item_sqldataaccess' => 'NO SQL'
501 'attributes' => array(
502 'name' => 'edit_item'
510 'attributes' => array(
511 'name' => 'item_name'
519 'attributes' => array(
520 'name' => 'item_type',
521 'value' => 'FUNCTION'
529 'attributes' => array(
530 'name' => 'routine_changetype'
540 'attributes' => array(
541 'name' => 'routine_addparameter'
549 'attributes' => array(
550 'name' => 'routine_removeparameter'
558 'attributes' => array(
559 'name' => 'item_returntype'
567 'attributes' => array(
568 'name' => 'item_returnlength'
576 'attributes' => array(
577 'name' => 'item_returnopts_num'
585 'attributes' => array(
586 'name' => 'item_definition'
594 'attributes' => array(
595 'name' => 'item_isdeterministic'
603 'attributes' => array(
604 'name' => 'item_definer'
612 'attributes' => array(
613 'name' => 'item_securitytype'
621 'attributes' => array(
622 'name' => 'item_sqldataaccess'
630 'attributes' => array(
631 'name' => 'item_comment'
639 'attributes' => array(
640 'name' => 'editor_process_edit'
649 * @depends testgetParameterRow_ajax
650 * @dataProvider provider_editor_3
652 public function testgetEditorForm_3($data, $matcher)
654 $GLOBALS['is_ajax_request'] = true;
655 PMA_RTN_setGlobals();
656 $this->assertTag($matcher, PMA_RTN_getEditorForm('edit', 'remove', $data), false);
659 public function provider_editor_3()
662 'item_name' => 'foo',
663 'item_original_name' => 'bar',
664 'item_returnlength' => '',
665 'item_returnopts_num' => 'UNSIGNED',
666 'item_returnopts_text' => '',
667 'item_definition' => 'SELECT 1',
668 'item_comment' => '',
669 'item_definer' => '',
670 'item_type' => 'FUNCTION',
671 'item_type_toggle' => 'PROCEDURE',
672 'item_original_type' => 'FUNCTION',
673 'item_num_params' => 1,
674 'item_param_dir' => array(0 => ''),
675 'item_param_name' => array(0 => 'baz'),
676 'item_param_type' => array(0 => 'INT'),
677 'item_param_length' => array(0 => '20'),
678 'item_param_opts_num' => array(0 => 'UNSIGNED'),
679 'item_param_opts_text' => array(0 => ''),
680 'item_returntype' => 'INT',
681 'item_isdeterministic' => '',
682 'item_securitytype_definer' => '',
683 'item_securitytype_invoker' => '',
684 'item_sqldataaccess' => 'NO SQL'
692 'attributes' => array(
693 'name' => 'edit_item'
701 'attributes' => array(
702 'name' => 'item_name'
710 'attributes' => array(
711 'name' => 'item_type'
719 'attributes' => array(
720 'name' => 'routine_addparameter'
728 'attributes' => array(
729 'name' => 'routine_removeparameter'
737 'attributes' => array(
738 'name' => 'item_returntype'
746 'attributes' => array(
747 'name' => 'item_returnlength'
755 'attributes' => array(
756 'name' => 'item_returnopts_num'
764 'attributes' => array(
765 'name' => 'item_definition'
773 'attributes' => array(
774 'name' => 'item_isdeterministic'
782 'attributes' => array(
783 'name' => 'item_definer'
791 'attributes' => array(
792 'name' => 'item_securitytype'
800 'attributes' => array(
801 'name' => 'item_sqldataaccess'
809 'attributes' => array(
810 'name' => 'item_comment'
818 'attributes' => array(
819 'name' => 'ajax_request'
827 'attributes' => array(
828 'name' => 'editor_process_edit'
837 * @depends testgetParameterRow_ajax
838 * @dataProvider provider_editor_4
840 public function testgetEditorForm_4($data, $matcher)
842 $GLOBALS['is_ajax_request'] = false;
843 PMA_RTN_setGlobals();
844 $this->assertTag($matcher, PMA_RTN_getEditorForm('edit', 'change', $data), false);
847 public function provider_editor_4()
850 'item_name' => 'foo',
851 'item_original_name' => 'bar',
852 'item_returnlength' => '',
853 'item_returnopts_num' => '',
854 'item_returnopts_text' => '',
855 'item_definition' => 'SELECT 1',
856 'item_comment' => '',
857 'item_definer' => '',
858 'item_type' => 'FUNCTION',
859 'item_type_toggle' => 'PROCEDURE',
860 'item_original_type' => 'PROCEDURE',
861 'item_num_params' => 1,
862 'item_param_dir' => array(0 => 'IN'),
863 'item_param_name' => array(0 => 'baz'),
864 'item_param_type' => array(0 => 'INT'),
865 'item_param_length' => array(0 => '20'),
866 'item_param_opts_num' => array(0 => 'UNSIGNED'),
867 'item_param_opts_text' => array(0 => ''),
868 'item_returntype' => '',
869 'item_isdeterministic' => '',
870 'item_securitytype_definer' => '',
871 'item_securitytype_invoker' => '',
872 'item_sqldataaccess' => 'NO SQL'
880 'attributes' => array(
881 'name' => 'item_type',
882 'value' => 'PROCEDURE'