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

/wheels/tests/controller/provides/renderwith.cfc

http://cfwheels.googlecode.com/
ColdFusion CFScript | 116 lines | 102 code | 14 blank | 0 comment | 0 complexity | b84cc5367b5b5ca5d4c58b3c72288ea0 MD5 | raw file
  1<cfcomponent extends="wheelsMapping.Test">
  2
  3	<cffunction name="setup">
  4		<cfset $ENV = duplicate(application)>
  5		<cfset params = {controller="test", action="test"}>
  6		<cfset application.wheels.viewPath = "wheels/tests/_assets/views">
  7	</cffunction>
  8
  9	<cffunction name="teardown">
 10		<cfset application = $ENV>
 11		<cfset $header(name="content-type", value="text/html" , charset="utf-8") />
 12	</cffunction>
 13
 14
 15	<cffunction name="test_throws_error_without_data_argument">
 16		<cfset loc.controller = controller("test", params)>
 17		<cftry>
 18			<cfset result = loc.controller.renderWith()>
 19			<cfcatch type="any">
 20				<cfset assert('true eq true') />
 21			</cfcatch>
 22		</cftry>
 23	</cffunction>
 24
 25	<cffunction name="test_current_action_as_xml_with_template_returning_string_to_controller">
 26		<cfset params.format = "xml">
 27		<cfset loc.controller = controller("test", params)>
 28		<cfset loc.controller.provides("xml") />
 29		<cfset user = model("user").findOne(where="username = 'tonyp'") />
 30		<cfset loc.data = loc.controller.renderWith(data=user, layout=false, returnAs="string")>
 31		<cfset assert("loc.data Contains 'xml template content'")>
 32	</cffunction>
 33
 34	<cffunction name="test_current_action_as_xml_with_template">
 35		<cfset params.format = "xml">
 36		<cfset loc.controller = controller("test", params)>
 37		<cfset loc.controller.provides("xml") />
 38		<cfset user = model("user").findOne(where="username = 'tonyp'") />
 39		<cfset loc.controller.renderWith(data=user, layout=false)>
 40		<cfset assert("loc.controller.response() Contains 'xml template content'")>
 41	</cffunction>
 42
 43	<cffunction name="test_current_action_as_xml_without_template">
 44		<cfset params.action = "test2">
 45		<cfset params.format = "xml">
 46		<cfset loc.controller = controller("test", params)>
 47		<cfset loc.controller.provides("xml") />
 48		<cfset user = model("user").findOne(where="username = 'tonyp'") />
 49		<cfset loc.controller.renderWith(data=user)>
 50		<cfset assert("IsXml(loc.controller.response()) eq true")>
 51	</cffunction>
 52
 53	<cffunction name="test_current_action_as_xml_without_template_returning_string_to_controller">
 54		<cfset params.action = "test2">
 55		<cfset params.format = "xml">
 56		<cfset loc.controller = controller("test", params)>
 57		<cfset loc.controller.provides("xml") />
 58		<cfset user = model("user").findOne(where="username = 'tonyp'") />
 59		<cfset loc.data = loc.controller.renderWith(data=user, returnAs="string")>
 60		<cfset assert("IsXml(loc.data) eq true")>
 61	</cffunction>
 62
 63	<cffunction name="test_current_action_as_json_with_template">
 64		<cfset params.format = "json">
 65		<cfset loc.controller = controller("test", params)>
 66		<cfset loc.controller.provides("json") />
 67		<cfset user = model("user").findOne(where="username = 'tonyp'") />
 68		<cfset loc.controller.renderWith(data=user, layout=false)>
 69		<cfset assert("loc.controller.response() Contains 'json template content'")>
 70	</cffunction>
 71
 72	<cffunction name="test_current_action_as_json_without_template">
 73		<cfset params.action = "test2">
 74		<cfset params.format = "json">
 75		<cfset loc.controller = controller("test", params)>
 76		<cfset loc.controller.provides("json") />
 77		<cfset user = model("user").findOne(where="username = 'tonyp'") />
 78		<cfset loc.controller.renderWith(data=user)>
 79		<cfset assert("IsJSON(loc.controller.response()) eq true")>
 80	</cffunction>
 81
 82	<cffunction name="test_current_action_as_json_without_template_returning_string_to_controller">
 83		<cfset params.action = "test2">
 84		<cfset params.format = "json">
 85		<cfset loc.controller = controller("test", params)>
 86		<cfset loc.controller.provides("json") />
 87		<cfset user = model("user").findOne(where="username = 'tonyp'") />
 88		<cfset loc.data = loc.controller.renderWith(data=user, returnAs="string")>
 89		<cfset assert("IsJSON(loc.data) eq true")>
 90	</cffunction>
 91
 92	<cffunction name="test_current_action_as_pdf_with_template_throws_error">
 93		<cfset params.format = "pdf">
 94		<cfset loc.controller = controller("test", params)>
 95		<cfset loc.controller.provides("pdf") />
 96		<cfset user = model("user").findOne(where="username = 'tonyp'") />
 97		<cftry>
 98			<cfset loc.controller.renderWith(data=user, layout=false)>
 99			<cfset fail(message="Error did not occur.")>
100			<cfcatch type="any">
101				<cfset assert("true eq true")>
102			</cfcatch>
103		</cftry>
104	</cffunction>
105
106 	<cffunction name="test_current_action_as_json_with_template_in_production">
107		<cfset application.wheels.cacheFileChecking = true>
108		<cfset params.format = "json">
109		<cfset loc.controller = controller("test", params)>
110		<cfset loc.controller.provides("json") />
111		<cfset user = model("user").findOne(where="username = 'tonyp'") />
112		<cfset loc.controller.renderWith(data=user, layout=false)>
113		<cfset assert("loc.controller.response() Contains 'json template content'")>
114	</cffunction>
115
116</cfcomponent>