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

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

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

/**
 * Tests for libraries/tbl_relation.lib.php
 *
 * @package PhpMyAdmin-test
 */
class PMA_TblRelationTest extends PHPUnit_Framework_TestCase
{
    /**
     * Configures environment
     *
     * @return void
     */
    protected function setUp()
    {
        $GLOBALS['server'] = 0;
        $GLOBALS['pmaThemeImage'] = 'theme/';
        $GLOBALS['cfg']['ShowHint'] = true;
        //$_SESSION
        $_SESSION['PMA_Theme'] = PMA_Theme::load('./themes/pmahomme');
        $_SESSION['PMA_Theme'] = new PMA_Theme();

        $GLOBALS['pma'] = new DataBasePMAMockForTblRelation();
        $GLOBALS['pma']->databases = new DataBaseMockForTblRelation();

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

        $GLOBALS['dbi'] = $dbi;
    }

    /**
     * Tests for PMA_getSQLToCreateForeignKey() method.
     *
     * @return void
     * @test
     */
    public function testPMAGetSQLToCreateForeignKey()
    {
        // @todo Move this test to PMA_Table_test
/*        $table = "PMA_table";
        $field = array("PMA_field1", "PMA_field2");
        $foreignDb = "foreignDb";
        $foreignTable = "foreignTable";
        $foreignField = array("foreignField1", "foreignField2");

        $sql =  PMA_getSQLToCreateForeignKey(
            $table, $field, $foreignDb, $foreignTable, $foreignField
        );
        $sql_excepted = 'ALTER TABLE `PMA_table` ADD  '
            . 'FOREIGN KEY (`PMA_field1`, `PMA_field2`) REFERENCES '
            . '`foreignDb`.`foreignTable`(`foreignField1`, `foreignField2`);';
        $this->assertEquals(
            $sql_excepted,
            $sql
        );*/
    }

    /**
     * Tests for PMA_getHtmlForCommonForm() method.
     *
     * @return void
     * @test
     */
    public function testPMAGetHtmlForCommonForm()
    {
        // @todo Find out a better method to test for HTML
    }

    /**
     * Tests for PMA_getQueryForDisplayUpdate() method.
     * @todo Move this test to PMA_Table_test
     *
     * @return void
     * @test
     */
    public function testPMAGetQueryForDisplayUpdate()
    {
    /*
        $disp = true;
        $display_field = '';
        $db = "pma_db";
        $table = "pma_table";
        $cfgRelation = array(
            'displaywork' => true,
            'relwork' => true,
            'displaywork' => true,
            'table_info' => 'table_info',
        );

        $GLOBALS['cfgRelation']['db'] = 'global_db';

        //case 1: $disp == true && $display_field == ''
        $query = PMA_getQueryForDisplayUpdate(
            $disp, $display_field, $db, $table, $cfgRelation
        );
        $query_expect = "DELETE FROM `global_db`.`table_info` "
            . "WHERE db_name  = 'pma_db' AND table_name = 'pma_table'";
        $this->assertEquals(
            $query_expect,
            $query
        );

        //case 2: $disp == true && $display_field == 'display_field'
        $display_field == 'display_field';
        $query = PMA_getQueryForDisplayUpdate(
            $disp, $display_field, $db, $table, $cfgRelation
        );
        $query_expect = "DELETE FROM `global_db`.`table_info` "
            . "WHERE db_name  = 'pma_db' AND table_name = 'pma_table'";
        $this->assertEquals(
            $query_expect,
            $query
        );

        //case 3: $disp == false && $display_field == 'display_field'
        $disp = false;
        $display_field = 'display_field';
        $query = PMA_getQueryForDisplayUpdate(
            $disp, $display_field, $db, $table, $cfgRelation
        );
        $query_expect = "INSERT INTO `global_db`.`table_info`"
            . "(db_name, table_name, display_field)"
            . " VALUES('pma_db','pma_table','display_field')";
        $this->assertEquals(
            $query_expect,
            $query
        );

        //case 4: $disp == false && $display_field == ''
        $disp = false;
        $display_field = '';
        $query = PMA_getQueryForDisplayUpdate(
            $disp, $display_field, $db, $table, $cfgRelation
        );
        $query_expect = '';
        $this->assertEquals(
            $query_expect,
            $query
        );*/
    }
}

/**
 * Mock class for DataBasePMAMock
 *
 * @package PhpMyAdmin-test
 */
Class DataBasePMAMockForTblRelation
{
    var $databases;
}

/**
 * Mock class for DataBaseMock
 *
 * @package PhpMyAdmin-test
 */
Class DataBaseMockForTblRelation
{
    /**
     * mock function to return table is existed
     *
     * @param string $name table name
     *
     * @return bool
     */
    function exists($name)
    {
        return true;
    }
}