PageRenderTime 16ms CodeModel.GetById 0ms RepoModel.GetById 0ms 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
Possible License(s): Apache-2.0, CPL-1.0
  1. <cfcomponent extends="wheelsMapping.Test">
  2. <cffunction name="setup">
  3. <cfset $$oldViewPath = application.wheels.viewPath>
  4. <cfset application.wheels.viewPath = "wheels/tests/_assets/views">
  5. </cffunction>
  6. <cfset params = {controller="test", action="test"}>
  7. <cfset loc.controller = controller("test", params)>
  8. <cffunction name="test_including_partial">
  9. <cfsavecontent variable="result"><cfoutput>#loc.controller.includePartial(partial="partialTemplate")#</cfoutput></cfsavecontent>
  10. <cfset assert("result Contains 'partial template content'")>
  11. </cffunction>
  12. <cffunction name="test_including_partial_loading_data">
  13. <cfsavecontent variable="result"><cfoutput>#loc.controller.includePartial(partial="partialDataImplicitPrivate")#</cfoutput></cfsavecontent>
  14. <cfset assert("result IS 'Apple,Banana,Kiwi'")>
  15. </cffunction>
  16. <cffunction name="test_including_partial_loading_data_allowed_from_explicit_public_method">
  17. <cfsavecontent variable="result"><cfoutput>#loc.controller.includePartial(partial="partialDataExplicitPublic", dataFunction="partialDataExplicitPublic")#</cfoutput></cfsavecontent>
  18. <cfset assert("result IS 'Apple,Banana,Kiwi'")>
  19. </cffunction>
  20. <cffunction name="test_including_partial_loading_data_not_allowed_from_implicit_public_method">
  21. <cfset result = "">
  22. <cftry>
  23. <cfsavecontent variable="result"><cfoutput>#loc.controller.includePartial(partial="partialDataImplicitPublic")#</cfoutput></cfsavecontent>
  24. <cfcatch type="any">
  25. <cfset result = cfcatch>
  26. </cfcatch>
  27. </cftry>
  28. <cfset assert("!issimplevalue(result)")>
  29. <cfset assert("result.type eq 'expression'")>
  30. </cffunction>
  31. <cffunction name="test_including_partial_with_query">
  32. <cfset usersQuery = model("user").findAll(order="firstName")>
  33. <cfset request.partialTests.currentTotal = 0>
  34. <cfset request.partialTests.thirdUserName = "">
  35. <cfsavecontent variable="result"><cfoutput>#loc.controller.includePartial(usersQuery)#</cfoutput></cfsavecontent>
  36. <cfset assert("request.partialTests.currentTotal IS 15 AND request.partialTests.thirdUserName IS 'Per'")>
  37. </cffunction>
  38. <cffunction name="test_including_partial_with_special_query_argument">
  39. <cfset usersQuery = model("user").findAll(order="firstName")>
  40. <cfset request.partialTests.currentTotal = 0>
  41. <cfset request.partialTests.thirdUserName = "">
  42. <cfset request.partialTests.noQueryArg = true>
  43. <cfsavecontent variable="result"><cfoutput>#loc.controller.includePartial(partial="custom", query=usersQuery)#</cfoutput></cfsavecontent>
  44. <cfset assert("request.partialTests.noQueryArg IS true AND request.partialTests.currentTotal IS 15 AND request.partialTests.thirdUserName IS 'Per'")>
  45. </cffunction>
  46. <cffunction name="test_including_partial_with_normal_query_argument">
  47. <cfset usersQuery = model("user").findAll(order="firstName")>
  48. <cfsavecontent variable="result"><cfoutput>#loc.controller.includePartial(partial="custom", customQuery=usersQuery)#</cfoutput></cfsavecontent>
  49. <cfset assert("Trim(result) IS 'Per'")>
  50. </cffunction>
  51. <cffunction name="test_including_partial_with_special_objects_argument">
  52. <cfset usersArray = model("user").findAll(order="firstName", returnAs="objects")>
  53. <cfset request.partialTests.currentTotal = 0>
  54. <cfset request.partialTests.thirdUserName = "">
  55. <cfset request.partialTests.thirdObjectExists = false>
  56. <cfset request.partialTests.noObjectsArg = true>
  57. <cfsavecontent variable="result"><cfoutput>#loc.controller.includePartial(partial="custom", objects=usersArray)#</cfoutput></cfsavecontent>
  58. <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'")>
  59. </cffunction>
  60. <cffunction name="test_including_partial_with_object">
  61. <cfset userObject = model("user").findOne(order="firstName")>
  62. <cfset request.wheelsTests.objectTestsPassed = false>
  63. <cfsavecontent variable="result"><cfoutput>#loc.controller.includePartial(userObject)#</cfoutput></cfsavecontent>
  64. <cfset assert("request.wheelsTests.objectTestsPassed IS true AND Trim(result) IS 'Chris'")>
  65. </cffunction>
  66. <cffunction name="teardown">
  67. <cfset application.wheels.viewPath = $$oldViewPath>
  68. </cffunction>
  69. </cfcomponent>