PageRenderTime 50ms CodeModel.GetById 18ms RepoModel.GetById 0ms 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
Possible License(s): Apache-2.0, CPL-1.0
  1. <cfcomponent extends="wheelsMapping.Test">
  2. <cfset params = {controller="test", action="test"}>
  3. <cfset loc.controller = controller("dummy", params)>
  4. <cffunction name="setup">
  5. <cfset args = StructNew()>
  6. <cfset args.$testingMode = true>
  7. </cffunction>
  8. <cffunction name="test_only_file_supplied">
  9. <cfset args.file = "../wheels/tests/_assets/files/cfwheels-logo.png">
  10. <cfset loc.r = loc.controller.sendFile(argumentCollection=args)>
  11. <cfset assert('loc.r.file eq "cfwheels-logo.png"')>
  12. <cfset assert('loc.r.mime eq "image/png"')>
  13. <cfset assert('loc.r.name eq "cfwheels-logo.png"')>
  14. </cffunction>
  15. <cffunction name="test_file_and_name_supplied">
  16. <cfset args.file = "../wheels/tests/_assets/files/cfwheels-logo.png">
  17. <cfset args.name = "A Weird FileName.png">
  18. <cfset loc.r = loc.controller.sendFile(argumentCollection=args)>
  19. <cfset assert('loc.r.file eq "cfwheels-logo.png"')>
  20. <cfset assert('loc.r.mime eq "image/png"')>
  21. <cfset assert('loc.r.name eq "A Weird FileName.png"')>
  22. </cffunction>
  23. <cffunction name="test_change_disposition">
  24. <cfset args.file = "../wheels/tests/_assets/files/cfwheels-logo.png">
  25. <cfset args.disposition = "attachment">
  26. <cfset loc.r = loc.controller.sendFile(argumentCollection=args)>
  27. <cfset assert('loc.r.file eq "cfwheels-logo.png"')>
  28. <cfset assert('loc.r.disposition eq "attachment"')>
  29. <cfset assert('loc.r.mime eq "image/png"')>
  30. <cfset assert('loc.r.name eq "cfwheels-logo.png"')>
  31. </cffunction>
  32. <cffunction name="test_overload_mimetype">
  33. <cfset args.file = "../wheels/tests/_assets/files/cfwheels-logo.png">
  34. <cfset args.type = "wheels/custom">
  35. <cfset loc.r = loc.controller.sendFile(argumentCollection=args)>
  36. <cfset assert('loc.r.file eq "cfwheels-logo.png"')>
  37. <cfset assert('loc.r.disposition eq "attachment"')>
  38. <cfset assert('loc.r.mime eq "wheels/custom"')>
  39. <cfset assert('loc.r.name eq "cfwheels-logo.png"')>
  40. </cffunction>
  41. <cffunction name="test_no_extension_one_file_exists">
  42. <cfset args.file = "../wheels/tests/_assets/files/sendFile">
  43. <cfset loc.r = loc.controller.sendFile(argumentCollection=args)>
  44. <cfset assert('loc.r.file eq "sendFile.txt"')>
  45. <cfset assert('loc.r.mime eq "text/plain"')>
  46. <cfset assert('loc.r.name eq "sendFile.txt"')>
  47. </cffunction>
  48. <cffunction name="test_no_extension_multiple_files_exists">
  49. <cfset args.file = "../wheels/tests/_assets/files/cfwheels-logo">
  50. <cfset loc.r = raised("loc.controller.sendFile(argumentCollection=args)")>
  51. <cfset assert('loc.r eq "Wheels.FileNotFound"')>
  52. </cffunction>
  53. <cffunction name="test_specifying_a_directory">
  54. <cfset args.directory = expandPath("/wheelsMapping/tests/_assets")>
  55. <cfset args.file = "files/cfwheels-logo.png">
  56. <cfset loc.r = loc.controller.sendFile(argumentCollection=args)>
  57. <cfset assert('loc.r.file eq "cfwheels-logo.png"')>
  58. <cfset assert('loc.r.mime eq "image/png"')>
  59. <cfset assert('loc.r.name eq "cfwheels-logo.png"')>
  60. </cffunction>
  61. </cfcomponent>