Added unit tests for Routines, Triggers and Events
This commit is contained in:
parent
60fdffbafa
commit
8489f415c9
@ -35,6 +35,7 @@
|
||||
<file>test/Environment_test.php</file>
|
||||
<directory suffix="_test.php">test/libraries/core</directory>
|
||||
<directory suffix="_test.php">test/libraries/common</directory>
|
||||
<directory suffix="_test.php">test/libraries/rte</directory>
|
||||
<directory suffix="_test.php">test/libraries</directory>
|
||||
</testsuite>
|
||||
<!--<testsuite name="Selenium">-->
|
||||
|
||||
104
test/libraries/rte/PMA_EVN_getDataFromRequest_test.php
Normal file
104
test/libraries/rte/PMA_EVN_getDataFromRequest_test.php
Normal file
@ -0,0 +1,104 @@
|
||||
<?php
|
||||
/* vim: set expandtab sw=4 ts=4 sts=4: */
|
||||
/**
|
||||
* Test for fetching event data from HTTP request
|
||||
*
|
||||
* @package phpMyAdmin-test
|
||||
*/
|
||||
|
||||
/*
|
||||
* Include to test.
|
||||
*/
|
||||
require_once 'libraries/rte/rte_events.lib.php';
|
||||
|
||||
class PMA_EVN_getDataFromRequest_test extends PHPUnit_Framework_TestCase
|
||||
{
|
||||
/**
|
||||
* @dataProvider provider
|
||||
*/
|
||||
public function testgetDataFromRequest_empty($in, $out)
|
||||
{
|
||||
global $_REQUEST;
|
||||
|
||||
unset($_REQUEST);
|
||||
foreach ($in as $key => $value) {
|
||||
if ($value !== '') {
|
||||
$_REQUEST[$key] = $value;
|
||||
}
|
||||
}
|
||||
$this->assertEquals($out, PMA_EVN_getDataFromRequest());
|
||||
}
|
||||
|
||||
public function provider()
|
||||
{
|
||||
return array(
|
||||
array(
|
||||
array(
|
||||
'item_name' => '',
|
||||
'item_type' => '',
|
||||
'item_original_name' => '',
|
||||
'item_status' => '',
|
||||
'item_execute_at' => '',
|
||||
'item_interval_value' => '',
|
||||
'item_interval_field' => '',
|
||||
'item_starts' => '',
|
||||
'item_ends' => '',
|
||||
'item_definition' => '',
|
||||
'item_preserve' => '',
|
||||
'item_comment' => '',
|
||||
'item_definer' => ''
|
||||
),
|
||||
array(
|
||||
'item_name' => '',
|
||||
'item_type' => 'ONE TIME',
|
||||
'item_type_toggle' => 'RECURRING',
|
||||
'item_original_name' => '',
|
||||
'item_status' => '',
|
||||
'item_execute_at' => '',
|
||||
'item_interval_value' => '',
|
||||
'item_interval_field' => '',
|
||||
'item_starts' => '',
|
||||
'item_ends' => '',
|
||||
'item_definition' => '',
|
||||
'item_preserve' => '',
|
||||
'item_comment' => '',
|
||||
'item_definer' => ''
|
||||
)
|
||||
),
|
||||
array(
|
||||
array(
|
||||
'item_name' => 'foo',
|
||||
'item_type' => 'RECURRING',
|
||||
'item_original_name' => 'foo',
|
||||
'item_status' => 'foo',
|
||||
'item_execute_at' => 'foo',
|
||||
'item_interval_value' => 'foo',
|
||||
'item_interval_field' => 'foo',
|
||||
'item_starts' => 'foo',
|
||||
'item_ends' => 'foo',
|
||||
'item_definition' => 'foo',
|
||||
'item_preserve' => 'foo',
|
||||
'item_comment' => 'foo',
|
||||
'item_definer' => 'foo'
|
||||
),
|
||||
array(
|
||||
'item_name' => 'foo',
|
||||
'item_type' => 'RECURRING',
|
||||
'item_type_toggle' => 'ONE TIME',
|
||||
'item_original_name' => 'foo',
|
||||
'item_status' => 'foo',
|
||||
'item_execute_at' => 'foo',
|
||||
'item_interval_value' => 'foo',
|
||||
'item_interval_field' => 'foo',
|
||||
'item_starts' => 'foo',
|
||||
'item_ends' => 'foo',
|
||||
'item_definition' => 'foo',
|
||||
'item_preserve' => 'foo',
|
||||
'item_comment' => 'foo',
|
||||
'item_definer' => 'foo'
|
||||
)
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
?>
|
||||
445
test/libraries/rte/PMA_EVN_getEditorForm_test.php
Normal file
445
test/libraries/rte/PMA_EVN_getEditorForm_test.php
Normal file
@ -0,0 +1,445 @@
|
||||
<?php
|
||||
/* vim: set expandtab sw=4 ts=4 sts=4: */
|
||||
/**
|
||||
* Test for generating event editor
|
||||
*
|
||||
* @package phpMyAdmin-test
|
||||
*/
|
||||
require_once 'libraries/php-gettext/gettext.inc';
|
||||
require_once 'libraries/url_generating.lib.php';
|
||||
require_once 'libraries/common.lib.php';
|
||||
/*
|
||||
* Include to test.
|
||||
*/
|
||||
require_once 'libraries/rte/rte_events.lib.php';
|
||||
|
||||
class PMA_EVN_getEditorForm_test extends PHPUnit_Framework_TestCase
|
||||
{
|
||||
public function setUp()
|
||||
{
|
||||
if (! function_exists('PMA_DBI_get_tables')) {
|
||||
function PMA_DBI_get_tables($db)
|
||||
{
|
||||
return array('table1', 'table`2');
|
||||
}
|
||||
}
|
||||
$GLOBALS['tear_down']['token'] = false;
|
||||
$GLOBALS['tear_down']['server'] = false;
|
||||
if (! isset($_SESSION[' PMA_token '])) {
|
||||
$_SESSION[' PMA_token '] = '';
|
||||
$GLOBALS['tear_down']['token'] = true;
|
||||
}
|
||||
if (! isset($GLOBALS['cfg']['ServerDefault'])) {
|
||||
$GLOBALS['cfg']['ServerDefault'] = '';
|
||||
$GLOBALS['tear_down']['server'] = true;
|
||||
}
|
||||
}
|
||||
|
||||
public function tearDown()
|
||||
{
|
||||
if ($GLOBALS['tear_down']['token']) {
|
||||
unset($_SESSION[' PMA_token ']);
|
||||
}
|
||||
if ($GLOBALS['tear_down']['server']) {
|
||||
unset($GLOBALS['cfg']['ServerDefault']);
|
||||
}
|
||||
unset($GLOBALS['tear_down']);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider provider_add
|
||||
*/
|
||||
public function testgetEditorForm_add($data, $matcher)
|
||||
{
|
||||
$GLOBALS['is_ajax_request'] = false;
|
||||
PMA_EVN_setGlobals();
|
||||
$this->assertTag($matcher, PMA_EVN_getEditorForm('add', 'change', $data), '', false);
|
||||
}
|
||||
|
||||
public function provider_add()
|
||||
{
|
||||
$data = array(
|
||||
'item_name' => '',
|
||||
'item_type' => 'ONE TIME',
|
||||
'item_type_toggle' => 'RECURRING',
|
||||
'item_original_name' => '',
|
||||
'item_status' => '',
|
||||
'item_execute_at' => '',
|
||||
'item_interval_value' => '',
|
||||
'item_interval_field' => '',
|
||||
'item_starts' => '',
|
||||
'item_ends' => '',
|
||||
'item_definition' => '',
|
||||
'item_preserve' => '',
|
||||
'item_comment' => '',
|
||||
'item_definer' => ''
|
||||
);
|
||||
|
||||
return array(
|
||||
array(
|
||||
$data,
|
||||
array(
|
||||
'tag' => 'input',
|
||||
'attributes' => array(
|
||||
'name' => 'add_item'
|
||||
)
|
||||
)
|
||||
),
|
||||
array(
|
||||
$data,
|
||||
array(
|
||||
'tag' => 'input',
|
||||
'attributes' => array(
|
||||
'name' => 'item_name'
|
||||
)
|
||||
)
|
||||
),
|
||||
array(
|
||||
$data,
|
||||
array(
|
||||
'tag' => 'select',
|
||||
'attributes' => array(
|
||||
'name' => 'item_status'
|
||||
)
|
||||
)
|
||||
),
|
||||
array(
|
||||
$data,
|
||||
array(
|
||||
'tag' => 'input',
|
||||
'attributes' => array(
|
||||
'name' => 'item_type'
|
||||
)
|
||||
)
|
||||
),
|
||||
array(
|
||||
$data,
|
||||
array(
|
||||
'tag' => 'input',
|
||||
'attributes' => array(
|
||||
'name' => 'item_changetype'
|
||||
)
|
||||
)
|
||||
),
|
||||
array(
|
||||
$data,
|
||||
array(
|
||||
'tag' => 'input',
|
||||
'attributes' => array(
|
||||
'name' => 'item_execute_at'
|
||||
)
|
||||
)
|
||||
),
|
||||
array(
|
||||
$data,
|
||||
array(
|
||||
'tag' => 'input',
|
||||
'attributes' => array(
|
||||
'name' => 'item_interval_value'
|
||||
)
|
||||
)
|
||||
),
|
||||
array(
|
||||
$data,
|
||||
array(
|
||||
'tag' => 'select',
|
||||
'attributes' => array(
|
||||
'name' => 'item_interval_field'
|
||||
)
|
||||
)
|
||||
),
|
||||
array(
|
||||
$data,
|
||||
array(
|
||||
'tag' => 'input',
|
||||
'attributes' => array(
|
||||
'name' => 'item_starts'
|
||||
)
|
||||
)
|
||||
),
|
||||
array(
|
||||
$data,
|
||||
array(
|
||||
'tag' => 'input',
|
||||
'attributes' => array(
|
||||
'name' => 'item_ends'
|
||||
)
|
||||
)
|
||||
),
|
||||
array(
|
||||
$data,
|
||||
array(
|
||||
'tag' => 'textarea',
|
||||
'attributes' => array(
|
||||
'name' => 'item_definition'
|
||||
)
|
||||
)
|
||||
),
|
||||
array(
|
||||
$data,
|
||||
array(
|
||||
'tag' => 'input',
|
||||
'attributes' => array(
|
||||
'name' => 'item_preserve'
|
||||
)
|
||||
)
|
||||
),
|
||||
array(
|
||||
$data,
|
||||
array(
|
||||
'tag' => 'input',
|
||||
'attributes' => array(
|
||||
'name' => 'item_definer'
|
||||
)
|
||||
)
|
||||
),
|
||||
array(
|
||||
$data,
|
||||
array(
|
||||
'tag' => 'input',
|
||||
'attributes' => array(
|
||||
'name' => 'item_comment'
|
||||
)
|
||||
)
|
||||
),
|
||||
array(
|
||||
$data,
|
||||
array(
|
||||
'tag' => 'input',
|
||||
'attributes' => array(
|
||||
'name' => 'editor_process_add'
|
||||
)
|
||||
)
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider provider_edit
|
||||
*/
|
||||
public function testgetEditorForm_edit($data, $matcher)
|
||||
{
|
||||
$GLOBALS['is_ajax_request'] = false;
|
||||
PMA_EVN_setGlobals();
|
||||
$this->assertTag($matcher, PMA_EVN_getEditorForm('edit', 'change', $data), '', false);
|
||||
}
|
||||
|
||||
public function provider_edit()
|
||||
{
|
||||
$data = array(
|
||||
'item_name' => 'foo',
|
||||
'item_type' => 'RECURRING',
|
||||
'item_type_toggle' => 'ONE TIME',
|
||||
'item_original_name' => 'bar',
|
||||
'item_status' => 'ENABLED',
|
||||
'item_execute_at' => '',
|
||||
'item_interval_value' => '1',
|
||||
'item_interval_field' => 'DAY',
|
||||
'item_starts' => '',
|
||||
'item_ends' => '',
|
||||
'item_definition' => 'SET @A=1;',
|
||||
'item_preserve' => '',
|
||||
'item_comment' => '',
|
||||
'item_definer' => ''
|
||||
);
|
||||
|
||||
return array(
|
||||
array(
|
||||
$data,
|
||||
array(
|
||||
'tag' => 'input',
|
||||
'attributes' => array(
|
||||
'name' => 'edit_item'
|
||||
)
|
||||
)
|
||||
),
|
||||
array(
|
||||
$data,
|
||||
array(
|
||||
'tag' => 'input',
|
||||
'attributes' => array(
|
||||
'name' => 'item_name'
|
||||
)
|
||||
)
|
||||
),
|
||||
array(
|
||||
$data,
|
||||
array(
|
||||
'tag' => 'select',
|
||||
'attributes' => array(
|
||||
'name' => 'item_status'
|
||||
)
|
||||
)
|
||||
),
|
||||
array(
|
||||
$data,
|
||||
array(
|
||||
'tag' => 'input',
|
||||
'attributes' => array(
|
||||
'name' => 'item_type'
|
||||
)
|
||||
)
|
||||
),
|
||||
array(
|
||||
$data,
|
||||
array(
|
||||
'tag' => 'input',
|
||||
'attributes' => array(
|
||||
'name' => 'item_changetype'
|
||||
)
|
||||
)
|
||||
),
|
||||
array(
|
||||
$data,
|
||||
array(
|
||||
'tag' => 'input',
|
||||
'attributes' => array(
|
||||
'name' => 'item_execute_at'
|
||||
)
|
||||
)
|
||||
),
|
||||
array(
|
||||
$data,
|
||||
array(
|
||||
'tag' => 'input',
|
||||
'attributes' => array(
|
||||
'name' => 'item_interval_value'
|
||||
)
|
||||
)
|
||||
),
|
||||
array(
|
||||
$data,
|
||||
array(
|
||||
'tag' => 'select',
|
||||
'attributes' => array(
|
||||
'name' => 'item_interval_field'
|
||||
)
|
||||
)
|
||||
),
|
||||
array(
|
||||
$data,
|
||||
array(
|
||||
'tag' => 'input',
|
||||
'attributes' => array(
|
||||
'name' => 'item_starts'
|
||||
)
|
||||
)
|
||||
),
|
||||
array(
|
||||
$data,
|
||||
array(
|
||||
'tag' => 'input',
|
||||
'attributes' => array(
|
||||
'name' => 'item_ends'
|
||||
)
|
||||
)
|
||||
),
|
||||
array(
|
||||
$data,
|
||||
array(
|
||||
'tag' => 'textarea',
|
||||
'attributes' => array(
|
||||
'name' => 'item_definition'
|
||||
)
|
||||
)
|
||||
),
|
||||
array(
|
||||
$data,
|
||||
array(
|
||||
'tag' => 'input',
|
||||
'attributes' => array(
|
||||
'name' => 'item_preserve'
|
||||
)
|
||||
)
|
||||
),
|
||||
array(
|
||||
$data,
|
||||
array(
|
||||
'tag' => 'input',
|
||||
'attributes' => array(
|
||||
'name' => 'item_definer'
|
||||
)
|
||||
)
|
||||
),
|
||||
array(
|
||||
$data,
|
||||
array(
|
||||
'tag' => 'input',
|
||||
'attributes' => array(
|
||||
'name' => 'item_comment'
|
||||
)
|
||||
)
|
||||
),
|
||||
array(
|
||||
$data,
|
||||
array(
|
||||
'tag' => 'input',
|
||||
'attributes' => array(
|
||||
'name' => 'editor_process_edit'
|
||||
)
|
||||
)
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider provider_ajax
|
||||
*/
|
||||
public function testgetEditorForm_ajax($data, $matcher)
|
||||
{
|
||||
$GLOBALS['is_ajax_request'] = true;
|
||||
PMA_EVN_setGlobals();
|
||||
$this->assertTag($matcher, PMA_EVN_getEditorForm('edit', 'change', $data), '', false);
|
||||
}
|
||||
|
||||
public function provider_ajax()
|
||||
{
|
||||
$data = array(
|
||||
'item_name' => '',
|
||||
'item_type' => 'RECURRING',
|
||||
'item_type_toggle' => 'ONE TIME',
|
||||
'item_original_name' => '',
|
||||
'item_status' => 'ENABLED',
|
||||
'item_execute_at' => '',
|
||||
'item_interval_value' => '',
|
||||
'item_interval_field' => 'DAY',
|
||||
'item_starts' => '',
|
||||
'item_ends' => '',
|
||||
'item_definition' => '',
|
||||
'item_preserve' => '',
|
||||
'item_comment' => '',
|
||||
'item_definer' => ''
|
||||
);
|
||||
|
||||
return array(
|
||||
array(
|
||||
$data,
|
||||
array(
|
||||
'tag' => 'select',
|
||||
'attributes' => array(
|
||||
'name' => 'item_type'
|
||||
)
|
||||
)
|
||||
),
|
||||
array(
|
||||
$data,
|
||||
array(
|
||||
'tag' => 'input',
|
||||
'attributes' => array(
|
||||
'name' => 'editor_process_edit'
|
||||
)
|
||||
)
|
||||
),
|
||||
array(
|
||||
$data,
|
||||
array(
|
||||
'tag' => 'input',
|
||||
'attributes' => array(
|
||||
'name' => 'ajax_request'
|
||||
)
|
||||
)
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
?>
|
||||
144
test/libraries/rte/PMA_EVN_getQueryFromRequest_test.php
Normal file
144
test/libraries/rte/PMA_EVN_getQueryFromRequest_test.php
Normal file
@ -0,0 +1,144 @@
|
||||
<?php
|
||||
/* vim: set expandtab sw=4 ts=4 sts=4: */
|
||||
/**
|
||||
* Test for generating CREATE EVENT query from HTTP request
|
||||
*
|
||||
* @package phpMyAdmin-test
|
||||
*/
|
||||
|
||||
/*
|
||||
* Needed for PMA_backquote()
|
||||
*/
|
||||
require_once 'libraries/common.lib.php';
|
||||
|
||||
/*
|
||||
* Needed by PMA_EVN_getQueryFromRequest()
|
||||
*/
|
||||
require_once 'libraries/php-gettext/gettext.inc';
|
||||
|
||||
/*
|
||||
* Include to test.
|
||||
*/
|
||||
require_once 'libraries/rte/rte_events.lib.php';
|
||||
|
||||
|
||||
class PMA_EVN_getQueryFromRequest_test extends PHPUnit_Framework_TestCase
|
||||
{
|
||||
/**
|
||||
* @dataProvider provider
|
||||
*/
|
||||
public function testgetQueryFromRequest($request, $query, $num_err)
|
||||
{
|
||||
global $_REQUEST, $errors;
|
||||
|
||||
$errors = array();
|
||||
PMA_EVN_setGlobals();
|
||||
|
||||
unset($_REQUEST);
|
||||
$_REQUEST = $request;
|
||||
|
||||
$this->assertEquals($query, PMA_EVN_getQueryFromRequest());
|
||||
$this->assertEquals($num_err, count($errors));
|
||||
}
|
||||
|
||||
public function provider()
|
||||
{
|
||||
return array(
|
||||
// Testing success
|
||||
array(
|
||||
array( // simple once-off event
|
||||
'item_name' => 's o m e e v e n t\\',
|
||||
'item_type' => 'ONE TIME',
|
||||
'item_execute_at' => '2050-01-01 00:00:00',
|
||||
'item_definition' => 'SET @A=0;'
|
||||
),
|
||||
'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;',
|
||||
0
|
||||
),
|
||||
array(
|
||||
array( // full once-off event
|
||||
'item_name' => 'evn',
|
||||
'item_definer' => 'me@home',
|
||||
'item_type' => 'ONE TIME',
|
||||
'item_execute_at' => '2050-01-01 00:00:00',
|
||||
'item_preserve' => 'ON',
|
||||
'item_status' => 'ENABLED',
|
||||
'item_definition' => 'SET @A=0;'
|
||||
),
|
||||
'CREATE DEFINER=`me`@`home` EVENT `evn` ON SCHEDULE AT \'2050-01-01 00:00:00\' ON COMPLETION PRESERVE ENABLE DO SET @A=0;',
|
||||
0
|
||||
),
|
||||
array(
|
||||
array( // simple recurring event
|
||||
'item_name' => 'rec_``evn',
|
||||
'item_type' => 'RECURRING',
|
||||
'item_interval_value' => '365',
|
||||
'item_interval_field' => 'DAY',
|
||||
'item_status' => 'DISABLED',
|
||||
'item_definition' => 'SET @A=0;'
|
||||
),
|
||||
'CREATE EVENT `rec_````evn` ON SCHEDULE EVERY 365 DAY ON COMPLETION NOT PRESERVE DISABLE DO SET @A=0;',
|
||||
0
|
||||
),
|
||||
array(
|
||||
array( // full recurring event
|
||||
'item_name' => 'rec_evn2',
|
||||
'item_definer' => 'evil``user><\\@work\\',
|
||||
'item_type' => 'RECURRING',
|
||||
'item_interval_value' => '365',
|
||||
'item_interval_field' => 'DAY',
|
||||
'item_starts' => '1900-01-01',
|
||||
'item_ends' => '2050-01-01',
|
||||
'item_preserve' => 'ON',
|
||||
'item_status' => 'SLAVESIDE_DISABLED',
|
||||
'item_definition' => 'SET @A=0;'
|
||||
),
|
||||
'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;',
|
||||
0
|
||||
),
|
||||
// Testing failures
|
||||
array(
|
||||
array( // empty request
|
||||
),
|
||||
'CREATE EVENT ON SCHEDULE ON COMPLETION NOT PRESERVE DO ',
|
||||
3
|
||||
),
|
||||
array(
|
||||
array(
|
||||
'item_name' => 's o m e e v e n t\\',
|
||||
'item_definer' => 'someuser', // invalid definer format
|
||||
'item_type' => 'ONE TIME',
|
||||
'item_execute_at' => '', // no execution time
|
||||
'item_definition' => 'SET @A=0;'
|
||||
),
|
||||
'CREATE EVENT `s o m e e v e n t\` ON SCHEDULE ON COMPLETION NOT PRESERVE DO SET @A=0;',
|
||||
2
|
||||
),
|
||||
array(
|
||||
array(
|
||||
'item_name' => 'rec_``evn',
|
||||
'item_type' => 'RECURRING',
|
||||
'item_interval_value' => '', // no interval value
|
||||
'item_interval_field' => 'DAY',
|
||||
'item_status' => 'DISABLED',
|
||||
'item_definition' => 'SET @A=0;'
|
||||
),
|
||||
'CREATE EVENT `rec_````evn` ON SCHEDULE ON COMPLETION NOT PRESERVE DISABLE DO SET @A=0;',
|
||||
1
|
||||
),
|
||||
array(
|
||||
array( // simple recurring event
|
||||
'item_name' => 'rec_``evn',
|
||||
'item_type' => 'RECURRING',
|
||||
'item_interval_value' => '365',
|
||||
'item_interval_field' => 'CENTURIES', // invalid interval field
|
||||
'item_status' => 'DISABLED',
|
||||
'item_definition' => 'SET @A=0;'
|
||||
),
|
||||
'CREATE EVENT `rec_````evn` ON SCHEDULE ON COMPLETION NOT PRESERVE DISABLE DO SET @A=0;',
|
||||
1
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
?>
|
||||
163
test/libraries/rte/PMA_RTN_ParameterParser_test.php
Normal file
163
test/libraries/rte/PMA_RTN_ParameterParser_test.php
Normal file
@ -0,0 +1,163 @@
|
||||
<?php
|
||||
/* vim: set expandtab sw=4 ts=4 sts=4: */
|
||||
/**
|
||||
* Test for parsing of Routine parameters
|
||||
*
|
||||
* @package phpMyAdmin-test
|
||||
*/
|
||||
|
||||
/*
|
||||
* Needed for PMA_unQuote() and PMA_SQP_parse()
|
||||
*/
|
||||
require_once 'libraries/common.lib.php';
|
||||
require_once 'libraries/sqlparser.lib.php';
|
||||
|
||||
/*
|
||||
* Include to test.
|
||||
*/
|
||||
require_once 'libraries/rte/rte_routines.lib.php';
|
||||
|
||||
|
||||
class PMA_RTN_parameterParser_test extends PHPUnit_Framework_TestCase
|
||||
{
|
||||
/**
|
||||
* @dataProvider definer_provider
|
||||
*/
|
||||
public function test_parseDefiner($source, $target)
|
||||
{
|
||||
PMA_RTN_setGlobals();
|
||||
$this->assertEquals($target, PMA_RTN_parseRoutineDefiner(PMA_SQP_parse($source)));
|
||||
}
|
||||
|
||||
public function definer_provider()
|
||||
{
|
||||
return array(
|
||||
array('CREATE PROCEDURE FOO() SELECT NULL', ''),
|
||||
array('CREATE DEFINER=`root`@`localhost` PROCEDURE FOO() SELECT NULL', 'root@localhost'),
|
||||
array('CREATE DEFINER=`root\\`@`localhost` PROCEDURE FOO() SELECT NULL', 'root\\@localhost'),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider param_provider
|
||||
*/
|
||||
public function test_parseOneParameter($source, $target)
|
||||
{
|
||||
PMA_RTN_setGlobals();
|
||||
$this->assertEquals($target, PMA_RTN_parseOneParameter($source));
|
||||
}
|
||||
|
||||
public function param_provider()
|
||||
{
|
||||
return array(
|
||||
array('`foo` TEXT', array('', 'foo', 'TEXT', '', '')),
|
||||
array('`foo` INT(20)', array('', 'foo', 'INT', '20', '')),
|
||||
array('DECIMAL(5,5)', array('', '', 'DECIMAL', '5,5', '')),
|
||||
array('IN `fo``fo` INT UNSIGNED', array('IN', 'fo`fo', 'INT', '', 'UNSIGNED')),
|
||||
array('OUT bar VARCHAR(1) CHARSET utf8', array('OUT', 'bar', 'VARCHAR', '1', 'utf8')),
|
||||
array('`"baz\'\'` ENUM(\'a\', \'b\') CHARSET latin1', array('', '"baz\'\'', 'ENUM', '\'a\',\'b\'', 'latin1')),
|
||||
array('INOUT `foo` DECIMAL(5,2) UNSIGNED ZEROFILL', array('INOUT', 'foo', 'DECIMAL', '5,2', 'UNSIGNED ZEROFILL')),
|
||||
array('`foo``s func` SET(\'test\'\'esc"\', \'more\\\'esc\')', array('', 'foo`s func', 'SET', '\'test\'\'esc"\',\'more\\\'esc\'', ''))
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @depends test_parseOneParameter
|
||||
* @dataProvider query_provider
|
||||
*/
|
||||
public function test_parseAllParameters($query, $type, $target)
|
||||
{
|
||||
PMA_RTN_setGlobals();
|
||||
$this->assertEquals($target, PMA_RTN_parseAllParameters(PMA_SQP_parse($query), $type));
|
||||
}
|
||||
|
||||
public function query_provider()
|
||||
{
|
||||
return array(
|
||||
array(
|
||||
'CREATE PROCEDURE `foo`() SET @A=0',
|
||||
'PROCEDURE',
|
||||
array(
|
||||
'num' => 0,
|
||||
'dir' => array(),
|
||||
'name' => array(),
|
||||
'type' => array(),
|
||||
'length' => array(),
|
||||
'opts' => array()
|
||||
)
|
||||
),
|
||||
array(
|
||||
'CREATE DEFINER=`user\\`@`somehost``(` FUNCTION `foo```(`baz` INT) BEGIN SELECT NULL; END',
|
||||
'FUNCTION',
|
||||
array(
|
||||
'num' => 1,
|
||||
'dir' => array(
|
||||
0 => ''
|
||||
),
|
||||
'name' => array(
|
||||
0 => 'baz'
|
||||
),
|
||||
'type' => array(
|
||||
0 => 'INT'
|
||||
),
|
||||
'length' => array(
|
||||
0 => ''
|
||||
),
|
||||
'opts' => array(
|
||||
0 => ''
|
||||
)
|
||||
)
|
||||
),
|
||||
array(
|
||||
'CREATE PROCEDURE `foo`(IN `baz\\)` INT(25) zerofill unsigned) BEGIN SELECT NULL; END',
|
||||
'PROCEDURE',
|
||||
array(
|
||||
'num' => 1,
|
||||
'dir' => array(
|
||||
0 => 'IN'
|
||||
),
|
||||
'name' => array(
|
||||
0 => 'baz\\)'
|
||||
),
|
||||
'type' => array(
|
||||
0 => 'INT'
|
||||
),
|
||||
'length' => array(
|
||||
0 => '25'
|
||||
),
|
||||
'opts' => array(
|
||||
0 => 'UNSIGNED ZEROFILL'
|
||||
)
|
||||
)
|
||||
),
|
||||
array(
|
||||
'CREATE PROCEDURE `foo`(IN `baz\\` INT(001) zerofill, out bazz varchar(15) charset UTF8) BEGIN SELECT NULL; END',
|
||||
'PROCEDURE',
|
||||
array(
|
||||
'num' => 2,
|
||||
'dir' => array(
|
||||
0 => 'IN',
|
||||
1 => 'OUT'
|
||||
),
|
||||
'name' => array(
|
||||
0 => 'baz\\',
|
||||
1 => 'bazz'
|
||||
),
|
||||
'type' => array(
|
||||
0 => 'INT',
|
||||
1 => 'VARCHAR'
|
||||
),
|
||||
'length' => array(
|
||||
0 => '1',
|
||||
1 => '15'
|
||||
),
|
||||
'opts' => array(
|
||||
0 => 'ZEROFILL',
|
||||
1 => 'utf8'
|
||||
)
|
||||
)
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
?>
|
||||
197
test/libraries/rte/PMA_RTN_getDataFromRequest_test.php
Normal file
197
test/libraries/rte/PMA_RTN_getDataFromRequest_test.php
Normal file
@ -0,0 +1,197 @@
|
||||
<?php
|
||||
/* vim: set expandtab sw=4 ts=4 sts=4: */
|
||||
/**
|
||||
* Test for fetching routine data from HTTP request
|
||||
*
|
||||
* @package phpMyAdmin-test
|
||||
*/
|
||||
|
||||
require_once 'libraries/data_mysql.inc.php';
|
||||
require_once 'libraries/common.lib.php';
|
||||
|
||||
|
||||
/*
|
||||
* Include to test.
|
||||
*/
|
||||
require_once 'libraries/rte/rte_routines.lib.php';
|
||||
|
||||
class PMA_RTN_getDataFromRequest_test extends PHPUnit_Framework_TestCase
|
||||
{
|
||||
/**
|
||||
* @dataProvider provider
|
||||
*/
|
||||
public function testgetDataFromRequest($in, $out)
|
||||
{
|
||||
global $cfg, $_REQUEST;
|
||||
|
||||
if (! isset($cfg['ColumnTypes'])) {
|
||||
$this->markTestSkipped('Can\'t get column types'); // FIXME
|
||||
}
|
||||
|
||||
unset($_REQUEST);
|
||||
foreach ($in as $key => $value) {
|
||||
if ($value !== '') {
|
||||
$_REQUEST[$key] = $value;
|
||||
}
|
||||
}
|
||||
PMA_RTN_setGlobals();
|
||||
$this->assertEquals($out, PMA_RTN_getDataFromRequest());
|
||||
}
|
||||
|
||||
public function provider()
|
||||
{
|
||||
return array(
|
||||
array(
|
||||
array(
|
||||
'item_name' => '',
|
||||
'item_original_name' => '',
|
||||
'item_returnlength' => '',
|
||||
'item_returnopts_num' => '',
|
||||
'item_returnopts_text' => '',
|
||||
'item_definition' => '',
|
||||
'item_comment' => '',
|
||||
'item_definer' => '',
|
||||
'item_type' => '',
|
||||
'item_type_toggle' => '',
|
||||
'item_original_type' => '',
|
||||
'item_param_dir' => '',
|
||||
'item_param_name' => '',
|
||||
'item_param_type' => '',
|
||||
'item_param_length' => '',
|
||||
'item_param_opts_num' => '',
|
||||
'item_param_opts_text' => '',
|
||||
'item_returntype' => '',
|
||||
'item_isdeterministic' => '',
|
||||
'item_securitytype' => '',
|
||||
'item_sqldataaccess' => ''
|
||||
),
|
||||
array(
|
||||
'item_name' => '',
|
||||
'item_original_name' => '',
|
||||
'item_returnlength' => '',
|
||||
'item_returnopts_num' => '',
|
||||
'item_returnopts_text' => '',
|
||||
'item_definition' => '',
|
||||
'item_comment' => '',
|
||||
'item_definer' => '',
|
||||
'item_type' => 'PROCEDURE',
|
||||
'item_type_toggle' => 'FUNCTION',
|
||||
'item_original_type' => 'PROCEDURE',
|
||||
'item_num_params' => 0,
|
||||
'item_param_dir' => array(),
|
||||
'item_param_name' => array(),
|
||||
'item_param_type' => array(),
|
||||
'item_param_length' => array(),
|
||||
'item_param_opts_num' => array(),
|
||||
'item_param_opts_text' => array(),
|
||||
'item_returntype' => '',
|
||||
'item_isdeterministic' => '',
|
||||
'item_securitytype_definer' => '',
|
||||
'item_securitytype_invoker' => '',
|
||||
'item_sqldataaccess' => ''
|
||||
)
|
||||
),
|
||||
array(
|
||||
array(
|
||||
'item_name' => 'proc2',
|
||||
'item_original_name' => 'proc',
|
||||
'item_returnlength' => '',
|
||||
'item_returnopts_num' => '',
|
||||
'item_returnopts_text' => '',
|
||||
'item_definition' => 'SELECT NULL',
|
||||
'item_comment' => 'some text',
|
||||
'item_definer' => 'root@localhost',
|
||||
'item_type' => 'PROCEDURE',
|
||||
'item_type_toggle' => 'FUNCTION',
|
||||
'item_original_type' => 'PROCEDURE',
|
||||
'item_param_dir' => array(0 => 'IN', 1 => 'FAIL'),
|
||||
'item_param_name' => array(0 => 'bar', 1 => 'baz'),
|
||||
'item_param_type' => array(0 => 'INT', 1 => 'FAIL'),
|
||||
'item_param_length' => array(0 => '20', 1 => ''),
|
||||
'item_param_opts_num' => array(0 => 'UNSIGNED', 1 => ''),
|
||||
'item_param_opts_text' => array(0 => '', 1 => 'latin1'),
|
||||
'item_returntype' => '',
|
||||
'item_isdeterministic' => 'ON',
|
||||
'item_securitytype' => 'INVOKER',
|
||||
'item_sqldataaccess' => 'NO SQL'
|
||||
),
|
||||
array(
|
||||
'item_name' => 'proc2',
|
||||
'item_original_name' => 'proc',
|
||||
'item_returnlength' => '',
|
||||
'item_returnopts_num' => '',
|
||||
'item_returnopts_text' => '',
|
||||
'item_definition' => 'SELECT NULL',
|
||||
'item_comment' => 'some text',
|
||||
'item_definer' => 'root@localhost',
|
||||
'item_type' => 'PROCEDURE',
|
||||
'item_type_toggle' => 'FUNCTION',
|
||||
'item_original_type' => 'PROCEDURE',
|
||||
'item_num_params' => 2,
|
||||
'item_param_dir' => array(0 => 'IN', 1 => ''),
|
||||
'item_param_name' => array(0 => 'bar', 1 => 'baz'),
|
||||
'item_param_type' => array(0 => 'INT', 1 => ''),
|
||||
'item_param_length' => array(0 => '20', 1 => ''),
|
||||
'item_param_opts_num' => array(0 => 'UNSIGNED', 1 => ''),
|
||||
'item_param_opts_text' => array(0 => '', 1 => 'latin1'),
|
||||
'item_returntype' => '',
|
||||
'item_isdeterministic' => ' checked=\'checked\'',
|
||||
'item_securitytype_definer' => '',
|
||||
'item_securitytype_invoker' => ' selected=\'selected\'',
|
||||
'item_sqldataaccess' => 'NO SQL'
|
||||
)
|
||||
),
|
||||
array(
|
||||
array(
|
||||
'item_name' => 'func2',
|
||||
'item_original_name' => 'func',
|
||||
'item_returnlength' => '20',
|
||||
'item_returnopts_num' => '',
|
||||
'item_returnopts_text' => 'CHARSET utf8',
|
||||
'item_definition' => 'SELECT NULL',
|
||||
'item_comment' => 'some text',
|
||||
'item_definer' => 'root@localhost',
|
||||
'item_type' => 'FUNCTION',
|
||||
'item_type_toggle' => 'PROCEDURE',
|
||||
'item_original_type' => 'FUNCTION',
|
||||
'item_param_dir' => array(0 => '', 1 => ''),
|
||||
'item_param_name' => array(0 => 'bar', 1 => 'baz'),
|
||||
'item_param_type' => array(0 => '<s>XSS</s>', 1 => 'TEXT'),
|
||||
'item_param_length' => array(0 => '10,10', 1 => ''),
|
||||
'item_param_opts_num' => array(0 => 'UNSIGNED', 1 => ''),
|
||||
'item_param_opts_text' => array(0 => '', 1 => 'utf8'),
|
||||
'item_returntype' => 'VARCHAR',
|
||||
'item_isdeterministic' => '',
|
||||
'item_securitytype' => 'DEFINER',
|
||||
'item_sqldataaccess' => ''
|
||||
),
|
||||
array(
|
||||
'item_name' => 'func2',
|
||||
'item_original_name' => 'func',
|
||||
'item_returnlength' => '20',
|
||||
'item_returnopts_num' => '',
|
||||
'item_returnopts_text' => 'CHARSET utf8',
|
||||
'item_definition' => 'SELECT NULL',
|
||||
'item_comment' => 'some text',
|
||||
'item_definer' => 'root@localhost',
|
||||
'item_type' => 'FUNCTION',
|
||||
'item_type_toggle' => 'PROCEDURE',
|
||||
'item_original_type' => 'FUNCTION',
|
||||
'item_num_params' => '2',
|
||||
'item_param_dir' => array(),
|
||||
'item_param_name' => array(0 => 'bar', 1 => 'baz'),
|
||||
'item_param_type' => array(0 => '', 1 => 'TEXT'),
|
||||
'item_param_length' => array(0 => '10,10', 1 => ''),
|
||||
'item_param_opts_num' => array(0 => 'UNSIGNED', 1 => ''),
|
||||
'item_param_opts_text' => array(0 => '', 1 => 'utf8'),
|
||||
'item_returntype' => 'VARCHAR',
|
||||
'item_isdeterministic' => '',
|
||||
'item_securitytype_definer' => ' selected=\'selected\'',
|
||||
'item_securitytype_invoker' => '',
|
||||
'item_sqldataaccess' => ''
|
||||
)
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
?>
|
||||
885
test/libraries/rte/PMA_RTN_getEditorForm_test.php
Normal file
885
test/libraries/rte/PMA_RTN_getEditorForm_test.php
Normal file
@ -0,0 +1,885 @@
|
||||
<?php
|
||||
/* vim: set expandtab sw=4 ts=4 sts=4: */
|
||||
/**
|
||||
* Test for generating routine editor
|
||||
*
|
||||
* @package phpMyAdmin-test
|
||||
*/
|
||||
require_once 'libraries/common.lib.php';
|
||||
require_once 'libraries/data_mysql.inc.php';
|
||||
require_once 'libraries/php-gettext/gettext.inc';
|
||||
require_once 'libraries/url_generating.lib.php';
|
||||
/*
|
||||
* Include to test.
|
||||
*/
|
||||
require_once 'libraries/rte/rte_routines.lib.php';
|
||||
|
||||
class PMA_RTN_getEditorForm_test extends PHPUnit_Framework_TestCase
|
||||
{
|
||||
public function setUp()
|
||||
{
|
||||
if (! function_exists('PMA_generateCharsetDropdownBox')) {
|
||||
function PMA_generateCharsetDropdownBox() {}
|
||||
}
|
||||
if (! defined('PMA_CSDROPDOWN_CHARSET')) {
|
||||
define('PMA_CSDROPDOWN_CHARSET', '');
|
||||
}
|
||||
if (! function_exists('PMA_DBI_get_tables')) {
|
||||
function PMA_DBI_get_tables($db)
|
||||
{
|
||||
return array('table1', 'table`2');
|
||||
}
|
||||
}
|
||||
$GLOBALS['tear_down']['token'] = false;
|
||||
$GLOBALS['tear_down']['server'] = false;
|
||||
if (! isset($_SESSION[' PMA_token '])) {
|
||||
$_SESSION[' PMA_token '] = '';
|
||||
$GLOBALS['tear_down']['token'] = true;
|
||||
}
|
||||
if (! isset($GLOBALS['cfg']['ServerDefault'])) {
|
||||
$GLOBALS['cfg']['ServerDefault'] = '';
|
||||
$GLOBALS['tear_down']['server'] = true;
|
||||
}
|
||||
}
|
||||
|
||||
public function tearDown()
|
||||
{
|
||||
if ($GLOBALS['tear_down']['token']) {
|
||||
unset($_SESSION[' PMA_token ']);
|
||||
}
|
||||
if ($GLOBALS['tear_down']['server']) {
|
||||
unset($GLOBALS['cfg']['ServerDefault']);
|
||||
}
|
||||
unset($GLOBALS['tear_down']);
|
||||
}
|
||||
|
||||
public function testgetParameterRow_empty()
|
||||
{
|
||||
$GLOBALS['is_ajax_request'] = false;
|
||||
PMA_RTN_setGlobals();
|
||||
$this->assertEquals('', PMA_RTN_getParameterRow(array(), 0));
|
||||
}
|
||||
|
||||
/**
|
||||
* @depends testgetParameterRow_empty
|
||||
* @dataProvider provider_row
|
||||
*/
|
||||
public function testgetParameterRow($data, $index, $matcher)
|
||||
{
|
||||
$GLOBALS['is_ajax_request'] = false;
|
||||
PMA_RTN_setGlobals();
|
||||
$this->assertTag($matcher, PMA_RTN_getParameterRow($data, $index), false);
|
||||
}
|
||||
|
||||
public function provider_row()
|
||||
{
|
||||
$data = array(
|
||||
'item_name' => '',
|
||||
'item_original_name' => '',
|
||||
'item_returnlength' => '',
|
||||
'item_returnopts_num' => '',
|
||||
'item_returnopts_text' => '',
|
||||
'item_definition' => '',
|
||||
'item_comment' => '',
|
||||
'item_definer' => '',
|
||||
'item_type' => 'PROCEDURE',
|
||||
'item_type_toggle' => 'FUNCTION',
|
||||
'item_original_type' => 'PROCEDURE',
|
||||
'item_num_params' => 1,
|
||||
'item_param_dir' => array(0 => 'IN'),
|
||||
'item_param_name' => array(0 => 'foo'),
|
||||
'item_param_type' => array(0 => 'INT'),
|
||||
'item_param_length' => array(0 => ''),
|
||||
'item_param_opts_num' => array(0 => 'UNSIGNED'),
|
||||
'item_param_opts_text' => array(0 => ''),
|
||||
'item_returntype' => '',
|
||||
'item_isdeterministic' => '',
|
||||
'item_securitytype_definer' => '',
|
||||
'item_securitytype_invoker' => '',
|
||||
'item_sqldataaccess' => ''
|
||||
);
|
||||
|
||||
return array(
|
||||
array(
|
||||
$data,
|
||||
0,
|
||||
array(
|
||||
'tag' => 'select',
|
||||
'attributes' => array(
|
||||
'name' => 'item_param_dir[0]'
|
||||
)
|
||||
)
|
||||
),
|
||||
array(
|
||||
$data,
|
||||
0,
|
||||
array(
|
||||
'tag' => 'input',
|
||||
'attributes' => array(
|
||||
'name' => 'item_param_name[0]'
|
||||
)
|
||||
)
|
||||
),
|
||||
array(
|
||||
$data,
|
||||
0,
|
||||
array(
|
||||
'tag' => 'select',
|
||||
'attributes' => array(
|
||||
'name' => 'item_param_type[0]'
|
||||
)
|
||||
)
|
||||
),
|
||||
array(
|
||||
$data,
|
||||
0,
|
||||
array(
|
||||
'tag' => 'input',
|
||||
'attributes' => array(
|
||||
'name' => 'item_param_length[0]'
|
||||
)
|
||||
)
|
||||
),
|
||||
array(
|
||||
$data,
|
||||
0,
|
||||
array(
|
||||
'tag' => 'select',
|
||||
'attributes' => array(
|
||||
'name' => 'item_param_opts_num[0]'
|
||||
)
|
||||
)
|
||||
),
|
||||
array(
|
||||
$data,
|
||||
0,
|
||||
array(
|
||||
'tag' => 'a',
|
||||
'attributes' => array(
|
||||
'class' => 'routine_param_remove_anchor'
|
||||
)
|
||||
)
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @depends testgetParameterRow
|
||||
* @dataProvider provider_row_ajax
|
||||
*/
|
||||
public function testgetParameterRow_ajax($data, $matcher)
|
||||
{
|
||||
$GLOBALS['is_ajax_request'] = false;
|
||||
PMA_RTN_setGlobals();
|
||||
$this->assertTag($matcher, PMA_RTN_getParameterRow($data), false);
|
||||
}
|
||||
|
||||
public function provider_row_ajax()
|
||||
{
|
||||
$data = array(
|
||||
'item_name' => '',
|
||||
'item_original_name' => '',
|
||||
'item_returnlength' => '',
|
||||
'item_returnopts_num' => '',
|
||||
'item_returnopts_text' => '',
|
||||
'item_definition' => '',
|
||||
'item_comment' => '',
|
||||
'item_definer' => '',
|
||||
'item_type' => 'PROCEDURE',
|
||||
'item_type_toggle' => 'FUNCTION',
|
||||
'item_original_type' => 'PROCEDURE',
|
||||
'item_num_params' => 1,
|
||||
'item_param_dir' => array(0 => 'IN'),
|
||||
'item_param_name' => array(0 => 'foo'),
|
||||
'item_param_type' => array(0 => 'INT'),
|
||||
'item_param_length' => array(0 => ''),
|
||||
'item_param_opts_num' => array(0 => 'UNSIGNED'),
|
||||
'item_param_opts_text' => array(0 => ''),
|
||||
'item_returntype' => '',
|
||||
'item_isdeterministic' => '',
|
||||
'item_securitytype_definer' => '',
|
||||
'item_securitytype_invoker' => '',
|
||||
'item_sqldataaccess' => ''
|
||||
);
|
||||
|
||||
return array(
|
||||
array(
|
||||
$data,
|
||||
array(
|
||||
'tag' => 'select',
|
||||
'attributes' => array(
|
||||
'name' => 'item_param_dir[%s]'
|
||||
)
|
||||
)
|
||||
),
|
||||
array(
|
||||
$data,
|
||||
array(
|
||||
'tag' => 'input',
|
||||
'attributes' => array(
|
||||
'name' => 'item_param_name[%s]'
|
||||
)
|
||||
)
|
||||
),
|
||||
array(
|
||||
$data,
|
||||
array(
|
||||
'tag' => 'select',
|
||||
'attributes' => array(
|
||||
'name' => 'item_param_type[%s]'
|
||||
)
|
||||
)
|
||||
),
|
||||
array(
|
||||
$data,
|
||||
array(
|
||||
'tag' => 'input',
|
||||
'attributes' => array(
|
||||
'name' => 'item_param_length[%s]'
|
||||
)
|
||||
)
|
||||
),
|
||||
array(
|
||||
$data,
|
||||
array(
|
||||
'tag' => 'select',
|
||||
'attributes' => array(
|
||||
'name' => 'item_param_opts_num[%s]'
|
||||
)
|
||||
)
|
||||
),
|
||||
array(
|
||||
$data,
|
||||
array(
|
||||
'tag' => 'a',
|
||||
'attributes' => array(
|
||||
'class' => 'routine_param_remove_anchor'
|
||||
)
|
||||
)
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @depends testgetParameterRow_ajax
|
||||
* @dataProvider provider_editor_1
|
||||
*/
|
||||
public function testgetEditorForm_1($data, $matcher)
|
||||
{
|
||||
$GLOBALS['is_ajax_request'] = false;
|
||||
PMA_RTN_setGlobals();
|
||||
$this->assertTag($matcher, PMA_RTN_getEditorForm('add', '', $data), false);
|
||||
}
|
||||
|
||||
public function provider_editor_1()
|
||||
{
|
||||
$data = array(
|
||||
'item_name' => '',
|
||||
'item_original_name' => '',
|
||||
'item_returnlength' => '',
|
||||
'item_returnopts_num' => '',
|
||||
'item_returnopts_text' => '',
|
||||
'item_definition' => '',
|
||||
'item_comment' => '',
|
||||
'item_definer' => '',
|
||||
'item_type' => 'PROCEDURE',
|
||||
'item_type_toggle' => 'FUNCTION',
|
||||
'item_original_type' => 'PROCEDURE',
|
||||
'item_num_params' => 0,
|
||||
'item_param_dir' => array(),
|
||||
'item_param_name' => array(),
|
||||
'item_param_type' => array(),
|
||||
'item_param_length' => array(),
|
||||
'item_param_opts_num' => array(),
|
||||
'item_param_opts_text' => array(),
|
||||
'item_returntype' => '',
|
||||
'item_isdeterministic' => '',
|
||||
'item_securitytype_definer' => '',
|
||||
'item_securitytype_invoker' => '',
|
||||
'item_sqldataaccess' => ''
|
||||
);
|
||||
|
||||
return array(
|
||||
array(
|
||||
$data,
|
||||
array(
|
||||
'tag' => 'input',
|
||||
'attributes' => array(
|
||||
'name' => 'add_item'
|
||||
)
|
||||
)
|
||||
),
|
||||
array(
|
||||
$data,
|
||||
array(
|
||||
'tag' => 'input',
|
||||
'attributes' => array(
|
||||
'name' => 'item_name'
|
||||
)
|
||||
)
|
||||
),
|
||||
array(
|
||||
$data,
|
||||
array(
|
||||
'tag' => 'input',
|
||||
'attributes' => array(
|
||||
'name' => 'item_type'
|
||||
)
|
||||
)
|
||||
),
|
||||
array(
|
||||
$data,
|
||||
array(
|
||||
'tag' => 'input',
|
||||
'attributes' => array(
|
||||
'name' => 'routine_changetype'
|
||||
)
|
||||
)
|
||||
),
|
||||
|
||||
|
||||
array(
|
||||
$data,
|
||||
array(
|
||||
'tag' => 'input',
|
||||
'attributes' => array(
|
||||
'name' => 'routine_addparameter'
|
||||
)
|
||||
)
|
||||
),
|
||||
array(
|
||||
$data,
|
||||
array(
|
||||
'tag' => 'input',
|
||||
'attributes' => array(
|
||||
'name' => 'routine_removeparameter'
|
||||
)
|
||||
)
|
||||
),
|
||||
array(
|
||||
$data,
|
||||
array(
|
||||
'tag' => 'select',
|
||||
'attributes' => array(
|
||||
'name' => 'item_returntype'
|
||||
)
|
||||
)
|
||||
),
|
||||
array(
|
||||
$data,
|
||||
array(
|
||||
'tag' => 'input',
|
||||
'attributes' => array(
|
||||
'name' => 'item_returnlength'
|
||||
)
|
||||
)
|
||||
),
|
||||
array(
|
||||
$data,
|
||||
array(
|
||||
'tag' => 'select',
|
||||
'attributes' => array(
|
||||
'name' => 'item_returnopts_num'
|
||||
)
|
||||
)
|
||||
),
|
||||
array(
|
||||
$data,
|
||||
array(
|
||||
'tag' => 'textarea',
|
||||
'attributes' => array(
|
||||
'name' => 'item_definition'
|
||||
)
|
||||
)
|
||||
),
|
||||
array(
|
||||
$data,
|
||||
array(
|
||||
'tag' => 'input',
|
||||
'attributes' => array(
|
||||
'name' => 'item_isdeterministic'
|
||||
)
|
||||
)
|
||||
),
|
||||
array(
|
||||
$data,
|
||||
array(
|
||||
'tag' => 'input',
|
||||
'attributes' => array(
|
||||
'name' => 'item_definer'
|
||||
)
|
||||
)
|
||||
),
|
||||
array(
|
||||
$data,
|
||||
array(
|
||||
'tag' => 'select',
|
||||
'attributes' => array(
|
||||
'name' => 'item_securitytype'
|
||||
)
|
||||
)
|
||||
),
|
||||
array(
|
||||
$data,
|
||||
array(
|
||||
'tag' => 'select',
|
||||
'attributes' => array(
|
||||
'name' => 'item_sqldataaccess'
|
||||
)
|
||||
)
|
||||
),
|
||||
array(
|
||||
$data,
|
||||
array(
|
||||
'tag' => 'input',
|
||||
'attributes' => array(
|
||||
'name' => 'item_comment'
|
||||
)
|
||||
)
|
||||
),
|
||||
array(
|
||||
$data,
|
||||
array(
|
||||
'tag' => 'input',
|
||||
'attributes' => array(
|
||||
'name' => 'editor_process_add'
|
||||
)
|
||||
)
|
||||
),
|
||||
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @depends testgetParameterRow_ajax
|
||||
* @dataProvider provider_editor_2
|
||||
*/
|
||||
public function testgetEditorForm_2($data, $matcher)
|
||||
{
|
||||
$GLOBALS['is_ajax_request'] = false;
|
||||
PMA_RTN_setGlobals();
|
||||
$this->assertTag($matcher, PMA_RTN_getEditorForm('edit', 'change', $data), false);
|
||||
}
|
||||
|
||||
public function provider_editor_2()
|
||||
{
|
||||
$data = array(
|
||||
'item_name' => 'foo',
|
||||
'item_original_name' => 'bar',
|
||||
'item_returnlength' => '',
|
||||
'item_returnopts_num' => '',
|
||||
'item_returnopts_text' => '',
|
||||
'item_definition' => 'SELECT 1',
|
||||
'item_comment' => '',
|
||||
'item_definer' => '',
|
||||
'item_type' => 'PROCEDURE',
|
||||
'item_type_toggle' => 'FUNCTION',
|
||||
'item_original_type' => 'PROCEDURE',
|
||||
'item_num_params' => 1,
|
||||
'item_param_dir' => array(0 => 'IN'),
|
||||
'item_param_name' => array(0 => 'baz'),
|
||||
'item_param_type' => array(0 => 'INT'),
|
||||
'item_param_length' => array(0 => '20'),
|
||||
'item_param_opts_num' => array(0 => 'UNSIGNED'),
|
||||
'item_param_opts_text' => array(0 => ''),
|
||||
'item_returntype' => '',
|
||||
'item_isdeterministic' => '',
|
||||
'item_securitytype_definer' => '',
|
||||
'item_securitytype_invoker' => '',
|
||||
'item_sqldataaccess' => 'NO SQL'
|
||||
);
|
||||
|
||||
return array(
|
||||
array(
|
||||
$data,
|
||||
array(
|
||||
'tag' => 'input',
|
||||
'attributes' => array(
|
||||
'name' => 'edit_item'
|
||||
)
|
||||
)
|
||||
),
|
||||
array(
|
||||
$data,
|
||||
array(
|
||||
'tag' => 'input',
|
||||
'attributes' => array(
|
||||
'name' => 'item_name'
|
||||
)
|
||||
)
|
||||
),
|
||||
array(
|
||||
$data,
|
||||
array(
|
||||
'tag' => 'input',
|
||||
'attributes' => array(
|
||||
'name' => 'item_type',
|
||||
'value' => 'FUNCTION'
|
||||
)
|
||||
)
|
||||
),
|
||||
array(
|
||||
$data,
|
||||
array(
|
||||
'tag' => 'input',
|
||||
'attributes' => array(
|
||||
'name' => 'routine_changetype'
|
||||
)
|
||||
)
|
||||
),
|
||||
|
||||
|
||||
array(
|
||||
$data,
|
||||
array(
|
||||
'tag' => 'input',
|
||||
'attributes' => array(
|
||||
'name' => 'routine_addparameter'
|
||||
)
|
||||
)
|
||||
),
|
||||
array(
|
||||
$data,
|
||||
array(
|
||||
'tag' => 'input',
|
||||
'attributes' => array(
|
||||
'name' => 'routine_removeparameter'
|
||||
)
|
||||
)
|
||||
),
|
||||
array(
|
||||
$data,
|
||||
array(
|
||||
'tag' => 'select',
|
||||
'attributes' => array(
|
||||
'name' => 'item_returntype'
|
||||
)
|
||||
)
|
||||
),
|
||||
array(
|
||||
$data,
|
||||
array(
|
||||
'tag' => 'input',
|
||||
'attributes' => array(
|
||||
'name' => 'item_returnlength'
|
||||
)
|
||||
)
|
||||
),
|
||||
array(
|
||||
$data,
|
||||
array(
|
||||
'tag' => 'select',
|
||||
'attributes' => array(
|
||||
'name' => 'item_returnopts_num'
|
||||
)
|
||||
)
|
||||
),
|
||||
array(
|
||||
$data,
|
||||
array(
|
||||
'tag' => 'textarea',
|
||||
'attributes' => array(
|
||||
'name' => 'item_definition'
|
||||
)
|
||||
)
|
||||
),
|
||||
array(
|
||||
$data,
|
||||
array(
|
||||
'tag' => 'input',
|
||||
'attributes' => array(
|
||||
'name' => 'item_isdeterministic'
|
||||
)
|
||||
)
|
||||
),
|
||||
array(
|
||||
$data,
|
||||
array(
|
||||
'tag' => 'input',
|
||||
'attributes' => array(
|
||||
'name' => 'item_definer'
|
||||
)
|
||||
)
|
||||
),
|
||||
array(
|
||||
$data,
|
||||
array(
|
||||
'tag' => 'select',
|
||||
'attributes' => array(
|
||||
'name' => 'item_securitytype'
|
||||
)
|
||||
)
|
||||
),
|
||||
array(
|
||||
$data,
|
||||
array(
|
||||
'tag' => 'select',
|
||||
'attributes' => array(
|
||||
'name' => 'item_sqldataaccess'
|
||||
)
|
||||
)
|
||||
),
|
||||
array(
|
||||
$data,
|
||||
array(
|
||||
'tag' => 'input',
|
||||
'attributes' => array(
|
||||
'name' => 'item_comment'
|
||||
)
|
||||
)
|
||||
),
|
||||
array(
|
||||
$data,
|
||||
array(
|
||||
'tag' => 'input',
|
||||
'attributes' => array(
|
||||
'name' => 'editor_process_edit'
|
||||
)
|
||||
)
|
||||
),
|
||||
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @depends testgetParameterRow_ajax
|
||||
* @dataProvider provider_editor_3
|
||||
*/
|
||||
public function testgetEditorForm_3($data, $matcher)
|
||||
{
|
||||
$GLOBALS['is_ajax_request'] = true;
|
||||
PMA_RTN_setGlobals();
|
||||
$this->assertTag($matcher, PMA_RTN_getEditorForm('edit', 'remove', $data), false);
|
||||
}
|
||||
|
||||
public function provider_editor_3()
|
||||
{
|
||||
$data = array(
|
||||
'item_name' => 'foo',
|
||||
'item_original_name' => 'bar',
|
||||
'item_returnlength' => '',
|
||||
'item_returnopts_num' => 'UNSIGNED',
|
||||
'item_returnopts_text' => '',
|
||||
'item_definition' => 'SELECT 1',
|
||||
'item_comment' => '',
|
||||
'item_definer' => '',
|
||||
'item_type' => 'FUNCTION',
|
||||
'item_type_toggle' => 'PROCEDURE',
|
||||
'item_original_type' => 'FUNCTION',
|
||||
'item_num_params' => 1,
|
||||
'item_param_dir' => array(0 => ''),
|
||||
'item_param_name' => array(0 => 'baz'),
|
||||
'item_param_type' => array(0 => 'INT'),
|
||||
'item_param_length' => array(0 => '20'),
|
||||
'item_param_opts_num' => array(0 => 'UNSIGNED'),
|
||||
'item_param_opts_text' => array(0 => ''),
|
||||
'item_returntype' => 'INT',
|
||||
'item_isdeterministic' => '',
|
||||
'item_securitytype_definer' => '',
|
||||
'item_securitytype_invoker' => '',
|
||||
'item_sqldataaccess' => 'NO SQL'
|
||||
);
|
||||
|
||||
return array(
|
||||
array(
|
||||
$data,
|
||||
array(
|
||||
'tag' => 'input',
|
||||
'attributes' => array(
|
||||
'name' => 'edit_item'
|
||||
)
|
||||
)
|
||||
),
|
||||
array(
|
||||
$data,
|
||||
array(
|
||||
'tag' => 'input',
|
||||
'attributes' => array(
|
||||
'name' => 'item_name'
|
||||
)
|
||||
)
|
||||
),
|
||||
array(
|
||||
$data,
|
||||
array(
|
||||
'tag' => 'select',
|
||||
'attributes' => array(
|
||||
'name' => 'item_type'
|
||||
)
|
||||
)
|
||||
),
|
||||
array(
|
||||
$data,
|
||||
array(
|
||||
'tag' => 'input',
|
||||
'attributes' => array(
|
||||
'name' => 'routine_addparameter'
|
||||
)
|
||||
)
|
||||
),
|
||||
array(
|
||||
$data,
|
||||
array(
|
||||
'tag' => 'input',
|
||||
'attributes' => array(
|
||||
'name' => 'routine_removeparameter'
|
||||
)
|
||||
)
|
||||
),
|
||||
array(
|
||||
$data,
|
||||
array(
|
||||
'tag' => 'select',
|
||||
'attributes' => array(
|
||||
'name' => 'item_returntype'
|
||||
)
|
||||
)
|
||||
),
|
||||
array(
|
||||
$data,
|
||||
array(
|
||||
'tag' => 'input',
|
||||
'attributes' => array(
|
||||
'name' => 'item_returnlength'
|
||||
)
|
||||
)
|
||||
),
|
||||
array(
|
||||
$data,
|
||||
array(
|
||||
'tag' => 'select',
|
||||
'attributes' => array(
|
||||
'name' => 'item_returnopts_num'
|
||||
)
|
||||
)
|
||||
),
|
||||
array(
|
||||
$data,
|
||||
array(
|
||||
'tag' => 'textarea',
|
||||
'attributes' => array(
|
||||
'name' => 'item_definition'
|
||||
)
|
||||
)
|
||||
),
|
||||
array(
|
||||
$data,
|
||||
array(
|
||||
'tag' => 'input',
|
||||
'attributes' => array(
|
||||
'name' => 'item_isdeterministic'
|
||||
)
|
||||
)
|
||||
),
|
||||
array(
|
||||
$data,
|
||||
array(
|
||||
'tag' => 'input',
|
||||
'attributes' => array(
|
||||
'name' => 'item_definer'
|
||||
)
|
||||
)
|
||||
),
|
||||
array(
|
||||
$data,
|
||||
array(
|
||||
'tag' => 'select',
|
||||
'attributes' => array(
|
||||
'name' => 'item_securitytype'
|
||||
)
|
||||
)
|
||||
),
|
||||
array(
|
||||
$data,
|
||||
array(
|
||||
'tag' => 'select',
|
||||
'attributes' => array(
|
||||
'name' => 'item_sqldataaccess'
|
||||
)
|
||||
)
|
||||
),
|
||||
array(
|
||||
$data,
|
||||
array(
|
||||
'tag' => 'input',
|
||||
'attributes' => array(
|
||||
'name' => 'item_comment'
|
||||
)
|
||||
)
|
||||
),
|
||||
array(
|
||||
$data,
|
||||
array(
|
||||
'tag' => 'input',
|
||||
'attributes' => array(
|
||||
'name' => 'ajax_request'
|
||||
)
|
||||
)
|
||||
),
|
||||
array(
|
||||
$data,
|
||||
array(
|
||||
'tag' => 'input',
|
||||
'attributes' => array(
|
||||
'name' => 'editor_process_edit'
|
||||
)
|
||||
)
|
||||
),
|
||||
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @depends testgetParameterRow_ajax
|
||||
* @dataProvider provider_editor_4
|
||||
*/
|
||||
public function testgetEditorForm_4($data, $matcher)
|
||||
{
|
||||
$GLOBALS['is_ajax_request'] = false;
|
||||
PMA_RTN_setGlobals();
|
||||
$this->assertTag($matcher, PMA_RTN_getEditorForm('edit', 'change', $data), false);
|
||||
}
|
||||
|
||||
public function provider_editor_4()
|
||||
{
|
||||
$data = array(
|
||||
'item_name' => 'foo',
|
||||
'item_original_name' => 'bar',
|
||||
'item_returnlength' => '',
|
||||
'item_returnopts_num' => '',
|
||||
'item_returnopts_text' => '',
|
||||
'item_definition' => 'SELECT 1',
|
||||
'item_comment' => '',
|
||||
'item_definer' => '',
|
||||
'item_type' => 'FUNCTION',
|
||||
'item_type_toggle' => 'PROCEDURE',
|
||||
'item_original_type' => 'PROCEDURE',
|
||||
'item_num_params' => 1,
|
||||
'item_param_dir' => array(0 => 'IN'),
|
||||
'item_param_name' => array(0 => 'baz'),
|
||||
'item_param_type' => array(0 => 'INT'),
|
||||
'item_param_length' => array(0 => '20'),
|
||||
'item_param_opts_num' => array(0 => 'UNSIGNED'),
|
||||
'item_param_opts_text' => array(0 => ''),
|
||||
'item_returntype' => '',
|
||||
'item_isdeterministic' => '',
|
||||
'item_securitytype_definer' => '',
|
||||
'item_securitytype_invoker' => '',
|
||||
'item_sqldataaccess' => 'NO SQL'
|
||||
);
|
||||
|
||||
return array(
|
||||
array(
|
||||
$data,
|
||||
array(
|
||||
'tag' => 'input',
|
||||
'attributes' => array(
|
||||
'name' => 'item_type',
|
||||
'value' => 'PROCEDURE'
|
||||
)
|
||||
)
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
?>
|
||||
244
test/libraries/rte/PMA_RTN_getExecuteForm_test.php
Normal file
244
test/libraries/rte/PMA_RTN_getExecuteForm_test.php
Normal file
@ -0,0 +1,244 @@
|
||||
<?php
|
||||
/* vim: set expandtab sw=4 ts=4 sts=4: */
|
||||
/**
|
||||
* Test for generating routine execution dialog
|
||||
*
|
||||
* @package phpMyAdmin-test
|
||||
*/
|
||||
require_once 'libraries/common.lib.php';
|
||||
require_once 'libraries/sqlparser.lib.php';
|
||||
require_once 'libraries/php-gettext/gettext.inc';
|
||||
require_once 'libraries/url_generating.lib.php';
|
||||
/*
|
||||
* Include to test.
|
||||
*/
|
||||
require_once 'libraries/rte/rte_routines.lib.php';
|
||||
|
||||
class PMA_RTN_getExecuteForm_test extends PHPUnit_Framework_TestCase
|
||||
{
|
||||
public function setUp()
|
||||
{
|
||||
global $cfg;
|
||||
|
||||
if (! defined('PMA_MYSQL_INT_VERSION')) {
|
||||
define('PMA_MYSQL_INT_VERSION', 51000);
|
||||
}
|
||||
|
||||
if (! function_exists('PMA_generateCharsetDropdownBox')) {
|
||||
function PMA_generateCharsetDropdownBox() {}
|
||||
}
|
||||
if (! defined('PMA_CSDROPDOWN_CHARSET')) {
|
||||
define('PMA_CSDROPDOWN_CHARSET', '');
|
||||
}
|
||||
if (! function_exists('PMA_DBI_get_tables')) {
|
||||
function PMA_DBI_get_tables($db)
|
||||
{
|
||||
return array('table1', 'table`2');
|
||||
}
|
||||
}
|
||||
$GLOBALS['tear_down']['token'] = false;
|
||||
$GLOBALS['tear_down']['server'] = false;
|
||||
$GLOBALS['tear_down']['default'] = false;
|
||||
if (! isset($_SESSION[' PMA_token '])) {
|
||||
$_SESSION[' PMA_token '] = '';
|
||||
$GLOBALS['tear_down']['token'] = true;
|
||||
}
|
||||
if (! isset($GLOBALS['cfg']['ServerDefault'])) {
|
||||
$GLOBALS['cfg']['ServerDefault'] = '';
|
||||
$GLOBALS['tear_down']['server'] = true;
|
||||
}
|
||||
$cfg['ShowFunctionFields'] = true;
|
||||
if (! isset($GLOBALS['cfg']['DefaultFunctions'])) {
|
||||
$cfg['DefaultFunctions']['FUNC_NUMBER'] = '';
|
||||
$cfg['DefaultFunctions']['FUNC_DATE'] = '';
|
||||
$GLOBALS['tear_down']['default'] = true;
|
||||
}
|
||||
eval(substr(file_get_contents('libraries/data_mysql.inc.php'), 5, -3)); // FIXME
|
||||
}
|
||||
|
||||
public function tearDown()
|
||||
{
|
||||
if ($GLOBALS['tear_down']['token']) {
|
||||
unset($_SESSION[' PMA_token ']);
|
||||
}
|
||||
if ($GLOBALS['tear_down']['server']) {
|
||||
unset($GLOBALS['cfg']['ServerDefault']);
|
||||
}
|
||||
if ($GLOBALS['tear_down']['default']) {
|
||||
unset($GLOBALS['cfg']['DefaultFunctions']);
|
||||
}
|
||||
unset($GLOBALS['tear_down']);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @dataProvider provider_1
|
||||
*/
|
||||
public function testgetExecuteForm_1($data, $matcher)
|
||||
{
|
||||
$GLOBALS['is_ajax_request'] = false;
|
||||
PMA_RTN_setGlobals();
|
||||
$this->assertTag($matcher, PMA_RTN_getExecuteForm($data), false);
|
||||
}
|
||||
|
||||
public function provider_1()
|
||||
{
|
||||
$data = array(
|
||||
'item_name' => 'foo',
|
||||
'item_returnlength' => '',
|
||||
'item_returnopts_num' => '',
|
||||
'item_returnopts_text' => '',
|
||||
'item_definition' => 'SELECT 1;',
|
||||
'item_comment' => '',
|
||||
'item_definer' => '',
|
||||
'item_type' => 'PROCEDURE',
|
||||
'item_num_params' => 6,
|
||||
'item_param_dir' => array(0 => 'IN', 1 => 'OUT', 2 => 'IN', 3 => 'IN', 4 => 'IN', 5 => 'IN'),
|
||||
'item_param_name' => array(0 => 'foo', 1 => 'foa', 2 => 'fob', 3 => 'foc', 4 => 'fod', 5 => 'foe'),
|
||||
'item_param_type' => array(0 => 'DATE', 1 => 'VARCHAR', 2 => 'DATETIME', 3 => 'GEOMETRY', 4 => 'ENUM', 5 => 'SET'),
|
||||
'item_param_length' => array(0 => '', 1 => '22', 2 => '', 3 => '', 4 => "'a','b'", 5 => "'a','b'"),
|
||||
'item_param_opts_num' => array(0 => '', 1 => '', 2 => '', 3 => '', 4 => '', 5 => ''),
|
||||
'item_param_opts_text' => array(0 => '', 1 => 'utf8', 2 => '', 3 => '', 4 => '', 5 => ''),
|
||||
'item_returntype' => '',
|
||||
'item_isdeterministic' => '',
|
||||
'item_securitytype_definer' => '',
|
||||
'item_securitytype_invoker' => '',
|
||||
'item_sqldataaccess' => ''
|
||||
);
|
||||
|
||||
return array(
|
||||
array(
|
||||
$data,
|
||||
array(
|
||||
'tag' => 'input',
|
||||
'attributes' => array(
|
||||
'name' => 'item_name'
|
||||
)
|
||||
)
|
||||
),
|
||||
array(
|
||||
$data,
|
||||
array(
|
||||
'tag' => 'select',
|
||||
'attributes' => array(
|
||||
'name' => 'funcs[foo]'
|
||||
)
|
||||
)
|
||||
),
|
||||
array(
|
||||
$data,
|
||||
array(
|
||||
'tag' => 'input',
|
||||
'attributes' => array(
|
||||
'name' => 'params[foo]',
|
||||
'class' => 'datefield'
|
||||
)
|
||||
)
|
||||
),
|
||||
array(
|
||||
$data,
|
||||
array(
|
||||
'tag' => 'select',
|
||||
'attributes' => array(
|
||||
'name' => 'funcs[fob]'
|
||||
)
|
||||
)
|
||||
),
|
||||
array(
|
||||
$data,
|
||||
array(
|
||||
'tag' => 'input',
|
||||
'attributes' => array(
|
||||
'name' => 'params[fob]',
|
||||
'class' => 'datetimefield'
|
||||
)
|
||||
)
|
||||
),
|
||||
array(
|
||||
$data,
|
||||
array(
|
||||
'tag' => 'input',
|
||||
'attributes' => array(
|
||||
'name' => 'params[fod][]'
|
||||
),
|
||||
)
|
||||
),
|
||||
array(
|
||||
$data,
|
||||
array(
|
||||
'tag' => 'input',
|
||||
'attributes' => array(
|
||||
'name' => 'params[foe][]'
|
||||
),
|
||||
)
|
||||
),
|
||||
array(
|
||||
$data,
|
||||
array(
|
||||
'tag' => 'input',
|
||||
'attributes' => array(
|
||||
'name' => 'execute_routine'
|
||||
)
|
||||
)
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider provider_2
|
||||
*/
|
||||
public function testgetExecuteForm_2($data, $matcher)
|
||||
{
|
||||
$GLOBALS['is_ajax_request'] = true;
|
||||
PMA_RTN_setGlobals();
|
||||
$this->assertTag($matcher, PMA_RTN_getExecuteForm($data), false);
|
||||
}
|
||||
|
||||
public function provider_2()
|
||||
{
|
||||
$data = array(
|
||||
'item_name' => 'foo',
|
||||
'item_returnlength' => '',
|
||||
'item_returnopts_num' => '',
|
||||
'item_returnopts_text' => '',
|
||||
'item_definition' => 'SELECT 1;',
|
||||
'item_comment' => '',
|
||||
'item_definer' => '',
|
||||
'item_type' => 'PROCEDURE',
|
||||
'item_num_params' => 6,
|
||||
'item_param_dir' => array(0 => 'IN', 1 => 'OUT', 2 => 'IN', 3 => 'IN', 4 => 'IN', 5 => 'IN'),
|
||||
'item_param_name' => array(0 => 'foo', 1 => 'foa', 2 => 'fob', 3 => 'foc', 4 => 'fod', 5 => 'foe'),
|
||||
'item_param_type' => array(0 => 'DATE', 1 => 'VARCHAR', 2 => 'DATETIME', 3 => 'GEOMETRY', 4 => 'ENUM', 5 => 'SET'),
|
||||
'item_param_length' => array(0 => '', 1 => '22', 2 => '', 3 => '', 4 => "'a','b'", 5 => "'a','b'"),
|
||||
'item_param_opts_num' => array(0 => '', 1 => '', 2 => '', 3 => '', 4 => '', 5 => ''),
|
||||
'item_param_opts_text' => array(0 => '', 1 => 'utf8', 2 => '', 3 => '', 4 => '', 5 => ''),
|
||||
'item_returntype' => '',
|
||||
'item_isdeterministic' => '',
|
||||
'item_securitytype_definer' => '',
|
||||
'item_securitytype_invoker' => '',
|
||||
'item_sqldataaccess' => ''
|
||||
);
|
||||
|
||||
return array(
|
||||
array(
|
||||
$data,
|
||||
array(
|
||||
'tag' => 'input',
|
||||
'attributes' => array(
|
||||
'name' => 'execute_routine'
|
||||
)
|
||||
)
|
||||
),
|
||||
array(
|
||||
$data,
|
||||
array(
|
||||
'tag' => 'input',
|
||||
'attributes' => array(
|
||||
'name' => 'ajax_request'
|
||||
)
|
||||
)
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
?>
|
||||
247
test/libraries/rte/PMA_RTN_getQueryFromRequest_test.php
Normal file
247
test/libraries/rte/PMA_RTN_getQueryFromRequest_test.php
Normal file
@ -0,0 +1,247 @@
|
||||
<?php
|
||||
/* vim: set expandtab sw=4 ts=4 sts=4: */
|
||||
/**
|
||||
* Test for generating CREATE [PROCEDURE|FUNCTION] query from HTTP request
|
||||
*
|
||||
* @package phpMyAdmin-test
|
||||
*/
|
||||
|
||||
/*
|
||||
* Needed for PMA_backquote() and PMA_RTN_getQueryFromRequest()
|
||||
*/
|
||||
//require_once 'libraries/data_mysql.inc.php';
|
||||
require_once 'libraries/common.lib.php';
|
||||
require_once 'libraries/php-gettext/gettext.inc';
|
||||
|
||||
/*
|
||||
* Include to test.
|
||||
*/
|
||||
require_once 'libraries/rte/rte_routines.lib.php';
|
||||
|
||||
|
||||
class PMA_RTN_getQueryFromRequest_test extends PHPUnit_Framework_TestCase
|
||||
{
|
||||
/**
|
||||
* @dataProvider provider
|
||||
*/
|
||||
public function testgetQueryFromRequest($request, $query, $num_err)
|
||||
{
|
||||
global $_REQUEST, $errors, $cfg;
|
||||
|
||||
// FIXME: the below two lines are needed to get the test to work,
|
||||
// but are definitely the wrong way to go about the issue
|
||||
// of $cfg['ColumnTypes'] being undefined
|
||||
$cfg['ShowFunctionFields'] = false;
|
||||
eval(substr(file_get_contents('libraries/data_mysql.inc.php'), 5, -3));
|
||||
|
||||
if (! isset($cfg['ColumnTypes'])) {
|
||||
$this->markTestSkipped('Can\'t get column types'); // FIXME
|
||||
}
|
||||
|
||||
$errors = array();
|
||||
PMA_RTN_setGlobals();
|
||||
|
||||
unset($_REQUEST);
|
||||
$_REQUEST = $request;
|
||||
$this->assertEquals($query, PMA_RTN_getQueryFromRequest());
|
||||
$this->assertEquals($num_err, count($errors));
|
||||
}
|
||||
|
||||
public function provider()
|
||||
{
|
||||
return array(
|
||||
// Testing success
|
||||
array(
|
||||
array(
|
||||
'item_name' => 'p r o c',
|
||||
'item_returnlength' => '',
|
||||
'item_returnopts_num' => '',
|
||||
'item_returnopts_text' => '',
|
||||
'item_definition' => 'SELECT 0;',
|
||||
'item_comment' => 'foo',
|
||||
'item_definer' => 'me@home',
|
||||
'item_type' => 'PROCEDURE',
|
||||
'item_num_params' => '0',
|
||||
'item_param_dir' => '',
|
||||
'item_param_name' => '',
|
||||
'item_param_type' => '',
|
||||
'item_param_length' => '',
|
||||
'item_param_opts_num' => '',
|
||||
'item_param_opts_text' => '',
|
||||
'item_returntype' => '',
|
||||
'item_isdeterministic' => '',
|
||||
'item_securitytype' => 'INVOKER',
|
||||
'item_sqldataaccess' => 'NO SQL'
|
||||
),
|
||||
'CREATE DEFINER=`me`@`home` PROCEDURE `p r o c`() COMMENT \'foo\' DETERMINISTIC NO SQL SQL SECURITY INVOKER SELECT 0;',
|
||||
0
|
||||
),
|
||||
array(
|
||||
array(
|
||||
'item_name' => 'pr``oc',
|
||||
'item_returnlength' => '',
|
||||
'item_returnopts_num' => '',
|
||||
'item_returnopts_text' => '',
|
||||
'item_definition' => 'SELECT \'foobar\';',
|
||||
'item_comment' => '',
|
||||
'item_definer' => 'someuser@somehost',
|
||||
'item_type' => 'PROCEDURE',
|
||||
'item_num_params' => '2',
|
||||
'item_param_dir' => array('IN', 'INOUT'),
|
||||
'item_param_name' => array('pa`ram', 'par 2'),
|
||||
'item_param_type' => array('INT', 'ENUM'),
|
||||
'item_param_length' => array('10', '\'a\', \'b\''),
|
||||
'item_param_opts_num' => array('ZEROFILL', ''),
|
||||
'item_param_opts_text' => array('utf8', 'latin1'),
|
||||
'item_returntype' => '',
|
||||
'item_securitytype' => 'DEFINER',
|
||||
'item_sqldataaccess' => 'foobar'
|
||||
),
|
||||
'CREATE DEFINER=`someuser`@`somehost` PROCEDURE `pr````oc`(IN `pa``ram` INT(10) ZEROFILL, INOUT `par 2` ENUM(\'a\', \'b\') CHARSET latin1) NOT DETERMINISTIC SQL SECURITY DEFINER SELECT \'foobar\';',
|
||||
0
|
||||
),
|
||||
array(
|
||||
array(
|
||||
'item_name' => 'func\\',
|
||||
'item_returnlength' => '5,5',
|
||||
'item_returnopts_num' => 'UNSIGNED ZEROFILL',
|
||||
'item_returnopts_text' => '',
|
||||
'item_definition' => 'SELECT \'foobar\';',
|
||||
'item_comment' => 'foo\'s bar',
|
||||
'item_definer' => '',
|
||||
'item_type' => 'FUNCTION',
|
||||
'item_num_params' => '1',
|
||||
'item_param_dir' => '',
|
||||
'item_param_name' => array('pa`ram'),
|
||||
'item_param_type' => array('VARCHAR'),
|
||||
'item_param_length' => array('45'),
|
||||
'item_param_opts_num' => array(''),
|
||||
'item_param_opts_text' => array('latin1'),
|
||||
'item_returntype' => 'DECIMAL',
|
||||
'item_isdeterministic' => 'ON',
|
||||
'item_securitytype' => 'DEFINER',
|
||||
'item_sqldataaccess' => 'READ SQL DATA'
|
||||
),
|
||||
'CREATE FUNCTION `func\\`(`pa``ram` VARCHAR(45) CHARSET latin1) RETURNS DECIMAL(5,5) UNSIGNED ZEROFILL COMMENT \'foo\'\'s bar\' DETERMINISTIC SQL SECURITY DEFINER SELECT \'foobar\';',
|
||||
0
|
||||
),
|
||||
array(
|
||||
array(
|
||||
'item_name' => 'func',
|
||||
'item_returnlength' => '20',
|
||||
'item_returnopts_num' => '',
|
||||
'item_returnopts_text' => 'utf8',
|
||||
'item_definition' => 'SELECT 0;',
|
||||
'item_comment' => '',
|
||||
'item_definer' => '',
|
||||
'item_type' => 'FUNCTION',
|
||||
'item_num_params' => '1',
|
||||
'item_returntype' => 'VARCHAR',
|
||||
'item_securitytype' => 'DEFINER',
|
||||
'item_sqldataaccess' => 'READ SQL DATA'
|
||||
),
|
||||
'CREATE FUNCTION `func`() RETURNS VARCHAR(20) CHARSET utf8 NOT DETERMINISTIC SQL SECURITY DEFINER SELECT 0;',
|
||||
0
|
||||
),
|
||||
// Testing failures
|
||||
array(
|
||||
array(
|
||||
),
|
||||
'CREATE () NOT DETERMINISTIC ', // invalid query
|
||||
3
|
||||
),
|
||||
array(
|
||||
array(
|
||||
'item_name' => 'proc',
|
||||
'item_returnlength' => '',
|
||||
'item_returnopts_num' => '',
|
||||
'item_returnopts_text' => '',
|
||||
'item_definition' => 'SELECT 0;',
|
||||
'item_comment' => 'foo',
|
||||
'item_definer' => 'mehome', // invalid definer format
|
||||
'item_type' => 'PROCEDURE',
|
||||
'item_num_params' => '0',
|
||||
'item_param_dir' => '',
|
||||
'item_param_name' => '',
|
||||
'item_param_type' => '',
|
||||
'item_param_length' => '',
|
||||
'item_param_opts_num' => '',
|
||||
'item_param_opts_text' => '',
|
||||
'item_returntype' => '',
|
||||
'item_isdeterministic' => '',
|
||||
'item_securitytype' => 'INVOKER',
|
||||
'item_sqldataaccess' => 'NO SQL'
|
||||
),
|
||||
'CREATE PROCEDURE `proc`() COMMENT \'foo\' DETERMINISTIC NO SQL SQL SECURITY INVOKER SELECT 0;', // valid query
|
||||
1
|
||||
),
|
||||
array(
|
||||
array(
|
||||
'item_name' => 'proc',
|
||||
'item_returnlength' => '',
|
||||
'item_returnopts_num' => '',
|
||||
'item_returnopts_text' => '',
|
||||
'item_definition' => 'SELECT 0;',
|
||||
'item_comment' => '',
|
||||
'item_definer' => '',
|
||||
'item_type' => 'PROCEDURE',
|
||||
'item_num_params' => '2',
|
||||
'item_param_dir' => array('FAIL', 'INOUT'), // invalid direction
|
||||
'item_param_name' => array('pa`ram', 'goo'),
|
||||
'item_param_type' => array('INT', 'ENUM'),
|
||||
'item_param_length' => array('10', ''), // missing ENUM values
|
||||
'item_param_opts_num' => array('ZEROFILL', ''),
|
||||
'item_param_opts_text' => array('utf8', 'latin1'),
|
||||
'item_returntype' => '',
|
||||
'item_securitytype' => 'DEFINER',
|
||||
'item_sqldataaccess' => 'foobar' // invalid, will just be ignored withour throwing errors
|
||||
),
|
||||
'CREATE PROCEDURE `proc`((10) ZEROFILL, INOUT `goo` ENUM CHARSET latin1) NOT DETERMINISTIC SQL SECURITY DEFINER SELECT 0;', // invalid query
|
||||
2
|
||||
),
|
||||
array(
|
||||
array(
|
||||
'item_name' => 'func',
|
||||
'item_returnlength' => '', // missing length for VARCHAR
|
||||
'item_returnopts_num' => '',
|
||||
'item_returnopts_text' => 'utf8',
|
||||
'item_definition' => 'SELECT 0;',
|
||||
'item_comment' => '',
|
||||
'item_definer' => '',
|
||||
'item_type' => 'FUNCTION',
|
||||
'item_num_params' => '2',
|
||||
'item_param_dir' => array('IN'),
|
||||
'item_param_name' => array(''), // missing name
|
||||
'item_param_type' => array('INT'),
|
||||
'item_param_length' => array('10'),
|
||||
'item_param_opts_num' => array('ZEROFILL'),
|
||||
'item_param_opts_text' => array('latin1'),
|
||||
'item_returntype' => 'VARCHAR',
|
||||
'item_securitytype' => 'DEFINER',
|
||||
'item_sqldataaccess' => ''
|
||||
),
|
||||
'CREATE FUNCTION `func`() RETURNS VARCHAR CHARSET utf8 NOT DETERMINISTIC SQL SECURITY DEFINER SELECT 0;', // invalid query
|
||||
2
|
||||
),
|
||||
array(
|
||||
array(
|
||||
'item_name' => 'func',
|
||||
'item_returnlength' => '',
|
||||
'item_returnopts_num' => '',
|
||||
'item_returnopts_text' => '',
|
||||
'item_definition' => 'SELECT 0;',
|
||||
'item_comment' => '',
|
||||
'item_definer' => '',
|
||||
'item_type' => 'FUNCTION',
|
||||
'item_num_params' => '0',
|
||||
'item_returntype' => 'FAIL', // invalid return type
|
||||
'item_securitytype' => 'DEFINER',
|
||||
'item_sqldataaccess' => ''
|
||||
),
|
||||
'CREATE FUNCTION `func`() NOT DETERMINISTIC SQL SECURITY DEFINER SELECT 0;', // invalid query
|
||||
1
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
?>
|
||||
78
test/libraries/rte/PMA_TRI_getDataFromRequest_test.php
Normal file
78
test/libraries/rte/PMA_TRI_getDataFromRequest_test.php
Normal file
@ -0,0 +1,78 @@
|
||||
<?php
|
||||
/* vim: set expandtab sw=4 ts=4 sts=4: */
|
||||
/**
|
||||
* Test for fetching trigger data from HTTP request
|
||||
*
|
||||
* @package phpMyAdmin-test
|
||||
*/
|
||||
|
||||
/*
|
||||
* Include to test.
|
||||
*/
|
||||
require_once 'libraries/rte/rte_triggers.lib.php';
|
||||
|
||||
class PMA_TRI_getDataFromRequest_test extends PHPUnit_Framework_TestCase
|
||||
{
|
||||
/**
|
||||
* @dataProvider provider
|
||||
*/
|
||||
public function testgetDataFromRequest_empty($in, $out)
|
||||
{
|
||||
global $_REQUEST;
|
||||
|
||||
unset($_REQUEST);
|
||||
foreach ($in as $key => $value) {
|
||||
if ($value !== '') {
|
||||
$_REQUEST[$key] = $value;
|
||||
}
|
||||
}
|
||||
$this->assertEquals($out, PMA_TRI_getDataFromRequest());
|
||||
}
|
||||
|
||||
public function provider()
|
||||
{
|
||||
return array(
|
||||
array(
|
||||
array(
|
||||
'item_name' => '',
|
||||
'item_table' => '',
|
||||
'item_original_name' => '',
|
||||
'item_action_timing' => '',
|
||||
'item_event_manipulation' => '',
|
||||
'item_definition' => '',
|
||||
'item_definer' => ''
|
||||
),
|
||||
array(
|
||||
'item_name' => '',
|
||||
'item_table' => '',
|
||||
'item_original_name' => '',
|
||||
'item_action_timing' => '',
|
||||
'item_event_manipulation' => '',
|
||||
'item_definition' => '',
|
||||
'item_definer' => ''
|
||||
)
|
||||
),
|
||||
array(
|
||||
array(
|
||||
'item_name' => 'foo',
|
||||
'item_table' => 'foo',
|
||||
'item_original_name' => 'foo',
|
||||
'item_action_timing' => 'foo',
|
||||
'item_event_manipulation' => 'foo',
|
||||
'item_definition' => 'foo',
|
||||
'item_definer' => 'foo'
|
||||
),
|
||||
array(
|
||||
'item_name' => 'foo',
|
||||
'item_table' => 'foo',
|
||||
'item_original_name' => 'foo',
|
||||
'item_action_timing' => 'foo',
|
||||
'item_event_manipulation' => 'foo',
|
||||
'item_definition' => 'foo',
|
||||
'item_definer' => 'foo'
|
||||
)
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
?>
|
||||
289
test/libraries/rte/PMA_TRI_getEditorForm_test.php
Normal file
289
test/libraries/rte/PMA_TRI_getEditorForm_test.php
Normal file
@ -0,0 +1,289 @@
|
||||
<?php
|
||||
/* vim: set expandtab sw=4 ts=4 sts=4: */
|
||||
/**
|
||||
* Test for generating trigger editor
|
||||
*
|
||||
* @package phpMyAdmin-test
|
||||
*/
|
||||
require_once 'libraries/php-gettext/gettext.inc';
|
||||
require_once 'libraries/url_generating.lib.php';
|
||||
require_once 'libraries/common.lib.php';
|
||||
/*
|
||||
* Include to test.
|
||||
*/
|
||||
require_once 'libraries/rte/rte_triggers.lib.php';
|
||||
|
||||
class PMA_TRI_getEditorForm_test extends PHPUnit_Framework_TestCase
|
||||
{
|
||||
public function setUp()
|
||||
{
|
||||
if (! function_exists('PMA_DBI_get_tables')) {
|
||||
function PMA_DBI_get_tables($db)
|
||||
{
|
||||
return array('table1', 'table`2');
|
||||
}
|
||||
}
|
||||
$GLOBALS['tear_down']['token'] = false;
|
||||
$GLOBALS['tear_down']['server'] = false;
|
||||
if (! isset($_SESSION[' PMA_token '])) {
|
||||
$_SESSION[' PMA_token '] = '';
|
||||
$GLOBALS['tear_down']['token'] = true;
|
||||
}
|
||||
if (! isset($GLOBALS['cfg']['ServerDefault'])) {
|
||||
$GLOBALS['cfg']['ServerDefault'] = '';
|
||||
$GLOBALS['tear_down']['server'] = true;
|
||||
}
|
||||
}
|
||||
|
||||
public function tearDown()
|
||||
{
|
||||
if ($GLOBALS['tear_down']['token']) {
|
||||
unset($_SESSION[' PMA_token ']);
|
||||
}
|
||||
if ($GLOBALS['tear_down']['server']) {
|
||||
unset($GLOBALS['cfg']['ServerDefault']);
|
||||
}
|
||||
unset($GLOBALS['tear_down']);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider provider_add
|
||||
*/
|
||||
public function testgetEditorForm_add($data, $matcher)
|
||||
{
|
||||
$GLOBALS['is_ajax_request'] = false;
|
||||
PMA_TRI_setGlobals();
|
||||
$this->assertTag($matcher, PMA_TRI_getEditorForm('add', $data), '', false);
|
||||
}
|
||||
|
||||
public function provider_add()
|
||||
{
|
||||
$data = array(
|
||||
'item_name' => '',
|
||||
'item_table' => 'table1',
|
||||
'item_original_name' => '',
|
||||
'item_action_timing' => '',
|
||||
'item_event_manipulation' => '',
|
||||
'item_definition' => '',
|
||||
'item_definer' => ''
|
||||
);
|
||||
|
||||
return array(
|
||||
array(
|
||||
$data,
|
||||
array(
|
||||
'tag' => 'input',
|
||||
'attributes' => array(
|
||||
'name' => 'add_item'
|
||||
)
|
||||
)
|
||||
),
|
||||
array(
|
||||
$data,
|
||||
array(
|
||||
'tag' => 'input',
|
||||
'attributes' => array(
|
||||
'name' => 'item_name'
|
||||
)
|
||||
)
|
||||
),
|
||||
array(
|
||||
$data,
|
||||
array(
|
||||
'tag' => 'select',
|
||||
'attributes' => array(
|
||||
'name' => 'item_table'
|
||||
)
|
||||
)
|
||||
),
|
||||
array(
|
||||
$data,
|
||||
array(
|
||||
'tag' => 'select',
|
||||
'attributes' => array(
|
||||
'name' => 'item_timing'
|
||||
)
|
||||
)
|
||||
),
|
||||
array(
|
||||
$data,
|
||||
array(
|
||||
'tag' => 'select',
|
||||
'attributes' => array(
|
||||
'name' => 'item_event'
|
||||
)
|
||||
)
|
||||
),
|
||||
array(
|
||||
$data,
|
||||
array(
|
||||
'tag' => 'textarea',
|
||||
'attributes' => array(
|
||||
'name' => 'item_definition'
|
||||
)
|
||||
)
|
||||
),
|
||||
array(
|
||||
$data,
|
||||
array(
|
||||
'tag' => 'input',
|
||||
'attributes' => array(
|
||||
'name' => 'item_definer'
|
||||
)
|
||||
)
|
||||
),
|
||||
array(
|
||||
$data,
|
||||
array(
|
||||
'tag' => 'input',
|
||||
'attributes' => array(
|
||||
'name' => 'editor_process_add'
|
||||
)
|
||||
)
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider provider_edit
|
||||
*/
|
||||
public function testgetEditorForm_edit($data, $matcher)
|
||||
{
|
||||
$GLOBALS['is_ajax_request'] = false;
|
||||
PMA_TRI_setGlobals();
|
||||
$this->assertTag($matcher, PMA_TRI_getEditorForm('edit', $data), '', false);
|
||||
}
|
||||
|
||||
public function provider_edit()
|
||||
{
|
||||
$data = array(
|
||||
'item_name' => 'foo',
|
||||
'item_table' => 'table1',
|
||||
'item_original_name' => 'bar',
|
||||
'item_action_timing' => 'BEFORE',
|
||||
'item_event_manipulation' => 'INSERT',
|
||||
'item_definition' => 'SET @A=1;',
|
||||
'item_definer' => ''
|
||||
);
|
||||
|
||||
return array(
|
||||
array(
|
||||
$data,
|
||||
array(
|
||||
'tag' => 'input',
|
||||
'attributes' => array(
|
||||
'name' => 'edit_item'
|
||||
)
|
||||
)
|
||||
),
|
||||
array(
|
||||
$data,
|
||||
array(
|
||||
'tag' => 'input',
|
||||
'attributes' => array(
|
||||
'name' => 'item_name'
|
||||
)
|
||||
)
|
||||
),
|
||||
array(
|
||||
$data,
|
||||
array(
|
||||
'tag' => 'select',
|
||||
'attributes' => array(
|
||||
'name' => 'item_table'
|
||||
)
|
||||
)
|
||||
),
|
||||
array(
|
||||
$data,
|
||||
array(
|
||||
'tag' => 'select',
|
||||
'attributes' => array(
|
||||
'name' => 'item_timing'
|
||||
)
|
||||
)
|
||||
),
|
||||
array(
|
||||
$data,
|
||||
array(
|
||||
'tag' => 'select',
|
||||
'attributes' => array(
|
||||
'name' => 'item_event'
|
||||
)
|
||||
)
|
||||
),
|
||||
array(
|
||||
$data,
|
||||
array(
|
||||
'tag' => 'textarea',
|
||||
'attributes' => array(
|
||||
'name' => 'item_definition'
|
||||
)
|
||||
)
|
||||
),
|
||||
array(
|
||||
$data,
|
||||
array(
|
||||
'tag' => 'input',
|
||||
'attributes' => array(
|
||||
'name' => 'item_definer'
|
||||
)
|
||||
)
|
||||
),
|
||||
array(
|
||||
$data,
|
||||
array(
|
||||
'tag' => 'input',
|
||||
'attributes' => array(
|
||||
'name' => 'editor_process_edit'
|
||||
)
|
||||
)
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider provider_ajax
|
||||
*/
|
||||
public function testgetEditorForm_ajax($data, $matcher)
|
||||
{
|
||||
$GLOBALS['is_ajax_request'] = true;
|
||||
PMA_TRI_setGlobals();
|
||||
$this->assertTag($matcher, PMA_TRI_getEditorForm('edit', $data), '', false);
|
||||
}
|
||||
|
||||
public function provider_ajax()
|
||||
{
|
||||
$data = array(
|
||||
'item_name' => 'foo',
|
||||
'item_table' => 'table1',
|
||||
'item_original_name' => 'bar',
|
||||
'item_action_timing' => 'BEFORE',
|
||||
'item_event_manipulation' => 'INSERT',
|
||||
'item_definition' => 'SET @A=1;',
|
||||
'item_definer' => ''
|
||||
);
|
||||
|
||||
return array(
|
||||
array(
|
||||
$data,
|
||||
array(
|
||||
'tag' => 'input',
|
||||
'attributes' => array(
|
||||
'name' => 'editor_process_edit'
|
||||
)
|
||||
)
|
||||
),
|
||||
array(
|
||||
$data,
|
||||
array(
|
||||
'tag' => 'input',
|
||||
'attributes' => array(
|
||||
'name' => 'ajax_request'
|
||||
)
|
||||
)
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
?>
|
||||
103
test/libraries/rte/PMA_TRI_getQueryFromRequest_test.php
Normal file
103
test/libraries/rte/PMA_TRI_getQueryFromRequest_test.php
Normal file
@ -0,0 +1,103 @@
|
||||
<?php
|
||||
/* vim: set expandtab sw=4 ts=4 sts=4: */
|
||||
/**
|
||||
* Test for generating CREATE TRIGGER query from HTTP request
|
||||
*
|
||||
* @package phpMyAdmin-test
|
||||
*/
|
||||
|
||||
/*
|
||||
* Needed for PMA_backquote()
|
||||
*/
|
||||
require_once 'libraries/common.lib.php';
|
||||
|
||||
/*
|
||||
* Needed by PMA_TRI_getQueryFromRequest()
|
||||
*/
|
||||
require_once 'libraries/php-gettext/gettext.inc';
|
||||
|
||||
/*
|
||||
* Include to test.
|
||||
*/
|
||||
require_once 'libraries/rte/rte_triggers.lib.php';
|
||||
|
||||
|
||||
class PMA_TRI_getQueryFromRequest_test extends PHPUnit_Framework_TestCase
|
||||
{
|
||||
public function setUp()
|
||||
{
|
||||
if (! function_exists('PMA_DBI_get_tables')) {
|
||||
function PMA_DBI_get_tables($db)
|
||||
{
|
||||
return array('table1', 'table`2');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider provider
|
||||
*/
|
||||
public function testgetQueryFromRequest($definer, $name, $timing, $event, $table, $definition, $query, $num_err)
|
||||
{
|
||||
global $_REQUEST, $errors;
|
||||
|
||||
$errors = array();
|
||||
PMA_TRI_setGlobals();
|
||||
|
||||
$_REQUEST['item_definer'] = $definer;
|
||||
$_REQUEST['item_name'] = $name;
|
||||
$_REQUEST['item_timing'] = $timing;
|
||||
$_REQUEST['item_event'] = $event;
|
||||
$_REQUEST['item_table'] = $table;
|
||||
$_REQUEST['item_definition'] = $definition;
|
||||
|
||||
$this->assertEquals($query, PMA_TRI_getQueryFromRequest());
|
||||
$this->assertEquals($num_err, count($errors));
|
||||
}
|
||||
|
||||
public function provider()
|
||||
{
|
||||
return array(
|
||||
array('',
|
||||
'',
|
||||
'',
|
||||
'',
|
||||
'',
|
||||
'',
|
||||
'CREATE TRIGGER ON FOR EACH ROW ',
|
||||
5
|
||||
),
|
||||
array(
|
||||
'root',
|
||||
'trigger',
|
||||
'BEFORE',
|
||||
'INSERT',
|
||||
'table`2',
|
||||
'SET @A=NULL',
|
||||
'CREATE TRIGGER `trigger` BEFORE INSERT ON `table``2` FOR EACH ROW SET @A=NULL',
|
||||
1
|
||||
),
|
||||
array(
|
||||
'foo`s@host',
|
||||
'trigger`s test',
|
||||
'AFTER',
|
||||
'foo',
|
||||
'table3',
|
||||
'BEGIN SET @A=1; SET @B=2; END',
|
||||
'CREATE DEFINER=`foo``s`@`host` TRIGGER `trigger``s test` AFTER ON FOR EACH ROW BEGIN SET @A=1; SET @B=2; END',
|
||||
2
|
||||
),
|
||||
array(
|
||||
'root@localhost',
|
||||
'trigger',
|
||||
'BEFORE',
|
||||
'INSERT',
|
||||
'table1',
|
||||
'SET @A=NULL',
|
||||
'CREATE DEFINER=`root`@`localhost` TRIGGER `trigger` BEFORE INSERT ON `table1` FOR EACH ROW SET @A=NULL',
|
||||
0
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
?>
|
||||
Loading…
Reference in New Issue
Block a user