2 /* vim: set expandtab sw=4 ts=4 sts=4: */
4 * Test for generating CREATE EVENT query from HTTP request
6 * @package phpMyAdmin-test
10 * Needed for PMA_backquote()
12 require_once 'libraries/common.lib.php';
15 * Needed by PMA_EVN_getQueryFromRequest()
17 require_once 'libraries/php-gettext/gettext.inc';
22 require_once 'libraries/rte/rte_events.lib.php';
25 class PMA_EVN_getQueryFromRequest_test
extends PHPUnit_Framework_TestCase
28 * @dataProvider provider
30 public function testgetQueryFromRequest($request, $query, $num_err)
32 global $_REQUEST, $errors;
40 $this->assertEquals($query, PMA_EVN_getQueryFromRequest());
41 $this->assertEquals($num_err, count($errors));
44 public function provider()
49 array( // simple once-off event
50 'item_name' => 's o m e e v e n t\\',
51 'item_type' => 'ONE TIME',
52 'item_execute_at' => '2050-01-01 00:00:00',
53 'item_definition' => 'SET @A=0;'
55 'CREATE EVENT `s o m e e v e n t\` ON SCHEDULE AT \'2050-01-01 00:00:00\' ON COMPLETION NOT PRESERVE DO SET @A=0;',
59 array( // full once-off event
61 'item_definer' => 'me@home',
62 'item_type' => 'ONE TIME',
63 'item_execute_at' => '2050-01-01 00:00:00',
64 'item_preserve' => 'ON',
65 'item_status' => 'ENABLED',
66 'item_definition' => 'SET @A=0;'
68 'CREATE DEFINER=`me`@`home` EVENT `evn` ON SCHEDULE AT \'2050-01-01 00:00:00\' ON COMPLETION PRESERVE ENABLE DO SET @A=0;',
72 array( // simple recurring event
73 'item_name' => 'rec_``evn',
74 'item_type' => 'RECURRING',
75 'item_interval_value' => '365',
76 'item_interval_field' => 'DAY',
77 'item_status' => 'DISABLED',
78 'item_definition' => 'SET @A=0;'
80 'CREATE EVENT `rec_````evn` ON SCHEDULE EVERY 365 DAY ON COMPLETION NOT PRESERVE DISABLE DO SET @A=0;',
84 array( // full recurring event
85 'item_name' => 'rec_evn2',
86 'item_definer' => 'evil``user><\\@work\\',
87 'item_type' => 'RECURRING',
88 'item_interval_value' => '365',
89 'item_interval_field' => 'DAY',
90 'item_starts' => '1900-01-01',
91 'item_ends' => '2050-01-01',
92 'item_preserve' => 'ON',
93 'item_status' => 'SLAVESIDE_DISABLED',
94 'item_definition' => 'SET @A=0;'
96 'CREATE DEFINER=`evil````user><\`@`work\` EVENT `rec_evn2` ON SCHEDULE EVERY 365 DAY STARTS \'1900-01-01\' ENDS \'2050-01-01\' ON COMPLETION PRESERVE DISABLE ON SLAVE DO SET @A=0;',
101 array( // empty request
103 'CREATE EVENT ON SCHEDULE ON COMPLETION NOT PRESERVE DO ',
108 'item_name' => 's o m e e v e n t\\',
109 'item_definer' => 'someuser', // invalid definer format
110 'item_type' => 'ONE TIME',
111 'item_execute_at' => '', // no execution time
112 'item_definition' => 'SET @A=0;'
114 'CREATE EVENT `s o m e e v e n t\` ON SCHEDULE ON COMPLETION NOT PRESERVE DO SET @A=0;',
119 'item_name' => 'rec_``evn',
120 'item_type' => 'RECURRING',
121 'item_interval_value' => '', // no interval value
122 'item_interval_field' => 'DAY',
123 'item_status' => 'DISABLED',
124 'item_definition' => 'SET @A=0;'
126 'CREATE EVENT `rec_````evn` ON SCHEDULE ON COMPLETION NOT PRESERVE DISABLE DO SET @A=0;',
130 array( // simple recurring event
131 'item_name' => 'rec_``evn',
132 'item_type' => 'RECURRING',
133 'item_interval_value' => '365',
134 'item_interval_field' => 'CENTURIES', // invalid interval field
135 'item_status' => 'DISABLED',
136 'item_definition' => 'SET @A=0;'
138 'CREATE EVENT `rec_````evn` ON SCHEDULE ON COMPLETION NOT PRESERVE DISABLE DO SET @A=0;',