Merge remote branch 'origin/master' into mlewandow-branch01
[phpmyadmin/mlewandow.git] / test / PMA_quoting_slashing_test.php
blobf8010255493b3f396357608ad10722e4f584ed9e
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 */
10 /**
11 * Tests core.
13 require_once 'PHPUnit/Framework.php';
15 /**
16 * Include to test.
18 require_once './libraries/common.lib.php';
20 /**
21 * Test quoting, slashing, backslashing.
24 class PMA_quoting_slashing_test extends PHPUnit_Framework_TestCase
27 /**
28 * sqlAddslashes test
31 public function testAddSlashes() {
32 $string = "\'test''\''\'\r\t\n";
34 $this->assertEquals("\\\\\\\\\'test\'\'\\\\\\\\\'\'\\\\\\\\\'\\r\\t\\n", PMA_sqlAddslashes($string, true, true, true));
35 $this->assertEquals("\\\\\\\\''test''''\\\\\\\\''''\\\\\\\\''\\r\\t\\n", PMA_sqlAddslashes($string, true, true, false));
36 $this->assertEquals("\\\\\\\\\'test\'\'\\\\\\\\\'\'\\\\\\\\\'\r\t\n", PMA_sqlAddslashes($string, true, false, true));
37 $this->assertEquals("\\\\\\\\''test''''\\\\\\\\''''\\\\\\\\''\r\t\n", PMA_sqlAddslashes($string, true, false, false));
38 $this->assertEquals("\\\\\'test\'\'\\\\\'\'\\\\\'\\r\\t\\n", PMA_sqlAddslashes($string, false, true, true));
39 $this->assertEquals("\\\\''test''''\\\\''''\\\\''\\r\\t\\n", PMA_sqlAddslashes($string, false, true, false));
40 $this->assertEquals("\\\\\'test\'\'\\\\\'\'\\\\\'\r\t\n", PMA_sqlAddslashes($string, false, false, true));
41 $this->assertEquals("\\\\''test''''\\\\''''\\\\''\r\t\n", PMA_sqlAddslashes($string, false, false, false));
44 /**
45 * data provider for unQuote test
48 public function unQuoteProvider() {
49 return array(
50 array('"test\'"', "test'"),
51 array("'test''", "test'"),
52 array("`test'`", "test'"),
53 array("'test'test", "'test'test")
57 /**
58 * unQuote test
59 * @dataProvider unQuoteProvider
62 public function testUnQuote($param, $expected) {
63 $this->assertEquals($expected, PMA_unQuote($param));
66 /**
67 * data provider for unQuote test with chosen quote
70 public function unQuoteSelectedProvider() {
71 return array(
72 array('"test\'"', "test'"),
73 array("'test''", "'test''"),
74 array("`test'`", "`test'`"),
75 array("'test'test", "'test'test")
79 /**
80 * unQuote test with chosen quote
81 * @dataProvider unQuoteSelectedProvider
84 public function testUnQuoteSelectedChar($param, $expected) {
85 $this->assertEquals($expected, PMA_unQuote($param, '"'));
88 /**
89 * data provider for backquote test
92 public function backquoteDataProvider() {
93 return array(
94 array('0', '`0`'),
95 array('test', '`test`'),
96 array('te`st', '`te``st`'),
97 array(array('test', 'te`st', '', '*'), array('`test`', '`te``st`', '', '*'))
102 * backquote test with different param $do_it (true, false)
103 * @dataProvider backquoteDataProvider
106 public function testBackquote($a, $b) {
107 $this->assertEquals($a, PMA_backquote($a, false));
108 $this->assertEquals($b, PMA_backquote($a));