Translation update done using Pootle.
[phpmyadmin/ammaryasirr.git] / test / libraries / rte / PMA_RTN_ParameterParser_test.php
blobfa80f8b49040bc1a79a61e00dfd7698ca50c2bd0
1 <?php
2 /* vim: set expandtab sw=4 ts=4 sts=4: */
3 /**
4 * Test for parsing of Routine parameters
6 * @package phpMyAdmin-test
7 */
9 /*
10 * Needed for PMA_unQuote() and PMA_SQP_parse()
12 require_once 'libraries/common.lib.php';
13 require_once 'libraries/sqlparser.lib.php';
16 * Include to test.
18 require_once 'libraries/rte/rte_routines.lib.php';
21 class PMA_RTN_parameterParser_test extends PHPUnit_Framework_TestCase
23 /**
24 * @dataProvider definer_provider
26 public function test_parseDefiner($source, $target)
28 PMA_RTN_setGlobals();
29 $this->assertEquals($target, PMA_RTN_parseRoutineDefiner(PMA_SQP_parse($source)));
32 public function definer_provider()
34 return array(
35 array('CREATE PROCEDURE FOO() SELECT NULL', ''),
36 array('CREATE DEFINER=`root`@`localhost` PROCEDURE FOO() SELECT NULL', 'root@localhost'),
37 array('CREATE DEFINER=`root\\`@`localhost` PROCEDURE FOO() SELECT NULL', 'root\\@localhost'),
41 /**
42 * @dataProvider param_provider
44 public function test_parseOneParameter($source, $target)
46 PMA_RTN_setGlobals();
47 $this->assertEquals($target, PMA_RTN_parseOneParameter($source));
50 public function param_provider()
52 return array(
53 array('`foo` TEXT', array('', 'foo', 'TEXT', '', '')),
54 array('`foo` INT(20)', array('', 'foo', 'INT', '20', '')),
55 array('DECIMAL(5,5)', array('', '', 'DECIMAL', '5,5', '')),
56 array('IN `fo``fo` INT UNSIGNED', array('IN', 'fo`fo', 'INT', '', 'UNSIGNED')),
57 array('OUT bar VARCHAR(1) CHARSET utf8', array('OUT', 'bar', 'VARCHAR', '1', 'utf8')),
58 array('`"baz\'\'` ENUM(\'a\', \'b\') CHARSET latin1', array('', '"baz\'\'', 'ENUM', '\'a\',\'b\'', 'latin1')),
59 array('INOUT `foo` DECIMAL(5,2) UNSIGNED ZEROFILL', array('INOUT', 'foo', 'DECIMAL', '5,2', 'UNSIGNED ZEROFILL')),
60 array('`foo``s func` SET(\'test\'\'esc"\', \'more\\\'esc\')', array('', 'foo`s func', 'SET', '\'test\'\'esc"\',\'more\\\'esc\'', ''))
64 /**
65 * @depends test_parseOneParameter
66 * @dataProvider query_provider
68 public function test_parseAllParameters($query, $type, $target)
70 PMA_RTN_setGlobals();
71 $this->assertEquals($target, PMA_RTN_parseAllParameters(PMA_SQP_parse($query), $type));
74 public function query_provider()
76 return array(
77 array(
78 'CREATE PROCEDURE `foo`() SET @A=0',
79 'PROCEDURE',
80 array(
81 'num' => 0,
82 'dir' => array(),
83 'name' => array(),
84 'type' => array(),
85 'length' => array(),
86 'opts' => array()
89 array(
90 'CREATE DEFINER=`user\\`@`somehost``(` FUNCTION `foo```(`baz` INT) BEGIN SELECT NULL; END',
91 'FUNCTION',
92 array(
93 'num' => 1,
94 'dir' => array(
95 0 => ''
97 'name' => array(
98 0 => 'baz'
100 'type' => array(
101 0 => 'INT'
103 'length' => array(
104 0 => ''
106 'opts' => array(
107 0 => ''
111 array(
112 'CREATE PROCEDURE `foo`(IN `baz\\)` INT(25) zerofill unsigned) BEGIN SELECT NULL; END',
113 'PROCEDURE',
114 array(
115 'num' => 1,
116 'dir' => array(
117 0 => 'IN'
119 'name' => array(
120 0 => 'baz\\)'
122 'type' => array(
123 0 => 'INT'
125 'length' => array(
126 0 => '25'
128 'opts' => array(
129 0 => 'UNSIGNED ZEROFILL'
133 array(
134 'CREATE PROCEDURE `foo`(IN `baz\\` INT(001) zerofill, out bazz varchar(15) charset UTF8) BEGIN SELECT NULL; END',
135 'PROCEDURE',
136 array(
137 'num' => 2,
138 'dir' => array(
139 0 => 'IN',
140 1 => 'OUT'
142 'name' => array(
143 0 => 'baz\\',
144 1 => 'bazz'
146 'type' => array(
147 0 => 'INT',
148 1 => 'VARCHAR'
150 'length' => array(
151 0 => '1',
152 1 => '15'
154 'opts' => array(
155 0 => 'ZEROFILL',
156 1 => 'utf8'