PageRenderTime 404ms CodeModel.GetById 241ms app.highlight 1ms RepoModel.GetById 160ms 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
 1<cfcomponent extends="wheelsMapping.Test">
 2
 3	<cfset params = {controller="dummy", action="dummy"}>
 4
 5	<cffunction name="setup">
 6		<cfset var loc = StructNew()>
 7		<cfset copies = {}>
 8		<cfset StructAppend(copies, Duplicate(application.wheels))>
 9		<cfset test.controller = controller("dummy", params)>
10		<cfset loc.route = StructNew()>
11		<cfset loc.route.name = "pagination">
12		<cfset loc.route.pattern = "pag/ina/tion/[special]">
13		<cfset loc.route.controller = "pagi">
14		<cfset loc.route.action = "nation">
15		<cfset loc.route.variables = "special">
16		<cfset ArrayInsertAt(application.wheels.routes, 2, loc.route)>
17		<cfset application.wheels.namedRoutePositions.pagination = [2]>
18		<cfset application.wheels.URLRewriting = "on">
19	</cffunction>
20
21	<cffunction name="teardown">
22		<cfset StructAppend(application.wheels, duplicate(copies), true)>
23	</cffunction>
24	
25	<cffunction name="test_current_page">
26		<cfset var loc = StructNew()>
27		<cfset loc.authors = model("author").findAll(page=2, perPage=3, order="lastName")>
28		<cfset loc.link = test.controller.linkTo(text="2", params="page=2")>
29		<cfset result = test.controller.paginationLinks(linkToCurrentPage=true)>
30		<cfset assert("result Contains '#loc.link#'")>
31		<cfset result = test.controller.paginationLinks(linkToCurrentPage=false)>
32		<cfset assert("result Does Not Contain '#loc.link#' AND result Contains '2'")>
33	</cffunction>
34
35	<cffunction name="test_route">
36		<cfset var loc = StructNew()>
37		<cfset loc.authors = model("author").findAll(page=2, perPage=3, order="lastName")>
38		<cfset loc.link = test.controller.linkTo(route="pagination", special=99, text="3", params="page=3")>
39		<cfset result = test.controller.paginationLinks(route="pagination", special=99)>
40		<cfset assert("result Contains '#loc.link#' AND result Contains '?page='")>
41	</cffunction>
42
43	<cffunction name="test_page_as_route_param">
44		<cfset var loc = StructNew()>
45		<cfset loc.authors = model("author").findAll(page=2, perPage=3, order="lastName")>
46		<cfset loc.addToPattern = "/[page]">
47		<cfset loc.addToVariables = ",page">
48		<cfset application.wheels.routes[2].pattern = application.wheels.routes[2].pattern & loc.addToPattern>
49		<cfset application.wheels.routes[2].variables = application.wheels.routes[2].variables & loc.addToVariables>
50		<cfset loc.link = test.controller.linkTo(route="pagination", special=99, text="3", page=3)>
51		<cfset result = test.controller.paginationLinks(route="pagination", special=99, pageNumberAsParam=false)>
52		<cfset assert("result Contains '#loc.link#' AND result Does Not Contain '?page='")>
53	</cffunction>
54	
55</cfcomponent>