forked from phpmyadmin/phpmyadmin
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPMA_Scripts_test.php
More file actions
161 lines (145 loc) · 3.96 KB
/
Copy pathPMA_Scripts_test.php
File metadata and controls
161 lines (145 loc) · 3.96 KB
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
/**
* Tests for Script.class.php
*
* @package PhpMyAdmin-test
*/
/*
* Include to test.
*/
require_once 'libraries/Scripts.class.php';
require_once 'libraries/js_escape.lib.php';
require_once 'libraries/url_generating.lib.php';
/**
* Tests for Script.class.php
*
* @package PhpMyAdmin-test
*/
class PMA_Scripts_Test extends PHPUnit_Framework_TestCase
{
/**
* @access protected
*/
protected $object;
/**
* Sets up the fixture, for example, opens a network connection.
* This method is called before a test is executed.
*
* @access protected
* @return void
*/
protected function setUp()
{
$this->object = new PMA_Scripts();
if (! defined('PMA_USR_BROWSER_AGENT')) {
define('PMA_USR_BROWSER_AGENT', 'MOZILLA');
}
}
/**
* Tears down the fixture, for example, closes a network connection.
* This method is called after a test is executed.
*
* @access protected
* @return void
*/
protected function tearDown()
{
unset($this->object);
}
/**
* Call private functions by setting visibility to public.
*
* @param string $name method name
* @param array $params parameters for the invocation
*
* @return the output from the private method.
*/
private function _callPrivateFunction($name, $params)
{
$class = new ReflectionClass('PMA_Scripts');
$method = $class->getMethod($name);
$method->setAccessible(true);
return $method->invokeArgs($this->object, $params);
}
/**
* Test for _includeFile
*
* @return void
*
* @group medium
*/
public function testIncludeFile()
{
$this->assertEquals(
'<script type="text/javascript" src="js/get_scripts.js.php?lang=en'
. '&token=token&scripts[]=common.js"></script>',
$this->_callPrivateFunction(
'_includeFiles',
array(
array(
array(
'has_onload' => false,
'filename' => 'common.js',
'conditional_ie' => false
)
)
)
)
);
}
/**
* Test for getDisplay
*
* @return void
*/
public function testGetDisplay()
{
$this->object->addFile('common.js');
$this->object->addEvent('onClick', 'doSomething');
$this->assertRegExp(
'@<script type="text/javascript" src="js/get_scripts.js.php\\?lang=en'
. '&token=token&scripts\\[\\]=common.js"></script><script type="text/'
. 'javascript">// <!\\[CDATA\\[' . "\n"
. 'AJAX.scriptHandler.add\\("common.js",1\\);' . "\n"
. '\\$\\(function\\(\\) \\{AJAX.fireOnload\\("common.js"\\);\\}\\);'
. "\n" . '\\$\\(window\\).bind\\(\'onClick\', doSomething\\);' . "\n"
. '// ]]></script>@',
$this->object->getDisplay()
);
}
/**
* test for addCode
*
* @return void
*/
public function testAddCode()
{
$this->object->addCode('alert(\'CodeAdded\')');
$this->assertEquals(
'<script type="text/javascript">// <![CDATA[
alert(\'CodeAdded\')
AJAX.scriptHandler;
$(function() {});
// ]]></script>',
$this->object->getDisplay()
);
}
/**
* test for getFiles
*
* @return void
*/
public function testGetFiles()
{
// codemirror's onload event is blacklisted
$this->object->addFile('codemirror/lib/codemirror.js');
$this->object->addFile('common.js');
$this->assertEquals(
array(
array('name' => 'codemirror/lib/codemirror.js', 'fire' => 0),
array('name' => 'common.js', 'fire' => 1)
),
$this->object->getFiles()
);
}
}