htmlgrid 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- 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
@@ -0,0 +1,138 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
#
|
3
|
+
# HtmlGrid -- HyperTextMarkupLanguage Framework
|
4
|
+
# Copyright (C) 2003 ywesee - intellectual capital connected
|
5
|
+
# Hannes Wyss
|
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
|
+
# TestComponent -- htmlgrid -- 26.11.2002 -- hwyss@ywesee.com
|
25
|
+
|
26
|
+
$: << File.expand_path("../lib", File.dirname(__FILE__))
|
27
|
+
$: << File.expand_path("../ext", File.dirname(__FILE__))
|
28
|
+
|
29
|
+
require 'test/unit'
|
30
|
+
require 'htmlgrid/component'
|
31
|
+
|
32
|
+
module HtmlGrid
|
33
|
+
class Component
|
34
|
+
attr_reader :model, :session, :container
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
class TestComponent < Test::Unit::TestCase
|
39
|
+
class StubAttributeComponent < HtmlGrid::Component
|
40
|
+
HTML_ATTRIBUTES = { "key" => "val" }
|
41
|
+
end
|
42
|
+
class StubInitComponent < HtmlGrid::Component
|
43
|
+
attr_reader :init_called
|
44
|
+
def init
|
45
|
+
@init_called = true
|
46
|
+
end
|
47
|
+
end
|
48
|
+
class StubLabelComponent < HtmlGrid::Component
|
49
|
+
LABEL = true
|
50
|
+
end
|
51
|
+
class StubContainer
|
52
|
+
attr_accessor :onsubmit
|
53
|
+
end
|
54
|
+
def setup
|
55
|
+
@component = HtmlGrid::Component.new(nil, nil)
|
56
|
+
end
|
57
|
+
def test_initialize1
|
58
|
+
assert_nothing_raised {
|
59
|
+
HtmlGrid::Component.new("foo", "bar")
|
60
|
+
}
|
61
|
+
comp = HtmlGrid::Component.new("foo", "bar")
|
62
|
+
assert_equal("foo", comp.model)
|
63
|
+
assert_equal("bar", comp.session)
|
64
|
+
assert_equal(nil, comp.container)
|
65
|
+
assert_equal(false, comp.label?)
|
66
|
+
assert_nothing_raised {
|
67
|
+
comp.label = true
|
68
|
+
}
|
69
|
+
assert_equal(true, comp.label?)
|
70
|
+
end
|
71
|
+
def test_initialize2
|
72
|
+
assert_nothing_raised {
|
73
|
+
HtmlGrid::Component.new("foo", "bar", "baz")
|
74
|
+
}
|
75
|
+
comp = HtmlGrid::Component.new("foo", "bar", "baz")
|
76
|
+
assert_equal("foo", comp.model)
|
77
|
+
assert_equal("bar", comp.session)
|
78
|
+
assert_equal("baz", comp.container)
|
79
|
+
end
|
80
|
+
def test_initialize3
|
81
|
+
comp = StubAttributeComponent.new("foo", "bar")
|
82
|
+
expected = { "key" => "val" }
|
83
|
+
assert_respond_to(comp, :attributes)
|
84
|
+
assert_equal(expected, comp.attributes)
|
85
|
+
assert_equal(expected, StubAttributeComponent::HTML_ATTRIBUTES)
|
86
|
+
assert_nothing_raised {
|
87
|
+
comp.attributes.store("other", "val")
|
88
|
+
}
|
89
|
+
expected2 = { "key" => "val", "other" => "val" }
|
90
|
+
assert_equal(expected2, comp.attributes)
|
91
|
+
assert_equal(expected, StubAttributeComponent::HTML_ATTRIBUTES)
|
92
|
+
assert_equal({}, @component.attributes)
|
93
|
+
assert_equal({}, HtmlGrid::Component::HTML_ATTRIBUTES)
|
94
|
+
assert_nothing_raised {
|
95
|
+
@component.attributes.store("third", "val")
|
96
|
+
}
|
97
|
+
expected = {"third"=>"val"}
|
98
|
+
assert_equal(expected, @component.attributes)
|
99
|
+
assert_equal({}, HtmlGrid::Component::HTML_ATTRIBUTES)
|
100
|
+
end
|
101
|
+
def test_initialize4
|
102
|
+
comp = StubInitComponent.new("foo", "bar")
|
103
|
+
assert_equal(true, comp.init_called)
|
104
|
+
end
|
105
|
+
def test_initialize5
|
106
|
+
comp = StubLabelComponent.new(nil, nil)
|
107
|
+
assert_equal(true, comp.label?)
|
108
|
+
end
|
109
|
+
def test_escape
|
110
|
+
txt = "Guten Tag! & wie gehts uns denn heute? '<' schlechter oder '>' besser?"
|
111
|
+
control = txt.dup
|
112
|
+
expected = "Guten Tag! & wie gehts uns denn heute? '<' schlechter oder '>' besser?"
|
113
|
+
assert_equal(expected, @component.escape(txt))
|
114
|
+
assert_equal(control, txt)
|
115
|
+
assert_equal(expected, @component.escape(txt))
|
116
|
+
end
|
117
|
+
def test_escape_symbols
|
118
|
+
txt = "\263"
|
119
|
+
expected = "≥"
|
120
|
+
assert_equal(expected, @component.escape_symbols(txt))
|
121
|
+
end
|
122
|
+
def test_onsubmit
|
123
|
+
@component.onsubmit = 'submitted'
|
124
|
+
assert_equal({}, @component.attributes)
|
125
|
+
cont = StubContainer.new
|
126
|
+
comp = HtmlGrid::Component.new("foo", "bar", cont)
|
127
|
+
comp.onsubmit = 'submitted'
|
128
|
+
assert_equal('submitted', cont.onsubmit)
|
129
|
+
end
|
130
|
+
def test_set_attribute
|
131
|
+
assert_equal({}, @component.attributes)
|
132
|
+
@component.set_attribute('href', 'http://www.ywesee.com')
|
133
|
+
expected = {
|
134
|
+
'href' => 'http://www.ywesee.com',
|
135
|
+
}
|
136
|
+
assert_equal(expected, @component.attributes)
|
137
|
+
end
|
138
|
+
end
|
@@ -0,0 +1,201 @@
|
|
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
|
+
# TestComposite -- htmlgrid -- 24.10.2002 -- hwyss@ywesee.com
|
25
|
+
|
26
|
+
$: << File.expand_path('../lib', File.dirname(__FILE__))
|
27
|
+
$: << File.dirname(__FILE__)
|
28
|
+
|
29
|
+
require 'test/unit'
|
30
|
+
require 'stub/cgi'
|
31
|
+
require 'htmlgrid/composite'
|
32
|
+
require 'htmlgrid/inputtext'
|
33
|
+
require 'htmlgrid/form'
|
34
|
+
|
35
|
+
class StubComposite < HtmlGrid::Composite
|
36
|
+
attr_writer :container
|
37
|
+
COMPONENTS = {
|
38
|
+
[0,0,0] => :baz,
|
39
|
+
[0,0,1] => :foo,
|
40
|
+
[0,0,2] => :baz,
|
41
|
+
[0,1,0] => :baz,
|
42
|
+
[0,1,1] => :baz,
|
43
|
+
}
|
44
|
+
LABELS = true
|
45
|
+
SYMBOL_MAP = {
|
46
|
+
:bar => HtmlGrid::InputText,
|
47
|
+
}
|
48
|
+
attr_reader :model, :session
|
49
|
+
public :resolve_offset, :labels?
|
50
|
+
def init
|
51
|
+
@barcount=0
|
52
|
+
super
|
53
|
+
end
|
54
|
+
def foo(model, lookandfeel)
|
55
|
+
"Foo"
|
56
|
+
end
|
57
|
+
def baz(model, lookandfeel)
|
58
|
+
@barcount += 1
|
59
|
+
"Baz#{@barcount}"
|
60
|
+
end
|
61
|
+
end
|
62
|
+
class StubCompositeComponent < HtmlGrid::Component
|
63
|
+
def to_html(context)
|
64
|
+
context.a(@attributes) { 'brafoo' }
|
65
|
+
end
|
66
|
+
end
|
67
|
+
class StubComposite2 < HtmlGrid::Composite
|
68
|
+
COMPONENTS = {
|
69
|
+
[0,0] => StubCompositeComponent,
|
70
|
+
}
|
71
|
+
end
|
72
|
+
class StubComposite3 < StubComposite2
|
73
|
+
COMPONENT_CSS_MAP = {[0,0,4,4]=>'standard'}
|
74
|
+
end
|
75
|
+
class StubComposite4 < StubComposite3
|
76
|
+
CSS_MAP = {[0,0]=>'dradnats'}
|
77
|
+
COMPONENT_CSS_MAP = {[0,0,4,4]=>'standard'}
|
78
|
+
end
|
79
|
+
class StubCompositeNoLabel < HtmlGrid::Composite
|
80
|
+
LABELS = false
|
81
|
+
COMPONENTS = {}
|
82
|
+
public :labels?
|
83
|
+
end
|
84
|
+
class StubCompositeModel
|
85
|
+
end
|
86
|
+
class StubCompositeLookandfeel
|
87
|
+
def attributes(key)
|
88
|
+
{}
|
89
|
+
end
|
90
|
+
def lookup(key)
|
91
|
+
end
|
92
|
+
def base_url
|
93
|
+
'http://www.oddb.org/de/gcc'
|
94
|
+
end
|
95
|
+
end
|
96
|
+
class StubCompositeSession
|
97
|
+
def lookandfeel
|
98
|
+
StubCompositeLookandfeel.new
|
99
|
+
end
|
100
|
+
def error(key)
|
101
|
+
end
|
102
|
+
end
|
103
|
+
class StubCompositeForm < HtmlGrid::Form
|
104
|
+
COMPONENTS = {
|
105
|
+
[0,0] => StubComposite
|
106
|
+
}
|
107
|
+
EVENT = :foo
|
108
|
+
end
|
109
|
+
class StubCompositeColspan1 < HtmlGrid::Composite
|
110
|
+
COMPONENTS = {}
|
111
|
+
end
|
112
|
+
class StubCompositeColspan2 < HtmlGrid::Composite
|
113
|
+
COMPONENTS = {
|
114
|
+
[0,0] => :foo,
|
115
|
+
}
|
116
|
+
end
|
117
|
+
class StubCompositeColspan3 < HtmlGrid::Composite
|
118
|
+
COMPONENTS = {
|
119
|
+
[0,0] => :foo,
|
120
|
+
[1,0] => :bar,
|
121
|
+
}
|
122
|
+
end
|
123
|
+
class StubCompositeColspan4 < HtmlGrid::Composite
|
124
|
+
COMPONENTS = {
|
125
|
+
[0,0] => :foo,
|
126
|
+
[2,0] => :bar,
|
127
|
+
}
|
128
|
+
end
|
129
|
+
|
130
|
+
class TestComposite < Test::Unit::TestCase
|
131
|
+
def setup
|
132
|
+
@composite = StubComposite.new(StubCompositeModel.new, StubCompositeSession.new)
|
133
|
+
end
|
134
|
+
def test_create_method
|
135
|
+
foo = nil
|
136
|
+
assert_nothing_raised {
|
137
|
+
foo = @composite.create(:foo, @composite.model)
|
138
|
+
}
|
139
|
+
assert_equal("Foo", foo)
|
140
|
+
end
|
141
|
+
def test_create_symbol
|
142
|
+
bar = nil
|
143
|
+
assert_nothing_raised {
|
144
|
+
bar = @composite.create(:bar, @composite.model)
|
145
|
+
}
|
146
|
+
assert_equal(HtmlGrid::InputText, bar.class)
|
147
|
+
end
|
148
|
+
def test_full_colspan1
|
149
|
+
composite = StubCompositeColspan1.new(StubCompositeModel.new, StubCompositeSession.new)
|
150
|
+
assert_nothing_raised { composite.full_colspan }
|
151
|
+
assert_equal(nil, composite.full_colspan)
|
152
|
+
end
|
153
|
+
def test_full_colspan2
|
154
|
+
composite = StubCompositeColspan2.new(StubCompositeModel.new, StubCompositeSession.new)
|
155
|
+
assert_nothing_raised { composite.full_colspan }
|
156
|
+
assert_equal(nil, composite.full_colspan)
|
157
|
+
end
|
158
|
+
def test_full_colspan3
|
159
|
+
composite = StubCompositeColspan3.new(StubCompositeModel.new, StubCompositeSession.new)
|
160
|
+
assert_nothing_raised { composite.full_colspan }
|
161
|
+
assert_equal(2, composite.full_colspan)
|
162
|
+
end
|
163
|
+
def test_full_colspan4
|
164
|
+
composite = StubCompositeColspan4.new(StubCompositeModel.new, StubCompositeSession.new)
|
165
|
+
assert_nothing_raised { composite.full_colspan }
|
166
|
+
assert_equal(3, composite.full_colspan)
|
167
|
+
end
|
168
|
+
def test_labels1
|
169
|
+
composite = StubCompositeNoLabel.new(StubCompositeModel.new, StubCompositeSession.new)
|
170
|
+
assert_equal(false, composite.labels?)
|
171
|
+
end
|
172
|
+
def test_labels2
|
173
|
+
assert_equal(true, @composite.labels?)
|
174
|
+
end
|
175
|
+
def test_to_html
|
176
|
+
expected = '<TABLE cellspacing="0"><TR><TD>Baz1FooBaz2</TD></TR><TR><TD>Baz3Baz4</TD></TR></TABLE>'
|
177
|
+
assert_equal(expected, @composite.to_html(CGI.new))
|
178
|
+
end
|
179
|
+
def test_resolve_offset
|
180
|
+
matrix = [1,2,3,4]
|
181
|
+
assert_equal(matrix, @composite.resolve_offset(matrix))
|
182
|
+
offset = [5,6]
|
183
|
+
expected = [6,8,3,4]
|
184
|
+
assert_equal(expected, @composite.resolve_offset(matrix, offset))
|
185
|
+
end
|
186
|
+
def test_event
|
187
|
+
assert_nothing_raised { @composite.event() }
|
188
|
+
form = StubCompositeForm.new(@composite.model, @composite.session)
|
189
|
+
@composite.container = form
|
190
|
+
assert_equal(:foo, @composite.event())
|
191
|
+
end
|
192
|
+
def test_component_css_map
|
193
|
+
composite = StubComposite2.new(StubCompositeModel.new, StubCompositeSession.new)
|
194
|
+
expected = '<TABLE cellspacing="0"><TR><TD><A>brafoo</A></TD></TR></TABLE>'
|
195
|
+
assert_equal(expected, composite.to_html(CGI.new))
|
196
|
+
composite = StubComposite3.new(StubCompositeModel.new, StubCompositeSession.new)
|
197
|
+
expected = '<TABLE cellspacing="0"><TR><TD><A class="standard">brafoo</A></TD></TR></TABLE>'
|
198
|
+
assert_equal(expected, composite.to_html(CGI.new))
|
199
|
+
composite = StubComposite4.new(StubCompositeModel.new, StubCompositeSession.new)
|
200
|
+
end
|
201
|
+
end
|
@@ -0,0 +1,60 @@
|
|
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
|
+
# TestDateValue -- htmlgrid -- 10.03.2003 -- hwyss@ywesee.com
|
25
|
+
|
26
|
+
$: << File.expand_path("../lib", File.dirname(__FILE__))
|
27
|
+
|
28
|
+
require 'test/unit'
|
29
|
+
require 'htmlgrid/datevalue'
|
30
|
+
require 'stub/cgi'
|
31
|
+
require 'date'
|
32
|
+
|
33
|
+
class StubDateLookandfeel
|
34
|
+
def lookup(key)
|
35
|
+
'%d.%m.%Y'
|
36
|
+
end
|
37
|
+
def attributes(key)
|
38
|
+
{}
|
39
|
+
end
|
40
|
+
end
|
41
|
+
class StubDateSession
|
42
|
+
def lookandfeel
|
43
|
+
StubDateLookandfeel.new
|
44
|
+
end
|
45
|
+
end
|
46
|
+
class StubDateProvider
|
47
|
+
def date
|
48
|
+
Date.new(2002,1,1)
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
class TestDateValue < Test::Unit::TestCase
|
53
|
+
def setup
|
54
|
+
@component = HtmlGrid::DateValue.new(:date, StubDateProvider.new,
|
55
|
+
StubDateSession.new)
|
56
|
+
end
|
57
|
+
def test_formatted
|
58
|
+
assert_equal('01.01.2002', @component.to_html(CGI.new))
|
59
|
+
end
|
60
|
+
end
|
data/test/test_form.rb
ADDED
@@ -0,0 +1,123 @@
|
|
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
|
+
# TestForm -- htmlgrid -- 25.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 'htmlgrid/form'
|
31
|
+
require 'stub/cgi'
|
32
|
+
|
33
|
+
class StubFormModel; end
|
34
|
+
class StubFormLookandfeel
|
35
|
+
def attributes(key)
|
36
|
+
{}
|
37
|
+
end
|
38
|
+
def base_url
|
39
|
+
'http://test.oddb.org/de/gcc'
|
40
|
+
end
|
41
|
+
def flavor
|
42
|
+
'gcc'
|
43
|
+
end
|
44
|
+
def language
|
45
|
+
'de'
|
46
|
+
end
|
47
|
+
def lookup(key)
|
48
|
+
'Submit-Value'
|
49
|
+
end
|
50
|
+
def lookandfeel
|
51
|
+
self
|
52
|
+
end
|
53
|
+
def state
|
54
|
+
0
|
55
|
+
end
|
56
|
+
end
|
57
|
+
class StubFormComponent < HtmlGrid::Component
|
58
|
+
def init
|
59
|
+
self.onsubmit = 'submitted'
|
60
|
+
end
|
61
|
+
end
|
62
|
+
class Form < HtmlGrid::Form
|
63
|
+
EVENT = :foo
|
64
|
+
COMPONENTS = {}
|
65
|
+
public :submit
|
66
|
+
end
|
67
|
+
class StubForm2 < HtmlGrid::Form
|
68
|
+
EVENT = :foo
|
69
|
+
COMPONENTS = {
|
70
|
+
[0,0] => StubFormComponent,
|
71
|
+
}
|
72
|
+
end
|
73
|
+
class StubFormMultiPart < HtmlGrid::Form
|
74
|
+
EVENT = :foo
|
75
|
+
COMPONENTS = {}
|
76
|
+
TAG_METHOD = :multipart_form
|
77
|
+
end
|
78
|
+
|
79
|
+
class TestForm < Test::Unit::TestCase
|
80
|
+
def setup
|
81
|
+
@model = StubFormModel.new
|
82
|
+
@lookandfeel = StubFormLookandfeel.new
|
83
|
+
@form = Form.new(@model, @lookandfeel)
|
84
|
+
end
|
85
|
+
def test_event
|
86
|
+
assert_equal(:foo, @form.event)
|
87
|
+
end
|
88
|
+
def test_multipart
|
89
|
+
form = StubFormMultiPart.new(@model, @lookandfeel)
|
90
|
+
result = form.to_html(CGI.new)
|
91
|
+
expected = '<FORM ACCEPT-CHARSET="ISO-8859-1" NAME="stdform" METHOD="POST" ENCTYPE="multipart/form-data" ACTION="http://test.oddb.org/de/gcc">'
|
92
|
+
assert_equal(0, result.index(expected), "expected\n#{result}\nto start with\n#{expected}")
|
93
|
+
end
|
94
|
+
def test_to_html
|
95
|
+
result = @form.to_html(CGI.new)
|
96
|
+
expected = [
|
97
|
+
'<INPUT NAME="flavor" TYPE="hidden" VALUE="gcc">',
|
98
|
+
'<INPUT NAME="language" TYPE="hidden" VALUE="de">',
|
99
|
+
'<INPUT NAME="event" TYPE="hidden" ID="event" VALUE="foo">',
|
100
|
+
'<INPUT NAME="state_id" TYPE="hidden" VALUE="1">',
|
101
|
+
]
|
102
|
+
expected.each { |line|
|
103
|
+
assert(result.index(line), "\nmissing #{line}\n in #{result}")
|
104
|
+
}
|
105
|
+
end
|
106
|
+
def test_submit
|
107
|
+
expected = '<INPUT name="foo" type="submit" value="Submit-Value">'
|
108
|
+
assert_equal(expected, @form.submit(@model, @lookandfeel).to_html(CGI.new))
|
109
|
+
end
|
110
|
+
def test_onsubmit
|
111
|
+
@form.onsubmit = 'submitted'
|
112
|
+
expected = 'onSubmit="submitted"'
|
113
|
+
result = /<FORM[^>]+>/.match(@form.to_html(CGI.new))[0]
|
114
|
+
assert(result.index(expected), "missing:\n#{expected}\nin:\n#{result}")
|
115
|
+
end
|
116
|
+
def test_onsubmit_init
|
117
|
+
form = nil
|
118
|
+
assert_nothing_raised { form = StubForm2.new(@model, @lookandfeel) }
|
119
|
+
expected = 'onSubmit="submitted"'
|
120
|
+
result = /<FORM[^>]+>/.match(form.to_html(CGI.new))[0]
|
121
|
+
assert(result.index(expected), "missing:\n#{expected}\nin:\n#{result}")
|
122
|
+
end
|
123
|
+
end
|
@@ -0,0 +1,111 @@
|
|
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
|
+
#TestFormList -- htmlgrid -- 25.03.2003 --aschrafl@ywesee.com
|
25
|
+
|
26
|
+
$: << File.dirname(__FILE__)
|
27
|
+
$: << File.expand_path("../lib", File.dirname(__FILE__))
|
28
|
+
|
29
|
+
require 'test/unit'
|
30
|
+
require 'htmlgrid/formlist'
|
31
|
+
require 'stub/cgi'
|
32
|
+
|
33
|
+
class StubFormList < HtmlGrid::FormList
|
34
|
+
attr_reader :model
|
35
|
+
COMPONENTS = {
|
36
|
+
[0,0] => :jaguar,
|
37
|
+
[1,0] => :panther,
|
38
|
+
}
|
39
|
+
CSS_MAP = {
|
40
|
+
[0,0] => 'flecken',
|
41
|
+
[1,0] => 'schwarz',
|
42
|
+
}
|
43
|
+
SORT_HEADER = false
|
44
|
+
SORT_DEFAULT = :foo
|
45
|
+
end
|
46
|
+
class StubFormListLookandfeel
|
47
|
+
def lookup(key)
|
48
|
+
key.to_s
|
49
|
+
end
|
50
|
+
def attributes(key)
|
51
|
+
{}
|
52
|
+
end
|
53
|
+
def base_url
|
54
|
+
"http://www.ywesee.com"
|
55
|
+
end
|
56
|
+
def event_url(event)
|
57
|
+
"http://www.ywesee.com/event"
|
58
|
+
end
|
59
|
+
def flavor
|
60
|
+
"strawberry"
|
61
|
+
end
|
62
|
+
def language
|
63
|
+
"de"
|
64
|
+
end
|
65
|
+
end
|
66
|
+
class StubFormListSession
|
67
|
+
attr_accessor :event
|
68
|
+
def lookandfeel
|
69
|
+
StubFormListLookandfeel.new
|
70
|
+
end
|
71
|
+
def state
|
72
|
+
0
|
73
|
+
end
|
74
|
+
end
|
75
|
+
class StubFormListModel
|
76
|
+
attr_reader :foo
|
77
|
+
def initialize(foo)
|
78
|
+
@foo = foo
|
79
|
+
end
|
80
|
+
def jaguar
|
81
|
+
'Jaguar'
|
82
|
+
end
|
83
|
+
def panther
|
84
|
+
'Panther'
|
85
|
+
end
|
86
|
+
end
|
87
|
+
|
88
|
+
class TestFormList < Test::Unit::TestCase
|
89
|
+
def setup
|
90
|
+
model = [
|
91
|
+
StubFormListModel.new(3),
|
92
|
+
StubFormListModel.new(2),
|
93
|
+
StubFormListModel.new(4),
|
94
|
+
StubFormListModel.new(1),
|
95
|
+
]
|
96
|
+
@list = StubFormList.new(model, StubFormListSession.new)
|
97
|
+
end
|
98
|
+
def test_to_html
|
99
|
+
result = @list.to_html(CGI.new)
|
100
|
+
[
|
101
|
+
'<FORM ACCEPT-CHARSET="ISO-8859-1" NAME="stdform" METHOD="POST" ENCTYPE="application/x-www-form-urlencoded" ACTION="http://www.ywesee.com">',
|
102
|
+
'<INPUT name="new_item" type="submit" value="new_item">',
|
103
|
+
'<INPUT NAME="flavor" TYPE="hidden" VALUE="strawberry">',
|
104
|
+
'<INPUT NAME="language" TYPE="hidden" VALUE="de">',
|
105
|
+
'<INPUT NAME="event" TYPE="hidden" ID="event" VALUE="new_item">',
|
106
|
+
'<INPUT NAME="state_id" TYPE="hidden" VALUE="1">',
|
107
|
+
].each { |expected|
|
108
|
+
assert_not_nil(result.index(expected), "missing:\n#{expected}\nin:\n#{result}")
|
109
|
+
}
|
110
|
+
end
|
111
|
+
end
|