PageRenderTime 309ms CodeModel.GetById 101ms app.highlight 1ms RepoModel.GetById 111ms app.codeStats 14ms

/wheels/tests/view/urls/urlFor.cfc

http://cfwheels.googlecode.com/
ColdFusion CFScript | 94 lines | 82 code | 12 blank | 0 comment | 0 complexity | a3cb0689880df580f076443421e78cb6 MD5 | raw file
 1<cfcomponent extends="wheelsMapping.Test">
 2
 3	<cffunction name="setup">
 4		<cfset params.controller = "Blog">
 5		<cfset params.action = "edit">
 6		<cfset params.key = "1">
 7
 8		<cfset loc.controller = controller(params.controller, params)>
 9		<cfset loc.args = {}>
10		<cfset loc.args.controller = "Blog">
11		<cfset loc.args.action = "edit">
12		<cfset loc.args.key = "1">
13		<cfset loc.args.params = "param1=foo&param2=bar">
14		<cfset loc.args.$URLRewriting = "On">
15		<cfset oldScriptName = request.cgi.script_name>
16	</cffunction>
17
18	<cffunction name="teardown">
19		<cfset request.cgi.script_name = oldScriptName>
20	</cffunction>
21
22	<cffunction name="test_all_arguments_with_url_rewriting">
23		<cfset request.cgi.script_name = "/rewrite.cfm">
24		<cfset loc.e = "#application.wheels.webpath#blog/edit/1?param1=foo&param2=bar">
25		<cfset loc.r = loc.controller.urlFor(argumentcollection=loc.args)>
26		<cfset assert("loc.e eq loc.r")>
27	</cffunction>
28
29	<cffunction name="test_missing_controller_with_url_rewriting">
30		<cfset request.cgi.script_name = "/rewrite.cfm">
31		<cfset StructDelete(loc.args, "controller")>
32		<cfset loc.e = "#application.wheels.webpath#blog/edit/1?param1=foo&param2=bar">
33		<cfset loc.r = loc.controller.urlFor(argumentcollection=loc.args)>
34		<cfset assert("loc.e eq loc.r")>
35	</cffunction>
36
37	<cffunction name="test_missing_action_with_url_rewriting">
38		<cfset request.cgi.script_name = "/rewrite.cfm">
39		<cfset StructDelete(loc.args, "action")>
40		<cfset loc.e = "#application.wheels.webpath#blog/edit/1?param1=foo&param2=bar">
41		<cfset loc.r = loc.controller.urlFor(argumentcollection=loc.args)>
42		<cfset assert("loc.e eq loc.r")>
43	</cffunction>
44
45	<cffunction name="test_missing_controller_and_action_with_url_rewriting">
46		<cfset request.cgi.script_name = "/rewrite.cfm">
47		<cfset StructDelete(loc.args, "controller")>
48		<cfset StructDelete(loc.args, "action")>
49		<cfset loc.e = "#application.wheels.webpath#blog/edit/1?param1=foo&param2=bar">
50		<cfset loc.r = loc.controller.urlFor(argumentcollection=loc.args)>
51		<cfset assert("loc.e eq loc.r")>
52	</cffunction>
53
54	<cffunction name="test_all_arguments_without_url_rewriting">
55		<cfset request.cgi.script_name = "/index.cfm">
56		<cfset loc.args.$URLRewriting = "Off">
57		<cfset loc.webRoot = Replace("#application.wheels.webpath##ListLast(request.cgi.script_name, '/')#", "//", "/")>
58		<cfset loc.e = "#loc.webRoot#?controller=blog&action=edit&key=1&param1=foo&param2=bar">
59		<cfset loc.r = loc.controller.urlFor(argumentcollection=loc.args)>
60		<cfset assert("loc.e eq loc.r")>
61	</cffunction>
62
63	<cffunction name="test_missing_controller_without_url_rewriting">
64		<cfset request.cgi.script_name = "/index.cfm">
65		<cfset loc.args.$URLRewriting = "Off">
66		<cfset StructDelete(loc.args, "controller")>
67		<cfset loc.webRoot = Replace("#application.wheels.webpath##ListLast(request.cgi.script_name, '/')#", "//", "/")>
68		<cfset loc.e = "#loc.webRoot#?controller=blog&action=edit&key=1&param1=foo&param2=bar">
69		<cfset loc.r = loc.controller.urlFor(argumentcollection=loc.args)>
70		<cfset assert("loc.e eq loc.r")>
71	</cffunction>
72
73	<cffunction name="test_missing_action_without_url_rewriting">
74		<cfset request.cgi.script_name = "/index.cfm">
75		<cfset loc.args.$URLRewriting = "Off">
76		<cfset StructDelete(loc.args, "action")>
77		<cfset loc.webRoot = Replace("#application.wheels.webpath##ListLast(request.cgi.script_name, '/')#", "//", "/")>
78		<cfset loc.e = "#loc.webRoot#?controller=blog&action=edit&key=1&param1=foo&param2=bar">
79		<cfset loc.r = loc.controller.urlFor(argumentcollection=loc.args)>
80		<cfset assert("loc.e eq loc.r")>
81	</cffunction>
82
83	<cffunction name="test_missing_controller_and_action_without_url_rewriting">
84		<cfset request.cgi.script_name = "/index.cfm">
85		<cfset loc.args.$URLRewriting = "Off">
86		<cfset StructDelete(loc.args, "controller")>
87		<cfset StructDelete(loc.args, "action")>
88		<cfset loc.webRoot = Replace("#application.wheels.webpath##ListLast(request.cgi.script_name, '/')#", "//", "/")>
89		<cfset loc.e = "#loc.webRoot#?controller=blog&action=edit&key=1&param1=foo&param2=bar">
90		<cfset loc.r = loc.controller.urlFor(argumentcollection=loc.args)>
91		<cfset assert("loc.e eq loc.r")>
92	</cffunction>
93
94</cfcomponent>