Welcome to mirror list, hosted at ThFree Co, Russian Federation.

PMA_string_test.php « libraries « test - github.com/phpmyadmin/phpmyadmin.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 535b59bcbddc309e8500cb04c66992bece5f746c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
<?php
/* vim: set expandtab sw=4 ts=4 sts=4: */
/**
 * Tests for Specialized String Functions for phpMyAdmin
 *
 * @package PhpMyAdmin-test
 */

/*
 * Include to test.
 */
require_once 'libraries/String.class.php';

/**
 * Tests for Specialized String Functions for phpMyAdmin
 *
 * @package PhpMyAdmin-test
 */
class PMA_String_Test extends PHPUnit_Framework_TestCase
{
    /**
     * @var PMA_String
     */
    private $_testObj;

    /**
     * Setup function for test cases
     *
     * @access protected
     * @return void
     */
    protected function setUp()
    {
        $this->_testObj = new PMA_String();
    }

    /**
     * Test for charIsEscaped()
     *
     * @param boolean $expected Expected value from test
     * @param string  $str      String to check for
     * @param integer $pos      Character to check for
     * @param integer $start    Starting position of string
     *
     * @return void
     * @test
     * @dataProvider charIsEscapedData
     */
    public function testCharIsEscaped($expected, $str, $pos, $start)
    {
        $this->assertEquals(
            $expected,
            $this->_testObj->charIsEscaped($str, $pos, $start)
        );
    }

    /**
     * Data provider for testCharIsEscaped
     *
     * @return array Test data
     */
    public function charIsEscapedData()
    {
        return array(
            array(false, 'test', -1, 0),
            array(false, 'test', 5, 3),
            array(false, 'test', 3, 5),
            array(true, '\\test', 1, -1),
            array(false, '\\\\test', 2, -1),
            array(true, '\\\\tes\\t', 6, 0)
        );
    }

    /**
     * Test for numberInRangeInclusive()
     *
     * @param bool    $expected Expected value from test
     * @param integer $num      Number to check for
     * @param integer $lower    Lower bound
     * @param integer $upper    Upper bound
     *
     * @return void
     * @test
     * @dataProvider numberInRangeData
     */
    public function testNumberInRangeInclusive(
        $expected, $num, $lower, $upper
    ) {
        $this->assertEquals(
            $expected,
            $this->_testObj->numberInRangeInclusive($num, $lower, $upper)
        );
    }

    /**
     * Data provider for testNumberInRangeInclusive
     *
     * @return array Test data
     */
    public function numberInRangeData()
    {
        return array(
            array(true, 2, 2, 3),
            array(true, 5, 4, 5),
            array(true, 50, 0, 100),
            array(false, -1, 0, 20),
            array(false, 31, 0, 30)
        );
    }

    /**
     * Test for isSqlIdentifier()
     *
     * @param boolean $expected     Expected value from test
     * @param string  $c            Character to check for
     * @param boolean $dot_is_valid whether the dot character is valid or not
     *
     * @return void
     * @test
     * @dataProvider isSqlIdentifierData
     */
    public function testIsSqlIdentifier($expected, $c, $dot_is_valid = false)
    {
        $this->assertEquals(
            $expected,
            $this->_testObj->isSqlIdentifier($c, $dot_is_valid)
        );
    }

    /**
     * Data provider for testIsSqlIdentifier
     *
     * @return array Test data
     */
    public function isSqlIdentifierData()
    {
        return array(
            array(true, '2'),
            array(true, 'a'),
            array(true, '.', true),
            array(false, '.'),
            array(true, 'À'),
            array(false, '×'),
            array(false, 'ù'),
            array(true, '_'),
            array(true, '$')
        );
    }
}
?>