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

PMA_build_html_for_db_test.php « libraries « test - github.com/phpmyadmin/phpmyadmin.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: dd5b539e37fdbcb1c6b8997c0067a8858d07bf10 (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
<?php
/* vim: set expandtab sw=4 ts=4 sts=4: */
/**
 * tests for build_html_for_db.lib.php
 *
 * @package PhpMyAdmin-test
 */

/*
 * Include to test.
 */

$GLOBALS['server'] = 0;
require_once 'libraries/Util.class.php';
require_once 'libraries/php-gettext/gettext.inc';
require_once 'libraries/build_html_for_db.lib.php';
require_once 'libraries/js_escape.lib.php';
require_once 'libraries/Theme.class.php';
require_once 'libraries/database_interface.inc.php';
require_once 'libraries/Tracker.class.php';
require_once 'libraries/Types.class.php';
require_once 'libraries/mysql_charsets.inc.php';

/**
 * tests for build_html_for_db.lib.php
 *
 * @package PhpMyAdmin-test
 */
class PMA_BuildHtmlForDb_Test extends PHPUnit_Framework_TestCase
{
    /**
     * Prepares environment for the test.
     *
     * @return void
     */
    public function setUp()
    {
        global $cfg;

        $cfg['ShowFunctionFields'] = false;
        $GLOBALS['server'] = 0;
        $cfg['ServerDefault'] = 1;

        $GLOBALS['PMA_Types'] = new PMA_Types_MySQL();
        $_SESSION['PMA_Theme'] = new PMA_Theme();
        $GLOBALS['cfg']['ActionLinksMode'] = 'icons';

        $GLOBALS['pmaThemePath'] = $_SESSION['PMA_Theme']->getPath();
        $GLOBALS['pmaThemeImage'] = 'theme/';

        $GLOBALS['cfg']['DefaultTabDatabase'] = 'db_structure.php';
    }

    /**
     * Test for PMA_getColumnOrder
     *
     * @return void
     */
    public function testGetColumnOrder()
    {
        $this->assertEquals(
            array(
                'DEFAULT_COLLATION_NAME' => array(
                    'disp_name' => __('Collation'),
                    'description_function' => 'PMA_getCollationDescr',
                    'format'    => 'string',
                    'footer'    => 'utf8_general_ci'
                ),
                'SCHEMA_TABLES' => array(
                    'disp_name' => __('Tables'),
                    'format'    => 'number',
                    'footer'    => 0
                ),
                'SCHEMA_TABLE_ROWS' => array(
                    'disp_name' => __('Rows'),
                    'format'    => 'number',
                    'footer'    => 0
                ),
                'SCHEMA_DATA_LENGTH' => array(
                    'disp_name' => __('Data'),
                    'format'    => 'byte',
                    'footer'    => 0
                ),
                'SCHEMA_INDEX_LENGTH' => array(
                    'disp_name' => __('Indexes'),
                    'format'    => 'byte',
                    'footer'    => 0
                ),
                'SCHEMA_LENGTH' => array(
                    'disp_name' => __('Total'),
                    'format'    => 'byte',
                    'footer'    => 0
                )
            ),
            PMA_getColumnOrder()
        );
    }

    /**
     * Test for PMA_buildHtmlForDb
     *
     * @param array   $current           Current
     * @param boolean $is_superuser      Is superuser
     * @param string  $url_query         URL query
     * @param array   $column_order      Column order
     * @param array   $replication_types Replication types
     * @param array   $replication_info  Replication info
     * @param array   $html_segments     HTML segments
     *
     * @return void
     * @dataProvider providerForTestBuildHtmlForDb
     *
     * @group medium
     */
    public function testBuildHtmlForDb($current, $is_superuser,
        $url_query, $column_order, $replication_types,
        $replication_info, $html_segments
    ) {
        $result = PMA_buildHtmlForDb(
            $current, $is_superuser, $url_query,
            $column_order, $replication_types, $replication_info
        );
        $this->assertEquals(
            $column_order,
            $result[0]
        );
        foreach ($html_segments as $html_segment) {
            $this->assertContains(
                $html_segment,
                $result[1]
            );
        }
    }

    /**
     * Data for testBuildHtmlForDb
     *
     * @return array data for testBuildHtmlForDb test case
     */
    public function providerForTestBuildHtmlForDb()
    {
        return array(
            array(
                array('SCHEMA_NAME' => 'pma'),
                true,
                'target=main.php',
                PMA_getColumnOrder(),
                array(
                    'SCHEMA_NAME' => 'pma',
                ),
                array(
                    'pma' => array(
                        'status' => 'true',
                        'Ignore_DB' => array(
                                        'pma' => 'pma'
                                       ),
                    )
                ),
                array(
                    '<td class="tool">',
                    '<input type="checkbox" name="selected_dbs[]"'
                    . ' class="checkall" title="pma" value="pma"'
                )
            ),
            array(
                array('SCHEMA_NAME' => 'INFORMATION_SCHEMA'),
                true,
                'target=main.php',
                PMA_getColumnOrder(),
                array(
                    'SCHEMA_NAME' => 'INFORMATION_SCHEMA',
                ),
                array(
                    'INFORMATION_SCHEMA' => array(
                        'status' => 'false',
                        'Ignore_DB' => array(
                            'INFORMATION_SCHEMA' => 'INFORMATION_SCHEMA'
                        )
                    )
                ),
                array(
                    '<input type="checkbox" name="selected_dbs[]" class="checkall"'
                    . ' title="INFORMATION_SCHEMA" value="INFORMATION_SCHEMA"'
                    . ' disabled="disabled"'
                )
            )
        );
    }
}