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/data_mysql.inc.php';
10 require_once 'libraries/php-gettext/gettext.inc';
11 require_once 'libraries/url_generating.lib.php';
15 require_once 'libraries/rte/rte_routines.lib.php';
17 class PMA_RTN_getEditorForm_test
extends PHPUnit_Framework_TestCase
19 public function setUp()
21 if (! function_exists('PMA_generateCharsetDropdownBox')) {
22 function PMA_generateCharsetDropdownBox() {}
24 if (! defined('PMA_CSDROPDOWN_CHARSET')) {
25 define('PMA_CSDROPDOWN_CHARSET', '');
27 if (! function_exists('PMA_DBI_get_tables')) {
28 function PMA_DBI_get_tables($db)
30 return array('table1', 'table`2');
33 $GLOBALS['tear_down']['token'] = false;
34 $GLOBALS['tear_down']['server'] = false;
35 if (! isset($_SESSION[' PMA_token '])) {
36 $_SESSION[' PMA_token '] = '';
37 $GLOBALS['tear_down']['token'] = true;
39 if (! isset($GLOBALS['cfg']['ServerDefault'])) {
40 $GLOBALS['cfg']['ServerDefault'] = '';
41 $GLOBALS['tear_down']['server'] = true;
45 public function tearDown()
47 if ($GLOBALS['tear_down']['token']) {
48 unset($_SESSION[' PMA_token ']);
50 if ($GLOBALS['tear_down']['server']) {
51 unset($GLOBALS['cfg']['ServerDefault']);
53 unset($GLOBALS['tear_down']);
56 public function testgetParameterRow_empty()
58 $GLOBALS['is_ajax_request'] = false;
60 $this->assertEquals('', PMA_RTN_getParameterRow(array(), 0));
64 * @depends testgetParameterRow_empty
65 * @dataProvider provider_row
67 public function testgetParameterRow($data, $index, $matcher)
69 $GLOBALS['is_ajax_request'] = false;
71 $this->assertTag($matcher, PMA_RTN_getParameterRow($data, $index), false);
74 public function provider_row()
78 'item_original_name' => '',
79 'item_returnlength' => '',
80 'item_returnopts_num' => '',
81 'item_returnopts_text' => '',
82 'item_definition' => '',
85 'item_type' => 'PROCEDURE',
86 'item_type_toggle' => 'FUNCTION',
87 'item_original_type' => 'PROCEDURE',
88 'item_num_params' => 1,
89 'item_param_dir' => array(0 => 'IN'),
90 'item_param_name' => array(0 => 'foo'),
91 'item_param_type' => array(0 => 'INT'),
92 'item_param_length' => array(0 => ''),
93 'item_param_opts_num' => array(0 => 'UNSIGNED'),
94 'item_param_opts_text' => array(0 => ''),
95 'item_returntype' => '',
96 'item_isdeterministic' => '',
97 'item_securitytype_definer' => '',
98 'item_securitytype_invoker' => '',
99 'item_sqldataaccess' => ''
108 'attributes' => array(
109 'name' => 'item_param_dir[0]'
118 'attributes' => array(
119 'name' => 'item_param_name[0]'
128 'attributes' => array(
129 'name' => 'item_param_type[0]'
138 'attributes' => array(
139 'name' => 'item_param_length[0]'
148 'attributes' => array(
149 'name' => 'item_param_opts_num[0]'
158 'attributes' => array(
159 'class' => 'routine_param_remove_anchor'
167 * @depends testgetParameterRow
168 * @dataProvider provider_row_ajax
170 public function testgetParameterRow_ajax($data, $matcher)
172 $GLOBALS['is_ajax_request'] = false;
173 PMA_RTN_setGlobals();
174 $this->assertTag($matcher, PMA_RTN_getParameterRow($data), false);
177 public function provider_row_ajax()
181 'item_original_name' => '',
182 'item_returnlength' => '',
183 'item_returnopts_num' => '',
184 'item_returnopts_text' => '',
185 'item_definition' => '',
186 'item_comment' => '',
187 'item_definer' => '',
188 'item_type' => 'PROCEDURE',
189 'item_type_toggle' => 'FUNCTION',
190 'item_original_type' => 'PROCEDURE',
191 'item_num_params' => 1,
192 'item_param_dir' => array(0 => 'IN'),
193 'item_param_name' => array(0 => 'foo'),
194 'item_param_type' => array(0 => 'INT'),
195 'item_param_length' => array(0 => ''),
196 'item_param_opts_num' => array(0 => 'UNSIGNED'),
197 'item_param_opts_text' => array(0 => ''),
198 'item_returntype' => '',
199 'item_isdeterministic' => '',
200 'item_securitytype_definer' => '',
201 'item_securitytype_invoker' => '',
202 'item_sqldataaccess' => ''
210 'attributes' => array(
211 'name' => 'item_param_dir[%s]'
219 'attributes' => array(
220 'name' => 'item_param_name[%s]'
228 'attributes' => array(
229 'name' => 'item_param_type[%s]'
237 'attributes' => array(
238 'name' => 'item_param_length[%s]'
246 'attributes' => array(
247 'name' => 'item_param_opts_num[%s]'
255 'attributes' => array(
256 'class' => 'routine_param_remove_anchor'
264 * @depends testgetParameterRow_ajax
265 * @dataProvider provider_editor_1
267 public function testgetEditorForm_1($data, $matcher)
269 $GLOBALS['is_ajax_request'] = false;
270 PMA_RTN_setGlobals();
271 $this->assertTag($matcher, PMA_RTN_getEditorForm('add', '', $data), false);
274 public function provider_editor_1()
278 'item_original_name' => '',
279 'item_returnlength' => '',
280 'item_returnopts_num' => '',
281 'item_returnopts_text' => '',
282 'item_definition' => '',
283 'item_comment' => '',
284 'item_definer' => '',
285 'item_type' => 'PROCEDURE',
286 'item_type_toggle' => 'FUNCTION',
287 'item_original_type' => 'PROCEDURE',
288 'item_num_params' => 0,
289 'item_param_dir' => array(),
290 'item_param_name' => array(),
291 'item_param_type' => array(),
292 'item_param_length' => array(),
293 'item_param_opts_num' => array(),
294 'item_param_opts_text' => array(),
295 'item_returntype' => '',
296 'item_isdeterministic' => '',
297 'item_securitytype_definer' => '',
298 'item_securitytype_invoker' => '',
299 'item_sqldataaccess' => ''
307 'attributes' => array(
316 'attributes' => array(
317 'name' => 'item_name'
325 'attributes' => array(
326 'name' => 'item_type'
334 'attributes' => array(
335 'name' => 'routine_changetype'
345 'attributes' => array(
346 'name' => 'routine_addparameter'
354 'attributes' => array(
355 'name' => 'routine_removeparameter'
363 'attributes' => array(
364 'name' => 'item_returntype'
372 'attributes' => array(
373 'name' => 'item_returnlength'
381 'attributes' => array(
382 'name' => 'item_returnopts_num'
390 'attributes' => array(
391 'name' => 'item_definition'
399 'attributes' => array(
400 'name' => 'item_isdeterministic'
408 'attributes' => array(
409 'name' => 'item_definer'
417 'attributes' => array(
418 'name' => 'item_securitytype'
426 'attributes' => array(
427 'name' => 'item_sqldataaccess'
435 'attributes' => array(
436 'name' => 'item_comment'
444 'attributes' => array(
445 'name' => 'editor_process_add'
454 * @depends testgetParameterRow_ajax
455 * @dataProvider provider_editor_2
457 public function testgetEditorForm_2($data, $matcher)
459 $GLOBALS['is_ajax_request'] = false;
460 PMA_RTN_setGlobals();
461 $this->assertTag($matcher, PMA_RTN_getEditorForm('edit', 'change', $data), false);
464 public function provider_editor_2()
467 'item_name' => 'foo',
468 'item_original_name' => 'bar',
469 'item_returnlength' => '',
470 'item_returnopts_num' => '',
471 'item_returnopts_text' => '',
472 'item_definition' => 'SELECT 1',
473 'item_comment' => '',
474 'item_definer' => '',
475 'item_type' => 'PROCEDURE',
476 'item_type_toggle' => 'FUNCTION',
477 'item_original_type' => 'PROCEDURE',
478 'item_num_params' => 1,
479 'item_param_dir' => array(0 => 'IN'),
480 'item_param_name' => array(0 => 'baz'),
481 'item_param_type' => array(0 => 'INT'),
482 'item_param_length' => array(0 => '20'),
483 'item_param_opts_num' => array(0 => 'UNSIGNED'),
484 'item_param_opts_text' => array(0 => ''),
485 'item_returntype' => '',
486 'item_isdeterministic' => '',
487 'item_securitytype_definer' => '',
488 'item_securitytype_invoker' => '',
489 'item_sqldataaccess' => 'NO SQL'
497 'attributes' => array(
498 'name' => 'edit_item'
506 'attributes' => array(
507 'name' => 'item_name'
515 'attributes' => array(
516 'name' => 'item_type',
517 'value' => 'FUNCTION'
525 'attributes' => array(
526 'name' => 'routine_changetype'
536 'attributes' => array(
537 'name' => 'routine_addparameter'
545 'attributes' => array(
546 'name' => 'routine_removeparameter'
554 'attributes' => array(
555 'name' => 'item_returntype'
563 'attributes' => array(
564 'name' => 'item_returnlength'
572 'attributes' => array(
573 'name' => 'item_returnopts_num'
581 'attributes' => array(
582 'name' => 'item_definition'
590 'attributes' => array(
591 'name' => 'item_isdeterministic'
599 'attributes' => array(
600 'name' => 'item_definer'
608 'attributes' => array(
609 'name' => 'item_securitytype'
617 'attributes' => array(
618 'name' => 'item_sqldataaccess'
626 'attributes' => array(
627 'name' => 'item_comment'
635 'attributes' => array(
636 'name' => 'editor_process_edit'
645 * @depends testgetParameterRow_ajax
646 * @dataProvider provider_editor_3
648 public function testgetEditorForm_3($data, $matcher)
650 $GLOBALS['is_ajax_request'] = true;
651 PMA_RTN_setGlobals();
652 $this->assertTag($matcher, PMA_RTN_getEditorForm('edit', 'remove', $data), false);
655 public function provider_editor_3()
658 'item_name' => 'foo',
659 'item_original_name' => 'bar',
660 'item_returnlength' => '',
661 'item_returnopts_num' => 'UNSIGNED',
662 'item_returnopts_text' => '',
663 'item_definition' => 'SELECT 1',
664 'item_comment' => '',
665 'item_definer' => '',
666 'item_type' => 'FUNCTION',
667 'item_type_toggle' => 'PROCEDURE',
668 'item_original_type' => 'FUNCTION',
669 'item_num_params' => 1,
670 'item_param_dir' => array(0 => ''),
671 'item_param_name' => array(0 => 'baz'),
672 'item_param_type' => array(0 => 'INT'),
673 'item_param_length' => array(0 => '20'),
674 'item_param_opts_num' => array(0 => 'UNSIGNED'),
675 'item_param_opts_text' => array(0 => ''),
676 'item_returntype' => 'INT',
677 'item_isdeterministic' => '',
678 'item_securitytype_definer' => '',
679 'item_securitytype_invoker' => '',
680 'item_sqldataaccess' => 'NO SQL'
688 'attributes' => array(
689 'name' => 'edit_item'
697 'attributes' => array(
698 'name' => 'item_name'
706 'attributes' => array(
707 'name' => 'item_type'
715 'attributes' => array(
716 'name' => 'routine_addparameter'
724 'attributes' => array(
725 'name' => 'routine_removeparameter'
733 'attributes' => array(
734 'name' => 'item_returntype'
742 'attributes' => array(
743 'name' => 'item_returnlength'
751 'attributes' => array(
752 'name' => 'item_returnopts_num'
760 'attributes' => array(
761 'name' => 'item_definition'
769 'attributes' => array(
770 'name' => 'item_isdeterministic'
778 'attributes' => array(
779 'name' => 'item_definer'
787 'attributes' => array(
788 'name' => 'item_securitytype'
796 'attributes' => array(
797 'name' => 'item_sqldataaccess'
805 'attributes' => array(
806 'name' => 'item_comment'
814 'attributes' => array(
815 'name' => 'ajax_request'
823 'attributes' => array(
824 'name' => 'editor_process_edit'
833 * @depends testgetParameterRow_ajax
834 * @dataProvider provider_editor_4
836 public function testgetEditorForm_4($data, $matcher)
838 $GLOBALS['is_ajax_request'] = false;
839 PMA_RTN_setGlobals();
840 $this->assertTag($matcher, PMA_RTN_getEditorForm('edit', 'change', $data), false);
843 public function provider_editor_4()
846 'item_name' => 'foo',
847 'item_original_name' => 'bar',
848 'item_returnlength' => '',
849 'item_returnopts_num' => '',
850 'item_returnopts_text' => '',
851 'item_definition' => 'SELECT 1',
852 'item_comment' => '',
853 'item_definer' => '',
854 'item_type' => 'FUNCTION',
855 'item_type_toggle' => 'PROCEDURE',
856 'item_original_type' => 'PROCEDURE',
857 'item_num_params' => 1,
858 'item_param_dir' => array(0 => 'IN'),
859 'item_param_name' => array(0 => 'baz'),
860 'item_param_type' => array(0 => 'INT'),
861 'item_param_length' => array(0 => '20'),
862 'item_param_opts_num' => array(0 => 'UNSIGNED'),
863 'item_param_opts_text' => array(0 => ''),
864 'item_returntype' => '',
865 'item_isdeterministic' => '',
866 'item_securitytype_definer' => '',
867 'item_securitytype_invoker' => '',
868 'item_sqldataaccess' => 'NO SQL'
876 'attributes' => array(
877 'name' => 'item_type',
878 'value' => 'PROCEDURE'