1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* Test - ListTable class |
4
|
|
|
* @package fwolflib |
5
|
|
|
* @subpackage class-test |
6
|
|
|
* @copyright Copyright 2009, Fwolf |
7
|
|
|
* @author Fwolf <[email protected]> |
8
|
|
|
* @since 2009-12-08 |
9
|
|
|
*/ |
10
|
|
|
|
11
|
|
|
// Define like this, so test can run both under eclipse and web alone. |
12
|
|
|
// {{{ |
13
|
|
|
if (! defined('SIMPLE_TEST')) { |
14
|
|
|
define('SIMPLE_TEST', 'simpletest/'); |
15
|
|
|
require_once(SIMPLE_TEST . 'autorun.php'); |
16
|
|
|
} |
17
|
|
|
// Then set output encoding |
18
|
|
|
//header('Content-Type: text/html; charset=utf-8'); |
19
|
|
|
// }}} |
20
|
|
|
|
21
|
|
|
// Require library define file which need test |
22
|
|
|
require_once('fwlib/class/list-table.php'); |
23
|
|
|
require_once('fwlib/func/ecl.php'); |
24
|
|
|
require_once('fwlib/func/request.php'); |
25
|
|
|
require_once('fwlib/func/string.php'); |
26
|
|
|
require_once('smarty/Smarty.class.php'); |
27
|
|
|
|
28
|
|
|
class TestListTable extends UnitTestCase { |
29
|
|
|
|
30
|
|
|
/** |
31
|
|
|
* Table data, without title |
32
|
|
|
* @var array |
33
|
|
|
*/ |
34
|
|
|
protected $aD = array(); |
35
|
|
|
|
36
|
|
|
/** |
37
|
|
|
* Table title |
38
|
|
|
* @var array |
39
|
|
|
*/ |
40
|
|
|
protected $aT = array(); |
41
|
|
|
|
42
|
|
|
/** |
43
|
|
|
* ListTable instance |
44
|
|
|
* @var object |
45
|
|
|
*/ |
46
|
|
|
protected $oLt = null; |
47
|
|
|
|
48
|
|
|
/** |
49
|
|
|
* Css |
50
|
|
|
* @var string |
51
|
|
|
*/ |
52
|
|
|
public $sCss = ''; |
53
|
|
|
|
54
|
|
|
/** |
55
|
|
|
* Js |
56
|
|
|
* @var string |
57
|
|
|
*/ |
58
|
|
|
public $sJs = ''; |
59
|
|
|
|
60
|
|
|
/** |
61
|
|
|
* Tpl filename |
62
|
|
|
* @var string |
63
|
|
|
*/ |
64
|
|
|
public $sTpl = 'list-table.test.tpl'; |
65
|
|
|
|
66
|
|
|
|
67
|
|
|
/** |
68
|
|
|
* Constructor |
69
|
|
|
*/ |
70
|
|
|
public function __construct() { |
71
|
|
|
$o_tpl = new Smarty(); |
72
|
|
|
// Configure dir |
73
|
|
|
$o_tpl->compile_dir = '/tmp/'; |
74
|
|
|
$o_tpl->template_dir = '/tmp/'; |
75
|
|
|
$o_tpl->cache_dir = '/tmp/'; |
76
|
|
|
|
77
|
|
|
$this->oLt = new ListTable($o_tpl); |
|
|
|
|
78
|
|
|
|
79
|
|
|
$this->GenCss(); |
80
|
|
|
$this->GenJs(); |
81
|
|
|
$this->GenTbl(); |
82
|
|
|
$this->GenTpl(); |
83
|
|
|
|
84
|
|
|
} // end of func __construct |
85
|
|
|
|
86
|
|
|
|
87
|
|
|
/** |
88
|
|
|
* Generate css for better table view |
89
|
|
|
*/ |
90
|
|
|
protected function GenCss() { |
91
|
|
|
$this->sCss = ' |
92
|
|
|
<style type="text/css" media="screen, print"> |
93
|
|
|
<!-- |
94
|
|
|
div.fl_lt { |
95
|
|
|
border: 1px solid red; |
96
|
|
|
margin: auto; |
97
|
|
|
width: 70%; |
98
|
|
|
} |
99
|
|
|
/* Single line table */ |
100
|
|
|
table, td, th { |
101
|
|
|
border: 1px solid black; |
102
|
|
|
border-collapse: collapse; |
103
|
|
|
width: 100%; |
104
|
|
|
/* 等宽表格 */ |
105
|
|
|
/*table-layout: fixed;*/ |
106
|
|
|
} |
107
|
|
|
--> |
108
|
|
|
</style> |
109
|
|
|
|
110
|
|
|
<!-- This MUST before table code --> |
111
|
|
|
<script type="text/javascript" src="/js/jquery.js"> |
112
|
|
|
</script> |
113
|
|
|
|
114
|
|
|
'; |
115
|
|
|
} // end of func GenCss |
116
|
|
|
|
117
|
|
|
|
118
|
|
|
/** |
119
|
|
|
* Generate js for better table view |
120
|
|
|
*/ |
121
|
|
|
protected function GenJs() { |
122
|
|
|
$this->sJs = ' |
123
|
|
|
<!-- This MUST be after table code --> |
124
|
|
|
<script type="text/javascript"> |
125
|
|
|
<!--//--><![CDATA[//> |
126
|
|
|
<!-- |
127
|
|
|
|
128
|
|
|
// Assign width for col n |
129
|
|
|
|
130
|
|
|
// If "table-layout: fixed;" is assigned also, |
131
|
|
|
// then td width is assigned + fixed_for_left, |
132
|
|
|
// content width exceed limit will auto wrap, |
133
|
|
|
// but overflow content can also been seen. |
134
|
|
|
|
135
|
|
|
$(".fl_lt table").css("table-layout", "fixed"); |
136
|
|
|
|
137
|
|
|
$(".fl_lt tr > td:nth-child(2)").css("background-color", "green"); |
138
|
|
|
// * include th & td |
139
|
|
|
$(".fl_lt tr > *:nth-child(1)").css("width", "12em"); |
140
|
|
|
//$(".fl_lt tr > td:nth-child(1)").css("width", "1em"); |
141
|
|
|
|
142
|
|
|
// If "table-layout: fixed;" is not assigned, |
143
|
|
|
// width limit will work, but overflow content |
144
|
|
|
// will make width raise. |
145
|
|
|
$(".fl_lt-lt1 tr > *:nth-child(1)").css("width", "50%"); |
146
|
|
|
|
147
|
|
|
//--><!]]> |
148
|
|
|
</script> |
149
|
|
|
|
150
|
|
|
'; |
151
|
|
|
} // end of func GenJs |
152
|
|
|
|
153
|
|
|
|
154
|
|
|
/** |
155
|
|
|
* Generate random table title & data |
156
|
|
|
*/ |
157
|
|
|
protected function GenTbl() { |
158
|
|
|
$i_col = 6; |
159
|
|
|
$i_row = 50; |
160
|
|
|
|
161
|
|
|
for ($i = 0; $i < $i_col; $i++) { |
162
|
|
|
$this->aT[$i] = RandomString(3, 'A'); |
|
|
|
|
163
|
|
|
} |
164
|
|
|
|
165
|
|
|
for ($j = 0; $j < $i_row; $j++) { |
166
|
|
|
$this->aD[$j][0] = "$j - <strong>0</strong> - " . RandomString(20, 'a'); |
|
|
|
|
167
|
|
|
for ($i = 1; $i < $i_col; $i++) { |
168
|
|
|
$this->aD[$j][$i] = "$j - $i"; |
169
|
|
|
} |
170
|
|
|
} |
171
|
|
|
|
172
|
|
|
} // end of func GenTbl |
173
|
|
|
|
174
|
|
|
|
175
|
|
|
/** |
176
|
|
|
* Generate tpl, this is also standard ListTable tpl |
177
|
|
|
*/ |
178
|
|
|
protected function GenTpl() { |
179
|
|
|
$s = file_get_contents(FWOLFLIB . 'class/list-table.tpl'); |
180
|
|
|
file_put_contents('/tmp/' . $this->sTpl, $s); |
181
|
|
|
} // end of func GenTpl |
182
|
|
|
|
183
|
|
|
|
184
|
|
|
function TestBasicTable() { |
|
|
|
|
185
|
|
|
$ar_conf = array( |
186
|
|
|
'tpl' => $this->sTpl, |
187
|
|
|
'page_size' => 3, |
188
|
|
|
); |
189
|
|
|
$this->oLt->SetCfg($ar_conf); |
190
|
|
|
|
191
|
|
|
$this->oLt->SetData($this->aD, $this->aT); |
192
|
|
|
//$this->oLt->SetId(''); |
193
|
|
|
$this->oLt->SetPager(); |
194
|
|
|
|
195
|
|
|
echo $this->sCss; |
196
|
|
|
echo($this->oLt->GetHtml()); |
197
|
|
|
|
198
|
|
|
// Another table in same page |
199
|
|
|
$this->oLt->SetId('lt1'); |
200
|
|
|
// Data is trimmed, need re-make |
201
|
|
|
$this->GenTbl(); |
202
|
|
|
$this->oLt->SetData($this->aD, $this->aT); |
203
|
|
|
// Set sort |
204
|
|
|
$this->oLt->SetOrderby(0, 'asc'); |
205
|
|
|
// MUST refresh pager |
206
|
|
|
$this->oLt->SetPager(); |
207
|
|
|
echo($this->oLt->GetHtml()); |
208
|
|
|
|
209
|
|
|
echo $this->sJs; |
210
|
|
|
|
211
|
|
|
Ecl('ListTable::GetSqlInfoFromUrl()'); |
|
|
|
|
212
|
|
|
echo('<pre>' |
213
|
|
|
. var_export($this->oLt->GetSqlInfoFromUrl(), true) |
214
|
|
|
. '</pre>'); |
215
|
|
|
|
216
|
|
|
Ecl('ListTable::GetSqlInfo()'); |
|
|
|
|
217
|
|
|
echo('<pre>' |
218
|
|
|
. var_export($this->oLt->GetSqlInfo(), true) |
219
|
|
|
. '</pre>'); |
220
|
|
|
} // end of func TestBasicTable |
221
|
|
|
|
222
|
|
|
} // end of class TestListTable |
223
|
|
|
|
224
|
|
|
|
225
|
|
|
// Change output charset in this way. |
226
|
|
|
// {{{ |
227
|
|
|
$s_url = GetSelfUrl(false); |
|
|
|
|
228
|
|
|
$s_url = substr($s_url, strrpos($s_url, '/') + 1); |
229
|
|
|
if ('list-table.test.php' == $s_url) { |
230
|
|
|
$test = new TestListTable(); |
231
|
|
|
$test->run(new HtmlReporter('utf-8')); |
232
|
|
|
} |
233
|
|
|
// }}} |
234
|
|
|
?> |
|
|
|
|
235
|
|
|
|
This class, trait or interface has been deprecated. The supplier of the file has supplied an explanatory message.
The explanatory message should give you some clue as to whether and when the type will be removed from the class and what other constant to use instead.