Advisor: mark that 'Rate of reading fixed position' may be wrong, requires further...
[phpmyadmin/thilanka.git] / test / libraries / common / PMA_quoting_slashing_test.php
blobd4e7104bdf1a7702b81cca66e6e2c227010ee2bb
1 <?php
2 /* vim: set expandtab sw=4 ts=4 sts=4: */
3 /**
4 * Test for quoting, slashing/backslashing
6 * @package phpMyAdmin-test
7 * @version $Id: PMA_quoting_slashing_test.php
8 * @group common.lib-tests
9 */
12 * Include to test.
14 require_once 'libraries/common.lib.php';
15 require_once 'libraries/sqlparser.data.php';
17 class PMA_quoting_slashing_test extends PHPUnit_Framework_TestCase
20 /**
21 * sqlAddslashes test
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));
36 /**
37 * data provider for unQuote test
39 * @return array
41 public function unQuoteProvider() {
42 return array(
43 array('"test\'"', "test'"),
44 array("'test''", "test'"),
45 array("`test'`", "test'"),
46 array("'test'test", "'test'test")
50 /**
51 * unQuote test
52 * @dataProvider unQuoteProvider
54 public function testUnQuote($param, $expected) {
55 $this->assertEquals($expected, PMA_unQuote($param));
58 /**
59 * data provider for unQuote test with chosen quote
61 * @return array
63 public function unQuoteSelectedProvider() {
64 return array(
65 array('"test\'"', "test'"),
66 array("'test''", "'test''"),
67 array("`test'`", "`test'`"),
68 array("'test'test", "'test'test")
72 /**
73 * unQuote test with chosen quote
74 * @dataProvider unQuoteSelectedProvider
76 public function testUnQuoteSelectedChar($param, $expected) {
77 $this->assertEquals($expected, PMA_unQuote($param, '"'));
80 /**
81 * data provider for backquote test
83 * @return array
85 public function backquoteDataProvider() {
86 return array(
87 array('0', '`0`'),
88 array('test', '`test`'),
89 array('te`st', '`te``st`'),
90 array(array('test', 'te`st', '', '*'), array('`test`', '`te``st`', '', '*'))
94 /**
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));
102 // Test backquote
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));