Fixed: Not selecting a datalabel used to issue a notice(undefined offset)
[phpmyadmin/ammaryasirr.git] / test / libraries / rte / PMA_RTN_getEditorForm_test.php
blob2fd01290d5cb069f8401646474fdac2aced7529d
1 <?php
2 /* vim: set expandtab sw=4 ts=4 sts=4: */
3 /**
4 * Test for generating routine editor
6 * @package phpMyAdmin-test
7 */
8 require_once 'libraries/common.lib.php';
9 require_once 'libraries/php-gettext/gettext.inc';
10 require_once 'libraries/url_generating.lib.php';
12 * Include to test.
14 require_once 'libraries/rte/rte_routines.lib.php';
16 class PMA_RTN_getEditorForm_test extends PHPUnit_Framework_TestCase
18 public function setUp()
20 global $cfg;
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;
63 PMA_RTN_setGlobals();
64 $this->assertEquals('', PMA_RTN_getParameterRow(array(), 0));
67 /**
68 * @depends testgetParameterRow_empty
69 * @dataProvider provider_row
71 public function testgetParameterRow($data, $index, $matcher)
73 $GLOBALS['is_ajax_request'] = false;
74 PMA_RTN_setGlobals();
75 $this->assertTag($matcher, PMA_RTN_getParameterRow($data, $index), false);
78 public function provider_row()
80 $data = array(
81 'item_name' => '',
82 'item_original_name' => '',
83 'item_returnlength' => '',
84 'item_returnopts_num' => '',
85 'item_returnopts_text' => '',
86 'item_definition' => '',
87 'item_comment' => '',
88 'item_definer' => '',
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' => ''
106 return array(
107 array(
108 $data,
110 array(
111 'tag' => 'select',
112 'attributes' => array(
113 'name' => 'item_param_dir[0]'
117 array(
118 $data,
120 array(
121 'tag' => 'input',
122 'attributes' => array(
123 'name' => 'item_param_name[0]'
127 array(
128 $data,
130 array(
131 'tag' => 'select',
132 'attributes' => array(
133 'name' => 'item_param_type[0]'
137 array(
138 $data,
140 array(
141 'tag' => 'input',
142 'attributes' => array(
143 'name' => 'item_param_length[0]'
147 array(
148 $data,
150 array(
151 'tag' => 'select',
152 'attributes' => array(
153 'name' => 'item_param_opts_num[0]'
157 array(
158 $data,
160 array(
161 'tag' => 'a',
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()
183 $data = array(
184 'item_name' => '',
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' => ''
209 return array(
210 array(
211 $data,
212 array(
213 'tag' => 'select',
214 'attributes' => array(
215 'name' => 'item_param_dir[%s]'
219 array(
220 $data,
221 array(
222 'tag' => 'input',
223 'attributes' => array(
224 'name' => 'item_param_name[%s]'
228 array(
229 $data,
230 array(
231 'tag' => 'select',
232 'attributes' => array(
233 'name' => 'item_param_type[%s]'
237 array(
238 $data,
239 array(
240 'tag' => 'input',
241 'attributes' => array(
242 'name' => 'item_param_length[%s]'
246 array(
247 $data,
248 array(
249 'tag' => 'select',
250 'attributes' => array(
251 'name' => 'item_param_opts_num[%s]'
255 array(
256 $data,
257 array(
258 'tag' => 'a',
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()
280 $data = array(
281 'item_name' => '',
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' => ''
306 return array(
307 array(
308 $data,
309 array(
310 'tag' => 'input',
311 'attributes' => array(
312 'name' => 'add_item'
316 array(
317 $data,
318 array(
319 'tag' => 'input',
320 'attributes' => array(
321 'name' => 'item_name'
325 array(
326 $data,
327 array(
328 'tag' => 'input',
329 'attributes' => array(
330 'name' => 'item_type'
334 array(
335 $data,
336 array(
337 'tag' => 'input',
338 'attributes' => array(
339 'name' => 'routine_changetype'
345 array(
346 $data,
347 array(
348 'tag' => 'input',
349 'attributes' => array(
350 'name' => 'routine_addparameter'
354 array(
355 $data,
356 array(
357 'tag' => 'input',
358 'attributes' => array(
359 'name' => 'routine_removeparameter'
363 array(
364 $data,
365 array(
366 'tag' => 'select',
367 'attributes' => array(
368 'name' => 'item_returntype'
372 array(
373 $data,
374 array(
375 'tag' => 'input',
376 'attributes' => array(
377 'name' => 'item_returnlength'
381 array(
382 $data,
383 array(
384 'tag' => 'select',
385 'attributes' => array(
386 'name' => 'item_returnopts_num'
390 array(
391 $data,
392 array(
393 'tag' => 'textarea',
394 'attributes' => array(
395 'name' => 'item_definition'
399 array(
400 $data,
401 array(
402 'tag' => 'input',
403 'attributes' => array(
404 'name' => 'item_isdeterministic'
408 array(
409 $data,
410 array(
411 'tag' => 'input',
412 'attributes' => array(
413 'name' => 'item_definer'
417 array(
418 $data,
419 array(
420 'tag' => 'select',
421 'attributes' => array(
422 'name' => 'item_securitytype'
426 array(
427 $data,
428 array(
429 'tag' => 'select',
430 'attributes' => array(
431 'name' => 'item_sqldataaccess'
435 array(
436 $data,
437 array(
438 'tag' => 'input',
439 'attributes' => array(
440 'name' => 'item_comment'
444 array(
445 $data,
446 array(
447 'tag' => 'input',
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()
470 $data = array(
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'
496 return array(
497 array(
498 $data,
499 array(
500 'tag' => 'input',
501 'attributes' => array(
502 'name' => 'edit_item'
506 array(
507 $data,
508 array(
509 'tag' => 'input',
510 'attributes' => array(
511 'name' => 'item_name'
515 array(
516 $data,
517 array(
518 'tag' => 'input',
519 'attributes' => array(
520 'name' => 'item_type',
521 'value' => 'FUNCTION'
525 array(
526 $data,
527 array(
528 'tag' => 'input',
529 'attributes' => array(
530 'name' => 'routine_changetype'
536 array(
537 $data,
538 array(
539 'tag' => 'input',
540 'attributes' => array(
541 'name' => 'routine_addparameter'
545 array(
546 $data,
547 array(
548 'tag' => 'input',
549 'attributes' => array(
550 'name' => 'routine_removeparameter'
554 array(
555 $data,
556 array(
557 'tag' => 'select',
558 'attributes' => array(
559 'name' => 'item_returntype'
563 array(
564 $data,
565 array(
566 'tag' => 'input',
567 'attributes' => array(
568 'name' => 'item_returnlength'
572 array(
573 $data,
574 array(
575 'tag' => 'select',
576 'attributes' => array(
577 'name' => 'item_returnopts_num'
581 array(
582 $data,
583 array(
584 'tag' => 'textarea',
585 'attributes' => array(
586 'name' => 'item_definition'
590 array(
591 $data,
592 array(
593 'tag' => 'input',
594 'attributes' => array(
595 'name' => 'item_isdeterministic'
599 array(
600 $data,
601 array(
602 'tag' => 'input',
603 'attributes' => array(
604 'name' => 'item_definer'
608 array(
609 $data,
610 array(
611 'tag' => 'select',
612 'attributes' => array(
613 'name' => 'item_securitytype'
617 array(
618 $data,
619 array(
620 'tag' => 'select',
621 'attributes' => array(
622 'name' => 'item_sqldataaccess'
626 array(
627 $data,
628 array(
629 'tag' => 'input',
630 'attributes' => array(
631 'name' => 'item_comment'
635 array(
636 $data,
637 array(
638 'tag' => 'input',
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()
661 $data = array(
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'
687 return array(
688 array(
689 $data,
690 array(
691 'tag' => 'input',
692 'attributes' => array(
693 'name' => 'edit_item'
697 array(
698 $data,
699 array(
700 'tag' => 'input',
701 'attributes' => array(
702 'name' => 'item_name'
706 array(
707 $data,
708 array(
709 'tag' => 'select',
710 'attributes' => array(
711 'name' => 'item_type'
715 array(
716 $data,
717 array(
718 'tag' => 'input',
719 'attributes' => array(
720 'name' => 'routine_addparameter'
724 array(
725 $data,
726 array(
727 'tag' => 'input',
728 'attributes' => array(
729 'name' => 'routine_removeparameter'
733 array(
734 $data,
735 array(
736 'tag' => 'select',
737 'attributes' => array(
738 'name' => 'item_returntype'
742 array(
743 $data,
744 array(
745 'tag' => 'input',
746 'attributes' => array(
747 'name' => 'item_returnlength'
751 array(
752 $data,
753 array(
754 'tag' => 'select',
755 'attributes' => array(
756 'name' => 'item_returnopts_num'
760 array(
761 $data,
762 array(
763 'tag' => 'textarea',
764 'attributes' => array(
765 'name' => 'item_definition'
769 array(
770 $data,
771 array(
772 'tag' => 'input',
773 'attributes' => array(
774 'name' => 'item_isdeterministic'
778 array(
779 $data,
780 array(
781 'tag' => 'input',
782 'attributes' => array(
783 'name' => 'item_definer'
787 array(
788 $data,
789 array(
790 'tag' => 'select',
791 'attributes' => array(
792 'name' => 'item_securitytype'
796 array(
797 $data,
798 array(
799 'tag' => 'select',
800 'attributes' => array(
801 'name' => 'item_sqldataaccess'
805 array(
806 $data,
807 array(
808 'tag' => 'input',
809 'attributes' => array(
810 'name' => 'item_comment'
814 array(
815 $data,
816 array(
817 'tag' => 'input',
818 'attributes' => array(
819 'name' => 'ajax_request'
823 array(
824 $data,
825 array(
826 'tag' => 'input',
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()
849 $data = array(
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'
875 return array(
876 array(
877 $data,
878 array(
879 'tag' => 'input',
880 'attributes' => array(
881 'name' => 'item_type',
882 'value' => 'PROCEDURE'