2 /* vim: set expandtab sw=4 ts=4 sts=4: */
4 * Test for quoting, slashing/backslashing
6 * @package phpMyAdmin-test
7 * @version $Id: PMA_quoting_slashing_test.php
8 * @group common.lib-tests
14 require_once 'libraries/common.lib.php';
15 require_once 'libraries/sqlparser.data.php';
17 class PMA_quoting_slashing_test
extends PHPUnit_Framework_TestCase
23 public function testAddSlashes() {
24 $string = "\'test''\''\'\r\t\n";
26 $this->assertEquals("\\\\\\\\\'test\'\'\\\\\\\\\'\'\\\\\\\\\'\\r\\t\\n", PMA_sqlAddSlashes($string, true, true, true));
27 $this->assertEquals("\\\\\\\\''test''''\\\\\\\\''''\\\\\\\\''\\r\\t\\n", PMA_sqlAddSlashes($string, true, true, false));
28 $this->assertEquals("\\\\\\\\\'test\'\'\\\\\\\\\'\'\\\\\\\\\'\r\t\n", PMA_sqlAddSlashes($string, true, false, true));
29 $this->assertEquals("\\\\\\\\''test''''\\\\\\\\''''\\\\\\\\''\r\t\n", PMA_sqlAddSlashes($string, true, false, false));
30 $this->assertEquals("\\\\\'test\'\'\\\\\'\'\\\\\'\\r\\t\\n", PMA_sqlAddSlashes($string, false, true, true));
31 $this->assertEquals("\\\\''test''''\\\\''''\\\\''\\r\\t\\n", PMA_sqlAddSlashes($string, false, true, false));
32 $this->assertEquals("\\\\\'test\'\'\\\\\'\'\\\\\'\r\t\n", PMA_sqlAddSlashes($string, false, false, true));
33 $this->assertEquals("\\\\''test''''\\\\''''\\\\''\r\t\n", PMA_sqlAddSlashes($string, false, false, false));
37 * data provider for unQuote test
41 public function unQuoteProvider() {
43 array('"test\'"', "test'"),
44 array("'test''", "test'"),
45 array("`test'`", "test'"),
46 array("'test'test", "'test'test")
52 * @dataProvider unQuoteProvider
54 public function testUnQuote($param, $expected) {
55 $this->assertEquals($expected, PMA_unQuote($param));
59 * data provider for unQuote test with chosen quote
63 public function unQuoteSelectedProvider() {
65 array('"test\'"', "test'"),
66 array("'test''", "'test''"),
67 array("`test'`", "`test'`"),
68 array("'test'test", "'test'test")
73 * unQuote test with chosen quote
74 * @dataProvider unQuoteSelectedProvider
76 public function testUnQuoteSelectedChar($param, $expected) {
77 $this->assertEquals($expected, PMA_unQuote($param, '"'));
81 * data provider for backquote test
85 public function backquoteDataProvider() {
88 array('test', '`test`'),
89 array('te`st', '`te``st`'),
90 array(array('test', 'te`st', '', '*'), array('`test`', '`te``st`', '', '*'))
95 * backquote test with different param $do_it (true, false)
96 * @dataProvider backquoteDataProvider
98 public function testBackquote($a, $b) {
99 // Test bypass quoting (used by dump functions)
100 $this->assertEquals($a, PMA_backquote($a, false));
103 $this->assertEquals($b, PMA_backquote($a));
106 public function testBackquoteForbidenWords() {
107 global $PMA_SQPdata_forbidden_word;
109 foreach ($PMA_SQPdata_forbidden_word as $forbidden){
110 $this->assertEquals("`" . $forbidden . "`", PMA_backquote($forbidden, false));