| 1 | <!----------------------------------------------------------------------- |
|---|
| 2 | ******************************************************************************** |
|---|
| 3 | Copyright 2005-2007 ColdBox Framework by Luis Majano and Ortus Solutions, Corp |
|---|
| 4 | www.coldboxframework.com | www.luismajano.com | www.ortussolutions.com |
|---|
| 5 | ******************************************************************************** |
|---|
| 6 | |
|---|
| 7 | Author : Sana Ullah |
|---|
| 8 | Date : March 30 2008 |
|---|
| 9 | Description : |
|---|
| 10 | queryHelper plugin test |
|---|
| 11 | -----------------------------------------------------------------------> |
|---|
| 12 | <cfcomponent name="queryHelperTest" extends="coldbox.system.extras.testing.baseMXUnitTest" output="false"> |
|---|
| 13 | |
|---|
| 14 | <cffunction name="setUp" returntype="void" access="public" output="false"> |
|---|
| 15 | <cfscript> |
|---|
| 16 | //Setup ColdBox Mappings For this Test |
|---|
| 17 | setAppMapping("/coldbox/testharness"); |
|---|
| 18 | setConfigMapping(ExpandPath(instance.AppMapping & "/config/coldbox.xml.cfm")); |
|---|
| 19 | //Call the super setup method to setup the app. |
|---|
| 20 | super.setup(); |
|---|
| 21 | </cfscript> |
|---|
| 22 | |
|---|
| 23 | <cfscript> |
|---|
| 24 | variables.q1 = queryNew('idt,fname,lname,phone,location'); |
|---|
| 25 | variables.q2 = queryNew('idt,fname,lname,phone,location'); |
|---|
| 26 | variables.q3 = queryNew('idt,fname,lname,telephone,city'); |
|---|
| 27 | </cfscript> |
|---|
| 28 | |
|---|
| 29 | <cfloop from="1" to="10" index="i"> |
|---|
| 30 | <cfset queryAddRow(q1,1) /> |
|---|
| 31 | <cfset querySetCell(q1, 'idt', '#i#')> |
|---|
| 32 | <cfset querySetCell(q1, 'fname', 'fname-q1-#chr(65 + i)#')> |
|---|
| 33 | <cfset querySetCell(q1, 'lname', 'lname-q1-#chr(65 + i)#')> |
|---|
| 34 | <cfset querySetCell(q1, 'phone', 'phone-q1-954-555-5555-#i#')> |
|---|
| 35 | <cfset querySetCell(q1, 'location', 'location-q1-#chr(65 + i)#')> |
|---|
| 36 | </cfloop> |
|---|
| 37 | |
|---|
| 38 | <cfloop from="11" to="20" index="i"> |
|---|
| 39 | <cfset queryAddRow(q2,1) /> |
|---|
| 40 | <cfset querySetCell(q2, 'idt', '#i#')> |
|---|
| 41 | <cfset querySetCell(q2, 'fname', 'fname-q2-#chr(75 + i)#')> |
|---|
| 42 | <cfset querySetCell(q2, 'lname', 'lname-q2-#chr(75 + i)#')> |
|---|
| 43 | <cfset querySetCell(q2, 'phone', 'phone-q2-954-555-5555-#i#')> |
|---|
| 44 | <cfset querySetCell(q2, 'location', 'location-q2-#chr(75 + i)#')> |
|---|
| 45 | </cfloop> |
|---|
| 46 | |
|---|
| 47 | <cfloop from="6" to="15" index="i"> |
|---|
| 48 | <cfset queryAddRow(q3,1) /> |
|---|
| 49 | <cfset querySetCell(q3, 'idt', '#i#')> |
|---|
| 50 | <cfset querySetCell(q3, 'fname', 'fname-q3-#chr(65 + i)#')> |
|---|
| 51 | <cfset querySetCell(q3, 'lname', 'lname-q3-#chr(65 + i)#')> |
|---|
| 52 | <cfset querySetCell(q3, 'telephone', 'phone-q3-954-555-5555-#i#')> |
|---|
| 53 | <cfset querySetCell(q3, 'city', 'location-q3-#chr(65 + i)#')> |
|---|
| 54 | </cfloop> |
|---|
| 55 | </cffunction> |
|---|
| 56 | |
|---|
| 57 | <cffunction name="testPlugin" access="public" returntype="void" output="false"> |
|---|
| 58 | <!--- Now test some events ---> |
|---|
| 59 | <cfscript> |
|---|
| 60 | var plugin = getController().getPlugin("queryHelper"); |
|---|
| 61 | |
|---|
| 62 | AssertTrue( isObject(plugin) ); |
|---|
| 63 | </cfscript> |
|---|
| 64 | </cffunction> |
|---|
| 65 | |
|---|
| 66 | <cffunction name="testMethods" access="public" returntype="void" output="false"> |
|---|
| 67 | <!--- Now test some events ---> |
|---|
| 68 | <cfscript> |
|---|
| 69 | var plugin = getController().getPlugin("queryHelper"); |
|---|
| 70 | var jsonText = "{name:'luis',number:'23423'}"; |
|---|
| 71 | var local = structnew(); |
|---|
| 72 | |
|---|
| 73 | assertTrue(isQuery(plugin.filterQuery(variables.q1, 'idt', '9', 'cf_sql_integer')), "Returned value is not query"); |
|---|
| 74 | |
|---|
| 75 | assertTrue(isQuery(plugin.sortQuery(variables.q1, 'fname', 'DESC')), "Returned value is not query"); |
|---|
| 76 | |
|---|
| 77 | assertTrue(isArray(plugin.getColumnArray(variables.q1, 'fname')), "Returned value is not Array"); |
|---|
| 78 | |
|---|
| 79 | assertTrue(isValid('numeric',plugin.getCountDistinct(variables.q1, 'fname')), "Returned value is not number"); |
|---|
| 80 | |
|---|
| 81 | assertTrue(isValid('numeric',plugin.getRowNumber(variables.q1, '8', 'idt')), "Returned value is not number"); |
|---|
| 82 | |
|---|
| 83 | assertTrue(isValid('numeric',plugin.getRowNumber(variables.q3, '15', 'idt')), "Returned value is not number"); |
|---|
| 84 | |
|---|
| 85 | assertTrue(isQuery(plugin.doInnerJoin(q1,q3,"idt","idt")), "Returned value is not query"); |
|---|
| 86 | |
|---|
| 87 | assertTrue(isQuery(plugin.doLeftOuterJoin(q1,q3,"idt","idt")), "Returned value is not query"); |
|---|
| 88 | |
|---|
| 89 | assertTrue(isQuery(plugin.doQueryAppend(q3,q1)), "Returned value is not query"); |
|---|
| 90 | </cfscript> |
|---|
| 91 | </cffunction> |
|---|
| 92 | |
|---|
| 93 | </cfcomponent> |
|---|