PageRenderTime 193ms CodeModel.GetById 70ms app.highlight 2ms RepoModel.GetById 119ms app.codeStats 0ms

/wheels/tests/controller/rendering/specified_layouts.cfc

http://cfwheels.googlecode.com/
ColdFusion CFScript | 184 lines | 146 code | 38 blank | 0 comment | 0 complexity | d42ba522f13b4d5d3385be865cd41938 MD5 | raw file
  1<cfcomponent extends="wheelsMapping.Test">
  2
  3	<cffunction name="setup">
  4		<cfset request.cgi.http_x_requested_with = "">
  5	</cffunction>
  6
  7	<cffunction name="test_using_method">
  8		<cfset loc.args = {template="controller_layout_test"}>
  9		<cfset params = {controller="dummy", action="index"}>
 10		<cfset loc.controller = controller("dummy", params)>
 11		<cfset loc.controller.controller_layout_test = controller_layout_test>
 12		<cfset loc.controller.usesLayout(argumentCollection=loc.args)>
 13
 14		<cfset loc.e = "index_layout">
 15		<cfset loc.r = loc.controller.$useLayout("index")>
 16		<cfset assert('loc.e eq loc.r')>
 17
 18		<cfset loc.e = "show_layout">
 19		<cfset loc.r = loc.controller.$useLayout("show")>
 20		<cfset assert('loc.e eq loc.r')>
 21
 22		<cfset loc.e = "true">
 23		<cfset loc.r = loc.controller.$useLayout("list")>
 24		<cfset assert('loc.e eq loc.r')>
 25
 26		<cfset loc.args.usedefault = false>
 27		<cfset loc.controller.usesLayout(argumentCollection=loc.args)>
 28
 29		<cfset loc.e = "false">
 30		<cfset loc.r = loc.controller.$useLayout("list")>
 31		<cfset assert('loc.e eq loc.r')>
 32	</cffunction>
 33
 34	<cffunction name="test_ajax_request_with_no_layout_specified_should_fallback_to_template">
 35		<cfset request.cgi.http_x_requested_with = "XMLHTTPRequest">
 36		<cfset loc.args = {template="controller_layout_test"}>
 37		<cfset params = {controller="dummy", action="index"}>
 38		<cfset loc.controller = controller("dummy", params)>
 39		<cfset loc.controller.controller_layout_test = controller_layout_test>
 40		<cfset loc.controller.usesLayout(argumentCollection=loc.args)>
 41
 42		<cfset loc.e = "index_layout">
 43		<cfset loc.r = loc.controller.$useLayout("index")>
 44		<cfset assert('loc.e eq loc.r')>
 45	</cffunction>
 46
 47	<cffunction name="test_using_method_ajax">
 48		<cfset request.cgi.http_x_requested_with = "XMLHTTPRequest">
 49		<cfset loc.args = {template="controller_layout_test", ajax="controller_layout_test_ajax"}>
 50		<cfset params = {controller="dummy", action="index"}>
 51		<cfset loc.controller = controller("dummy", params)>
 52		<cfset loc.controller.controller_layout_test = controller_layout_test>
 53		<cfset loc.controller.controller_layout_test_ajax = controller_layout_test_ajax>
 54		<cfset loc.controller.usesLayout(argumentCollection=loc.args)>
 55
 56		<cfset loc.e = "index_layout_ajax">
 57		<cfset loc.r = loc.controller.$useLayout("index")>
 58		<cfset assert('loc.e eq loc.r')>
 59
 60		<cfset loc.e = "show_layout_ajax">
 61		<cfset loc.r = loc.controller.$useLayout("show")>
 62		<cfset assert('loc.e eq loc.r')>
 63
 64		<cfset loc.e = "true">
 65		<cfset loc.r = loc.controller.$useLayout("list")>
 66		<cfset assert('loc.e eq loc.r')>
 67
 68		<cfset loc.args.usedefault = false>
 69		<cfset loc.controller.usesLayout(argumentCollection=loc.args)>
 70
 71		<cfset loc.e = "false">
 72		<cfset loc.r = loc.controller.$useLayout("list")>
 73		<cfset assert('loc.e eq loc.r')>
 74	</cffunction>
 75
 76	<cffunction name="test_should_respect_exceptions">
 77		<cfset loc.args = {template="mylayout", except="index"}>
 78		<cfset params = {controller="dummy", action="index"}>
 79		<cfset loc.controller = controller("dummy", params)>
 80		<cfset loc.controller.usesLayout(argumentCollection=loc.args)>
 81
 82		<cfset loc.e = "mylayout">
 83		<cfset loc.r = loc.controller.$useLayout("show")>
 84		<cfset assert('loc.e eq loc.r')>
 85
 86		<cfset loc.e = "true">
 87		<cfset loc.r = loc.controller.$useLayout("index")>
 88		<cfset assert('loc.e eq loc.r')>
 89
 90		<cfset loc.args.usedefault = false>
 91		<cfset loc.controller.usesLayout(argumentCollection=loc.args)>
 92
 93		<cfset loc.e = "false">
 94		<cfset loc.r = loc.controller.$useLayout("index")>
 95		<cfset assert('loc.e eq loc.r')>
 96	</cffunction>
 97
 98	<cffunction name="test_should_respect_exceptions_ajax">
 99		<cfset request.cgi.http_x_requested_with = "XMLHTTPRequest">
100		<cfset loc.args = {template="mylayout", ajax="mylayout_ajax", except="index"}>
101		<cfset params = {controller="dummy", action="index"}>
102		<cfset loc.controller = controller("dummy", params)>
103		<cfset loc.controller.usesLayout(argumentCollection=loc.args)>
104
105		<cfset loc.e = "mylayout_ajax">
106		<cfset loc.r = loc.controller.$useLayout("show")>
107		<cfset assert('loc.e eq loc.r')>
108
109		<cfset loc.e = "true">
110		<cfset loc.r = loc.controller.$useLayout("index")>
111		<cfset assert('loc.e eq loc.r')>
112
113		<cfset loc.args.usedefault = false>
114		<cfset loc.controller.usesLayout(argumentCollection=loc.args)>
115
116		<cfset loc.e = "false">
117		<cfset loc.r = loc.controller.$useLayout("index")>
118		<cfset assert('loc.e eq loc.r')>
119	</cffunction>
120
121	<cffunction name="test_should_respect_only">
122		<cfset loc.args = {template="mylayout", only="index"}>
123		<cfset params = {controller="dummy", action="index"}>
124		<cfset loc.controller = controller("dummy", params)>
125		<cfset loc.controller.usesLayout(argumentCollection=loc.args)>
126
127		<cfset loc.e = "true">
128		<cfset loc.r = loc.controller.$useLayout("show")>
129		<cfset assert('loc.e eq loc.r')>
130
131		<cfset loc.e = "mylayout">
132		<cfset loc.r = loc.controller.$useLayout("index")>
133		<cfset assert('loc.e eq loc.r')>
134
135		<cfset loc.args.usedefault = false>
136		<cfset loc.controller.usesLayout(argumentCollection=loc.args)>
137
138		<cfset loc.e = "false">
139		<cfset loc.r = loc.controller.$useLayout("show")>
140		<cfset assert('loc.e eq loc.r')>
141	</cffunction>
142
143	<cffunction name="test_should_respect_only_ajax">
144		<cfset request.cgi.http_x_requested_with = "XMLHTTPRequest">
145		<cfset loc.args = {template="mylayout", ajax="mylayout_ajax", only="index"}>
146		<cfset params = {controller="dummy", action="index"}>
147		<cfset loc.controller = controller("dummy", params)>
148		<cfset loc.controller.usesLayout(argumentCollection=loc.args)>
149
150		<cfset loc.e = "true">
151		<cfset loc.r = loc.controller.$useLayout("show")>
152		<cfset assert('loc.e eq loc.r')>
153
154		<cfset loc.e = "mylayout_ajax">
155		<cfset loc.r = loc.controller.$useLayout("index")>
156		<cfset assert('loc.e eq loc.r')>
157
158		<cfset loc.args.usedefault = false>
159		<cfset loc.controller.usesLayout(argumentCollection=loc.args)>
160
161		<cfset loc.e = "false">
162		<cfset loc.r = loc.controller.$useLayout("show")>
163		<cfset assert('loc.e eq loc.r')>
164	</cffunction>
165
166	<cffunction name="controller_layout_test">
167		<cfif arguments.action eq "index">
168			<cfreturn "index_layout">
169		</cfif>
170		<cfif arguments.action eq "show">
171			<cfreturn "show_layout">
172		</cfif>
173	</cffunction>
174
175	<cffunction name="controller_layout_test_ajax">
176		<cfif arguments.action eq "index">
177			<cfreturn "index_layout_ajax">
178		</cfif>
179		<cfif arguments.action eq "show">
180			<cfreturn "show_layout_ajax">
181		</cfif>
182	</cffunction>
183
184</cfcomponent>