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
|
<?php
/* vim: set expandtab sw=4 ts=4 sts=4: */
/**
* Test for PhpMyAdmin\Navigation\Navigation class
*
* @package PhpMyAdmin-test
*/
namespace PhpMyAdmin\Tests\Navigation;
use PhpMyAdmin\Navigation\Navigation;
use PhpMyAdmin\Tests\PmaTestCase;
/**
* Tests for PhpMyAdmin\Navigation\Navigation class
*
* @package PhpMyAdmin-test
*/
class NavigationTest extends PmaTestCase
{
/**
* @var PhpMyAdmin\Navigation\Navigation
*/
protected $object;
/**
* Sets up the fixture.
*
* @access protected
* @return void
*/
protected function setUp()
{
$this->object = new Navigation();
$GLOBALS['cfgRelation']['db'] = 'pmadb';
$GLOBALS['cfgRelation']['navigationhiding'] = 'navigationhiding';
$GLOBALS['cfg']['Server']['user'] = 'user';
$GLOBALS['cfg']['ActionLinksMode'] = 'both';
$GLOBALS['pmaThemeImage'] = '';
}
/**
* Tears down the fixture.
*
* @access protected
* @return void
*/
protected function tearDown()
{
unset($this->object);
}
/**
* Tests hideNavigationItem() method.
*
* @return void
* @test
*/
public function testHideNavigationItem()
{
$expectedQuery = "INSERT INTO `pmadb`.`navigationhiding`"
. "(`username`, `item_name`, `item_type`, `db_name`, `table_name`)"
. " VALUES ('user','itemName','itemType','db','')";
$dbi = $this->getMockBuilder('PhpMyAdmin\DatabaseInterface')
->disableOriginalConstructor()
->getMock();
$dbi->expects($this->once())
->method('tryQuery')
->with($expectedQuery);
$dbi->expects($this->any())->method('escapeString')
->will($this->returnArgument(0));
$GLOBALS['dbi'] = $dbi;
$this->object->hideNavigationItem('itemName', 'itemType', 'db');
}
/**
* Tests unhideNavigationItem() method.
*
* @return void
* @test
*/
public function testUnhideNavigationItem()
{
$expectedQuery = "DELETE FROM `pmadb`.`navigationhiding`"
. " WHERE `username`='user' AND `item_name`='itemName'"
. " AND `item_type`='itemType' AND `db_name`='db'";
$dbi = $this->getMockBuilder('PhpMyAdmin\DatabaseInterface')
->disableOriginalConstructor()
->getMock();
$dbi->expects($this->once())
->method('tryQuery')
->with($expectedQuery);
$dbi->expects($this->any())->method('escapeString')
->will($this->returnArgument(0));
$GLOBALS['dbi'] = $dbi;
$this->object->unhideNavigationItem('itemName', 'itemType', 'db');
}
/**
* Tests getItemUnhideDialog() method.
*
* @return void
* @test
*/
public function testGetItemUnhideDialog()
{
$expectedQuery = "SELECT `item_name`, `item_type`"
. " FROM `pmadb`.`navigationhiding`"
. " WHERE `username`='user' AND `db_name`='db' AND `table_name`=''";
$dbi = $this->getMockBuilder('PhpMyAdmin\DatabaseInterface')
->disableOriginalConstructor()
->getMock();
$dbi->expects($this->once())
->method('tryQuery')
->with($expectedQuery)
->will($this->returnValue(true));
$dbi->expects($this->at(3))
->method('fetchArray')
->will(
$this->returnValue(
array(
'item_name' => 'tableName',
'item_type' => 'table'
)
)
);
$dbi->expects($this->at(4))
->method('fetchArray')
->will(
$this->returnValue(
array(
'item_name' => 'viewName',
'item_type' => 'view'
)
)
);
$dbi->expects($this->at(5))
->method('fetchArray')
->will($this->returnValue(false));
$dbi->expects($this->once())
->method('freeResult');
$dbi->expects($this->any())->method('escapeString')
->will($this->returnArgument(0));
$GLOBALS['dbi'] = $dbi;
$html = $this->object->getItemUnhideDialog('db');
$this->assertContains(
'<td>tableName</td>',
$html
);
$this->assertContains(
'<a href="navigation.php?'
. 'unhideNavItem=1&itemType=table&'
. 'itemName=tableName&dbName=db&lang=en"'
. ' class="unhideNavItem ajax">',
$html
);
}
}
|