2 /* vim: set expandtab sw=4 ts=4 sts=4: */
4 * Test for quoting, slashing/backslashing
6 * @author Michal Biniek <michal@bystrzyca.pl>
7 * @package phpMyAdmin-test
8 * @version $Id: PMA_quoting_slashing_test.php
14 require_once 'PHPUnit/Framework.php';
19 require_once './libraries/common.lib.php';
22 * Test quoting, slashing, backslashing.
25 class PMA_quoting_slashing_test
extends PHPUnit_Framework_TestCase
32 public function testAddSlashes() {
33 $string = "\'test''\''\'\r\t\n";
35 $this->assertEquals("\\\\\\\\\'test\'\'\\\\\\\\\'\'\\\\\\\\\'\\r\\t\\n", PMA_sqlAddslashes($string, true, true, true));
36 $this->assertEquals("\\\\\\\\''test''''\\\\\\\\''''\\\\\\\\''\\r\\t\\n", PMA_sqlAddslashes($string, true, true, false));
37 $this->assertEquals("\\\\\\\\\'test\'\'\\\\\\\\\'\'\\\\\\\\\'\r\t\n", PMA_sqlAddslashes($string, true, false, true));
38 $this->assertEquals("\\\\\\\\''test''''\\\\\\\\''''\\\\\\\\''\r\t\n", PMA_sqlAddslashes($string, true, false, false));
39 $this->assertEquals("\\\\\'test\'\'\\\\\'\'\\\\\'\\r\\t\\n", PMA_sqlAddslashes($string, false, true, true));
40 $this->assertEquals("\\\\''test''''\\\\''''\\\\''\\r\\t\\n", PMA_sqlAddslashes($string, false, true, false));
41 $this->assertEquals("\\\\\'test\'\'\\\\\'\'\\\\\'\r\t\n", PMA_sqlAddslashes($string, false, false, true));
42 $this->assertEquals("\\\\''test''''\\\\''''\\\\''\r\t\n", PMA_sqlAddslashes($string, false, false, false));
46 * data provider for unQuote test
49 public function unQuoteProvider() {
51 array('"test\'"', "test'"),
52 array("'test''", "test'"),
53 array("`test'`", "test'"),
54 array("'test'test", "'test'test")
60 * @dataProvider unQuoteProvider
63 public function testUnQuote($param, $expected) {
64 $this->assertEquals($expected, PMA_unQuote($param));
68 * data provider for unQuote test with chosen quote
71 public function unQuoteSelectedProvider() {
73 array('"test\'"', "test'"),
74 array("'test''", "'test''"),
75 array("`test'`", "`test'`"),
76 array("'test'test", "'test'test")
81 * unQuote test with chosen quote
82 * @dataProvider unQuoteSelectedProvider
85 public function testUnQuoteSelectedChar($param, $expected) {
86 $this->assertEquals($expected, PMA_unQuote($param, '"'));
90 * data provider for backquote test
93 public function backquoteDataProvider() {
96 array('test', '`test`'),
97 array('te`st', '`te``st`'),
98 array(array('test', 'te`st', '', '*'), array('`test`', '`te``st`', '', '*'))
103 * backquote test with different param $do_it (true, false)
104 * @dataProvider backquoteDataProvider
107 public function testBackquote($a, $b) {
108 $this->assertEquals($a, PMA_backquote($a, false));
109 $this->assertEquals($b, PMA_backquote($a));