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

PMA_Util_test.php « classes « test - github.com/phpmyadmin/phpmyadmin.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: e88b0237d6e06e1097d111068770182ae43fec89 (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
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
<?php
/* vim: set expandtab sw=4 ts=4 sts=4: */
/**
 * Test for PMA_Util class
 *
 * @package PhpMyAdmin-test
 */

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

/**
 * Test for PMA_Util class
 *
 * @package PhpMyAdmin-test
 */
class PMA_Util_Test extends PHPUnit_Framework_TestCase
{
    /**
     * Test for analyze Limit Clause
     *
     * @return void
     */
    public function testAnalyzeLimitClause()
    {
        $limit_data = PMA_Util::analyzeLimitClause("limit 2,4");
        $this->assertEquals(
            '2',
            $limit_data['start']
        );
        $this->assertEquals(
            '4',
            $limit_data['length']
        );

        $limit_data = PMA_Util::analyzeLimitClause("limit 3");
        $this->assertEquals(
            '0',
            $limit_data['start']
        );
        $this->assertEquals(
            '3',
            $limit_data['length']
        );

        $limit_data = PMA_Util::analyzeLimitClause("limit 3,2,5");
        $this->assertFalse($limit_data);

        $limit_data = PMA_Util::analyzeLimitClause("limit");
        $this->assertFalse($limit_data);

        $limit_data = PMA_Util::analyzeLimitClause("limit ");
        $this->assertFalse($limit_data);
    }

    /**
     * Test for createGISData
     *
     * @return void
     */
    public function testCreateGISData()
    {
        $this->assertEquals(
            "abc",
            PMA_Util::createGISData("abc")
        );
        $this->assertEquals(
            "GeomFromText('POINT()',10)",
            PMA_Util::createGISData("'POINT()',10")
        );
    }

    /**
     * Test for getGISFunctions
     *
     * @return void
     */
    public function testGetGISFunctions()
    {
        $funcs = PMA_Util::getGISFunctions();
        $this->assertArrayHasKey(
            'Dimension',
            $funcs
        );
        $this->assertArrayHasKey(
            'GeometryType',
            $funcs
        );
        $this->assertArrayHasKey(
            'MBRDisjoint',
            $funcs
        );
    }

    /**
     * Test for Page Selector
     *
     * @return void
     */
    public function testPageSelector()
    {
        $this->assertContains(
            '<select class="pageselector ajax" name="pma" >',
            PMA_Util::pageselector("pma", 3)
        );
    }

    /**
     * Test version checking
     *
     * @return void
     *
     * @group large
     */
    public function testGetLatestVersion()
    {
        $GLOBALS['cfg']['ProxyUrl'] = PROXY_URL;
        $GLOBALS['cfg']['ProxyUser'] = PROXY_USER;
        $GLOBALS['cfg']['ProxyPass'] = PROXY_PASS;
        $GLOBALS['cfg']['VersionCheck'] = true;
        $version = PMA_Util::getLatestVersion();
        $this->assertNotEmpty($version->version);
        $this->assertNotEmpty($version->date);
    }

    /**
     * Test version to int conversion.
     *
     * @param string $version Version string
     * @param int    $numeric Integer matching version
     *
     * @return void
     *
     * @dataProvider dataVersions
     */
    public function testVersionToInt($version, $numeric)
    {
        $this->assertEquals(
            $numeric,
            PMA_Util::versionToInt($version)
        );
    }

    /**
     * Data provider for version parsing
     *
     * @return array with test data
     */
    public function dataVersions()
    {
        return array(
            array('1.0.0', 1000050),
            array('2.0.0.2-dev', 2000002),
            array('3.4.2.1', 3040251),
            array('3.4.2-dev3', 3040203),
            array('3.4.2-dev', 3040200),
            array('3.4.2-pl', 3040260),
            array('3.4.2-pl3', 3040263),
            array('4.4.2-rc22', 4040252),
            array('4.4.2-rc', 4040230),
            array('4.4.22-beta22', 4042242),
            array('4.4.22-beta', 4042220),
            array('4.4.21-alpha22', 4042132),
            array('4.4.20-alpha', 4042010),
            array('4.40.20-alpha-dev', 4402010),
            array('4.4a', 4000050),
            array('4.4.4-test', 4040400),
            array('4.1.0', 4010050),
            array('4.0.1.3', 4000153),
            array('4.1-dev', 4010000),
        );
    }

    /**
     * Test for isForeignKeyCheck
     *
     * @return void
     */
    public function testIsForeignKeyCheck()
    {
        $GLOBALS['cfg']['DBG'] = array();
        $GLOBALS['cfg']['DBG']['sql'] = false;

        $GLOBALS['cfg']['DefaultForeignKeyChecks'] = 'enable';
        $this->assertEquals(
            true,
            PMA_Util::isForeignKeyCheck()
        );

        $GLOBALS['cfg']['DefaultForeignKeyChecks'] = 'disable';
        $this->assertEquals(
            false,
            PMA_Util::isForeignKeyCheck()
        );

        $GLOBALS['cfg']['DefaultForeignKeyChecks'] = 'default';
        $this->assertEquals(
            true,
            PMA_Util::isForeignKeyCheck()
        );
    }

}