PageRenderTime 82ms CodeModel.GetById 41ms app.highlight 1ms RepoModel.GetById 39ms app.codeStats 0ms

/wheels/tests/model/crud/pagination.cfc

http://cfwheels.googlecode.com/
ColdFusion CFScript | 118 lines | 101 code | 17 blank | 0 comment | 0 complexity | 759724a2eafac1ec58539cc5244d1aa5 MD5 | raw file
  1<cfcomponent extends="wheelsMapping.Test">
  2
  3	<cffunction name="setup">
  4		<cfset loc.user = model("user")>
  5		<cfset loc.photo = model("photo")>
  6		<cfset loc.gallery = model("gallery")>
  7	</cffunction>
  8
  9	<cffunction name="test_exist_early_if_no_records_match_where_clause">
 10		<cfset loc.e = loc.user.findAll(where="firstname = 'somemoron'", perpage="2", page="1", handle="pagination_test_1", order="id")>
 11		<cfset assert('request.wheels.pagination_test_1.CURRENTPAGE eq 1')>
 12		<cfset assert('request.wheels.pagination_test_1.TOTALPAGES eq 0')>
 13		<cfset assert('request.wheels.pagination_test_1.TOTALRECORDS eq 0')>
 14		<cfset assert("loc.e.recordcount eq 0")>
 15	</cffunction>
 16
 17	<cffunction name="test_5_records_2_perpage_3_pages">
 18		<cfset loc.r = loc.user.findAll(select="id", order="id")>
 19
 20		<!--- 1st page --->
 21		<cfset loc.e = loc.user.findAll(select="id", perpage="2", page="1", handle="pagination_test_2", order="id")>
 22		<cfset assert('request.wheels.pagination_test_2.CURRENTPAGE eq 1')>
 23		<cfset assert('request.wheels.pagination_test_2.TOTALPAGES eq 3')>
 24		<cfset assert('request.wheels.pagination_test_2.TOTALRECORDS eq 5')>
 25		<cfset assert("loc.e.recordcount eq 2")>
 26		<cfset assert('loc.e.id[1] eq loc.r.id[1]')>
 27		<cfset assert('loc.e.id[2] eq loc.r.id[2]')>
 28
 29		<!--- 2nd page --->
 30		<cfset loc.e = loc.user.findAll(perpage="2", page="2", handle="pagination_test_3", order="id")>
 31		<cfset assert('request.wheels.pagination_test_3.CURRENTPAGE eq 2')>
 32		<cfset assert('request.wheels.pagination_test_3.TOTALPAGES eq 3')>
 33		<cfset assert('request.wheels.pagination_test_3.TOTALRECORDS eq 5')>
 34		<cfset assert("loc.e.recordcount eq 2")>
 35		<cfset assert('loc.e.id[1] eq loc.r.id[3]')>
 36		<cfset assert('loc.e.id[2] eq loc.r.id[4]')>
 37
 38		<!--- 3rd page --->
 39		<cfset loc.e = loc.user.findAll(perpage="2", page="3", handle="pagination_test_4", order="id")>
 40		<cfset assert('request.wheels.pagination_test_4.CURRENTPAGE eq 3')>
 41		<cfset assert('request.wheels.pagination_test_4.TOTALPAGES eq 3')>
 42		<cfset assert('request.wheels.pagination_test_4.TOTALRECORDS eq 5')>
 43		<cfset assert("loc.e.recordcount eq 1")>
 44		<cfset assert('loc.e.id[1] eq loc.r.id[5]')>
 45	</cffunction>
 46
 47	<cffunction name="test_specify_where_on_joined_table">
 48		<cfset loc.q = loc.gallery.findOne(
 49			include="user"
 50			,where="users.lastname = 'Petruzzi'"
 51			,orderby="id"
 52		)>
 53
 54		<!--- 10 records, 2 perpage, 5 pages --->
 55		<cfset loc.args = {
 56				perpage="2"
 57				,page="1"
 58				,handle="pagination_test"
 59				,order="id"
 60				,include="gallery"
 61				,where="galleryid = #loc.q.id#"
 62		}>
 63
 64		<cfset loc.args2 = duplicate(loc.args)>
 65		<cfset structdelete(loc.args2, "perpage", false)>
 66		<cfset structdelete(loc.args2, "page", false)>
 67		<cfset structdelete(loc.args2, "handle", false)>
 68		<cfset loc.r = loc.photo.findAll(argumentCollection=loc.args2)>
 69
 70		<!--- page 1 --->
 71		<cfset loc.e = loc.photo.findAll(argumentCollection=loc.args)>
 72		<cfset assert('loc.e.galleryid[1] eq loc.r.galleryid[1]')>
 73		<cfset assert('loc.e.galleryid[2] eq loc.r.galleryid[2]')>
 74
 75		<!--- page 3 --->
 76		<cfset loc.args.page = "3">
 77		<cfset loc.e = loc.photo.findAll(argumentCollection=loc.args)>
 78		<cfset assert('loc.e.galleryid[1] eq loc.r.galleryid[5]')>
 79		<cfset assert('loc.e.galleryid[2] eq loc.r.galleryid[6]')>
 80
 81		<!--- page 5 --->
 82		<cfset loc.args.page = "5">
 83		<cfset loc.e = loc.photo.findAll(argumentCollection=loc.args)>
 84		<cfset assert('loc.e.galleryid[1] eq loc.r.galleryid[9]')>
 85		<cfset assert('loc.e.galleryid[2] eq loc.r.galleryid[10]')>
 86	</cffunction>
 87
 88	<cffunction name="test_make_sure_that_remapped_columns_containing_desc_and_asc_work">
 89		<cfset loc.result = model("photo").findAll(page=1, perPage=20, order='DESCription1 DESC', handle="pagination_order_test_1")>
 90		<cfset assert('request.wheels.pagination_order_test_1.CURRENTPAGE eq 1')>
 91		<cfset assert('request.wheels.pagination_order_test_1.TOTALPAGES eq 13')>
 92		<cfset assert('request.wheels.pagination_order_test_1.TOTALRECORDS eq 250')>
 93	</cffunction>
 94
 95	<cffunction name="test_with_renamed_primary_key">
 96		<cfset loc.photo = model("photo2").findAll(
 97				page=1
 98				,perpage=3
 99				,where="DESCRIPTION1 LIKE '%test%'"
100		)>
101		<cfset assert('loc.photo.recordcount eq 3')>
102	</cffunction>
103	
104	<cffunction name="test_with_parameterize_set_to_false_with_string">
105		<cfset loc.result = model("photo").findAll(page=1, perPage=20, handle="pagination_order_test_1", parameterize="false", where="description1 LIKE '%photo%'")>
106		<cfset assert('request.wheels.pagination_order_test_1.CURRENTPAGE eq 1')>
107		<cfset assert('request.wheels.pagination_order_test_1.TOTALPAGES eq 13')>
108		<cfset assert('request.wheels.pagination_order_test_1.TOTALRECORDS eq 250')>
109	</cffunction>
110	
111	<cffunction name="test_with_parameterize_set_to_false_with_numeric">
112		<cfset loc.result = model("photo").findAll(page=1, perPage=20, handle="pagination_order_test_1", parameterize="false", where="id = 1")>
113		<cfset assert('request.wheels.pagination_order_test_1.CURRENTPAGE eq 1')>
114		<cfset assert('request.wheels.pagination_order_test_1.TOTALPAGES eq 1')>
115		<cfset assert('request.wheels.pagination_order_test_1.TOTALRECORDS eq 1')>
116	</cffunction>
117
118</cfcomponent>