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

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

/*
 * Include to test.
 */
require_once 'libraries/Template.class.php';
require_once 'libraries/Util.class.php';
require_once 'libraries/Table.class.php';
require_once 'libraries/Index.class.php';
require_once 'libraries/Message.class.php';
require_once 'libraries/database_interface.inc.php';
require_once 'libraries/php-gettext/gettext.inc';
require_once 'libraries/relation.lib.php';
require_once 'libraries/url_generating.lib.php';
require_once 'libraries/Theme.class.php';
require_once 'libraries/sanitizing.lib.php';

/**
 * Tests for libraries/tbl_indexes.lib.php
 *
 * @package PhpMyAdmin-test
 */
class PMA_TblIndexTest extends PHPUnit_Framework_TestCase
{

    /**
     * Setup function for test cases
     *
     * @access protected
     * @return void
     */
    protected function setUp()
    {
        /**
         * SET these to avoid undefined index error
         */
        $GLOBALS['server'] = 1;
        $GLOBALS['cfg']['Server']['pmadb'] = '';
        $GLOBALS['pmaThemeImage'] = 'theme/';
        $GLOBALS['cfg']['ServerDefault'] = "server";
        $GLOBALS['cfg']['ShowHint'] = true;

        $dbi = $this->getMockBuilder('PMA_DatabaseInterface')
            ->disableOriginalConstructor()
            ->getMock();

        $indexs = array(
            array(
                "Schema" => "Schema1",
                "Key_name"=>"Key_name1",
                "Column_name"=>"Column_name1"
            ),
            array(
                "Schema" => "Schema2",
                "Key_name"=>"Key_name2",
                "Column_name"=>"Column_name2"
            ),
            array(
                "Schema" => "Schema3",
                "Key_name"=>"Key_name3",
                "Column_name"=>"Column_name3"
            ),
        );

        $dbi->expects($this->any())->method('getTableIndexes')
            ->will($this->returnValue($indexs));

        $GLOBALS['dbi'] = $dbi;

        //$_SESSION
        $_SESSION['PMA_Theme'] = PMA_Theme::load('./themes/pmahomme');
        $_SESSION['PMA_Theme'] = new PMA_Theme();
    }

    /**
     * Tests for PMA_getSqlQueryForIndexCreateOrEdit() method.
     *
     * @return void
     * @test
     */
    public function testPMAGetSqlQueryForIndexCreateOrEdit()
    {
        $db = "pma_db";
        $table = "pma_table";
        $index = new PMA_Index();
        $error = false;

        $_REQUEST['old_index'] = "PRIMARY";

        $table = new PMA_Table($table, $db);
        $sql = $table->getSqlQueryForIndexCreateOrEdit($index, $error);

        $this->assertEquals(
            "ALTER TABLE `pma_db`.`pma_table` DROP PRIMARY KEY, ADD UNIQUE ;",
            $sql
        );
    }

    /**
     * Tests for PMA_getHtmlForIndexForm() method.
     *
     * @return void
     * @test
     */
    public function testPMAGetHtmlForIndexForm()
    {
        /**
         * @todo Find out a better method to test for HTML
         *
         * $fields = array("field_name" => "field_type");
         * $index = new PMA_Index();
         * $form_params = array(
         *     'db' => 'db',
         *     'table' => 'table',
         *     'create_index' => 1,
         * );
         * $add_fields = 3;
         *
         * $html = PMA_getHtmlForIndexForm(
         *     $fields, $index, $form_params, $add_fields
         * );
         *
         * //PMA_URL_getHiddenInputs
         * $this->assertContains(
         *     PMA_URL_getHiddenInputs($form_params),
         *     $html
         * );
         *
         * //Index name
         * $this->assertContains(
         *     __('Index name:'),
         *     $html
         * );
         * $doc_html = PMA_Util::showHint(
         *     PMA_Message::notice(
         *         __(
         *             '"PRIMARY" <b>must</b> be the name of'
         *             . ' and <b>only of</b> a primary key!'
         *         )
         *     )
         * );
         * $this->assertContains(
         *     $doc_html,
         *     $html
         * );
         *
         * //Index name
         * $this->assertContains(
         *     __('Index name:'),
         *     $html
         * );
         * $this->assertContains(
         *     PMA_Util::showMySQLDocu('ALTER_TABLE'),
         *     $html
         * );
         *
         * //generateIndexSelector
         * $this->assertContains(
         *     PMA\Template::trim($index->generateIndexChoiceSelector(false)),
         *     $html
         * );
         *
         * //items
         * $this->assertContains(
         *     __('Column'),
         *     $html
         * );
         * $this->assertContains(
         *     __('Size'),
         *     $html
         * );
         * $this->assertContains(
         *     sprintf(__('Add %s column(s) to index'), 1),
         *     $html
         * );
         *
         * //$field_name & $field_type
         * $this->assertContains(
         *     "field_name",
         *     $html
         * );
         * $this->assertContains(
         *     "field_type",
         *     $html
         * );
         */
        $this->markTestIncomplete('Not yet implemented!');
    }
}
?>