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

/wheels/tests/controller/miscellaneous/sendfile.cfc

http://cfwheels.googlecode.com/
ColdFusion CFScript | 71 lines | 61 code | 10 blank | 0 comment | 0 complexity | bd84a37f683429700869ce1003a69239 MD5 | raw file
 1<cfcomponent extends="wheelsMapping.Test">
 2
 3	<cfset params = {controller="test", action="test"}>
 4	<cfset loc.controller = controller("dummy", params)>
 5	
 6	<cffunction name="setup">
 7		<cfset args = StructNew()>
 8		<cfset args.$testingMode = true>
 9	</cffunction>
10	
11	<cffunction name="test_only_file_supplied">
12		<cfset args.file = "../wheels/tests/_assets/files/cfwheels-logo.png">
13		<cfset loc.r = loc.controller.sendFile(argumentCollection=args)>
14		<cfset assert('loc.r.file eq "cfwheels-logo.png"')>
15		<cfset assert('loc.r.mime eq "image/png"')>
16		<cfset assert('loc.r.name eq "cfwheels-logo.png"')>
17	</cffunction>
18	
19	<cffunction name="test_file_and_name_supplied">
20		<cfset args.file = "../wheels/tests/_assets/files/cfwheels-logo.png">
21		<cfset args.name = "A Weird FileName.png">
22		<cfset loc.r = loc.controller.sendFile(argumentCollection=args)>
23		<cfset assert('loc.r.file eq "cfwheels-logo.png"')>
24		<cfset assert('loc.r.mime eq "image/png"')>
25		<cfset assert('loc.r.name eq "A Weird FileName.png"')>
26	</cffunction>
27	
28	<cffunction name="test_change_disposition">
29		<cfset args.file = "../wheels/tests/_assets/files/cfwheels-logo.png">
30		<cfset args.disposition = "attachment">
31		<cfset loc.r = loc.controller.sendFile(argumentCollection=args)>
32		<cfset assert('loc.r.file eq "cfwheels-logo.png"')>
33		<cfset assert('loc.r.disposition eq "attachment"')>
34		<cfset assert('loc.r.mime eq "image/png"')>
35		<cfset assert('loc.r.name eq "cfwheels-logo.png"')>
36	</cffunction>
37	
38	<cffunction name="test_overload_mimetype">
39		<cfset args.file = "../wheels/tests/_assets/files/cfwheels-logo.png">
40		<cfset args.type = "wheels/custom">
41		<cfset loc.r = loc.controller.sendFile(argumentCollection=args)>
42		<cfset assert('loc.r.file eq "cfwheels-logo.png"')>
43		<cfset assert('loc.r.disposition eq "attachment"')>
44		<cfset assert('loc.r.mime eq "wheels/custom"')>
45		<cfset assert('loc.r.name eq "cfwheels-logo.png"')>
46	</cffunction>
47	
48	<cffunction name="test_no_extension_one_file_exists">
49		<cfset args.file = "../wheels/tests/_assets/files/sendFile">
50		<cfset loc.r = loc.controller.sendFile(argumentCollection=args)>
51		<cfset assert('loc.r.file eq "sendFile.txt"')>
52		<cfset assert('loc.r.mime eq "text/plain"')>
53		<cfset assert('loc.r.name eq "sendFile.txt"')>
54	</cffunction>
55	
56	<cffunction name="test_no_extension_multiple_files_exists">
57		<cfset args.file = "../wheels/tests/_assets/files/cfwheels-logo">
58		<cfset loc.r = raised("loc.controller.sendFile(argumentCollection=args)")>
59		<cfset assert('loc.r eq "Wheels.FileNotFound"')>
60	</cffunction>
61	
62	<cffunction name="test_specifying_a_directory">
63		<cfset args.directory = expandPath("/wheelsMapping/tests/_assets")>
64		<cfset args.file = "files/cfwheels-logo.png">
65		<cfset loc.r = loc.controller.sendFile(argumentCollection=args)>
66		<cfset assert('loc.r.file eq "cfwheels-logo.png"')>
67		<cfset assert('loc.r.mime eq "image/png"')>
68		<cfset assert('loc.r.name eq "cfwheels-logo.png"')>
69	</cffunction>
70	
71</cfcomponent>