htmlgrid 1.2.0 → 1.2.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (70) hide show
  1. checksums.yaml +4 -4
  2. data/lib/htmlgrid/booleanvalue.rb +14 -14
  3. data/lib/htmlgrid/button.rb +9 -9
  4. data/lib/htmlgrid/centeredcomposite.rb +21 -20
  5. data/lib/htmlgrid/component.rb +214 -199
  6. data/lib/htmlgrid/composite.rb +332 -301
  7. data/lib/htmlgrid/datevalue.rb +12 -12
  8. data/lib/htmlgrid/div.rb +9 -9
  9. data/lib/htmlgrid/divcomposite.rb +44 -43
  10. data/lib/htmlgrid/divform.rb +8 -8
  11. data/lib/htmlgrid/divlist.rb +17 -19
  12. data/lib/htmlgrid/divtemplate.rb +6 -6
  13. data/lib/htmlgrid/dojotoolkit.rb +54 -48
  14. data/lib/htmlgrid/errormessage.rb +47 -43
  15. data/lib/htmlgrid/form.rb +70 -62
  16. data/lib/htmlgrid/formlist.rb +14 -14
  17. data/lib/htmlgrid/grid.rb +111 -67
  18. data/lib/htmlgrid/image.rb +17 -16
  19. data/lib/htmlgrid/infomessage.rb +15 -14
  20. data/lib/htmlgrid/input.rb +34 -32
  21. data/lib/htmlgrid/inputcheckbox.rb +13 -13
  22. data/lib/htmlgrid/inputcurrency.rb +9 -9
  23. data/lib/htmlgrid/inputdate.rb +11 -11
  24. data/lib/htmlgrid/inputfile.rb +13 -12
  25. data/lib/htmlgrid/inputradio.rb +9 -9
  26. data/lib/htmlgrid/inputtext.rb +10 -10
  27. data/lib/htmlgrid/javascript.rb +17 -16
  28. data/lib/htmlgrid/label.rb +53 -49
  29. data/lib/htmlgrid/labeltext.rb +8 -8
  30. data/lib/htmlgrid/link.rb +31 -27
  31. data/lib/htmlgrid/list.rb +121 -110
  32. data/lib/htmlgrid/namedcomponent.rb +28 -25
  33. data/lib/htmlgrid/pass.rb +11 -11
  34. data/lib/htmlgrid/passthru.rb +20 -17
  35. data/lib/htmlgrid/popuplink.rb +41 -39
  36. data/lib/htmlgrid/reset.rb +8 -8
  37. data/lib/htmlgrid/richtext.rb +22 -20
  38. data/lib/htmlgrid/select.rb +28 -26
  39. data/lib/htmlgrid/span.rb +9 -9
  40. data/lib/htmlgrid/spancomposite.rb +18 -18
  41. data/lib/htmlgrid/spanlist.rb +9 -9
  42. data/lib/htmlgrid/staticinput.rb +14 -13
  43. data/lib/htmlgrid/submit.rb +9 -9
  44. data/lib/htmlgrid/template.rb +120 -105
  45. data/lib/htmlgrid/text.rb +9 -9
  46. data/lib/htmlgrid/textarea.rb +19 -17
  47. data/lib/htmlgrid/ulcomposite.rb +22 -22
  48. data/lib/htmlgrid/ullist.rb +9 -9
  49. data/lib/htmlgrid/urllink.rb +38 -36
  50. data/lib/htmlgrid/value.rb +9 -9
  51. data/lib/htmlgrid/version.rb +2 -2
  52. data/test/stub/cgi.rb +10 -7
  53. data/test/suite.rb +3 -3
  54. data/test/test_add_row.rb +12 -13
  55. data/test/test_component.rb +121 -100
  56. data/test/test_composite.rb +85 -46
  57. data/test/test_datevalue.rb +28 -24
  58. data/test/test_divlist.rb +126 -0
  59. data/test/test_dojotoolkit.rb +41 -27
  60. data/test/test_form.rb +89 -73
  61. data/test/test_formlist.rb +77 -65
  62. data/test/test_grid.rb +256 -208
  63. data/test/test_input.rb +37 -31
  64. data/test/test_interaction_list.rb +106 -70
  65. data/test/test_label.rb +91 -77
  66. data/test/test_list.rb +110 -95
  67. data/test/test_select.rb +35 -30
  68. data/test/test_template.rb +63 -55
  69. data/test/test_text.rb +36 -31
  70. metadata +17 -2
@@ -21,92 +21,104 @@
21
21
  # ywesee - intellectual capital connected, Winterthurerstrasse 52, CH-8006 Zuerich, Switzerland
22
22
  # htmlgrid@ywesee.com, www.ywesee.com/htmlgrid
23
23
  #
24
- #TestFormList -- htmlgrid -- 25.03.2003 --aschrafl@ywesee.com
24
+ # TestFormList -- htmlgrid -- 25.03.2003 --aschrafl@ywesee.com
25
25
 
26
26
  $: << File.dirname(__FILE__)
27
27
  $: << File.expand_path("../lib", File.dirname(__FILE__))
28
28
 
29
- require 'minitest/autorun'
30
- require 'htmlgrid/formlist'
31
- require 'stub/cgi'
29
+ require "minitest/autorun"
30
+ require "htmlgrid/formlist"
31
+ require "stub/cgi"
32
32
 
33
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
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
45
  end
46
+
46
47
  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
48
+ def lookup(key)
49
+ key.to_s
50
+ end
51
+
52
+ def attributes(key)
53
+ {}
54
+ end
55
+
56
+ def base_url
57
+ "http://www.ywesee.com"
58
+ end
59
+
60
+ def event_url(event)
61
+ "http://www.ywesee.com/event"
62
+ end
63
+
64
+ def flavor
65
+ "strawberry"
66
+ end
67
+
68
+ def language
69
+ "de"
70
+ end
65
71
  end
72
+
66
73
  class StubFormListSession
67
- attr_accessor :event
68
- def lookandfeel
69
- StubFormListLookandfeel.new
70
- end
71
- def state
72
- 0
73
- end
74
+ attr_accessor :event
75
+ def lookandfeel
76
+ StubFormListLookandfeel.new
77
+ end
78
+
79
+ def state
80
+ 0
81
+ end
74
82
  end
83
+
75
84
  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
85
+ attr_reader :foo
86
+ def initialize(foo)
87
+ @foo = foo
88
+ end
89
+
90
+ def jaguar
91
+ "Jaguar"
92
+ end
93
+
94
+ def panther
95
+ "Panther"
96
+ end
86
97
  end
87
98
 
88
99
  class TestFormList < Minitest::Test
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
+ def setup
101
+ model = [
102
+ StubFormListModel.new(3),
103
+ StubFormListModel.new(2),
104
+ StubFormListModel.new(4),
105
+ StubFormListModel.new(1)
106
+ ]
107
+ @list = StubFormList.new(model, StubFormListSession.new)
108
+ end
109
+
110
+ def test_to_html
111
+ result = @list.to_html(CGI.new)
100
112
  expectations = [
101
113
  '<INPUT value="new_item" type="submit" name="new_item">',
102
114
  '<INPUT TYPE="hidden" NAME="flavor" VALUE="strawberry">',
103
115
  '<INPUT TYPE="hidden" NAME="language" VALUE="de">',
104
116
  '<INPUT NAME="event" ID="event" VALUE="new_item" TYPE="hidden">',
105
117
  '<FORM NAME="stdform" METHOD="POST" ACTION="http://www.ywesee.com" ACCEPT-CHARSET="UTF-8" ENCTYPE="application/x-www-form-urlencoded">',
106
- '<INPUT TYPE="hidden" NAME="state_id" VALUE="1">',
118
+ '<INPUT TYPE="hidden" NAME="state_id" VALUE="1">'
107
119
  ]
108
120
  expectations.each_with_index { |expected, idx|
109
- refute_nil(result.index(expected), "#{idx} missing:\n#{expected}\nin:\n#{result}")
110
- }
111
- end
121
+ refute_nil(result.index(expected), "#{idx} missing:\n#{expected}\nin:\n#{result}")
122
+ }
123
+ end
112
124
  end
data/test/test_grid.rb CHANGED
@@ -27,53 +27,62 @@ $: << File.expand_path("../lib", File.dirname(__FILE__))
27
27
  $: << File.expand_path("../ext", File.dirname(__FILE__))
28
28
  $: << File.dirname(__FILE__)
29
29
 
30
- require 'minitest/autorun'
31
- require 'stub/cgi'
32
- require 'htmlgrid/label'
33
- require 'htmlgrid/grid'
34
- require 'test_helper'
30
+ require "minitest/autorun"
31
+ require "stub/cgi"
32
+ require "htmlgrid/label"
33
+ require "htmlgrid/grid"
34
+ require "test_helper"
35
35
 
36
36
  class TestGrid < Minitest::Test
37
- class StubLabel
38
- include Enumerable
39
- def each
40
- yield "foo"
41
- yield "bar"
42
- end
43
- def to_html(cgi)
44
- "foo"
45
- end
46
- end
47
- class StubGridComponent
48
- attr_reader :attributes
49
- def initialize
50
- @attributes = {"class" => "foo"}
51
- end
52
- def to_html(context)
53
- "bar"
54
- end
55
- def set_attribute(key, value)
56
- @attributes.store(key, value)
57
- end
58
- end
59
- class StubNilComponent
60
- attr_reader :attributes
61
- def initialize
62
- @attributes = {}
63
- end
64
- def to_html(context)
65
- nil
66
- end
67
- end
37
+ class StubLabel
38
+ include Enumerable
39
+ def each
40
+ yield "foo"
41
+ yield "bar"
42
+ end
43
+
44
+ def to_html(cgi)
45
+ "foo"
46
+ end
47
+ end
48
+
49
+ class StubGridComponent
50
+ attr_reader :attributes
51
+ def initialize
52
+ @attributes = {"class" => "foo"}
53
+ end
54
+
55
+ def to_html(context)
56
+ "bar"
57
+ end
58
+
59
+ def set_attribute(key, value)
60
+ @attributes.store(key, value)
61
+ end
62
+ end
63
+
64
+ class StubNilComponent
65
+ attr_reader :attributes
66
+ def initialize
67
+ @attributes = {}
68
+ end
69
+
70
+ def to_html(context)
71
+ nil
72
+ end
73
+ end
74
+
68
75
  def setup
69
76
  @grid = HtmlGrid::Grid.new
70
77
  end
78
+
71
79
  def test_initialize
72
80
  assert_equal(1, @grid.width)
73
81
  assert_equal(1, @grid.height)
74
82
  expected = '<TABLE cellspacing="0"><TR><TD>&nbsp;</TD></TR></TABLE>'
75
- assert_equal(expected, @grid.to_html(CGI.new))
83
+ assert_equal(expected, @grid.to_html(CGI.new))
76
84
  end
85
+
77
86
  def test_add
78
87
  @grid.add("test", 0, 0)
79
88
  assert_equal(1, @grid.width)
@@ -81,6 +90,7 @@ class TestGrid < Minitest::Test
81
90
  expected = '<TABLE cellspacing="0"><TR><TD>test</TD></TR></TABLE>'
82
91
  assert_equal(expected, @grid.to_html(CGI.new))
83
92
  end
93
+
84
94
  def test_add2
85
95
  @grid.add(nil, 0, 0)
86
96
  @grid.add(nil, 0, 0)
@@ -89,6 +99,7 @@ class TestGrid < Minitest::Test
89
99
  expected = '<TABLE cellspacing="0"><TR><TD>&nbsp;</TD></TR></TABLE>'
90
100
  assert_equal(expected, @grid.to_html(CGI.new))
91
101
  end
102
+
92
103
  def test_add3
93
104
  @grid.add(2, 0, 0)
94
105
  assert_equal(1, @grid.width)
@@ -96,6 +107,7 @@ class TestGrid < Minitest::Test
96
107
  expected = '<TABLE cellspacing="0"><TR><TD>2</TD></TR></TABLE>'
97
108
  assert_equal(expected, @grid.to_html(CGI.new))
98
109
  end
110
+
99
111
  def test_add_field
100
112
  @grid.add_field("test", 0, 0)
101
113
  assert_equal(1, @grid.width)
@@ -103,30 +115,34 @@ class TestGrid < Minitest::Test
103
115
  expected = '<TABLE cellspacing="0"><TR><TD>test</TD></TR></TABLE>'
104
116
  assert_equal(expected, @grid.to_html(CGI.new))
105
117
  end
106
- def test_add_multiple
107
- @grid.add("test", 0, 0)
118
+
119
+ def test_add_multiple
120
+ @grid.add("test", 0, 0)
108
121
  assert_equal(1, @grid.width)
109
122
  assert_equal(1, @grid.height)
110
- @grid.add("foo", 0, 0)
123
+ @grid.add("foo", 0, 0)
111
124
  assert_equal(1, @grid.width)
112
125
  assert_equal(1, @grid.height)
113
126
  expected = '<TABLE cellspacing="0"><TR><TD>testfoo</TD></TR></TABLE>'
114
127
  assert_equal(expected, @grid.to_html(CGI.new))
115
- end
116
- def test_add_multiple__2
117
- @grid.add(["test", "foo"], 0, 0)
128
+ end
129
+
130
+ def test_add_multiple__2
131
+ @grid.add(["test", "foo"], 0, 0)
118
132
  assert_equal(1, @grid.width)
119
133
  assert_equal(1, @grid.height)
120
134
  expected = '<TABLE cellspacing="0"><TR><TD>testfoo</TD></TR></TABLE>'
121
135
  assert_equal(expected, @grid.to_html(CGI.new))
122
- end
123
- def test_add_multiple__3
124
- @grid.add(["test", nil, "foo"], 0, 0)
136
+ end
137
+
138
+ def test_add_multiple__3
139
+ @grid.add(["test", nil, "foo"], 0, 0)
125
140
  assert_equal(1, @grid.height)
126
141
  expected = '<TABLE cellspacing="0"><TR><TD>testfoo</TD></TR></TABLE>'
127
142
  assert_equal(expected, @grid.to_html(CGI.new))
128
143
  assert_equal(1, @grid.width)
129
- end
144
+ end
145
+
130
146
  def test_add_fieldx
131
147
  @grid.add("test", 1, 0)
132
148
  assert_equal(2, @grid.width)
@@ -134,6 +150,7 @@ class TestGrid < Minitest::Test
134
150
  expected = '<TABLE cellspacing="0"><TR><TD>&nbsp;</TD><TD>test</TD></TR></TABLE>'
135
151
  assert_equal(expected, @grid.to_html(CGI.new))
136
152
  end
153
+
137
154
  def test_add_fieldy
138
155
  @grid.add("test", 0, 1)
139
156
  assert_equal(1, @grid.width)
@@ -141,6 +158,7 @@ class TestGrid < Minitest::Test
141
158
  expected = '<TABLE cellspacing="0"><TR><TD>&nbsp;</TD></TR><TR><TD>test</TD></TR></TABLE>'
142
159
  assert_equal(expected, @grid.to_html(CGI.new))
143
160
  end
161
+
144
162
  def test_add_fieldxy
145
163
  @grid.add("test", 1, 1)
146
164
  assert_equal(2, @grid.width)
@@ -148,6 +166,7 @@ class TestGrid < Minitest::Test
148
166
  expected = '<TABLE cellspacing="0"><TR><TD>&nbsp;</TD><TD>&nbsp;</TD></TR><TR><TD>&nbsp;</TD><TD>test</TD></TR></TABLE>'
149
167
  assert_equal(expected, @grid.to_html(CGI.new))
150
168
  end
169
+
151
170
  def test_add_fieldyx
152
171
  @grid.add("test", 0, 1)
153
172
  @grid.add("test", 1, 0)
@@ -155,174 +174,197 @@ class TestGrid < Minitest::Test
155
174
  assert_equal(2, @grid.height)
156
175
  expected = '<TABLE cellspacing="0"><TR><TD>&nbsp;</TD><TD>test</TD></TR><TR><TD>test</TD><TD>&nbsp;</TD></TR></TABLE>'
157
176
  assert_equal(expected, @grid.to_html(CGI.new))
158
-
159
177
  end
178
+
160
179
  def test_add_row1
161
- @grid.add_row(["test1", "test2"], 0,0)
180
+ @grid.add_row(["test1", "test2"], 0, 0)
162
181
  assert_equal(2, @grid.width)
163
182
  assert_equal(1, @grid.height)
164
183
  expected = '<TABLE cellspacing="0"><TR><TD>test1</TD><TD>test2</TD></TR></TABLE>'
165
184
  assert_equal(expected, @grid.to_html(CGI.new))
166
185
  end
186
+
167
187
  def test_add_row2
168
- @grid.add_row(["test1", "test2"], 0,1)
188
+ @grid.add_row(["test1", "test2"], 0, 1)
169
189
  assert_equal(2, @grid.width)
170
190
  assert_equal(2, @grid.height)
171
191
  expected = '<TABLE cellspacing="0"><TR><TD>&nbsp;</TD><TD>&nbsp;</TD></TR><TR><TD>test1</TD><TD>test2</TD></TR></TABLE>'
172
192
  assert_equal(expected, @grid.to_html(CGI.new))
173
193
  end
194
+
174
195
  def test_add_row3
175
- @grid.add_row(["test1", "test2"], 1,0)
196
+ @grid.add_row(["test1", "test2"], 1, 0)
176
197
  assert_equal(3, @grid.width)
177
198
  assert_equal(1, @grid.height)
178
199
  expected = '<TABLE cellspacing="0"><TR><TD>&nbsp;</TD><TD>test1</TD><TD>test2</TD></TR></TABLE>'
179
200
  assert_equal(expected, @grid.to_html(CGI.new))
180
201
  end
202
+
181
203
  def test_add_column1
182
- @grid.add_column(["test1", "test2"], 0,0)
204
+ @grid.add_column(["test1", "test2"], 0, 0)
183
205
  assert_equal(1, @grid.width)
184
206
  assert_equal(2, @grid.height)
185
207
  expected = '<TABLE cellspacing="0"><TR><TD>test1</TD></TR><TR><TD>test2</TD></TR></TABLE>'
186
208
  assert_equal(expected, @grid.to_html(CGI.new))
187
209
  end
210
+
188
211
  def test_add_column2
189
- @grid.add_column(["test1", "test2"], 0,1)
212
+ @grid.add_column(["test1", "test2"], 0, 1)
190
213
  assert_equal(1, @grid.width)
191
214
  assert_equal(3, @grid.height)
192
215
  expected = '<TABLE cellspacing="0"><TR><TD>&nbsp;</TD></TR><TR><TD>test1</TD></TR><TR><TD>test2</TD></TR></TABLE>'
193
216
  assert_equal(expected, @grid.to_html(CGI.new))
194
217
  end
218
+
195
219
  def test_add_column3
196
- @grid.add_column(["test1", "test2"], 1,0)
220
+ @grid.add_column(["test1", "test2"], 1, 0)
197
221
  assert_equal(2, @grid.width)
198
222
  assert_equal(2, @grid.height)
199
223
  expected = '<TABLE cellspacing="0"><TR><TD>&nbsp;</TD><TD>test1</TD></TR><TR><TD>&nbsp;</TD><TD>test2</TD></TR></TABLE>'
200
224
  assert_equal(expected, @grid.to_html(CGI.new))
201
225
  end
202
- def test_add_tag1
203
- @grid.add_tag('TH', 0, 0)
204
- expected = '<TABLE cellspacing="0"><TR><TH>&nbsp;</TH></TR></TABLE>'
205
- assert_equal(expected, @grid.to_html(CGI.new))
206
- end
207
- def test_add_tag2
208
- @grid.add_tag('TH', 0, 0, 2)
209
- expected = '<TABLE cellspacing="0"><TR><TH>&nbsp;</TH><TH>&nbsp;</TH></TR></TABLE>'
210
- assert_equal(expected, @grid.to_html(CGI.new))
211
- end
212
- def test_add_tag3
213
- @grid.add_tag('TH', 0, 0, 1, 2)
214
- expected = '<TABLE cellspacing="0"><TR><TH>&nbsp;</TH></TR><TR><TH>&nbsp;</TH></TR></TABLE>'
215
- assert_equal(expected, @grid.to_html(CGI.new))
216
- end
217
- def test_add_component_style
218
- thing = StubGridComponent.new
219
- @grid.add(thing, 1,1)
220
- @grid.add_component_style('foobar', 0,0,2,2)
221
- assert_equal('foobar', thing.attributes['class'])
222
- end
223
- def test_add_style
224
- @grid.add_style('foo', 0,0)
225
- expected = '<TABLE cellspacing="0"><TR><TD class="foo">&nbsp;</TD></TR></TABLE>'
226
- assert_equal(expected, @grid.to_html(CGI.new))
227
- @grid.add(nil, 1,1)
228
- @grid.add_style('bar', 0, 1, 2)
229
- expected = '<TABLE cellspacing="0"><TR><TD class="foo">&nbsp;</TD>'
230
- expected << '<TD>&nbsp;</TD></TR><TR><TD class="bar">&nbsp;</TD>'
231
- expected << '<TD class="bar">&nbsp;</TD></TR></TABLE>'
232
- assert_equal(expected, @grid.to_html(CGI.new))
233
- @grid.add_style('foobar', 0,0,2,2)
234
- expected = '<TABLE cellspacing="0"><TR><TD class="foobar">&nbsp;</TD>'
235
- expected << '<TD class="foobar">&nbsp;</TD></TR>'
236
- expected << '<TR><TD class="foobar">&nbsp;</TD>'
237
- expected << '<TD class="foobar">&nbsp;</TD></TR></TABLE>'
238
- assert_equal(expected, @grid.to_html(CGI.new))
239
- end
240
- def test_add_attribute
241
- @grid.add_attribute('foo', 'bar', 0, 0)
242
- expected = '<TABLE cellspacing="0"><TR><TD foo="bar">&nbsp;</TD></TR></TABLE>'
243
- assert_equal(expected, @grid.to_html(CGI.new))
244
- end
245
- def test_set_colspan1
246
- @grid.set_colspan(1,1,2)
247
- expected = '<TABLE cellspacing="0"><TR><TD>&nbsp;</TD><TD>&nbsp;</TD><TD>&nbsp;</TD></TR><TR><TD>&nbsp;</TD><TD colspan="2">&nbsp;</TD></TR></TABLE>'
248
- assert_equal(expected, @grid.to_html(CGI.new))
249
- end
250
- def test_set_colspan2
226
+
227
+ def test_add_tag1
228
+ @grid.add_tag("TH", 0, 0)
229
+ expected = '<TABLE cellspacing="0"><TR><TH>&nbsp;</TH></TR></TABLE>'
230
+ assert_equal(expected, @grid.to_html(CGI.new))
231
+ end
232
+
233
+ def test_add_tag2
234
+ @grid.add_tag("TH", 0, 0, 2)
235
+ expected = '<TABLE cellspacing="0"><TR><TH>&nbsp;</TH><TH>&nbsp;</TH></TR></TABLE>'
236
+ assert_equal(expected, @grid.to_html(CGI.new))
237
+ end
238
+
239
+ def test_add_tag3
240
+ @grid.add_tag("TH", 0, 0, 1, 2)
241
+ expected = '<TABLE cellspacing="0"><TR><TH>&nbsp;</TH></TR><TR><TH>&nbsp;</TH></TR></TABLE>'
242
+ assert_equal(expected, @grid.to_html(CGI.new))
243
+ end
244
+
245
+ def test_add_component_style
246
+ thing = StubGridComponent.new
247
+ @grid.add(thing, 1, 1)
248
+ @grid.add_component_style("foobar", 0, 0, 2, 2)
249
+ assert_equal("foobar", thing.attributes["class"])
250
+ end
251
+
252
+ def test_add_style
253
+ @grid.add_style("foo", 0, 0)
254
+ expected = '<TABLE cellspacing="0"><TR><TD class="foo">&nbsp;</TD></TR></TABLE>'
255
+ assert_equal(expected, @grid.to_html(CGI.new))
256
+ @grid.add(nil, 1, 1)
257
+ @grid.add_style("bar", 0, 1, 2)
258
+ expected = '<TABLE cellspacing="0"><TR><TD class="foo">&nbsp;</TD>'
259
+ expected << '<TD>&nbsp;</TD></TR><TR><TD class="bar">&nbsp;</TD>'
260
+ expected << '<TD class="bar">&nbsp;</TD></TR></TABLE>'
261
+ assert_equal(expected, @grid.to_html(CGI.new))
262
+ @grid.add_style("foobar", 0, 0, 2, 2)
263
+ expected = '<TABLE cellspacing="0"><TR><TD class="foobar">&nbsp;</TD>'
264
+ expected << '<TD class="foobar">&nbsp;</TD></TR>'
265
+ expected << '<TR><TD class="foobar">&nbsp;</TD>'
266
+ expected << '<TD class="foobar">&nbsp;</TD></TR></TABLE>'
267
+ assert_equal(expected, @grid.to_html(CGI.new))
268
+ end
269
+
270
+ def test_add_attribute
271
+ @grid.add_attribute("foo", "bar", 0, 0)
272
+ expected = '<TABLE cellspacing="0"><TR><TD foo="bar">&nbsp;</TD></TR></TABLE>'
273
+ assert_equal(expected, @grid.to_html(CGI.new))
274
+ end
275
+
276
+ def test_set_colspan1
277
+ @grid.set_colspan(1, 1, 2)
278
+ expected = '<TABLE cellspacing="0"><TR><TD>&nbsp;</TD><TD>&nbsp;</TD><TD>&nbsp;</TD></TR><TR><TD>&nbsp;</TD><TD colspan="2">&nbsp;</TD></TR></TABLE>'
279
+ assert_equal(expected, @grid.to_html(CGI.new))
280
+ end
281
+
282
+ def test_set_colspan2
251
283
  @grid.add("test", 2, 2)
252
- @grid.set_colspan(0,0)
253
- expected = '<TABLE cellspacing="0"><TR><TD colspan="3">&nbsp;</TD></TR><TR><TD>&nbsp;</TD><TD>&nbsp;</TD><TD>&nbsp;</TD></TR><TR><TD>&nbsp;</TD><TD>&nbsp;</TD><TD>test</TD></TR></TABLE>'
254
- assert_equal(expected, @grid.to_html(CGI.new))
255
- @grid.set_colspan(1,1)
256
- expected = '<TABLE cellspacing="0"><TR><TD colspan="3">&nbsp;</TD></TR><TR><TD>&nbsp;</TD><TD colspan="2">&nbsp;</TD></TR><TR><TD>&nbsp;</TD><TD>&nbsp;</TD><TD>test</TD></TR></TABLE>'
257
- assert_equal(expected, @grid.to_html(CGI.new))
258
- end
259
- def test_push
260
- @grid.add("bar",4,0)
261
- @grid.push("foo")
262
- expected = '<TABLE cellspacing="0"><TR><TD>&nbsp;</TD><TD>&nbsp;</TD>'
263
- expected << '<TD>&nbsp;</TD><TD>&nbsp;</TD><TD>bar</TD></TR>'
264
- expected << '<TR><TD colspan="5">foo</TD></TR></TABLE>'
265
- assert_equal(expected, @grid.to_html(CGI.new))
266
- end
267
- def test_matrix
268
- matrix = [1,1]
284
+ @grid.set_colspan(0, 0)
285
+ expected = '<TABLE cellspacing="0"><TR><TD colspan="3">&nbsp;</TD></TR><TR><TD>&nbsp;</TD><TD>&nbsp;</TD><TD>&nbsp;</TD></TR><TR><TD>&nbsp;</TD><TD>&nbsp;</TD><TD>test</TD></TR></TABLE>'
286
+ assert_equal(expected, @grid.to_html(CGI.new))
287
+ @grid.set_colspan(1, 1)
288
+ expected = '<TABLE cellspacing="0"><TR><TD colspan="3">&nbsp;</TD></TR><TR><TD>&nbsp;</TD><TD colspan="2">&nbsp;</TD></TR><TR><TD>&nbsp;</TD><TD>&nbsp;</TD><TD>test</TD></TR></TABLE>'
289
+ assert_equal(expected, @grid.to_html(CGI.new))
290
+ end
291
+
292
+ def test_push
293
+ @grid.add("bar", 4, 0)
294
+ @grid.push("foo")
295
+ expected = '<TABLE cellspacing="0"><TR><TD>&nbsp;</TD><TD>&nbsp;</TD>'
296
+ expected << "<TD>&nbsp;</TD><TD>&nbsp;</TD><TD>bar</TD></TR>"
297
+ expected << '<TR><TD colspan="5">foo</TD></TR></TABLE>'
298
+ assert_equal(expected, @grid.to_html(CGI.new))
299
+ end
300
+
301
+ def test_matrix
302
+ matrix = [1, 1]
269
303
  @grid.add("test", *matrix)
270
304
  expected = '<TABLE cellspacing="0"><TR><TD>&nbsp;</TD><TD>&nbsp;</TD></TR><TR><TD>&nbsp;</TD><TD>test</TD></TR></TABLE>'
271
305
  assert_equal(expected, @grid.to_html(CGI.new))
272
- end
273
- def test_attributes
274
- ### this test has changed behavior: its not desirable to have magically
275
- ### transferred css information from a component to its container
276
- @grid.add(StubGridComponent.new, 0,0)
277
- expected = '<TABLE cellspacing="0"><TR><TD>bar</TD></TR></TABLE>'
278
- assert_equal(expected, @grid.to_html(CGI.new))
279
- end
280
- def test_set_attribute1
281
- @grid.set_attribute("foo", "bar")
282
- expected = '<TABLE cellspacing="0" foo="bar"><TR><TD>&nbsp;</TD></TR></TABLE>'
283
- assert_equal(expected, @grid.to_html(CGI.new))
284
- end
285
- def test_set_attribute2
286
- @grid.set_attribute("foo", nil)
287
- expected = '<TABLE cellspacing="0"><TR><TD>&nbsp;</TD></TR></TABLE>'
288
- assert_equal(expected, @grid.to_html(CGI.new))
289
- end
290
- def test_set_attributes
291
- hash = {"foo"=>"bar", "baz"=>"bash"}
292
- @grid.set_attributes(hash)
293
- expected = [
294
- '<TABLE cellspacing="0" foo="bar" baz="bash"><TR><TD>&nbsp;</TD></TR></TABLE>',
295
- '<TABLE cellspacing="0" baz="bash" foo="bar"><TR><TD>&nbsp;</TD></TR></TABLE>',
296
- ]
297
- result = @grid.to_html(CGI.new)
306
+ end
307
+
308
+ def test_attributes
309
+ ### this test has changed behavior: its not desirable to have magically
310
+ ### transferred css information from a component to its container
311
+ @grid.add(StubGridComponent.new, 0, 0)
312
+ expected = '<TABLE cellspacing="0"><TR><TD>bar</TD></TR></TABLE>'
313
+ assert_equal(expected, @grid.to_html(CGI.new))
314
+ end
315
+
316
+ def test_set_attribute1
317
+ @grid.set_attribute("foo", "bar")
318
+ expected = '<TABLE cellspacing="0" foo="bar"><TR><TD>&nbsp;</TD></TR></TABLE>'
319
+ assert_equal(expected, @grid.to_html(CGI.new))
320
+ end
321
+
322
+ def test_set_attribute2
323
+ @grid.set_attribute("foo", nil)
324
+ expected = '<TABLE cellspacing="0"><TR><TD>&nbsp;</TD></TR></TABLE>'
325
+ assert_equal(expected, @grid.to_html(CGI.new))
326
+ end
327
+
328
+ def test_set_attributes
329
+ hash = {"foo" => "bar", "baz" => "bash"}
330
+ @grid.set_attributes(hash)
331
+ expected = [
332
+ '<TABLE cellspacing="0" foo="bar" baz="bash"><TR><TD>&nbsp;</TD></TR></TABLE>',
333
+ '<TABLE cellspacing="0" baz="bash" foo="bar"><TR><TD>&nbsp;</TD></TR></TABLE>'
334
+ ]
335
+ result = @grid.to_html(CGI.new)
298
336
  assert_equal(true, expected.include?(result), result)
299
- end
300
- def test_set_row_attributes1
301
- @grid.set_row_attributes({'foo' => 'bar'}, 0)
302
- expected = '<TABLE cellspacing="0"><TR foo="bar"><TD>&nbsp;</TD></TR></TABLE>'
303
- assert_equal(expected, @grid.to_html(CGI.new))
304
- end
305
- def test_set_row_attributes2
306
- @grid.set_row_attributes({'foo' => 'bar'}, 1)
307
- expected = '<TABLE cellspacing="0"><TR><TD>&nbsp;</TD></TR><TR foo="bar"><TD>&nbsp;</TD></TR></TABLE>'
308
- assert_equal(expected, @grid.to_html(CGI.new))
309
- end
310
- def test_set_row_attributes3
311
- @grid.set_row_attributes({'foo' => 'bar'}, 1, 2)
312
- expected = '<TABLE cellspacing="0"><TR><TD>&nbsp;</TD><TD>&nbsp;</TD></TR><TR foo="bar"><TD>&nbsp;</TD><TD>&nbsp;</TD></TR></TABLE>'
313
- assert_equal(expected, @grid.to_html(CGI.new))
314
- end
315
- def test_insert_row
316
- assert_equal(1, @grid.height)
317
- @grid.add("testfeld", 0, 1)
318
- assert_equal(2, @grid.height)
319
- expected = '<TABLE cellspacing="0"><TR><TD>&nbsp;</TD></TR><TR><TD>testfeld</TD></TR></TABLE>'
320
- assert_equal(expected, @grid.to_html(CGI.new))
321
- @grid.insert_row(0, "testreihe")
322
- assert_equal(3, @grid.height)
323
- expected = '<TABLE cellspacing="0"><TR><TD>testreihe</TD></TR><TR><TD>&nbsp;</TD></TR><TR><TD>testfeld</TD></TR></TABLE>'
324
- assert_equal(expected, @grid.to_html(CGI.new))
325
- end
337
+ end
338
+
339
+ def test_set_row_attributes1
340
+ @grid.set_row_attributes({"foo" => "bar"}, 0)
341
+ expected = '<TABLE cellspacing="0"><TR foo="bar"><TD>&nbsp;</TD></TR></TABLE>'
342
+ assert_equal(expected, @grid.to_html(CGI.new))
343
+ end
344
+
345
+ def test_set_row_attributes2
346
+ @grid.set_row_attributes({"foo" => "bar"}, 1)
347
+ expected = '<TABLE cellspacing="0"><TR><TD>&nbsp;</TD></TR><TR foo="bar"><TD>&nbsp;</TD></TR></TABLE>'
348
+ assert_equal(expected, @grid.to_html(CGI.new))
349
+ end
350
+
351
+ def test_set_row_attributes3
352
+ @grid.set_row_attributes({"foo" => "bar"}, 1, 2)
353
+ expected = '<TABLE cellspacing="0"><TR><TD>&nbsp;</TD><TD>&nbsp;</TD></TR><TR foo="bar"><TD>&nbsp;</TD><TD>&nbsp;</TD></TR></TABLE>'
354
+ assert_equal(expected, @grid.to_html(CGI.new))
355
+ end
356
+
357
+ def test_insert_row
358
+ assert_equal(1, @grid.height)
359
+ @grid.add("testfeld", 0, 1)
360
+ assert_equal(2, @grid.height)
361
+ expected = '<TABLE cellspacing="0"><TR><TD>&nbsp;</TD></TR><TR><TD>testfeld</TD></TR></TABLE>'
362
+ assert_equal(expected, @grid.to_html(CGI.new))
363
+ @grid.insert_row(0, "testreihe")
364
+ assert_equal(3, @grid.height)
365
+ expected = '<TABLE cellspacing="0"><TR><TD>testreihe</TD></TR><TR><TD>&nbsp;</TD></TR><TR><TD>testfeld</TD></TR></TABLE>'
366
+ assert_equal(expected, @grid.to_html(CGI.new))
367
+ end
326
368
 
327
369
  # @todo
328
370
  # What does this test? (gabage collection?)
@@ -341,41 +383,47 @@ class TestGrid < Minitest::Test
341
383
  @grid.to_html(CGI.new)
342
384
  end
343
385
 
344
- def test_label
345
- label = StubLabel.new
346
- @grid.add(label, 0,0)
347
- result = @grid.to_html(CGI.new)
348
- assert_equal('<TABLE cellspacing="0"><TR><TD>foo</TD><TD>bar</TD></TR></TABLE>', result)
349
- end
350
- def test_field_attribute
351
- @grid.add_attribute('foo', 'bar', 0, 0)
352
- assert_equal('bar', @grid.field_attribute('foo', 0, 0))
353
- end
354
- def test_nil_attribute1
355
- @grid.add_attribute('foo', nil, 0, 0)
356
- @grid.to_html(CGI.new)
357
- end
358
- def test_nil_attribute2
359
- thing = StubGridComponent.new
360
- thing.set_attribute("class", nil)
361
- @grid.add(thing, 0,0)
386
+ def test_label
387
+ label = StubLabel.new
388
+ @grid.add(label, 0, 0)
389
+ result = @grid.to_html(CGI.new)
390
+ assert_equal('<TABLE cellspacing="0"><TR><TD>foo</TD><TD>bar</TD></TR></TABLE>', result)
391
+ end
392
+
393
+ def test_field_attribute
394
+ @grid.add_attribute("foo", "bar", 0, 0)
395
+ assert_equal("bar", @grid.field_attribute("foo", 0, 0))
396
+ end
397
+
398
+ def test_nil_attribute1
399
+ @grid.add_attribute("foo", nil, 0, 0)
400
+ @grid.to_html(CGI.new)
401
+ end
402
+
403
+ def test_nil_attribute2
404
+ thing = StubGridComponent.new
405
+ thing.set_attribute("class", nil)
406
+ @grid.add(thing, 0, 0)
362
407
  @grid.to_html(CGI.new)
363
- end
364
- def test_nil_component
365
- thing = StubNilComponent.new
366
- @grid.add(thing, 0,0)
408
+ end
409
+
410
+ def test_nil_component
411
+ thing = StubNilComponent.new
412
+ @grid.add(thing, 0, 0)
367
413
  @grid.to_html(CGI.new)
368
- end
369
- def test_add_negative
370
- assert( @grid.add('foo', -1, 0) )
371
- assert( @grid.add('foo', 0, -1) )
372
- assert( @grid.add(['foo', 'bar'], -1, 0) )
373
- assert( @grid.add(['foo', 'bar'], 0, -1) )
374
- end
375
- def test_add_style_negative
376
- assert( @grid.add_style('bar', -1, 1) )
377
- assert( @grid.add_style('bar', 1, -1) )
378
- assert( @grid.add_style('bar', 1, 1, -1) )
379
- assert( @grid.add_style('bar', 1, 1, 1,-1) )
380
- end
414
+ end
415
+
416
+ def test_add_negative
417
+ assert(@grid.add("foo", -1, 0))
418
+ assert(@grid.add("foo", 0, -1))
419
+ assert(@grid.add(["foo", "bar"], -1, 0))
420
+ assert(@grid.add(["foo", "bar"], 0, -1))
421
+ end
422
+
423
+ def test_add_style_negative
424
+ assert(@grid.add_style("bar", -1, 1))
425
+ assert(@grid.add_style("bar", 1, -1))
426
+ assert(@grid.add_style("bar", 1, 1, -1))
427
+ assert(@grid.add_style("bar", 1, 1, 1, -1))
428
+ end
381
429
  end