htmlgrid 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/History.txt +6 -0
- data/LICENCE.txt +515 -0
- data/Manifest.txt +82 -0
- data/README.txt +30 -0
- data/Rakefile +28 -0
- data/ext/htmlgrid/MANIFEST +3 -0
- data/ext/htmlgrid/Makefile +150 -0
- data/ext/htmlgrid/extconf.rb +33 -0
- data/ext/htmlgrid/grid.c +881 -0
- data/ext/htmlgrid/grid.o +0 -0
- data/ext/htmlgrid/htmlgrid.c +30 -0
- data/ext/htmlgrid/htmlgrid.o +0 -0
- data/ext/htmlgrid/htmlgrid.so +0 -0
- data/ext/htmlgrid/include/grid.h +79 -0
- data/ext/htmlgrid/include/htmlgrid.h +33 -0
- data/install.rb +1098 -0
- data/lib/htmlgrid/booleanvalue.rb +41 -0
- data/lib/htmlgrid/button.rb +36 -0
- data/lib/htmlgrid/centeredcomposite.rb +47 -0
- data/lib/htmlgrid/component.rb +232 -0
- data/lib/htmlgrid/composite.rb +350 -0
- data/lib/htmlgrid/datevalue.rb +39 -0
- data/lib/htmlgrid/div.rb +37 -0
- data/lib/htmlgrid/divcomposite.rb +52 -0
- data/lib/htmlgrid/divform.rb +35 -0
- data/lib/htmlgrid/divlist.rb +26 -0
- data/lib/htmlgrid/divtemplate.rb +12 -0
- data/lib/htmlgrid/dojotoolkit.rb +173 -0
- data/lib/htmlgrid/errormessage.rb +70 -0
- data/lib/htmlgrid/form.rb +93 -0
- data/lib/htmlgrid/formlist.rb +42 -0
- data/lib/htmlgrid/grid.rb +286 -0
- data/lib/htmlgrid/image.rb +43 -0
- data/lib/htmlgrid/infomessage.rb +41 -0
- data/lib/htmlgrid/input.rb +59 -0
- data/lib/htmlgrid/inputcheckbox.rb +41 -0
- data/lib/htmlgrid/inputcurrency.rb +36 -0
- data/lib/htmlgrid/inputdate.rb +38 -0
- data/lib/htmlgrid/inputfile.rb +40 -0
- data/lib/htmlgrid/inputradio.rb +37 -0
- data/lib/htmlgrid/inputtext.rb +37 -0
- data/lib/htmlgrid/javascript.rb +22 -0
- data/lib/htmlgrid/label.rb +90 -0
- data/lib/htmlgrid/labeltext.rb +35 -0
- data/lib/htmlgrid/link.rb +54 -0
- data/lib/htmlgrid/list.rb +170 -0
- data/lib/htmlgrid/namedcomponent.rb +52 -0
- data/lib/htmlgrid/pass.rb +38 -0
- data/lib/htmlgrid/passthru.rb +44 -0
- data/lib/htmlgrid/popuplink.rb +66 -0
- data/lib/htmlgrid/reset.rb +36 -0
- data/lib/htmlgrid/richtext.rb +26 -0
- data/lib/htmlgrid/select.rb +53 -0
- data/lib/htmlgrid/span.rb +37 -0
- data/lib/htmlgrid/spancomposite.rb +45 -0
- data/lib/htmlgrid/spanlist.rb +15 -0
- data/lib/htmlgrid/staticinput.rb +40 -0
- data/lib/htmlgrid/submit.rb +36 -0
- data/lib/htmlgrid/template.rb +130 -0
- data/lib/htmlgrid/text.rb +36 -0
- data/lib/htmlgrid/textarea.rb +49 -0
- data/lib/htmlgrid/ulcomposite.rb +49 -0
- data/lib/htmlgrid/ullist.rb +15 -0
- data/lib/htmlgrid/urllink.rb +65 -0
- data/lib/htmlgrid/value.rb +36 -0
- data/test/rebuild.rb +39 -0
- data/test/stub/cgi.rb +44 -0
- data/test/suite.rb +32 -0
- data/test/test_component.rb +138 -0
- data/test/test_composite.rb +201 -0
- data/test/test_datevalue.rb +60 -0
- data/test/test_form.rb +123 -0
- data/test/test_formlist.rb +111 -0
- data/test/test_grid.rb +395 -0
- data/test/test_input.rb +70 -0
- data/test/test_label.rb +116 -0
- data/test/test_list.rb +146 -0
- data/test/test_select.rb +78 -0
- data/test/test_template.rb +97 -0
- data/test/test_text.rb +63 -0
- data/usage-en.txt +112 -0
- data/widget/Tooltip.js +85 -0
- metadata +180 -0
data/test/test_grid.rb
ADDED
@@ -0,0 +1,395 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
#
|
3
|
+
# HtmlGrid -- HyperTextMarkupLanguage Framework
|
4
|
+
# Copyright (C) 2003 ywesee - intellectual capital connected
|
5
|
+
# Andreas Schrafl, Benjamin Fay, Hannes Wyss, Markus Huggler
|
6
|
+
#
|
7
|
+
# This library is free software; you can redistribute it and/or
|
8
|
+
# modify it under the terms of the GNU Lesser General Public
|
9
|
+
# License as published by the Free Software Foundation; either
|
10
|
+
# version 2.1 of the License, or (at your option) any later version.
|
11
|
+
#
|
12
|
+
# This library is distributed in the hope that it will be useful,
|
13
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
14
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
15
|
+
# Lesser General Public License for more details.
|
16
|
+
#
|
17
|
+
# You should have received a copy of the GNU Lesser General Public
|
18
|
+
# License along with this library; if not, write to the Free Software
|
19
|
+
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
20
|
+
#
|
21
|
+
# ywesee - intellectual capital connected, Winterthurerstrasse 52, CH-8006 Zuerich, Switzerland
|
22
|
+
# htmlgrid@ywesee.com, www.ywesee.com/htmlgrid
|
23
|
+
#
|
24
|
+
# TestGrid -- htmlgrid -- hwyss@ywesee.com
|
25
|
+
|
26
|
+
$: << File.expand_path("../lib", File.dirname(__FILE__))
|
27
|
+
$: << File.expand_path("../ext", File.dirname(__FILE__))
|
28
|
+
$: << File.dirname(__FILE__)
|
29
|
+
|
30
|
+
require 'test/unit'
|
31
|
+
require 'rebuild'
|
32
|
+
require 'stub/cgi'
|
33
|
+
require 'htmlgrid/label'
|
34
|
+
require 'htmlgrid/grid'
|
35
|
+
|
36
|
+
module HtmlGrid
|
37
|
+
class Grid
|
38
|
+
class Row
|
39
|
+
class Field
|
40
|
+
attr_reader :attributes
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
class TestGrid < Test::Unit::TestCase
|
47
|
+
class StubLabel
|
48
|
+
include Enumerable
|
49
|
+
def each
|
50
|
+
yield "foo"
|
51
|
+
yield "bar"
|
52
|
+
end
|
53
|
+
def to_html(cgi)
|
54
|
+
"foo"
|
55
|
+
end
|
56
|
+
end
|
57
|
+
class StubGridComponent
|
58
|
+
attr_reader :attributes
|
59
|
+
def initialize
|
60
|
+
@attributes = {"class" => "foo"}
|
61
|
+
end
|
62
|
+
def to_html(context)
|
63
|
+
"bar"
|
64
|
+
end
|
65
|
+
def set_attribute(key, value)
|
66
|
+
@attributes.store(key, value)
|
67
|
+
end
|
68
|
+
end
|
69
|
+
class StubNilComponent
|
70
|
+
attr_reader :attributes
|
71
|
+
def initialize
|
72
|
+
@attributes = {}
|
73
|
+
end
|
74
|
+
def to_html(context)
|
75
|
+
nil
|
76
|
+
end
|
77
|
+
end
|
78
|
+
def setup
|
79
|
+
@grid = HtmlGrid::Grid.new
|
80
|
+
end
|
81
|
+
def test_initialize
|
82
|
+
assert_equal(1, @grid.width)
|
83
|
+
assert_equal(1, @grid.height)
|
84
|
+
expected = '<TABLE cellspacing="0"><TR><TD> </TD></TR></TABLE>'
|
85
|
+
assert_equal(expected, @grid.to_html(CGI.new))
|
86
|
+
end
|
87
|
+
def test_add
|
88
|
+
@grid.add("test", 0, 0)
|
89
|
+
assert_equal(1, @grid.width)
|
90
|
+
assert_equal(1, @grid.height)
|
91
|
+
expected = '<TABLE cellspacing="0"><TR><TD>test</TD></TR></TABLE>'
|
92
|
+
assert_equal(expected, @grid.to_html(CGI.new))
|
93
|
+
end
|
94
|
+
def test_add2
|
95
|
+
@grid.add(nil, 0, 0)
|
96
|
+
@grid.add(nil, 0, 0)
|
97
|
+
assert_equal(1, @grid.width)
|
98
|
+
assert_equal(1, @grid.height)
|
99
|
+
expected = '<TABLE cellspacing="0"><TR><TD> </TD></TR></TABLE>'
|
100
|
+
assert_equal(expected, @grid.to_html(CGI.new))
|
101
|
+
end
|
102
|
+
def test_add3
|
103
|
+
@grid.add(2, 0, 0)
|
104
|
+
assert_equal(1, @grid.width)
|
105
|
+
assert_equal(1, @grid.height)
|
106
|
+
expected = '<TABLE cellspacing="0"><TR><TD>2</TD></TR></TABLE>'
|
107
|
+
assert_equal(expected, @grid.to_html(CGI.new))
|
108
|
+
end
|
109
|
+
def test_add_field
|
110
|
+
@grid.add_field("test", 0, 0)
|
111
|
+
assert_equal(1, @grid.width)
|
112
|
+
assert_equal(1, @grid.height)
|
113
|
+
expected = '<TABLE cellspacing="0"><TR><TD>test</TD></TR></TABLE>'
|
114
|
+
assert_equal(expected, @grid.to_html(CGI.new))
|
115
|
+
end
|
116
|
+
def test_add_multiple
|
117
|
+
@grid.add("test", 0, 0)
|
118
|
+
assert_equal(1, @grid.width)
|
119
|
+
assert_equal(1, @grid.height)
|
120
|
+
@grid.add("foo", 0, 0)
|
121
|
+
assert_equal(1, @grid.width)
|
122
|
+
assert_equal(1, @grid.height)
|
123
|
+
expected = '<TABLE cellspacing="0"><TR><TD>testfoo</TD></TR></TABLE>'
|
124
|
+
assert_equal(expected, @grid.to_html(CGI.new))
|
125
|
+
end
|
126
|
+
def test_add_multiple__2
|
127
|
+
@grid.add(["test", "foo"], 0, 0)
|
128
|
+
assert_equal(1, @grid.width)
|
129
|
+
assert_equal(1, @grid.height)
|
130
|
+
expected = '<TABLE cellspacing="0"><TR><TD>testfoo</TD></TR></TABLE>'
|
131
|
+
assert_equal(expected, @grid.to_html(CGI.new))
|
132
|
+
end
|
133
|
+
def test_add_multiple__3
|
134
|
+
@grid.add(["test", nil, "foo"], 0, 0)
|
135
|
+
assert_equal(2, @grid.width)
|
136
|
+
assert_equal(1, @grid.height)
|
137
|
+
expected = '<TABLE cellspacing="0"><TR><TD>test</TD><TD>foo</TD></TR></TABLE>'
|
138
|
+
assert_equal(expected, @grid.to_html(CGI.new))
|
139
|
+
end
|
140
|
+
def test_add_fieldx
|
141
|
+
@grid.add("test", 1, 0)
|
142
|
+
assert_equal(2, @grid.width)
|
143
|
+
assert_equal(1, @grid.height)
|
144
|
+
expected = '<TABLE cellspacing="0"><TR><TD> </TD><TD>test</TD></TR></TABLE>'
|
145
|
+
assert_equal(expected, @grid.to_html(CGI.new))
|
146
|
+
end
|
147
|
+
def test_add_fieldy
|
148
|
+
@grid.add("test", 0, 1)
|
149
|
+
assert_equal(1, @grid.width)
|
150
|
+
assert_equal(2, @grid.height)
|
151
|
+
expected = '<TABLE cellspacing="0"><TR><TD> </TD></TR><TR><TD>test</TD></TR></TABLE>'
|
152
|
+
assert_equal(expected, @grid.to_html(CGI.new))
|
153
|
+
end
|
154
|
+
def test_add_fieldxy
|
155
|
+
@grid.add("test", 1, 1)
|
156
|
+
assert_equal(2, @grid.width)
|
157
|
+
assert_equal(2, @grid.height)
|
158
|
+
expected = '<TABLE cellspacing="0"><TR><TD> </TD><TD> </TD></TR><TR><TD> </TD><TD>test</TD></TR></TABLE>'
|
159
|
+
assert_equal(expected, @grid.to_html(CGI.new))
|
160
|
+
end
|
161
|
+
def test_add_fieldyx
|
162
|
+
@grid.add("test", 0, 1)
|
163
|
+
@grid.add("test", 1, 0)
|
164
|
+
assert_equal(2, @grid.width)
|
165
|
+
assert_equal(2, @grid.height)
|
166
|
+
expected = '<TABLE cellspacing="0"><TR><TD> </TD><TD>test</TD></TR><TR><TD>test</TD><TD> </TD></TR></TABLE>'
|
167
|
+
assert_equal(expected, @grid.to_html(CGI.new))
|
168
|
+
|
169
|
+
end
|
170
|
+
def test_add_row1
|
171
|
+
@grid.add_row(["test1", "test2"], 0,0)
|
172
|
+
assert_equal(2, @grid.width)
|
173
|
+
assert_equal(1, @grid.height)
|
174
|
+
expected = '<TABLE cellspacing="0"><TR><TD>test1</TD><TD>test2</TD></TR></TABLE>'
|
175
|
+
assert_equal(expected, @grid.to_html(CGI.new))
|
176
|
+
end
|
177
|
+
def test_add_row2
|
178
|
+
@grid.add_row(["test1", "test2"], 0,1)
|
179
|
+
assert_equal(2, @grid.width)
|
180
|
+
assert_equal(2, @grid.height)
|
181
|
+
expected = '<TABLE cellspacing="0"><TR><TD> </TD><TD> </TD></TR><TR><TD>test1</TD><TD>test2</TD></TR></TABLE>'
|
182
|
+
assert_equal(expected, @grid.to_html(CGI.new))
|
183
|
+
end
|
184
|
+
def test_add_row3
|
185
|
+
@grid.add_row(["test1", "test2"], 1,0)
|
186
|
+
assert_equal(3, @grid.width)
|
187
|
+
assert_equal(1, @grid.height)
|
188
|
+
expected = '<TABLE cellspacing="0"><TR><TD> </TD><TD>test1</TD><TD>test2</TD></TR></TABLE>'
|
189
|
+
assert_equal(expected, @grid.to_html(CGI.new))
|
190
|
+
end
|
191
|
+
def test_add_column1
|
192
|
+
@grid.add_column(["test1", "test2"], 0,0)
|
193
|
+
assert_equal(1, @grid.width)
|
194
|
+
assert_equal(2, @grid.height)
|
195
|
+
expected = '<TABLE cellspacing="0"><TR><TD>test1</TD></TR><TR><TD>test2</TD></TR></TABLE>'
|
196
|
+
assert_equal(expected, @grid.to_html(CGI.new))
|
197
|
+
end
|
198
|
+
def test_add_column2
|
199
|
+
@grid.add_column(["test1", "test2"], 0,1)
|
200
|
+
assert_equal(1, @grid.width)
|
201
|
+
assert_equal(3, @grid.height)
|
202
|
+
expected = '<TABLE cellspacing="0"><TR><TD> </TD></TR><TR><TD>test1</TD></TR><TR><TD>test2</TD></TR></TABLE>'
|
203
|
+
assert_equal(expected, @grid.to_html(CGI.new))
|
204
|
+
end
|
205
|
+
def test_add_column3
|
206
|
+
@grid.add_column(["test1", "test2"], 1,0)
|
207
|
+
assert_equal(2, @grid.width)
|
208
|
+
assert_equal(2, @grid.height)
|
209
|
+
expected = '<TABLE cellspacing="0"><TR><TD> </TD><TD>test1</TD></TR><TR><TD> </TD><TD>test2</TD></TR></TABLE>'
|
210
|
+
assert_equal(expected, @grid.to_html(CGI.new))
|
211
|
+
end
|
212
|
+
def test_add_tag1
|
213
|
+
@grid.add_tag('TH', 0, 0)
|
214
|
+
expected = '<TABLE cellspacing="0"><TR><TH> </TH></TR></TABLE>'
|
215
|
+
assert_equal(expected, @grid.to_html(CGI.new))
|
216
|
+
end
|
217
|
+
def test_add_tag2
|
218
|
+
@grid.add_tag('TH', 0, 0, 2)
|
219
|
+
expected = '<TABLE cellspacing="0"><TR><TH> </TH><TH> </TH></TR></TABLE>'
|
220
|
+
assert_equal(expected, @grid.to_html(CGI.new))
|
221
|
+
end
|
222
|
+
def test_add_tag3
|
223
|
+
@grid.add_tag('TH', 0, 0, 1, 2)
|
224
|
+
expected = '<TABLE cellspacing="0"><TR><TH> </TH></TR><TR><TH> </TH></TR></TABLE>'
|
225
|
+
assert_equal(expected, @grid.to_html(CGI.new))
|
226
|
+
end
|
227
|
+
def test_add_component_style
|
228
|
+
thing = StubGridComponent.new
|
229
|
+
@grid.add(thing, 1,1)
|
230
|
+
@grid.add_component_style('foobar', 0,0,2,2)
|
231
|
+
assert_equal('foobar', thing.attributes['class'])
|
232
|
+
end
|
233
|
+
def test_add_style
|
234
|
+
@grid.add_style('foo', 0,0)
|
235
|
+
expected = '<TABLE cellspacing="0"><TR><TD class="foo"> </TD></TR></TABLE>'
|
236
|
+
assert_equal(expected, @grid.to_html(CGI.new))
|
237
|
+
@grid.add(nil, 1,1)
|
238
|
+
@grid.add_style('bar', 0, 1, 2)
|
239
|
+
expected = '<TABLE cellspacing="0"><TR><TD class="foo"> </TD>'
|
240
|
+
expected << '<TD> </TD></TR><TR><TD class="bar"> </TD>'
|
241
|
+
expected << '<TD class="bar"> </TD></TR></TABLE>'
|
242
|
+
assert_equal(expected, @grid.to_html(CGI.new))
|
243
|
+
@grid.add_style('foobar', 0,0,2,2)
|
244
|
+
expected = '<TABLE cellspacing="0"><TR><TD class="foobar"> </TD>'
|
245
|
+
expected << '<TD class="foobar"> </TD></TR>'
|
246
|
+
expected << '<TR><TD class="foobar"> </TD>'
|
247
|
+
expected << '<TD class="foobar"> </TD></TR></TABLE>'
|
248
|
+
assert_equal(expected, @grid.to_html(CGI.new))
|
249
|
+
end
|
250
|
+
def test_add_attribute
|
251
|
+
@grid.add_attribute('foo', 'bar', 0, 0)
|
252
|
+
expected = '<TABLE cellspacing="0"><TR><TD foo="bar"> </TD></TR></TABLE>'
|
253
|
+
assert_equal(expected, @grid.to_html(CGI.new))
|
254
|
+
end
|
255
|
+
def test_set_colspan1
|
256
|
+
assert_nothing_raised { @grid.set_colspan(1,1,2) }
|
257
|
+
expected = '<TABLE cellspacing="0"><TR><TD> </TD><TD> </TD><TD> </TD></TR><TR><TD> </TD><TD colspan="2"> </TD></TR></TABLE>'
|
258
|
+
assert_equal(expected, @grid.to_html(CGI.new))
|
259
|
+
end
|
260
|
+
def test_set_colspan2
|
261
|
+
@grid.add("test", 2, 2)
|
262
|
+
assert_nothing_raised { @grid.set_colspan(0,0) }
|
263
|
+
expected = '<TABLE cellspacing="0"><TR><TD colspan="3"> </TD></TR><TR><TD> </TD><TD> </TD><TD> </TD></TR><TR><TD> </TD><TD> </TD><TD>test</TD></TR></TABLE>'
|
264
|
+
assert_equal(expected, @grid.to_html(CGI.new))
|
265
|
+
assert_nothing_raised { @grid.set_colspan(1,1) }
|
266
|
+
expected = '<TABLE cellspacing="0"><TR><TD colspan="3"> </TD></TR><TR><TD> </TD><TD colspan="2"> </TD></TR><TR><TD> </TD><TD> </TD><TD>test</TD></TR></TABLE>'
|
267
|
+
assert_equal(expected, @grid.to_html(CGI.new))
|
268
|
+
end
|
269
|
+
def test_push
|
270
|
+
@grid.add("bar",4,0)
|
271
|
+
@grid.push("foo")
|
272
|
+
expected = '<TABLE cellspacing="0"><TR><TD> </TD><TD> </TD>'
|
273
|
+
expected << '<TD> </TD><TD> </TD><TD>bar</TD></TR>'
|
274
|
+
expected << '<TR><TD colspan="5">foo</TD></TR></TABLE>'
|
275
|
+
assert_equal(expected, @grid.to_html(CGI.new))
|
276
|
+
end
|
277
|
+
def test_matrix
|
278
|
+
matrix = [1,1]
|
279
|
+
assert_nothing_raised {
|
280
|
+
@grid.add("test", *matrix)
|
281
|
+
}
|
282
|
+
expected = '<TABLE cellspacing="0"><TR><TD> </TD><TD> </TD></TR><TR><TD> </TD><TD>test</TD></TR></TABLE>'
|
283
|
+
assert_equal(expected, @grid.to_html(CGI.new))
|
284
|
+
end
|
285
|
+
def test_attributes
|
286
|
+
### this test has changed behavior: its not desirable to have magically
|
287
|
+
### transferred css information from a component to its container
|
288
|
+
@grid.add(StubGridComponent.new, 0,0)
|
289
|
+
expected = '<TABLE cellspacing="0"><TR><TD>bar</TD></TR></TABLE>'
|
290
|
+
assert_equal(expected, @grid.to_html(CGI.new))
|
291
|
+
end
|
292
|
+
def test_set_attribute1
|
293
|
+
@grid.set_attribute("foo", "bar")
|
294
|
+
expected = '<TABLE cellspacing="0" foo="bar"><TR><TD> </TD></TR></TABLE>'
|
295
|
+
assert_equal(expected, @grid.to_html(CGI.new))
|
296
|
+
end
|
297
|
+
def test_set_attribute2
|
298
|
+
@grid.set_attribute("foo", nil)
|
299
|
+
expected = '<TABLE cellspacing="0"><TR><TD> </TD></TR></TABLE>'
|
300
|
+
assert_equal(expected, @grid.to_html(CGI.new))
|
301
|
+
end
|
302
|
+
def test_set_attributes
|
303
|
+
hash = {"foo"=>"bar", "baz"=>"bash"}
|
304
|
+
@grid.set_attributes(hash)
|
305
|
+
expected = [
|
306
|
+
'<TABLE cellspacing="0" foo="bar" baz="bash"><TR><TD> </TD></TR></TABLE>',
|
307
|
+
'<TABLE cellspacing="0" baz="bash" foo="bar"><TR><TD> </TD></TR></TABLE>',
|
308
|
+
]
|
309
|
+
result = @grid.to_html(CGI.new)
|
310
|
+
assert_equal(true, expected.include?(result), result)
|
311
|
+
end
|
312
|
+
def test_set_row_attributes1
|
313
|
+
@grid.set_row_attributes({'foo' => 'bar'}, 0)
|
314
|
+
expected = '<TABLE cellspacing="0"><TR foo="bar"><TD> </TD></TR></TABLE>'
|
315
|
+
assert_equal(expected, @grid.to_html(CGI.new))
|
316
|
+
end
|
317
|
+
def test_set_row_attributes2
|
318
|
+
@grid.set_row_attributes({'foo' => 'bar'}, 1)
|
319
|
+
expected = '<TABLE cellspacing="0"><TR><TD> </TD></TR><TR foo="bar"><TD> </TD></TR></TABLE>'
|
320
|
+
assert_equal(expected, @grid.to_html(CGI.new))
|
321
|
+
end
|
322
|
+
def test_set_row_attributes3
|
323
|
+
@grid.set_row_attributes({'foo' => 'bar'}, 1, 2)
|
324
|
+
expected = '<TABLE cellspacing="0"><TR><TD> </TD></TR><TR foo="bar"><TD> </TD></TR><TR foo="bar"><TD> </TD></TR></TABLE>'
|
325
|
+
assert_equal(expected, @grid.to_html(CGI.new))
|
326
|
+
end
|
327
|
+
def test_insert_row
|
328
|
+
assert_equal(1, @grid.height)
|
329
|
+
@grid.add("testfeld", 0, 1)
|
330
|
+
assert_equal(2, @grid.height)
|
331
|
+
expected = '<TABLE cellspacing="0"><TR><TD> </TD></TR><TR><TD>testfeld</TD></TR></TABLE>'
|
332
|
+
assert_equal(expected, @grid.to_html(CGI.new))
|
333
|
+
@grid.insert_row(0, "testreihe")
|
334
|
+
assert_equal(3, @grid.height)
|
335
|
+
expected = '<TABLE cellspacing="0"><TR><TD>testreihe</TD></TR><TR><TD> </TD></TR><TR><TD>testfeld</TD></TR></TABLE>'
|
336
|
+
assert_equal(expected, @grid.to_html(CGI.new))
|
337
|
+
end
|
338
|
+
def test_gc
|
339
|
+
100.times { |y|
|
340
|
+
200.times { |x|
|
341
|
+
str = "[#{x}, #{y}]: test"
|
342
|
+
@grid.add(str, x, y)
|
343
|
+
@grid.add(str, x, y)
|
344
|
+
@grid.add(str, x, y)
|
345
|
+
@grid.add(str, x, y)
|
346
|
+
}
|
347
|
+
}
|
348
|
+
assert_equal(100, @grid.height)
|
349
|
+
assert_equal(200, @grid.width)
|
350
|
+
result = @grid.to_html(CGI.new)
|
351
|
+
end
|
352
|
+
def test_label
|
353
|
+
label = StubLabel.new
|
354
|
+
@grid.add(label, 0,0)
|
355
|
+
result = @grid.to_html(CGI.new)
|
356
|
+
assert_equal('<TABLE cellspacing="0"><TR><TD>foo</TD><TD>bar</TD></TR></TABLE>', result)
|
357
|
+
end
|
358
|
+
def test_field_attribute
|
359
|
+
@grid.add_attribute('foo', 'bar', 0, 0)
|
360
|
+
assert_equal('bar', @grid.field_attribute('foo', 0, 0))
|
361
|
+
end
|
362
|
+
def test_nil_attribute1
|
363
|
+
@grid.add_attribute('foo', nil, 0, 0)
|
364
|
+
assert_nothing_raised {
|
365
|
+
@grid.to_html(CGI.new)
|
366
|
+
}
|
367
|
+
end
|
368
|
+
def test_nil_attribute2
|
369
|
+
thing = StubGridComponent.new
|
370
|
+
thing.set_attribute("class", nil)
|
371
|
+
@grid.add(thing, 0,0)
|
372
|
+
assert_nothing_raised {
|
373
|
+
@grid.to_html(CGI.new)
|
374
|
+
}
|
375
|
+
end
|
376
|
+
def test_nil_component
|
377
|
+
thing = StubNilComponent.new
|
378
|
+
@grid.add(thing, 0,0)
|
379
|
+
assert_nothing_raised {
|
380
|
+
@grid.to_html(CGI.new)
|
381
|
+
}
|
382
|
+
end
|
383
|
+
def test_add_negative
|
384
|
+
assert_raises(ArgumentError) { @grid.add('foo', -1, 0) }
|
385
|
+
assert_raises(ArgumentError) { @grid.add('foo', 0, -1) }
|
386
|
+
assert_raises(ArgumentError) { @grid.add(['foo', 'bar'], -1, 0) }
|
387
|
+
assert_raises(ArgumentError) { @grid.add(['foo', 'bar'], 0, -1) }
|
388
|
+
end
|
389
|
+
def test_add_style_negative
|
390
|
+
assert_raises(ArgumentError) { @grid.add_style('bar', -1, 1) }
|
391
|
+
assert_raises(ArgumentError) { @grid.add_style('bar', 1, -1) }
|
392
|
+
assert_raises(ArgumentError) { @grid.add_style('bar', 1, 1, -1) }
|
393
|
+
assert_raises(ArgumentError) { @grid.add_style('bar', 1, 1, 1,-1) }
|
394
|
+
end
|
395
|
+
end
|
data/test/test_input.rb
ADDED
@@ -0,0 +1,70 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
#
|
3
|
+
# HtmlGrid -- HyperTextMarkupLanguage Framework
|
4
|
+
# Copyright (C) 2003 ywesee - intellectual capital connected
|
5
|
+
# Andreas Schrafl, Benjamin Fay, Hannes Wyss, Markus Huggler
|
6
|
+
#
|
7
|
+
# This library is free software; you can redistribute it and/or
|
8
|
+
# modify it under the terms of the GNU Lesser General Public
|
9
|
+
# License as published by the Free Software Foundation; either
|
10
|
+
# version 2.1 of the License, or (at your option) any later version.
|
11
|
+
#
|
12
|
+
# This library is distributed in the hope that it will be useful,
|
13
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
14
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
15
|
+
# Lesser General Public License for more details.
|
16
|
+
#
|
17
|
+
# You should have received a copy of the GNU Lesser General Public
|
18
|
+
# License along with this library; if not, write to the Free Software
|
19
|
+
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
20
|
+
#
|
21
|
+
# ywesee - intellectual capital connected, Winterthurerstrasse 52, CH-8006 Zuerich, Switzerland
|
22
|
+
# htmlgrid@ywesee.com, www.ywesee.com/htmlgrid
|
23
|
+
#
|
24
|
+
# TestInput -- htmlgrid -- 18.11.2002 -- hwyss@ywesee.com
|
25
|
+
|
26
|
+
$: << File.expand_path("../lib", File.dirname(__FILE__))
|
27
|
+
|
28
|
+
require 'test/unit'
|
29
|
+
require 'stub/cgi'
|
30
|
+
require 'htmlgrid/button'
|
31
|
+
require 'htmlgrid/inputcurrency'
|
32
|
+
|
33
|
+
class StubInputLookandfeel
|
34
|
+
def attributes(key)
|
35
|
+
{
|
36
|
+
"bar" => "roz",
|
37
|
+
}
|
38
|
+
end
|
39
|
+
def lookup(key)
|
40
|
+
'Foo'
|
41
|
+
end
|
42
|
+
def lookandfeel
|
43
|
+
self
|
44
|
+
end
|
45
|
+
def format_price(price)
|
46
|
+
sprintf('%.2f', price.to_f/100.0) if price.to_i > 0
|
47
|
+
end
|
48
|
+
end
|
49
|
+
class StubInputModel
|
50
|
+
def foo
|
51
|
+
1234
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
class TestInput < Test::Unit::TestCase
|
56
|
+
def test_input
|
57
|
+
input = HtmlGrid::Input.new(:foo, nil, StubInputLookandfeel.new)
|
58
|
+
assert_equal('<INPUT name="foo" value="" bar="roz">', input.to_html(CGI.new))
|
59
|
+
end
|
60
|
+
def test_button
|
61
|
+
input = HtmlGrid::Button.new(:foo, nil, StubInputLookandfeel.new)
|
62
|
+
assert_equal('<INPUT name="foo" type="button" value="Foo" bar="roz">', input.to_html(CGI.new))
|
63
|
+
end
|
64
|
+
end
|
65
|
+
class TestInputCurrency < Test::Unit::TestCase
|
66
|
+
def test_to_html
|
67
|
+
input = HtmlGrid::InputCurrency.new(:foo, StubInputModel.new, StubInputLookandfeel.new)
|
68
|
+
assert_equal('<INPUT name="foo" type="text" value="12.34" bar="roz">', input.to_html(CGI.new))
|
69
|
+
end
|
70
|
+
end
|
data/test/test_label.rb
ADDED
@@ -0,0 +1,116 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
#
|
3
|
+
# HtmlGrid -- HyperTextMarkupLanguage Framework
|
4
|
+
# Copyright (C) 2003 ywesee - intellectual capital connected
|
5
|
+
# Andreas Schrafl, Benjamin Fay, Hannes Wyss, Markus Huggler
|
6
|
+
#
|
7
|
+
# This library is free software; you can redistribute it and/or
|
8
|
+
# modify it under the terms of the GNU Lesser General Public
|
9
|
+
# License as published by the Free Software Foundation; either
|
10
|
+
# version 2.1 of the License, or (at your option) any later version.
|
11
|
+
#
|
12
|
+
# This library is distributed in the hope that it will be useful,
|
13
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
14
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
15
|
+
# Lesser General Public License for more details.
|
16
|
+
#
|
17
|
+
# You should have received a copy of the GNU Lesser General Public
|
18
|
+
# License along with this library; if not, write to the Free Software
|
19
|
+
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
20
|
+
#
|
21
|
+
# ywesee - intellectual capital connected, Winterthurerstrasse 52, CH-8006 Zuerich, Switzerland
|
22
|
+
# htmlgrid@ywesee.com, www.ywesee.com/htmlgrid
|
23
|
+
#
|
24
|
+
# TestLabel -- htmlgrid -- 26.11.2002 -- hwyss@ywesee.com
|
25
|
+
|
26
|
+
$: << File.dirname(__FILE__)
|
27
|
+
$: << File.expand_path("../lib", File.dirname(__FILE__))
|
28
|
+
|
29
|
+
require 'test/unit'
|
30
|
+
require 'stub/cgi'
|
31
|
+
require 'htmlgrid/label'
|
32
|
+
require 'htmlgrid/composite'
|
33
|
+
|
34
|
+
class TestLabel < Test::Unit::TestCase
|
35
|
+
class StubLabelState
|
36
|
+
attr_reader :errors
|
37
|
+
def initialize(errors={})
|
38
|
+
@errors = errors
|
39
|
+
end
|
40
|
+
end
|
41
|
+
class StubLabelModel
|
42
|
+
end
|
43
|
+
class StubLabelSession
|
44
|
+
attr_writer :state
|
45
|
+
def state
|
46
|
+
@state ||= StubLabelState.new
|
47
|
+
end
|
48
|
+
def lookup(key)
|
49
|
+
case key
|
50
|
+
when :componentname
|
51
|
+
'Label'
|
52
|
+
when :named_component
|
53
|
+
'Named Label'
|
54
|
+
end
|
55
|
+
end
|
56
|
+
def lookandfeel
|
57
|
+
self
|
58
|
+
end
|
59
|
+
def error(key)
|
60
|
+
state.errors[key]
|
61
|
+
end
|
62
|
+
end
|
63
|
+
class StubLabelComponent < HtmlGrid::Component
|
64
|
+
attr_accessor :mey
|
65
|
+
def to_html(context)
|
66
|
+
'component'
|
67
|
+
end
|
68
|
+
def label?
|
69
|
+
true
|
70
|
+
end
|
71
|
+
def name
|
72
|
+
:componentname
|
73
|
+
end
|
74
|
+
def css_class
|
75
|
+
@mey
|
76
|
+
end
|
77
|
+
end
|
78
|
+
class StubLabelComposite < HtmlGrid::Composite
|
79
|
+
COMPONENTS = {
|
80
|
+
[0,0] => StubLabelComponent,
|
81
|
+
[0,1] => :named_component,
|
82
|
+
}
|
83
|
+
LABELS = true
|
84
|
+
def named_component(model, session)
|
85
|
+
@named_component ||= StubLabelComponent.new(model, session, self)
|
86
|
+
end
|
87
|
+
end
|
88
|
+
def setup
|
89
|
+
@session = StubLabelSession.new
|
90
|
+
#@label = HtmlGrid::Label.new(component)
|
91
|
+
end
|
92
|
+
def test_to_html1
|
93
|
+
composite = StubLabelComposite.new(StubLabelModel.new, @session)
|
94
|
+
expected = '<TABLE cellspacing="0"><TR>'
|
95
|
+
expected << '<TD><LABEL for="componentname">Label</LABEL></TD>'
|
96
|
+
expected << '<TD>component</TD></TR>'
|
97
|
+
expected << '<TR><TD><LABEL for="componentname">Named Label</LABEL></TD>'
|
98
|
+
expected << '<TD>component</TD></TR></TABLE>'
|
99
|
+
assert_equal(expected, composite.to_html(CGI.new))
|
100
|
+
end
|
101
|
+
def test_to_html2
|
102
|
+
@session.state = StubLabelState.new({:named_component => 'ein Error'})
|
103
|
+
composite = StubLabelComposite.new(StubLabelModel.new, @session)
|
104
|
+
expected = '<TABLE cellspacing="0"><TR><TD><LABEL for="componentname">Label</LABEL></TD><TD>component</TD></TR><TR><TD><LABEL class="error" for="componentname">Named Label</LABEL></TD><TD>component</TD></TR></TABLE>'
|
105
|
+
assert_equal(expected, composite.to_html(CGI.new))
|
106
|
+
end
|
107
|
+
=begin
|
108
|
+
def test_to_html3
|
109
|
+
composite = StubLabelComposite.new(StubLabelModel.new, @session)
|
110
|
+
composite.named_component(nil, nil).mey = 'mey'
|
111
|
+
@session.state = StubLabelState.new({:named_component => 'ein Error'})
|
112
|
+
expected = '<TABLE cellspacing="0"><TR><TD><LABEL for="componentname">Label</LABEL></TD><TD>component</TD></TR><TR><TD><LABEL class="e-mey" for="componentname">Named Label</LABEL></TD><TD>component</TD></TR></TABLE>'
|
113
|
+
assert_equal(expected, composite.to_html(CGI.new))
|
114
|
+
end
|
115
|
+
=end
|
116
|
+
end
|