PageRenderTime 169ms CodeModel.GetById 20ms RepoModel.GetById 0ms app.codeStats 0ms

/wheels/tests/view/links/paginationlinks.cfc

http://cfwheels.googlecode.com/
ColdFusion CFScript | 55 lines | 48 code | 7 blank | 0 comment | 0 complexity | 9dad46b2c4d0f5926d0a993fb1aac25b MD5 | raw file
Possible License(s): Apache-2.0, CPL-1.0
  1. <cfcomponent extends="wheelsMapping.Test">
  2. <cfset params = {controller="dummy", action="dummy"}>
  3. <cffunction name="setup">
  4. <cfset var loc = StructNew()>
  5. <cfset copies = {}>
  6. <cfset StructAppend(copies, Duplicate(application.wheels))>
  7. <cfset test.controller = controller("dummy", params)>
  8. <cfset loc.route = StructNew()>
  9. <cfset loc.route.name = "pagination">
  10. <cfset loc.route.pattern = "pag/ina/tion/[special]">
  11. <cfset loc.route.controller = "pagi">
  12. <cfset loc.route.action = "nation">
  13. <cfset loc.route.variables = "special">
  14. <cfset ArrayInsertAt(application.wheels.routes, 2, loc.route)>
  15. <cfset application.wheels.namedRoutePositions.pagination = [2]>
  16. <cfset application.wheels.URLRewriting = "on">
  17. </cffunction>
  18. <cffunction name="teardown">
  19. <cfset StructAppend(application.wheels, duplicate(copies), true)>
  20. </cffunction>
  21. <cffunction name="test_current_page">
  22. <cfset var loc = StructNew()>
  23. <cfset loc.authors = model("author").findAll(page=2, perPage=3, order="lastName")>
  24. <cfset loc.link = test.controller.linkTo(text="2", params="page=2")>
  25. <cfset result = test.controller.paginationLinks(linkToCurrentPage=true)>
  26. <cfset assert("result Contains '#loc.link#'")>
  27. <cfset result = test.controller.paginationLinks(linkToCurrentPage=false)>
  28. <cfset assert("result Does Not Contain '#loc.link#' AND result Contains '2'")>
  29. </cffunction>
  30. <cffunction name="test_route">
  31. <cfset var loc = StructNew()>
  32. <cfset loc.authors = model("author").findAll(page=2, perPage=3, order="lastName")>
  33. <cfset loc.link = test.controller.linkTo(route="pagination", special=99, text="3", params="page=3")>
  34. <cfset result = test.controller.paginationLinks(route="pagination", special=99)>
  35. <cfset assert("result Contains '#loc.link#' AND result Contains '?page='")>
  36. </cffunction>
  37. <cffunction name="test_page_as_route_param">
  38. <cfset var loc = StructNew()>
  39. <cfset loc.authors = model("author").findAll(page=2, perPage=3, order="lastName")>
  40. <cfset loc.addToPattern = "/[page]">
  41. <cfset loc.addToVariables = ",page">
  42. <cfset application.wheels.routes[2].pattern = application.wheels.routes[2].pattern & loc.addToPattern>
  43. <cfset application.wheels.routes[2].variables = application.wheels.routes[2].variables & loc.addToVariables>
  44. <cfset loc.link = test.controller.linkTo(route="pagination", special=99, text="3", page=3)>
  45. <cfset result = test.controller.paginationLinks(route="pagination", special=99, pageNumberAsParam=false)>
  46. <cfset assert("result Contains '#loc.link#' AND result Does Not Contain '?page='")>
  47. </cffunction>
  48. </cfcomponent>