PageRenderTime 77ms CodeModel.GetById 29ms RepoModel.GetById 5ms app.codeStats 0ms

/wheels/tests/view/urls/urlFor.cfc

http://cfwheels.googlecode.com/
ColdFusion CFScript | 94 lines | 82 code | 12 blank | 0 comment | 0 complexity | a3cb0689880df580f076443421e78cb6 MD5 | raw file
Possible License(s): Apache-2.0, CPL-1.0
  1. <cfcomponent extends="wheelsMapping.Test">
  2. <cffunction name="setup">
  3. <cfset params.controller = "Blog">
  4. <cfset params.action = "edit">
  5. <cfset params.key = "1">
  6. <cfset loc.controller = controller(params.controller, params)>
  7. <cfset loc.args = {}>
  8. <cfset loc.args.controller = "Blog">
  9. <cfset loc.args.action = "edit">
  10. <cfset loc.args.key = "1">
  11. <cfset loc.args.params = "param1=foo&param2=bar">
  12. <cfset loc.args.$URLRewriting = "On">
  13. <cfset oldScriptName = request.cgi.script_name>
  14. </cffunction>
  15. <cffunction name="teardown">
  16. <cfset request.cgi.script_name = oldScriptName>
  17. </cffunction>
  18. <cffunction name="test_all_arguments_with_url_rewriting">
  19. <cfset request.cgi.script_name = "/rewrite.cfm">
  20. <cfset loc.e = "#application.wheels.webpath#blog/edit/1?param1=foo&param2=bar">
  21. <cfset loc.r = loc.controller.urlFor(argumentcollection=loc.args)>
  22. <cfset assert("loc.e eq loc.r")>
  23. </cffunction>
  24. <cffunction name="test_missing_controller_with_url_rewriting">
  25. <cfset request.cgi.script_name = "/rewrite.cfm">
  26. <cfset StructDelete(loc.args, "controller")>
  27. <cfset loc.e = "#application.wheels.webpath#blog/edit/1?param1=foo&param2=bar">
  28. <cfset loc.r = loc.controller.urlFor(argumentcollection=loc.args)>
  29. <cfset assert("loc.e eq loc.r")>
  30. </cffunction>
  31. <cffunction name="test_missing_action_with_url_rewriting">
  32. <cfset request.cgi.script_name = "/rewrite.cfm">
  33. <cfset StructDelete(loc.args, "action")>
  34. <cfset loc.e = "#application.wheels.webpath#blog/edit/1?param1=foo&param2=bar">
  35. <cfset loc.r = loc.controller.urlFor(argumentcollection=loc.args)>
  36. <cfset assert("loc.e eq loc.r")>
  37. </cffunction>
  38. <cffunction name="test_missing_controller_and_action_with_url_rewriting">
  39. <cfset request.cgi.script_name = "/rewrite.cfm">
  40. <cfset StructDelete(loc.args, "controller")>
  41. <cfset StructDelete(loc.args, "action")>
  42. <cfset loc.e = "#application.wheels.webpath#blog/edit/1?param1=foo&param2=bar">
  43. <cfset loc.r = loc.controller.urlFor(argumentcollection=loc.args)>
  44. <cfset assert("loc.e eq loc.r")>
  45. </cffunction>
  46. <cffunction name="test_all_arguments_without_url_rewriting">
  47. <cfset request.cgi.script_name = "/index.cfm">
  48. <cfset loc.args.$URLRewriting = "Off">
  49. <cfset loc.webRoot = Replace("#application.wheels.webpath##ListLast(request.cgi.script_name, '/')#", "//", "/")>
  50. <cfset loc.e = "#loc.webRoot#?controller=blog&action=edit&key=1&param1=foo&param2=bar">
  51. <cfset loc.r = loc.controller.urlFor(argumentcollection=loc.args)>
  52. <cfset assert("loc.e eq loc.r")>
  53. </cffunction>
  54. <cffunction name="test_missing_controller_without_url_rewriting">
  55. <cfset request.cgi.script_name = "/index.cfm">
  56. <cfset loc.args.$URLRewriting = "Off">
  57. <cfset StructDelete(loc.args, "controller")>
  58. <cfset loc.webRoot = Replace("#application.wheels.webpath##ListLast(request.cgi.script_name, '/')#", "//", "/")>
  59. <cfset loc.e = "#loc.webRoot#?controller=blog&action=edit&key=1&param1=foo&param2=bar">
  60. <cfset loc.r = loc.controller.urlFor(argumentcollection=loc.args)>
  61. <cfset assert("loc.e eq loc.r")>
  62. </cffunction>
  63. <cffunction name="test_missing_action_without_url_rewriting">
  64. <cfset request.cgi.script_name = "/index.cfm">
  65. <cfset loc.args.$URLRewriting = "Off">
  66. <cfset StructDelete(loc.args, "action")>
  67. <cfset loc.webRoot = Replace("#application.wheels.webpath##ListLast(request.cgi.script_name, '/')#", "//", "/")>
  68. <cfset loc.e = "#loc.webRoot#?controller=blog&action=edit&key=1&param1=foo&param2=bar">
  69. <cfset loc.r = loc.controller.urlFor(argumentcollection=loc.args)>
  70. <cfset assert("loc.e eq loc.r")>
  71. </cffunction>
  72. <cffunction name="test_missing_controller_and_action_without_url_rewriting">
  73. <cfset request.cgi.script_name = "/index.cfm">
  74. <cfset loc.args.$URLRewriting = "Off">
  75. <cfset StructDelete(loc.args, "controller")>
  76. <cfset StructDelete(loc.args, "action")>
  77. <cfset loc.webRoot = Replace("#application.wheels.webpath##ListLast(request.cgi.script_name, '/')#", "//", "/")>
  78. <cfset loc.e = "#loc.webRoot#?controller=blog&action=edit&key=1&param1=foo&param2=bar">
  79. <cfset loc.r = loc.controller.urlFor(argumentcollection=loc.args)>
  80. <cfset assert("loc.e eq loc.r")>
  81. </cffunction>
  82. </cfcomponent>