PageRenderTime 4ms CodeModel.GetById 1ms app.highlight 1ms RepoModel.GetById 1ms app.codeStats 0ms

/wheels/tests/view/content/includePartial.cfc

http://cfwheels.googlecode.com/
ColdFusion CFScript | 82 lines | 69 code | 13 blank | 0 comment | 0 complexity | a794a7e61e8d1277229d2edf4bc2ada4 MD5 | raw file
 1<cfcomponent extends="wheelsMapping.Test">
 2
 3	<cffunction name="setup">
 4		<cfset $$oldViewPath = application.wheels.viewPath>
 5		<cfset application.wheels.viewPath = "wheels/tests/_assets/views">
 6	</cffunction>
 7
 8	<cfset params = {controller="test", action="test"}>
 9	<cfset loc.controller = controller("test", params)>
10
11	<cffunction name="test_including_partial">
12		<cfsavecontent variable="result"><cfoutput>#loc.controller.includePartial(partial="partialTemplate")#</cfoutput></cfsavecontent>
13		<cfset assert("result Contains 'partial template content'")>
14	</cffunction>
15
16	<cffunction name="test_including_partial_loading_data">
17		<cfsavecontent variable="result"><cfoutput>#loc.controller.includePartial(partial="partialDataImplicitPrivate")#</cfoutput></cfsavecontent>
18		<cfset assert("result IS 'Apple,Banana,Kiwi'")>
19	</cffunction>
20
21	<cffunction name="test_including_partial_loading_data_allowed_from_explicit_public_method">
22		<cfsavecontent variable="result"><cfoutput>#loc.controller.includePartial(partial="partialDataExplicitPublic", dataFunction="partialDataExplicitPublic")#</cfoutput></cfsavecontent>
23		<cfset assert("result IS 'Apple,Banana,Kiwi'")>
24	</cffunction>
25
26	<cffunction name="test_including_partial_loading_data_not_allowed_from_implicit_public_method">
27		<cfset result = "">
28		<cftry>
29		<cfsavecontent variable="result"><cfoutput>#loc.controller.includePartial(partial="partialDataImplicitPublic")#</cfoutput></cfsavecontent>
30			<cfcatch type="any">
31				<cfset result = cfcatch>
32			</cfcatch>
33		</cftry>
34		<cfset assert("!issimplevalue(result)")>
35		<cfset assert("result.type eq 'expression'")>
36	</cffunction>
37
38	<cffunction name="test_including_partial_with_query">
39		<cfset usersQuery = model("user").findAll(order="firstName")>
40		<cfset request.partialTests.currentTotal = 0>
41		<cfset request.partialTests.thirdUserName = "">
42		<cfsavecontent variable="result"><cfoutput>#loc.controller.includePartial(usersQuery)#</cfoutput></cfsavecontent>
43		<cfset assert("request.partialTests.currentTotal IS 15 AND request.partialTests.thirdUserName IS 'Per'")>
44	</cffunction>
45
46	<cffunction name="test_including_partial_with_special_query_argument">
47		<cfset usersQuery = model("user").findAll(order="firstName")>
48		<cfset request.partialTests.currentTotal = 0>
49		<cfset request.partialTests.thirdUserName = "">
50		<cfset request.partialTests.noQueryArg = true>
51		<cfsavecontent variable="result"><cfoutput>#loc.controller.includePartial(partial="custom", query=usersQuery)#</cfoutput></cfsavecontent>
52		<cfset assert("request.partialTests.noQueryArg IS true AND request.partialTests.currentTotal IS 15 AND request.partialTests.thirdUserName IS 'Per'")>
53	</cffunction>
54
55	<cffunction name="test_including_partial_with_normal_query_argument">
56		<cfset usersQuery = model("user").findAll(order="firstName")>
57		<cfsavecontent variable="result"><cfoutput>#loc.controller.includePartial(partial="custom", customQuery=usersQuery)#</cfoutput></cfsavecontent>
58		<cfset assert("Trim(result) IS 'Per'")>
59	</cffunction>
60
61	<cffunction name="test_including_partial_with_special_objects_argument">
62		<cfset usersArray = model("user").findAll(order="firstName", returnAs="objects")>
63		<cfset request.partialTests.currentTotal = 0>
64		<cfset request.partialTests.thirdUserName = "">
65		<cfset request.partialTests.thirdObjectExists = false>
66		<cfset request.partialTests.noObjectsArg = true>
67		<cfsavecontent variable="result"><cfoutput>#loc.controller.includePartial(partial="custom", objects=usersArray)#</cfoutput></cfsavecontent>
68		<cfset assert("request.partialTests.thirdObjectExists IS true AND request.partialTests.noObjectsArg IS true AND request.partialTests.currentTotal IS 15 AND request.partialTests.thirdUserName IS 'Per'")>
69	</cffunction>
70
71	<cffunction name="test_including_partial_with_object">
72		<cfset userObject = model("user").findOne(order="firstName")>
73		<cfset request.wheelsTests.objectTestsPassed = false>
74		<cfsavecontent variable="result"><cfoutput>#loc.controller.includePartial(userObject)#</cfoutput></cfsavecontent>
75		<cfset assert("request.wheelsTests.objectTestsPassed IS true AND Trim(result) IS 'Chris'")>
76	</cffunction>
77
78	<cffunction name="teardown">
79		<cfset application.wheels.viewPath = $$oldViewPath>
80	</cffunction>
81
82</cfcomponent>