lapillus 0.0.2
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/examples/guest_book.rb +50 -0
- data/examples/hello_world.rb +12 -0
- data/examples/persons.rb +30 -0
- data/examples/tc_guest_book.rb +34 -0
- data/examples/tc_hello_world.rb +24 -0
- data/examples/tc_persons.rb +13 -0
- data/html/GuestBook.html +24 -0
- data/html/HelloWorld.html +5 -0
- data/html/LapillusTesterTestPage.html +12 -0
- data/html/Persons.html +7 -0
- data/html/TestPage.html +8 -0
- data/html/TestRemotePanel.html +8 -0
- data/lib/changelog.txt +6 -0
- data/lib/lapillus/base.rb +276 -0
- data/lib/lapillus/behaviours.rb +208 -0
- data/lib/lapillus/components.rb +116 -0
- data/lib/lapillus/containers.rb +234 -0
- data/lib/lapillus/dispatcher.rb +216 -0
- data/lib/lapillus/form_components.rb +88 -0
- data/lib/lapillus/lapillus_server.rb +21 -0
- data/lib/lapillus/lapillus_testers.rb +167 -0
- data/lib/lapillus/mongrel_server.rb +69 -0
- data/lib/lapillus/multiview.rb +45 -0
- data/lib/lapillus/pager.rb +104 -0
- data/lib/lapillus/process_upload.rb +11 -0
- data/lib/lapillus/web_application.rb +12 -0
- data/lib/lapillus/webrick_server.rb +90 -0
- data/lib/lapillus.rb +33 -0
- data/lib/license.txt +24 -0
- data/test/tc_base.rb +63 -0
- data/test/tc_behaviours.rb +106 -0
- data/test/tc_bookmarkablepagelink.rb +58 -0
- data/test/tc_components.rb +285 -0
- data/test/tc_containers.rb +173 -0
- data/test/tc_dispatcher.rb +106 -0
- data/test/tc_examples.rb +193 -0
- data/test/tc_form.rb +231 -0
- data/test/tc_fragments.rb +114 -0
- data/test/tc_hierarchy.rb +34 -0
- data/test/tc_lapillus.rb +30 -0
- data/test/tc_lapillus_testers.rb +108 -0
- data/test/tc_multiview.rb +91 -0
- data/test/tc_pager.rb +94 -0
- data/test/tc_rendering.rb +74 -0
- data/test/ts_all_test.rb +20 -0
- metadata +94 -0
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
module ProcessUpload
|
|
2
|
+
def process_upload(uploaddir, uploaded_file, name)
|
|
3
|
+
File.makedirs "#{uploaddir}"
|
|
4
|
+
output = File.new("#{uploaddir}/#{name}","wb")
|
|
5
|
+
# puts "upload saved to <#{uploaddir}/#{@file_name}}>"
|
|
6
|
+
uploaded_file.each_byte{|b|
|
|
7
|
+
output.putc(b)
|
|
8
|
+
}
|
|
9
|
+
output.close
|
|
10
|
+
end
|
|
11
|
+
end
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
require 'webrick'
|
|
2
|
+
require 'cgi'
|
|
3
|
+
|
|
4
|
+
class WebrickServer
|
|
5
|
+
|
|
6
|
+
def initialize(port)
|
|
7
|
+
$stdout.sync=true
|
|
8
|
+
$stderr.sync=true
|
|
9
|
+
@port = port
|
|
10
|
+
@server = WEBrick::HTTPServer.new( :Port => @port)
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
def start
|
|
14
|
+
trap("INT"){ @server.shutdown }
|
|
15
|
+
trap('TERM'){ @server.shutdown }
|
|
16
|
+
@server.start
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
def mount(name, application)
|
|
20
|
+
@server.mount(name, WebrickServletCGIwrapper, application)
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
def allow_termination_for_test
|
|
24
|
+
Webrick::Terminate.set_server=@server
|
|
25
|
+
@server.mount("/terminate", Webrick::Terminate)
|
|
26
|
+
end
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
class WebrickServletCGIwrapper < WEBrick::HTTPServlet::AbstractServlet
|
|
30
|
+
|
|
31
|
+
include CGI::QueryExtension
|
|
32
|
+
|
|
33
|
+
@env
|
|
34
|
+
@res
|
|
35
|
+
@stdin
|
|
36
|
+
|
|
37
|
+
def initialize(server,*options)
|
|
38
|
+
# puts "initialize(#{server},#{options.to_yaml}) called"
|
|
39
|
+
super(server,*options)
|
|
40
|
+
@env=Hash.new # remove?
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
def stdinput
|
|
44
|
+
@stdin || $stdin # remove || $stdin
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
def env_table
|
|
48
|
+
@env
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
def out(options = "text/html")
|
|
52
|
+
# puts "out(#{options.to_yaml} called"
|
|
53
|
+
# puts "@output_cookies #{@output_cookies.to_yaml}"
|
|
54
|
+
|
|
55
|
+
options = { "type" => options } if options.kind_of?(String)
|
|
56
|
+
content = yield
|
|
57
|
+
|
|
58
|
+
@res.body = content
|
|
59
|
+
options.each{|key,val| @res[key]=val }
|
|
60
|
+
@res.cookies.concat(@output_cookies)
|
|
61
|
+
end
|
|
62
|
+
|
|
63
|
+
|
|
64
|
+
def service(req, res)
|
|
65
|
+
@res=res
|
|
66
|
+
@env = req.meta_vars.clone
|
|
67
|
+
@env.delete "SCRIPT_NAME"
|
|
68
|
+
@env["QUERY_STRING"] = req.request_uri.query
|
|
69
|
+
@env["REQUEST_URI"] = req.request_uri
|
|
70
|
+
|
|
71
|
+
@stdin=StringIO.new(req.body || "")
|
|
72
|
+
initialize_query()
|
|
73
|
+
|
|
74
|
+
Dispatcher.dispatch(self,@options[0])
|
|
75
|
+
end
|
|
76
|
+
end
|
|
77
|
+
|
|
78
|
+
module Webrick
|
|
79
|
+
class Terminate < WEBrick::HTTPServlet::AbstractServlet
|
|
80
|
+
def Terminate.set_server=server
|
|
81
|
+
@@server = server
|
|
82
|
+
end
|
|
83
|
+
|
|
84
|
+
def do_GET(req, res)
|
|
85
|
+
puts "trying to shutdown server"
|
|
86
|
+
@@server.shutdown
|
|
87
|
+
end
|
|
88
|
+
end
|
|
89
|
+
end
|
|
90
|
+
|
data/lib/lapillus.rb
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
#
|
|
2
|
+
# The MIT License
|
|
3
|
+
#
|
|
4
|
+
# Copyright (c) 2007 Bram Buitendijk, Ronald Haentjens Dekker,
|
|
5
|
+
# Meindert Kroese, Joris van Zundert
|
|
6
|
+
#
|
|
7
|
+
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
8
|
+
# of this software and associated documentation files (the "Software"), to deal
|
|
9
|
+
# in the Software without restriction, including without limitation the rights
|
|
10
|
+
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
11
|
+
# copies of the Software, and to permit persons to whom the Software is
|
|
12
|
+
# furnished to do so, subject to the following conditions:
|
|
13
|
+
#
|
|
14
|
+
# The above copyright notice and this permission notice shall be included in
|
|
15
|
+
# all copies or substantial portions of the Software.
|
|
16
|
+
#
|
|
17
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
18
|
+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
19
|
+
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
20
|
+
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
21
|
+
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
22
|
+
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
23
|
+
# THE SOFTWARE.
|
|
24
|
+
#
|
|
25
|
+
require 'lapillus/components'
|
|
26
|
+
require 'lapillus/form_components'
|
|
27
|
+
require 'lapillus/containers'
|
|
28
|
+
require 'lapillus/behaviours'
|
|
29
|
+
require 'lapillus/web_application'
|
|
30
|
+
require 'lapillus/dispatcher'
|
|
31
|
+
require 'lapillus/multiview'
|
|
32
|
+
require 'lapillus/pager'
|
|
33
|
+
require 'lapillus/lapillus_server'
|
data/lib/license.txt
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
#
|
|
2
|
+
# The MIT License
|
|
3
|
+
#
|
|
4
|
+
# Copyright (c) 2007 Bram Buitendijk, Ronald Haentjens Dekker,
|
|
5
|
+
# Meindert Kroese, Joris van Zundert
|
|
6
|
+
#
|
|
7
|
+
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
8
|
+
# of this software and associated documentation files (the "Software"), to deal
|
|
9
|
+
# in the Software without restriction, including without limitation the rights
|
|
10
|
+
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
11
|
+
# copies of the Software, and to permit persons to whom the Software is
|
|
12
|
+
# furnished to do so, subject to the following conditions:
|
|
13
|
+
#
|
|
14
|
+
# The above copyright notice and this permission notice shall be included in
|
|
15
|
+
# all copies or substantial portions of the Software.
|
|
16
|
+
#
|
|
17
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
18
|
+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
19
|
+
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
20
|
+
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
21
|
+
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
22
|
+
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
23
|
+
# THE SOFTWARE.
|
|
24
|
+
#
|
data/test/tc_base.rb
ADDED
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
require 'test/unit'
|
|
2
|
+
require 'lapillus/base'
|
|
3
|
+
|
|
4
|
+
include Lapillus
|
|
5
|
+
|
|
6
|
+
class TC_Base < Test::Unit::TestCase
|
|
7
|
+
|
|
8
|
+
# class TestContainer < Container
|
|
9
|
+
# attr_accessor :model
|
|
10
|
+
# add_component :comp1, Component, :model
|
|
11
|
+
# end
|
|
12
|
+
|
|
13
|
+
class Person
|
|
14
|
+
attr_reader :name
|
|
15
|
+
def initialize(name)
|
|
16
|
+
@name = name
|
|
17
|
+
end
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
def test_component_identifier
|
|
21
|
+
component = Component.new(:identifier)
|
|
22
|
+
assert_equal(:identifier, component.identifier)
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
#TODO assert exception raised when model is not set!
|
|
26
|
+
def test_component_model_without_symbol
|
|
27
|
+
model = Object.new
|
|
28
|
+
component = Component.new(:identifier, model)
|
|
29
|
+
assert_equal(model, component.model)
|
|
30
|
+
assert_equal(model, component.value)
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
# TODO: Reactivate!
|
|
34
|
+
# def test_component_model_with_symbol
|
|
35
|
+
# model = Object.new
|
|
36
|
+
# container = TestContainer.new(:container)
|
|
37
|
+
# container.model = model
|
|
38
|
+
# component = container.comp1
|
|
39
|
+
# assert_equal(model, component.model)
|
|
40
|
+
# end
|
|
41
|
+
|
|
42
|
+
#Note: value test without property is already done in test_component_model_without_symbol
|
|
43
|
+
def test_component_value_with_property
|
|
44
|
+
person = Person.new("Jantje")
|
|
45
|
+
component = Component.new(:id, person, :name)
|
|
46
|
+
assert_equal(person, component.model)
|
|
47
|
+
assert_equal(person.name, component.value)
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
# TODO: Reactivate!
|
|
51
|
+
# def test_container
|
|
52
|
+
# model = Object.new
|
|
53
|
+
# container = TestContainer.new(:container)
|
|
54
|
+
# container.model = model
|
|
55
|
+
# comp1 = container.comp1
|
|
56
|
+
# assert_equal(:comp1, comp1.identifier)
|
|
57
|
+
# assert(comp1.kind_of?(Component))
|
|
58
|
+
# assert_equal(model, comp1.model)
|
|
59
|
+
# assert_equal(container, comp1.parent)
|
|
60
|
+
# container.model = "hello world"
|
|
61
|
+
# assert_equal(container.model, comp1.value)
|
|
62
|
+
# end
|
|
63
|
+
end
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
require 'test/unit'
|
|
2
|
+
require 'rexml/document'
|
|
3
|
+
require 'lapillus'
|
|
4
|
+
|
|
5
|
+
class TC_Behaviours < Test::Unit::TestCase
|
|
6
|
+
def setup
|
|
7
|
+
super()
|
|
8
|
+
@html = "<html><span lapillus:id='component'/></html>"
|
|
9
|
+
@component = Label.new("component", "")
|
|
10
|
+
@webpage = Webpage.new
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
attr_reader :html, :component, :webpage
|
|
14
|
+
|
|
15
|
+
def test_attribute_modifier
|
|
16
|
+
component.add_behaviour(AttributeModifier.new("title", "hover"))
|
|
17
|
+
webpage.add(component)
|
|
18
|
+
output = webpage.render(html)
|
|
19
|
+
assert_equal("<html><span title=\"hover\" lapillus:id=\"component\"></span></html>", output)
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
def test_fade_in
|
|
23
|
+
component.add_behaviour(FadeIn.new("onmouseover", "id_of_component_to_fade_in"))
|
|
24
|
+
webpage.add(component)
|
|
25
|
+
output = webpage.render(html)
|
|
26
|
+
assert_equal("<html><span onmouseover=\"new Effect.Appear('id_of_component_to_fade_in');\" lapillus:id=\"component\"></span></html>", output)
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
def test_draggable
|
|
30
|
+
component.add_behaviour(Draggable.new)
|
|
31
|
+
html="<html><div id='parent'><span lapillus:id='component'/></div></html>"
|
|
32
|
+
webpage.add(component)
|
|
33
|
+
output = webpage.render(html)
|
|
34
|
+
path=component.path
|
|
35
|
+
expected = "<html><div id=\"parent\"><span id=\"#{path}\" lapillus:id=\"component\">"+
|
|
36
|
+
"<script language=\"javascript\" type=\"text/javascript\">\n"+
|
|
37
|
+
"// <![CDATA[\nnew Draggable('#{path}', {});\n// ]]>\n</script>"+
|
|
38
|
+
"</span></div></html>"
|
|
39
|
+
assert_equal(expected, output)
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
def test_droppable
|
|
43
|
+
component.add_behaviour(Droppable.new)
|
|
44
|
+
html="<html><div id='parent'><span lapillus:id='component'/></div></html>"
|
|
45
|
+
webpage.add(component)
|
|
46
|
+
output = webpage.render(html)
|
|
47
|
+
path=component.path
|
|
48
|
+
expected = "<html><div id=\"parent\"><span id=\"component\" lapillus:id=\"component\"><script language=\"javascript\" type=\"text/javascript\">\n// <![CDATA[\n Droppables.add('component', {\n onDrop: function(element) { \n new Ajax.Updater('component', '', { \n method:'get', parameters: { \n listener:'component',\n component:element.id\n }\n }); return false;\n }\n });\n// ]]>\n</script></span></div></html>"
|
|
49
|
+
assert_equal(expected, output)
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
def test_draggable_options
|
|
53
|
+
behaviour=Draggable.new("whatever:yes,skipthis:true")
|
|
54
|
+
behaviour.snap=true
|
|
55
|
+
behaviour.revert=true
|
|
56
|
+
behaviour.handle='handlebar'
|
|
57
|
+
behaviour.zindex=1000
|
|
58
|
+
behaviour.constraint='vertical'
|
|
59
|
+
behaviour.ghosting=true
|
|
60
|
+
behaviour.start_effect="function(){}"
|
|
61
|
+
behaviour.revert_effect="function(){}"
|
|
62
|
+
behaviour.end_effect="function(){}"
|
|
63
|
+
behaviour.change="function(){}"
|
|
64
|
+
component.add_behaviour(behaviour)
|
|
65
|
+
html="<html><div id='parent'><span lapillus:id='component'/></div></html>"
|
|
66
|
+
webpage.add(component)
|
|
67
|
+
output = webpage.render(html)
|
|
68
|
+
path=component.path
|
|
69
|
+
expected = "<html><div id=\"parent\"><span id=\"#{path}\" lapillus:id=\"component\">"+
|
|
70
|
+
"<script language=\"javascript\" type=\"text/javascript\">\n"+
|
|
71
|
+
"// <![CDATA[\nnew Draggable('#{path}', {change:function(){},constraint:'vertical',endeffect:function(){},ghosting:true,handle:'handlebar',revert:true,reverteffect:function(){},snap:true,starteffect:function(){},zindex:1000,whatever:yes,skipthis:true});\n// ]]>\n</script></span></div></html>"
|
|
72
|
+
assert_equal(expected, output)
|
|
73
|
+
end
|
|
74
|
+
|
|
75
|
+
def test_ajax_link_rendering
|
|
76
|
+
link = AjaxLink.new("ajaxlink")
|
|
77
|
+
webpage.add(link)
|
|
78
|
+
output = webpage.render("<html><a lapillus:id='ajaxlink'>de link text</a></html>")
|
|
79
|
+
javascript = "new Ajax.Request('', { method: 'get', parameters: { listener:'#{link.path}' }}); return false;"
|
|
80
|
+
assert_equal("<html><a href=\"#\" lapillus:id=\"ajaxlink\" onclick=\"#{javascript}\">de link text</a></html>", output)
|
|
81
|
+
end
|
|
82
|
+
|
|
83
|
+
class MyAjaxLink < AjaxLink
|
|
84
|
+
attr_reader :fragment_to_refresh
|
|
85
|
+
def initialize(id, fragment_to_refresh)
|
|
86
|
+
super(id)
|
|
87
|
+
@fragment_to_refresh = fragment_to_refresh
|
|
88
|
+
end
|
|
89
|
+
|
|
90
|
+
def on_click
|
|
91
|
+
fragment_to_refresh.render_component
|
|
92
|
+
end
|
|
93
|
+
end
|
|
94
|
+
|
|
95
|
+
def test_ajax_link_on_click
|
|
96
|
+
def webpage.default_htmlfile
|
|
97
|
+
return "<html><span lapillus:id='panel'></span><lapillus:fragment lapillus:id='fragment'>expected result</lapillus:fragment></html>"
|
|
98
|
+
end
|
|
99
|
+
fragment = Fragment.new("panel", "fragment")
|
|
100
|
+
link = MyAjaxLink.new("link", fragment)
|
|
101
|
+
webpage.add(fragment)
|
|
102
|
+
webpage.add(link)
|
|
103
|
+
assert_equal("expected result", link.on_click)
|
|
104
|
+
|
|
105
|
+
end
|
|
106
|
+
end
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
require 'test/unit'
|
|
2
|
+
require 'lapillus'
|
|
3
|
+
|
|
4
|
+
include Lapillus
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
class TC_BookmarkablePageLink < Test::Unit::TestCase
|
|
8
|
+
def html_template(input)
|
|
9
|
+
"<html>#{input}</html>"
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
def expected_html(output)
|
|
13
|
+
"<html>#{output}</html>"
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
def test_bookmarkablepagelink
|
|
17
|
+
webpage = Webpage.new
|
|
18
|
+
webpage.add(BookmarkablePageLink.new("myLink", "", Hash[:key => 'value']))
|
|
19
|
+
html = html_template('<a href="#" lapillus:id="myLink">click here</a>')
|
|
20
|
+
result = webpage.render(html)
|
|
21
|
+
assert_equal(expected_html('<a href="/key/value" lapillus:id="myLink">click here</a>'), result)
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
class MyLink < BookmarkablePageLink
|
|
25
|
+
label 'text', :model => "this text should be visible"
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
def test_bookmarkablepagelink_with_label
|
|
29
|
+
webpage = Webpage.new
|
|
30
|
+
webpage.add(MyLink.new("myLink", "", Hash[:key => 'value']))
|
|
31
|
+
html = html_template('<a href="#" lapillus:id="myLink"><span lapillus:id="text">link_text</span></a>')
|
|
32
|
+
expected = expected_html('<a href="/key/value" lapillus:id="myLink"><span lapillus:id="text">this text should be visible</span></a>')
|
|
33
|
+
result = webpage.render(html)
|
|
34
|
+
assert_equal(expected, result)
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
def test_bookmarkablepagelink_with_baseurl
|
|
38
|
+
webpage = Webpage.new
|
|
39
|
+
webpage.add(BookmarkablePageLink.new("myLink", "/base/page", Hash[:key => 'value']))
|
|
40
|
+
html = html_template('<a href="#" lapillus:id="myLink">text</a>')
|
|
41
|
+
expected = expected_html('<a href="/base/page/key/value" lapillus:id="myLink">text</a>')
|
|
42
|
+
result = webpage.render(html)
|
|
43
|
+
assert_equal(expected, result)
|
|
44
|
+
link = webpage["myLink"]
|
|
45
|
+
assert_equal("/base/page", link.page_url)
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
def test_bookmarkablepagelink_with_multiple_page_parameters
|
|
49
|
+
webpage = Webpage.new
|
|
50
|
+
webpage.add(BookmarkablePageLink.new("myLink", "", Hash["key" => 'value', "sleutel" => 'waarde']))
|
|
51
|
+
html = html_template('<a href="#" lapillus:id="myLink">click here</a>')
|
|
52
|
+
result = webpage.render(html)
|
|
53
|
+
expected = expected_html('<a href="/key/value/sleutel/waarde" lapillus:id="myLink">click here</a>')
|
|
54
|
+
assert_equal(expected, result)
|
|
55
|
+
end
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
end
|
|
@@ -0,0 +1,285 @@
|
|
|
1
|
+
require 'test/unit'
|
|
2
|
+
require 'lapillus'
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
include Lapillus
|
|
6
|
+
|
|
7
|
+
module Lapillus
|
|
8
|
+
class Component
|
|
9
|
+
public :remove_behaviour
|
|
10
|
+
public :render_component
|
|
11
|
+
end
|
|
12
|
+
end
|
|
13
|
+
class TC_Components < Test::Unit::TestCase
|
|
14
|
+
|
|
15
|
+
def test_component_id_no_value
|
|
16
|
+
component = Component.new("id")
|
|
17
|
+
assert_equal("id", component.identifier)
|
|
18
|
+
assert(!component.has_model?)
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
# def test_component_with_string #same thing with List
|
|
22
|
+
# component = Component.new("id", "string")
|
|
23
|
+
# assert(component.has_value?)
|
|
24
|
+
# assert_equal("string", component.value)
|
|
25
|
+
# end
|
|
26
|
+
|
|
27
|
+
# def test_component_set_value
|
|
28
|
+
# component = Component.new("id")
|
|
29
|
+
# assert(!component.has_value?)
|
|
30
|
+
# component.value = "new"
|
|
31
|
+
# assert(component.has_value?)
|
|
32
|
+
# assert_equal("new", component.value)
|
|
33
|
+
# end
|
|
34
|
+
|
|
35
|
+
class TestObject
|
|
36
|
+
attr_accessor :attribute
|
|
37
|
+
def initialize
|
|
38
|
+
@attribute = "first"
|
|
39
|
+
end
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
# def test_component_without_value_asks_parent
|
|
43
|
+
# container = Container.new("", TestObject.new)
|
|
44
|
+
# component = Component.new("attribute")
|
|
45
|
+
# container.add(component)
|
|
46
|
+
# assert(!component.has_value?)
|
|
47
|
+
# assert_equal("first", component.value)
|
|
48
|
+
# end
|
|
49
|
+
|
|
50
|
+
# def test_component_without_value_sets_parent
|
|
51
|
+
# test_object = TestObject.new
|
|
52
|
+
# container = Container.new("", test_object)
|
|
53
|
+
# component = Component.new("attribute")
|
|
54
|
+
# container.add(component)
|
|
55
|
+
# component.value = "second"
|
|
56
|
+
# assert(!component.has_value?)
|
|
57
|
+
# assert_equal("second", test_object.attribute)
|
|
58
|
+
# end
|
|
59
|
+
|
|
60
|
+
def test_render_component
|
|
61
|
+
def webpage.default_htmlfile
|
|
62
|
+
return '<html><span lapillus:id="label">My Label</span></html>'
|
|
63
|
+
end
|
|
64
|
+
label = Label.new("label", "My Label")
|
|
65
|
+
webpage.add(label)
|
|
66
|
+
html = label.render_component
|
|
67
|
+
assert_equal("My Label", html)
|
|
68
|
+
end
|
|
69
|
+
|
|
70
|
+
def test_render_component_with_remarks
|
|
71
|
+
def webpage.default_htmlfile
|
|
72
|
+
return '<html><span lapillus:id="panel"><!-- <span lapillus:id="remark">Bla</span> --><span lapillus:id="visible">huh</span></span></html>'
|
|
73
|
+
end
|
|
74
|
+
panel = Panel.new("panel")
|
|
75
|
+
remark = Label.new("remark", "whatever")
|
|
76
|
+
label = Label.new("visible", "My Label")
|
|
77
|
+
panel.add(remark)
|
|
78
|
+
panel.add(label)
|
|
79
|
+
webpage.add(panel)
|
|
80
|
+
html = panel.render_component
|
|
81
|
+
assert_equal("<!-- <span lapillus:id=\"remark\">Bla</span> --><span lapillus:id=\"visible\">My Label</span>", html)
|
|
82
|
+
end
|
|
83
|
+
|
|
84
|
+
#TODO: assert_exception_expected(component.parent=nil) can not set
|
|
85
|
+
#TODO: test_container_with_compound_model
|
|
86
|
+
#TODO: test_container_without_id (container ListView, WebPage)
|
|
87
|
+
attr_reader :webpage
|
|
88
|
+
|
|
89
|
+
def html_template(input)
|
|
90
|
+
"<html>#{input}</html>"
|
|
91
|
+
end
|
|
92
|
+
|
|
93
|
+
def expected_html(output)
|
|
94
|
+
"<html>#{output}</html>"
|
|
95
|
+
end
|
|
96
|
+
|
|
97
|
+
def setup
|
|
98
|
+
@webpage = Webpage.new
|
|
99
|
+
end
|
|
100
|
+
|
|
101
|
+
def test_label
|
|
102
|
+
label = Label.new("label", "hello world")
|
|
103
|
+
html = html_template('<span lapillus:id="label">this text should not be visible</span>')
|
|
104
|
+
expectation = expected_html('<span lapillus:id="label">hello world</span>')
|
|
105
|
+
webpage.add(label)
|
|
106
|
+
result = webpage.render(html)
|
|
107
|
+
assert_equal(expectation, result)
|
|
108
|
+
end
|
|
109
|
+
|
|
110
|
+
def test_label_ignore_newlines
|
|
111
|
+
label = Label.new("label", "hello world\nbye")
|
|
112
|
+
html = html_template('<span lapillus:id="label">this text should not be visible</span>')
|
|
113
|
+
expectation = expected_html("<span lapillus:id=\"label\">hello world\nbye</span>")
|
|
114
|
+
webpage.add(label)
|
|
115
|
+
result = webpage.render(html)
|
|
116
|
+
assert_equal(expectation, result)
|
|
117
|
+
end
|
|
118
|
+
|
|
119
|
+
def test_label_xml_escaping
|
|
120
|
+
label = Label.new("label", "hello world < > ' & \" ")
|
|
121
|
+
html = html_template('<span lapillus:id="label">this text should not be visible</span>')
|
|
122
|
+
expectation = expected_html('<span lapillus:id="label">hello world < > \' & " </span>')
|
|
123
|
+
webpage.add(label)
|
|
124
|
+
result = webpage.render(html)
|
|
125
|
+
assert_equal(expectation, result)
|
|
126
|
+
end
|
|
127
|
+
|
|
128
|
+
def html_template(input)
|
|
129
|
+
"<html><body>it is a brave new world!#{input}</body></html>"
|
|
130
|
+
end
|
|
131
|
+
|
|
132
|
+
def expected_html(output)
|
|
133
|
+
"<html><body>it is a brave new world!#{output}</body></html>"
|
|
134
|
+
end
|
|
135
|
+
|
|
136
|
+
def test_multilinelabel_paragraphs
|
|
137
|
+
label = MultiLineLabel.new("label", "a paragraph\n\n")
|
|
138
|
+
webpage.add(label)
|
|
139
|
+
html = html_template('<span lapillus:id="label">this text should not be visible</span>')
|
|
140
|
+
expectation = expected_html('<span lapillus:id="label"><p>a paragraph</p></span>')
|
|
141
|
+
result = webpage.render(html)
|
|
142
|
+
assert_equal(expectation, result)
|
|
143
|
+
end
|
|
144
|
+
|
|
145
|
+
def test_multilinelabel_paragraphs_2
|
|
146
|
+
label = MultiLineLabel.new("label", "a paragraph\n\n\nnext paragraph\n\n")
|
|
147
|
+
webpage.add(label)
|
|
148
|
+
html = html_template('<span lapillus:id="label">this text should not be visible</span>')
|
|
149
|
+
expectation = expected_html('<span lapillus:id="label"><p>a paragraph</p><p>next paragraph</p></span>')
|
|
150
|
+
result = webpage.render(html)
|
|
151
|
+
assert_equal(expectation, result)
|
|
152
|
+
end
|
|
153
|
+
|
|
154
|
+
def test_multilinelabel_newlines
|
|
155
|
+
label = MultiLineLabel.new("label", "hello world\nbye")
|
|
156
|
+
webpage.add(label)
|
|
157
|
+
html = html_template('<span lapillus:id="label">this text should not be visible</span>')
|
|
158
|
+
expectation = expected_html('<span lapillus:id="label">hello world<br/>bye</span>')
|
|
159
|
+
result = webpage.render(html)
|
|
160
|
+
assert_equal(expectation, result)
|
|
161
|
+
end
|
|
162
|
+
|
|
163
|
+
def test_multilinelabel_newlines_2
|
|
164
|
+
label = MultiLineLabel.new("label", "hello world\nbye\n")
|
|
165
|
+
webpage.add(label)
|
|
166
|
+
html = html_template('<span lapillus:id="label">this text should not be visible</span>')
|
|
167
|
+
expectation = expected_html('<span lapillus:id="label">hello world<br/>bye<br/></span>')
|
|
168
|
+
result = webpage.render(html)
|
|
169
|
+
assert_equal(expectation, result)
|
|
170
|
+
end
|
|
171
|
+
|
|
172
|
+
|
|
173
|
+
def test_multilinelabel_combi_br_p
|
|
174
|
+
label = MultiLineLabel.new("label", "a \nparagraph\n\n")
|
|
175
|
+
webpage.add(label)
|
|
176
|
+
html = html_template('<span lapillus:id="label">this text should not be visible</span>')
|
|
177
|
+
expectation = expected_html('<span lapillus:id="label"><p>a <br/>paragraph</p></span>')
|
|
178
|
+
result = webpage.render(html)
|
|
179
|
+
assert_equal(expectation, result)
|
|
180
|
+
end
|
|
181
|
+
|
|
182
|
+
def test_multilabel_with_html_content
|
|
183
|
+
label = MultiLineLabel.new("label", "a \n<p>paragraph</p>\n\n")
|
|
184
|
+
label.html_content=true
|
|
185
|
+
webpage.add(label)
|
|
186
|
+
html = html_template('<span lapillus:id="label">this text should not be visible</span>')
|
|
187
|
+
expectation = expected_html('<span lapillus:id="label"><p>a <br/><p>paragraph</p></p></span>')
|
|
188
|
+
result = webpage.render(html)
|
|
189
|
+
assert_equal(expectation.strip, result)
|
|
190
|
+
label.html_content=false
|
|
191
|
+
result = webpage.render(html)
|
|
192
|
+
expectation = expected_html('<span lapillus:id="label"><p>a <br/><p>paragraph</p></p></span>')
|
|
193
|
+
assert_equal(expectation.strip, result)
|
|
194
|
+
end
|
|
195
|
+
|
|
196
|
+
def test_multilinelabel_empty_string
|
|
197
|
+
label = MultiLineLabel.new("label", "")
|
|
198
|
+
webpage.add(label)
|
|
199
|
+
html = html_template('<span lapillus:id="label">this text should not be visible</span>')
|
|
200
|
+
expectation = expected_html('<span lapillus:id="label"></span>')
|
|
201
|
+
result = webpage.render(html)
|
|
202
|
+
assert_equal(expectation, result)
|
|
203
|
+
end
|
|
204
|
+
|
|
205
|
+
class TestBehaviour < Behaviour
|
|
206
|
+
end
|
|
207
|
+
|
|
208
|
+
class Test2Behaviour < Behaviour
|
|
209
|
+
end
|
|
210
|
+
|
|
211
|
+
def test_add_behaviour
|
|
212
|
+
test_component = Component.new("test")
|
|
213
|
+
test_behaviour = TestBehaviour.new
|
|
214
|
+
test_component.add_behaviour(test_behaviour)
|
|
215
|
+
assert(test_component.has_behaviour?(TestBehaviour))
|
|
216
|
+
assert(!test_component.has_behaviour?(Test2Behaviour))
|
|
217
|
+
assert_equal(test_behaviour, test_component.behaviour(TestBehaviour))
|
|
218
|
+
end
|
|
219
|
+
|
|
220
|
+
def test_remove_behaviour
|
|
221
|
+
test_component = Component.new("test")
|
|
222
|
+
test_behaviour = TestBehaviour.new
|
|
223
|
+
test_component.add_behaviour(test_behaviour)
|
|
224
|
+
assert(test_component.has_behaviour?(TestBehaviour))
|
|
225
|
+
test_component.remove_behaviour(TestBehaviour)
|
|
226
|
+
assert(!test_component.has_behaviour?(TestBehaviour))
|
|
227
|
+
end
|
|
228
|
+
|
|
229
|
+
class ImagePage < Webpage
|
|
230
|
+
image "my_image", :model => "picture1.jpg", :root_url => "/application"
|
|
231
|
+
end
|
|
232
|
+
|
|
233
|
+
def test_image
|
|
234
|
+
html = <<END
|
|
235
|
+
<html>
|
|
236
|
+
<body>
|
|
237
|
+
<img lapillus:id='my_image'/>
|
|
238
|
+
</body>
|
|
239
|
+
</html>
|
|
240
|
+
END
|
|
241
|
+
expected = <<END
|
|
242
|
+
<html>
|
|
243
|
+
<body>
|
|
244
|
+
<img src="/application/images/picture1.jpg" lapillus:id="my_image"/>
|
|
245
|
+
</body>
|
|
246
|
+
</html>
|
|
247
|
+
END
|
|
248
|
+
page = ImagePage.new
|
|
249
|
+
result = page.render(html)
|
|
250
|
+
assert_equal(expected.strip, result)
|
|
251
|
+
end
|
|
252
|
+
|
|
253
|
+
class ListViewImagePage < Webpage
|
|
254
|
+
listview "my_images", :model => ["pic1.jpg", "pic2.jpg"] do |the_image|
|
|
255
|
+
image "my_image", :model => the_image, :root_url => "/application"
|
|
256
|
+
end
|
|
257
|
+
end
|
|
258
|
+
|
|
259
|
+
def test_listview_with_image
|
|
260
|
+
html = <<END
|
|
261
|
+
<html>
|
|
262
|
+
<body>
|
|
263
|
+
<span lapillus:id='my_images'>
|
|
264
|
+
<img lapillus:id='my_image'/>
|
|
265
|
+
</span>
|
|
266
|
+
</body>
|
|
267
|
+
</html>
|
|
268
|
+
END
|
|
269
|
+
expected = <<END
|
|
270
|
+
<html>
|
|
271
|
+
<body>
|
|
272
|
+
<span lapillus:id=\"my_images\">
|
|
273
|
+
<img src=\"/application/images/pic1.jpg\" lapillus:id=\"my_image\"/>
|
|
274
|
+
|
|
275
|
+
<img src=\"/application/images/pic2.jpg\" lapillus:id=\"my_image\"/>
|
|
276
|
+
</span>
|
|
277
|
+
</body>
|
|
278
|
+
</html>
|
|
279
|
+
END
|
|
280
|
+
page = ListViewImagePage.new
|
|
281
|
+
result = page.render(html)
|
|
282
|
+
assert_equal(expected.strip, result)
|
|
283
|
+
end
|
|
284
|
+
|
|
285
|
+
end
|