3.3.9.1 release
[phpmyadmin/crack.git] / test / PMA_quoting_slashing_test.php
blob8d6bc26fa1cb61c97c80cce08ff51f41d2f54817
1 <?php
2 /* vim: set expandtab sw=4 ts=4 sts=4: */
3 /**
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
9 */
11 /**
12 * Tests core.
14 require_once 'PHPUnit/Framework.php';
16 /**
17 * Include to test.
19 require_once './libraries/common.lib.php';
21 /**
22 * Test quoting, slashing, backslashing.
25 class PMA_quoting_slashing_test extends PHPUnit_Framework_TestCase
28 /**
29 * sqlAddslashes test
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));
45 /**
46 * data provider for unQuote test
49 public function unQuoteProvider() {
50 return array(
51 array('"test\'"', "test'"),
52 array("'test''", "test'"),
53 array("`test'`", "test'"),
54 array("'test'test", "'test'test")
58 /**
59 * unQuote test
60 * @dataProvider unQuoteProvider
63 public function testUnQuote($param, $expected) {
64 $this->assertEquals($expected, PMA_unQuote($param));
67 /**
68 * data provider for unQuote test with chosen quote
71 public function unQuoteSelectedProvider() {
72 return array(
73 array('"test\'"', "test'"),
74 array("'test''", "'test''"),
75 array("`test'`", "`test'`"),
76 array("'test'test", "'test'test")
80 /**
81 * unQuote test with chosen quote
82 * @dataProvider unQuoteSelectedProvider
85 public function testUnQuoteSelectedChar($param, $expected) {
86 $this->assertEquals($expected, PMA_unQuote($param, '"'));
89 /**
90 * data provider for backquote test
93 public function backquoteDataProvider() {
94 return array(
95 array('0', '`0`'),
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));