|
1
|
|
|
<?php |
|
2
|
|
|
require_once(dirname(__FILE__).'/BaseCase.php'); |
|
3
|
|
|
|
|
4
|
|
|
/** |
|
5
|
|
|
* @package System.DataAccess.SQLMap |
|
6
|
|
|
*/ |
|
7
|
|
|
class StatementTest extends BaseCase |
|
8
|
|
|
{ |
|
9
|
|
|
function __construct() |
|
10
|
|
|
{ |
|
11
|
|
|
parent::__construct(); |
|
12
|
|
|
$this->initSqlMap(); |
|
13
|
|
|
|
|
14
|
|
|
//force autoload |
|
15
|
|
|
new Account; |
|
16
|
|
|
new Order; |
|
17
|
|
|
new LineItem; |
|
18
|
|
|
new LineItemCollection; |
|
19
|
|
|
new A; new B; new C; new D; new E; new F; |
|
|
|
|
|
|
20
|
|
|
} |
|
21
|
|
|
|
|
22
|
|
|
public function setup() |
|
23
|
|
|
{ |
|
24
|
|
|
|
|
25
|
|
|
} |
|
26
|
|
|
|
|
27
|
|
|
function resetDatabase() |
|
28
|
|
|
{ |
|
29
|
|
|
$this->initScript('account-init.sql'); |
|
30
|
|
|
$this->initScript('order-init.sql'); |
|
31
|
|
|
$this->initScript('line-item-init.sql'); |
|
32
|
|
|
// $this->initScript('enumeration-init.sql'); |
|
33
|
|
|
$this->initScript('other-init.sql'); |
|
34
|
|
|
} |
|
35
|
|
|
|
|
36
|
|
|
|
|
37
|
|
|
#region Object Query tests |
|
|
|
|
|
|
38
|
|
|
|
|
39
|
|
|
/** |
|
40
|
|
|
* Test Open connection with a connection string |
|
41
|
|
|
*/ |
|
42
|
|
|
function testOpenConnection() |
|
43
|
|
|
{ |
|
44
|
|
|
$conn = $this->sqlmap->getDbConnection(); |
|
45
|
|
|
$conn->setActive(true); |
|
46
|
|
|
$account= $this->sqlmap->QueryForObject("SelectWithProperty"); |
|
47
|
|
|
$conn->setActive(false); |
|
48
|
|
|
$this->assertAccount1($account); |
|
49
|
|
|
} |
|
50
|
|
|
|
|
51
|
|
|
/** |
|
52
|
|
|
* Test use a statement with property subtitution |
|
53
|
|
|
* (JIRA 22) |
|
54
|
|
|
*/ |
|
55
|
|
|
function testSelectWithProperty() |
|
56
|
|
|
{ |
|
57
|
|
|
$account= $this->sqlmap->QueryForObject("SelectWithProperty"); |
|
58
|
|
|
$this->assertAccount1($account); |
|
59
|
|
|
} |
|
60
|
|
|
|
|
61
|
|
|
/** |
|
62
|
|
|
* Test ExecuteQueryForObject Via ColumnName |
|
63
|
|
|
*/ |
|
64
|
|
|
function testExecuteQueryForObjectViaColumnName() |
|
65
|
|
|
{ |
|
66
|
|
|
$account= $this->sqlmap->QueryForObject("GetAccountViaColumnName", 1); |
|
67
|
|
|
$this->assertAccount1($account); |
|
68
|
|
|
} |
|
69
|
|
|
|
|
70
|
|
|
/** |
|
71
|
|
|
* Test ExecuteQueryForObject Via ColumnIndex |
|
72
|
|
|
*/ |
|
73
|
|
|
function testExecuteQueryForObjectViaColumnIndex() |
|
74
|
|
|
{ |
|
75
|
|
|
$account= $this->sqlmap->QueryForObject("GetAccountViaColumnIndex", 1); |
|
76
|
|
|
$this->assertAccount1($account); |
|
77
|
|
|
} |
|
78
|
|
|
|
|
79
|
|
|
/** |
|
80
|
|
|
* Test ExecuteQueryForObject Via ResultClass |
|
81
|
|
|
*/ |
|
82
|
|
|
function testExecuteQueryForObjectViaResultClass() |
|
83
|
|
|
{ |
|
84
|
|
|
$account= $this->sqlmap->QueryForObject("GetAccountViaResultClass", 1); |
|
85
|
|
|
$this->assertAccount1($account); |
|
86
|
|
|
} |
|
87
|
|
|
|
|
88
|
|
|
/** |
|
89
|
|
|
* Test ExecuteQueryForObject With simple ResultClass : string |
|
90
|
|
|
*/ |
|
91
|
|
|
function testExecuteQueryForObjectWithSimpleResultClass() |
|
92
|
|
|
{ |
|
93
|
|
|
$email = $this->sqlmap->QueryForObject("GetEmailAddressViaResultClass", 1); |
|
94
|
|
|
$this->assertIdentical("[email protected]", $email); |
|
95
|
|
|
} |
|
96
|
|
|
|
|
97
|
|
|
/** |
|
98
|
|
|
* Test ExecuteQueryForObject With simple ResultMap : string |
|
99
|
|
|
*/ |
|
100
|
|
|
function testExecuteQueryForObjectWithSimpleResultMap() |
|
101
|
|
|
{ |
|
102
|
|
|
$email = $this->sqlmap->QueryForObject("GetEmailAddressViaResultMap", 1); |
|
103
|
|
|
$this->assertIdentical("[email protected]", $email); |
|
104
|
|
|
} |
|
105
|
|
|
|
|
106
|
|
|
/** |
|
107
|
|
|
* Test Primitive ReturnValue : TDateTime |
|
108
|
|
|
*/ |
|
109
|
|
|
function testPrimitiveReturnValue() |
|
110
|
|
|
{ |
|
111
|
|
|
$CardExpiry = $this->sqlmap->QueryForObject("GetOrderCardExpiryViaResultClass", 1); |
|
112
|
|
|
$date = @mktime(8, 15, 00, 2, 15, 2003); |
|
113
|
|
|
$this->assertIdentical($date, $CardExpiry->getTimeStamp()); |
|
114
|
|
|
} |
|
115
|
|
|
|
|
116
|
|
|
/** |
|
117
|
|
|
* Test ExecuteQueryForObject with result object : Account |
|
118
|
|
|
*/ |
|
119
|
|
|
function testExecuteQueryForObjectWithResultObject() |
|
120
|
|
|
{ |
|
121
|
|
|
$account= new Account(); |
|
122
|
|
|
$testAccount = $this->sqlmap->QueryForObject("GetAccountViaColumnName", 1, $account); |
|
123
|
|
|
$this->assertAccount1($account); |
|
124
|
|
|
$this->assertTrue($account == $testAccount); |
|
125
|
|
|
} |
|
126
|
|
|
|
|
127
|
|
|
/** |
|
128
|
|
|
* Test ExecuteQueryForObject as array |
|
129
|
|
|
*/ |
|
130
|
|
|
function testExecuteQueryForObjectAsHashArray() |
|
131
|
|
|
{ |
|
132
|
|
|
$account = $this->sqlmap->QueryForObject("GetAccountAsHashtable", 1); |
|
133
|
|
|
$this->assertAccount1AsHashArray($account); |
|
134
|
|
|
} |
|
135
|
|
|
|
|
136
|
|
|
/** |
|
137
|
|
|
* Test ExecuteQueryForObject as Hashtable ResultClass |
|
138
|
|
|
*/ |
|
139
|
|
|
function testExecuteQueryForObjectAsHashtableResultClass() |
|
140
|
|
|
{ |
|
141
|
|
|
$account = $this->sqlmap->QueryForObject("GetAccountAsHashtableResultClass", 1); |
|
142
|
|
|
$this->assertAccount1AsHashArray($account); |
|
143
|
|
|
} |
|
144
|
|
|
|
|
145
|
|
|
/** |
|
146
|
|
|
* Test ExecuteQueryForObject via Hashtable |
|
147
|
|
|
*/ |
|
148
|
|
|
function testExecuteQueryForObjectViaHashtable() |
|
149
|
|
|
{ |
|
150
|
|
|
$param["LineItem_ID"] = 2; |
|
|
|
|
|
|
151
|
|
|
$param["Order_ID"] = 9; |
|
152
|
|
|
|
|
153
|
|
|
$testItem = $this->sqlmap->QueryForObject("GetSpecificLineItem", $param); |
|
154
|
|
|
|
|
155
|
|
|
$this->assertNotNull($testItem); |
|
156
|
|
|
$this->assertIdentical("TSM-12", $testItem->getCode()); |
|
157
|
|
|
} |
|
158
|
|
|
/**/ |
|
159
|
|
|
|
|
160
|
|
|
//TODO: Test Query Dynamic Sql Element |
|
|
|
|
|
|
161
|
|
|
function testQueryDynamicSqlElement() |
|
162
|
|
|
{ |
|
163
|
|
|
//$list = $this->sqlmap->QueryForList("GetDynamicOrderedEmailAddressesViaResultMap", "Account_ID"); |
|
164
|
|
|
|
|
165
|
|
|
//$this->assertIdentical("[email protected]", $list[0]); |
|
166
|
|
|
|
|
167
|
|
|
//list = $this->sqlmap->QueryForList("GetDynamicOrderedEmailAddressesViaResultMap", "Account_FirstName"); |
|
168
|
|
|
|
|
169
|
|
|
//$this->assertIdentical("[email protected]", $list[0]); |
|
170
|
|
|
|
|
171
|
|
|
} |
|
172
|
|
|
|
|
173
|
|
|
// TODO: Test Execute QueryForList With ResultMap With Dynamic Element |
|
|
|
|
|
|
174
|
|
|
function testExecuteQueryForListWithResultMapWithDynamicElement() |
|
175
|
|
|
{ |
|
176
|
|
|
//$list = $this->sqlmap->QueryForList("GetAllAccountsViaResultMapWithDynamicElement", "LIKE"); |
|
177
|
|
|
|
|
178
|
|
|
//$this->assertAccount1$list[0]); |
|
179
|
|
|
//$this->assertIdentical(3, $list->getCount()); |
|
180
|
|
|
//$this->assertIdentical(1, $list[0]->getID()); |
|
181
|
|
|
//$this->assertIdentical(2, $list[1]->getID()); |
|
182
|
|
|
//$this->assertIdentical(4, $list[2]->getID()); |
|
183
|
|
|
|
|
184
|
|
|
//list = $this->sqlmap->QueryForList("GetAllAccountsViaResultMapWithDynamicElement", "="); |
|
185
|
|
|
|
|
186
|
|
|
//$this->assertIdentical(0, $list->getCount()); |
|
187
|
|
|
} |
|
188
|
|
|
|
|
189
|
|
|
|
|
190
|
|
|
|
|
191
|
|
|
/** |
|
192
|
|
|
* Test Get Account Via Inline Parameters |
|
193
|
|
|
*/ |
|
194
|
|
|
function testExecuteQueryForObjectViaInlineParameters() |
|
195
|
|
|
{ |
|
196
|
|
|
$account= new Account(); |
|
197
|
|
|
$account->setID(1); |
|
198
|
|
|
|
|
199
|
|
|
$testAccount = $this->sqlmap->QueryForObject("GetAccountViaInlineParameters", $account); |
|
200
|
|
|
|
|
201
|
|
|
$this->assertAccount1($testAccount); |
|
202
|
|
|
} |
|
203
|
|
|
/**/ |
|
204
|
|
|
|
|
205
|
|
|
// TODO: Test ExecuteQuery For Object With Enum property |
|
|
|
|
|
|
206
|
|
|
|
|
207
|
|
|
function testExecuteQueryForObjectWithEnum() |
|
208
|
|
|
{ |
|
209
|
|
|
//$enumClass = $this->sqlmap->QueryForObject("GetEnumeration", 1); |
|
210
|
|
|
|
|
211
|
|
|
//$this->assertIdentical(enumClass.Day, Days.Sat); |
|
212
|
|
|
//$this->assertIdentical(enumClass.Color, Colors.Red); |
|
213
|
|
|
//$this->assertIdentical(enumClass.Month, Months.August); |
|
214
|
|
|
|
|
215
|
|
|
//enumClass = $this->sqlmap->QueryForObject("GetEnumeration", 3) as Enumeration; |
|
216
|
|
|
|
|
217
|
|
|
//$this->assertIdentical(enumClass.Day, Days.Mon); |
|
218
|
|
|
//$this->assertIdentical(enumClass.Color, Colors.Blue); |
|
219
|
|
|
//$this->assertIdentical(enumClass.Month, Months.September);*/ |
|
220
|
|
|
} |
|
221
|
|
|
|
|
222
|
|
|
#endregion |
|
|
|
|
|
|
223
|
|
|
|
|
224
|
|
|
#region List Query tests |
|
|
|
|
|
|
225
|
|
|
|
|
226
|
|
|
/** |
|
227
|
|
|
* Test QueryForList with Hashtable ResultMap |
|
228
|
|
|
*/ |
|
229
|
|
|
function testQueryForListWithHashtableResultMap() |
|
230
|
|
|
{ |
|
231
|
|
|
$this->initScript('account-init.sql'); |
|
232
|
|
|
$list = $this->sqlmap->QueryForList("GetAllAccountsAsHashMapViaResultMap"); |
|
233
|
|
|
|
|
234
|
|
|
$this->assertAccount1AsHashArray($list[0]); |
|
235
|
|
|
$this->assertIdentical(5, count($list)); |
|
236
|
|
|
|
|
237
|
|
|
$this->assertIdentical(1, (int)$list[0]["Id"]); |
|
238
|
|
|
$this->assertIdentical(2, (int)$list[1]["Id"]); |
|
239
|
|
|
$this->assertIdentical(3, (int)$list[2]["Id"]); |
|
240
|
|
|
$this->assertIdentical(4, (int)$list[3]["Id"]); |
|
241
|
|
|
$this->assertIdentical(5, (int)$list[4]["Id"]); |
|
242
|
|
|
} |
|
243
|
|
|
|
|
244
|
|
|
/** |
|
245
|
|
|
* Test QueryForList with Hashtable ResultClass |
|
246
|
|
|
*/ |
|
247
|
|
|
function testQueryForListWithHashtableResultClass() |
|
248
|
|
|
{ |
|
249
|
|
|
$list = $this->sqlmap->QueryForList("GetAllAccountsAsHashtableViaResultClass"); |
|
250
|
|
|
|
|
251
|
|
|
$this->assertAccount1AsHashArray($list[0]); |
|
252
|
|
|
$this->assertIdentical(5, count($list)); |
|
253
|
|
|
|
|
254
|
|
|
$this->assertIdentical(1, (int)$list[0]["Id"]); |
|
255
|
|
|
$this->assertIdentical(2, (int)$list[1]["Id"]); |
|
256
|
|
|
$this->assertIdentical(3, (int)$list[2]["Id"]); |
|
257
|
|
|
$this->assertIdentical(4, (int)$list[3]["Id"]); |
|
258
|
|
|
$this->assertIdentical(5, (int)$list[4]["Id"]); |
|
259
|
|
|
} |
|
260
|
|
|
|
|
261
|
|
|
/** |
|
262
|
|
|
* Test QueryForList with IList ResultClass |
|
263
|
|
|
*/ |
|
264
|
|
|
function testQueryForListWithIListResultClass() |
|
265
|
|
|
{ |
|
266
|
|
|
$list = $this->sqlmap->QueryForList("GetAllAccountsAsArrayListViaResultClass"); |
|
267
|
|
|
|
|
268
|
|
|
$listAccount = $list[0]; |
|
269
|
|
|
|
|
270
|
|
|
$this->assertIdentical(1,(int)$listAccount[0]); |
|
271
|
|
|
$this->assertIdentical("Joe",$listAccount[1]); |
|
272
|
|
|
$this->assertIdentical("Dalton",$listAccount[2]); |
|
273
|
|
|
$this->assertIdentical("[email protected]",$listAccount[3]); |
|
274
|
|
|
|
|
275
|
|
|
$this->assertIdentical(5, count($list)); |
|
276
|
|
|
|
|
277
|
|
|
$listAccount = $list[0]; |
|
278
|
|
|
$this->assertIdentical(1, (int)$listAccount[0]); |
|
279
|
|
|
$listAccount = $list[1]; |
|
280
|
|
|
$this->assertIdentical(2, (int)$listAccount[0]); |
|
281
|
|
|
$listAccount = $list[2]; |
|
282
|
|
|
$this->assertIdentical(3, (int)$listAccount[0]); |
|
283
|
|
|
$listAccount = $list[3]; |
|
284
|
|
|
$this->assertIdentical(4, (int)$listAccount[0]); |
|
285
|
|
|
$listAccount = $list[4]; |
|
286
|
|
|
$this->assertIdentical(5, (int)$listAccount[0]); |
|
287
|
|
|
} |
|
288
|
|
|
|
|
289
|
|
|
/** |
|
290
|
|
|
* Test QueryForList With ResultMap, result collection as ArrayList |
|
291
|
|
|
*/ |
|
292
|
|
|
function testQueryForListWithResultMap() |
|
293
|
|
|
{ |
|
294
|
|
|
$list = $this->sqlmap->QueryForList("GetAllAccountsViaResultMap"); |
|
295
|
|
|
|
|
296
|
|
|
$this->assertAccount1($list[0]); |
|
297
|
|
|
$this->assertIdentical(5, count($list)); |
|
298
|
|
|
$this->assertIdentical(1, $list[0]->getID()); |
|
299
|
|
|
$this->assertIdentical(2, $list[1]->getID()); |
|
300
|
|
|
$this->assertIdentical(3, $list[2]->getID()); |
|
301
|
|
|
$this->assertIdentical(4, $list[3]->getID()); |
|
302
|
|
|
$this->assertIdentical(5, $list[4]->getID()); |
|
303
|
|
|
} |
|
304
|
|
|
|
|
305
|
|
|
/** |
|
306
|
|
|
* Test ExecuteQueryForPaginatedList |
|
307
|
|
|
*/ |
|
308
|
|
|
function testExecuteQueryForPaginatedList() |
|
309
|
|
|
{ |
|
310
|
|
|
// Get List of all 5 |
|
311
|
|
|
$list = $this->sqlmap->QueryForPagedList("GetAllAccountsViaResultMap", null, 2); |
|
312
|
|
|
|
|
313
|
|
|
// Test initial state (page 0) |
|
314
|
|
|
$this->assertFalse($list->getIsPreviousPageAvailable()); |
|
315
|
|
|
$this->assertTrue($list->getIsNextPageAvailable()); |
|
316
|
|
|
$this->assertAccount1($list[0]); |
|
317
|
|
|
$this->assertIdentical(2, $list->getCount()); |
|
318
|
|
|
$this->assertIdentical(1, $list[0]->getID()); |
|
319
|
|
|
$this->assertIdentical(2, $list[1]->getID()); |
|
320
|
|
|
|
|
321
|
|
|
// Test illegal previous page (no effect, state should be same) |
|
322
|
|
|
$list->PreviousPage(); |
|
323
|
|
|
$this->assertFalse($list->getIsPreviousPageAvailable()); |
|
324
|
|
|
$this->assertTrue($list->getIsNextPageAvailable()); |
|
325
|
|
|
$this->assertAccount1($list[0]); |
|
326
|
|
|
$this->assertIdentical(2, $list->getCount()); |
|
327
|
|
|
$this->assertIdentical(1, $list[0]->getID()); |
|
328
|
|
|
$this->assertIdentical(2, $list[1]->getID()); |
|
329
|
|
|
|
|
330
|
|
|
// Test next (page 1) |
|
331
|
|
|
$list->NextPage(); |
|
332
|
|
|
$this->assertTrue($list->getIsPreviousPageAvailable()); |
|
333
|
|
|
$this->assertTrue($list->getIsNextPageAvailable()); |
|
334
|
|
|
$this->assertIdentical(2, $list->getCount()); |
|
335
|
|
|
$this->assertIdentical(3, $list[0]->getID()); |
|
336
|
|
|
$this->assertIdentical(4, $list[1]->getID()); |
|
337
|
|
|
|
|
338
|
|
|
// Test next (page 2 -last) |
|
339
|
|
|
$list->NextPage(); |
|
340
|
|
|
$this->assertTrue($list->getIsPreviousPageAvailable()); |
|
341
|
|
|
$this->assertFalse($list->getIsNextPageAvailable()); |
|
342
|
|
|
$this->assertIdentical(1, $list->getCount()); |
|
343
|
|
|
$this->assertIdentical(5, $list[0]->getID()); |
|
344
|
|
|
|
|
345
|
|
|
// Test previous (page 1) |
|
346
|
|
|
$list->PreviousPage(); |
|
347
|
|
|
$this->assertTrue($list->getIsPreviousPageAvailable()); |
|
348
|
|
|
$this->assertTrue($list->getIsNextPageAvailable()); |
|
349
|
|
|
$this->assertIdentical(2, $list->getCount()); |
|
350
|
|
|
$this->assertIdentical(3, $list[0]->getID()); |
|
351
|
|
|
$this->assertIdentical(4, $list[1]->getID()); |
|
352
|
|
|
|
|
353
|
|
|
// Test previous (page 0 -first) |
|
354
|
|
|
$list->PreviousPage(); |
|
355
|
|
|
$this->assertFalse($list->getIsPreviousPageAvailable()); |
|
356
|
|
|
$this->assertTrue($list->getIsNextPageAvailable()); |
|
357
|
|
|
$this->assertAccount1($list[0]); |
|
358
|
|
|
$this->assertIdentical(2, $list->getCount()); |
|
359
|
|
|
$this->assertIdentical(1, $list[0]->getID()); |
|
360
|
|
|
$this->assertIdentical(2, $list[1]->getID()); |
|
361
|
|
|
|
|
362
|
|
|
// Test goto (page 0) |
|
363
|
|
|
$list->GotoPage(0); |
|
364
|
|
|
$this->assertFalse($list->getIsPreviousPageAvailable()); |
|
365
|
|
|
$this->assertTrue($list->getIsNextPageAvailable()); |
|
366
|
|
|
$this->assertIdentical(2, $list->getCount()); |
|
367
|
|
|
$this->assertIdentical(1, $list[0]->getID()); |
|
368
|
|
|
$this->assertIdentical(2, $list[1]->getID()); |
|
369
|
|
|
|
|
370
|
|
|
// Test goto (page 1) |
|
371
|
|
|
$list->GotoPage(1); |
|
372
|
|
|
$this->assertTrue($list->getIsPreviousPageAvailable()); |
|
373
|
|
|
$this->assertTrue($list->getIsNextPageAvailable()); |
|
374
|
|
|
$this->assertIdentical(2, $list->getCount()); |
|
375
|
|
|
$this->assertIdentical(3, $list[0]->getID()); |
|
376
|
|
|
$this->assertIdentical(4, $list[1]->getID()); |
|
377
|
|
|
|
|
378
|
|
|
// Test goto (page 2) |
|
379
|
|
|
$list->GotoPage(2); |
|
380
|
|
|
$this->assertTrue($list->getIsPreviousPageAvailable()); |
|
381
|
|
|
$this->assertFalse($list->getIsNextPageAvailable()); |
|
382
|
|
|
$this->assertIdentical(1, $list->getCount()); |
|
383
|
|
|
$this->assertIdentical(5, $list[0]->getID()); |
|
384
|
|
|
|
|
385
|
|
|
// Test illegal goto (page 0) |
|
386
|
|
|
$list->GotoPage(3); |
|
387
|
|
|
$this->assertTrue($list->getIsPreviousPageAvailable()); |
|
388
|
|
|
$this->assertFalse($list->getIsNextPageAvailable()); |
|
389
|
|
|
$this->assertIdentical(0, $list->getCount()); |
|
390
|
|
|
|
|
391
|
|
|
$list = $this->sqlmap->QueryForPagedList("GetNoAccountsViaResultMap", null, 2); |
|
392
|
|
|
|
|
393
|
|
|
// Test empty list |
|
394
|
|
|
$this->assertFalse($list->getIsPreviousPageAvailable()); |
|
395
|
|
|
$this->assertFalse($list->getIsNextPageAvailable()); |
|
396
|
|
|
$this->assertIdentical(0, $list->getCount()); |
|
397
|
|
|
|
|
398
|
|
|
// Test next |
|
399
|
|
|
$list->NextPage(); |
|
400
|
|
|
$this->assertFalse($list->getIsPreviousPageAvailable()); |
|
401
|
|
|
$this->assertFalse($list->getIsNextPageAvailable()); |
|
402
|
|
|
$this->assertIdentical(0, $list->getCount()); |
|
403
|
|
|
|
|
404
|
|
|
// Test previous |
|
405
|
|
|
$list->PreviousPage(); |
|
406
|
|
|
$this->assertFalse($list->getIsPreviousPageAvailable()); |
|
407
|
|
|
$this->assertFalse($list->getIsNextPageAvailable()); |
|
408
|
|
|
$this->assertIdentical(0, $list->getCount()); |
|
409
|
|
|
|
|
410
|
|
|
// Test previous |
|
411
|
|
|
$list->GotoPage(0); |
|
412
|
|
|
$this->assertFalse($list->getIsPreviousPageAvailable()); |
|
413
|
|
|
$this->assertFalse($list->getIsNextPageAvailable()); |
|
414
|
|
|
$this->assertIdentical(0, $list->getCount()); |
|
415
|
|
|
$list = $this->sqlmap->QueryForPagedList("GetFewAccountsViaResultMap", null, 2); |
|
416
|
|
|
|
|
417
|
|
|
$this->assertFalse($list->getIsPreviousPageAvailable()); |
|
418
|
|
|
$this->assertFalse($list->getIsNextPageAvailable()); |
|
419
|
|
|
$this->assertIdentical(1, $list->getCount()); |
|
420
|
|
|
|
|
421
|
|
|
// Test next |
|
422
|
|
|
$list->NextPage(); |
|
423
|
|
|
$this->assertFalse($list->getIsPreviousPageAvailable()); |
|
424
|
|
|
$this->assertFalse($list->getIsNextPageAvailable()); |
|
425
|
|
|
$this->assertIdentical(1, $list->getCount()); |
|
426
|
|
|
// Test previous |
|
427
|
|
|
$list->PreviousPage(); |
|
428
|
|
|
$this->assertFalse($list->getIsPreviousPageAvailable()); |
|
429
|
|
|
$this->assertFalse($list->getIsNextPageAvailable()); |
|
430
|
|
|
$this->assertIdentical(1, $list->getCount()); |
|
431
|
|
|
|
|
432
|
|
|
// Test previous |
|
433
|
|
|
$list->GotoPage(0); |
|
434
|
|
|
$this->assertFalse($list->getIsPreviousPageAvailable()); |
|
435
|
|
|
$this->assertFalse($list->getIsNextPageAvailable()); |
|
436
|
|
|
$this->assertIdentical(1, $list->getCount()); |
|
437
|
|
|
|
|
438
|
|
|
|
|
439
|
|
|
$list = $this->sqlmap->QueryForPagedList("GetAllAccountsViaResultMap", null, 5); |
|
440
|
|
|
|
|
441
|
|
|
$this->assertIdentical(5, $list->getCount()); |
|
442
|
|
|
|
|
443
|
|
|
$list->NextPage(); |
|
444
|
|
|
$this->assertIdentical(5, $list->getCount()); |
|
445
|
|
|
|
|
446
|
|
|
$b = $list->getIsPreviousPageAvailable(); |
|
|
|
|
|
|
447
|
|
|
$list->PreviousPage(); |
|
448
|
|
|
$this->assertIdentical(5, $list->getCount()); |
|
449
|
|
|
} |
|
450
|
|
|
|
|
451
|
|
|
/** |
|
452
|
|
|
* Test QueryForList with ResultObject : |
|
453
|
|
|
* AccountCollection strongly typed collection |
|
454
|
|
|
*/ |
|
455
|
|
|
function testQueryForListWithResultObject() |
|
456
|
|
|
{ |
|
457
|
|
|
$accounts = new AccountCollection(); |
|
458
|
|
|
|
|
459
|
|
|
$this->sqlmap->QueryForList("GetAllAccountsViaResultMap", null, $accounts); |
|
460
|
|
|
$this->assertAccount1($accounts[0]); |
|
461
|
|
|
$this->assertIdentical(5, $accounts->getCount()); |
|
462
|
|
|
$this->assertIdentical(1, $accounts[0]->getID()); |
|
463
|
|
|
$this->assertIdentical(2, $accounts[1]->getID()); |
|
464
|
|
|
$this->assertIdentical(3, $accounts[2]->getID()); |
|
465
|
|
|
$this->assertIdentical(4, $accounts[3]->getID()); |
|
466
|
|
|
$this->assertIdentical(5, $accounts[4]->GetId()); |
|
467
|
|
|
} |
|
468
|
|
|
|
|
469
|
|
|
/** |
|
470
|
|
|
* Test QueryForList with ListClass : LineItemCollection |
|
471
|
|
|
*/ |
|
472
|
|
|
function testQueryForListWithListClass() |
|
473
|
|
|
{ |
|
474
|
|
|
$linesItem = $this->sqlmap->QueryForList("GetLineItemsForOrderWithListClass", 10); |
|
475
|
|
|
|
|
476
|
|
|
$this->assertNotNull($linesItem); |
|
477
|
|
|
$this->assertIdentical(2, $linesItem->getCount()); |
|
478
|
|
|
$this->assertIdentical("ESM-34", $linesItem[0]->getCode()); |
|
479
|
|
|
$this->assertIdentical("QSM-98", $linesItem[1]->getCode()); |
|
480
|
|
|
} |
|
481
|
|
|
|
|
482
|
|
|
/** |
|
483
|
|
|
* Test QueryForList with no result. |
|
484
|
|
|
*/ |
|
485
|
|
|
function testQueryForListWithNoResult() |
|
486
|
|
|
{ |
|
487
|
|
|
$list = $this->sqlmap->QueryForList("GetNoAccountsViaResultMap"); |
|
488
|
|
|
|
|
489
|
|
|
$this->assertIdentical(0, count($list)); |
|
490
|
|
|
} |
|
491
|
|
|
|
|
492
|
|
|
/** |
|
493
|
|
|
* Test QueryForList with ResultClass : Account. |
|
494
|
|
|
*/ |
|
495
|
|
|
function testQueryForListResultClass() |
|
496
|
|
|
{ |
|
497
|
|
|
$list = $this->sqlmap->QueryForList("GetAllAccountsViaResultClass"); |
|
498
|
|
|
|
|
499
|
|
|
$this->assertAccount1($list[0]); |
|
500
|
|
|
$this->assertIdentical(5, count($list)); |
|
501
|
|
|
$this->assertIdentical(1, $list[0]->getID()); |
|
502
|
|
|
$this->assertIdentical(2, $list[1]->getID()); |
|
503
|
|
|
$this->assertIdentical(3, $list[2]->getID()); |
|
504
|
|
|
$this->assertIdentical(4, $list[3]->getID()); |
|
505
|
|
|
$this->assertIdentical(5, $list[4]->getID()); |
|
506
|
|
|
} |
|
507
|
|
|
|
|
508
|
|
|
/** |
|
509
|
|
|
* Test QueryForList with simple resultClass : string |
|
510
|
|
|
*/ |
|
511
|
|
|
function testQueryForListWithSimpleResultClass() |
|
512
|
|
|
{ |
|
513
|
|
|
$list = $this->sqlmap->QueryForList("GetAllEmailAddressesViaResultClass"); |
|
514
|
|
|
|
|
515
|
|
|
$this->assertIdentical("[email protected]", $list[0]); |
|
516
|
|
|
$this->assertIdentical("[email protected]", $list[1]); |
|
517
|
|
|
$this->assertIdentical('', $list[2]); |
|
518
|
|
|
$this->assertIdentical("[email protected]", $list[3]); |
|
519
|
|
|
$this->assertIdentical('', $list[4]); |
|
520
|
|
|
} |
|
521
|
|
|
|
|
522
|
|
|
/** |
|
523
|
|
|
* Test QueryForList with simple ResultMap : string |
|
524
|
|
|
*/ |
|
525
|
|
|
function testQueryForListWithSimpleResultMap() |
|
526
|
|
|
{ |
|
527
|
|
|
$list = $this->sqlmap->QueryForList("GetAllEmailAddressesViaResultMap"); |
|
528
|
|
|
|
|
529
|
|
|
$this->assertIdentical("[email protected]", $list[0]); |
|
530
|
|
|
$this->assertIdentical("[email protected]", $list[1]); |
|
531
|
|
|
$this->assertIdentical('', $list[2]); |
|
532
|
|
|
$this->assertIdentical("[email protected]", $list[3]); |
|
533
|
|
|
$this->assertIdentical('', $list[4]); |
|
534
|
|
|
} |
|
535
|
|
|
|
|
536
|
|
|
/** |
|
537
|
|
|
* Test QueryForListWithSkipAndMax |
|
538
|
|
|
*/ |
|
539
|
|
|
function testQueryForListWithSkipAndMax() |
|
540
|
|
|
{ |
|
541
|
|
|
$list = $this->sqlmap->QueryForList("GetAllAccountsViaResultMap", null, null, 2, 2); |
|
542
|
|
|
|
|
543
|
|
|
$this->assertIdentical(2, count($list)); |
|
544
|
|
|
$this->assertIdentical(3, $list[0]->getID()); |
|
545
|
|
|
$this->assertIdentical(4, $list[1]->getID()); |
|
546
|
|
|
} |
|
547
|
|
|
|
|
548
|
|
|
|
|
549
|
|
|
/** |
|
550
|
|
|
* Test row delegate |
|
551
|
|
|
*/ |
|
552
|
|
|
function testQueryWithRowDelegate() |
|
553
|
|
|
{ |
|
554
|
|
|
//$handler = new SqlMapper.RowDelegate(this.RowHandler); |
|
555
|
|
|
|
|
556
|
|
|
//$list = $this->sqlmap->QueryWithRowDelegate("GetAllAccountsViaResultMap", null, handler); |
|
557
|
|
|
|
|
558
|
|
|
//$this->assertIdentical(5, _index); |
|
559
|
|
|
//$this->assertIdentical(5, $list->getCount()); |
|
560
|
|
|
//$this->assertAccount1$list[0]); |
|
561
|
|
|
//$this->assertIdentical(1, $list[0]->getID()); |
|
562
|
|
|
//$this->assertIdentical(2, $list[1]->getID()); |
|
563
|
|
|
//$this->assertIdentical(3, $list[2]->getID()); |
|
564
|
|
|
//$this->assertIdentical(4, $list[3]->getID()); |
|
565
|
|
|
//$this->assertIdentical(5, $list[4]->getID()); |
|
566
|
|
|
} |
|
567
|
|
|
|
|
568
|
|
|
#endregion |
|
|
|
|
|
|
569
|
|
|
|
|
570
|
|
|
#region Map Tests |
|
|
|
|
|
|
571
|
|
|
|
|
572
|
|
|
/** |
|
573
|
|
|
* Test ExecuteQueryForMap : Hashtable. |
|
574
|
|
|
*/ |
|
575
|
|
|
function testExecuteQueryForMap() |
|
576
|
|
|
{ |
|
577
|
|
|
$map = $this->sqlmap->QueryForMap("GetAllAccountsViaResultClass", null, "FirstName"); |
|
578
|
|
|
|
|
579
|
|
|
$this->assertIdentical(5, count($map)); |
|
580
|
|
|
$this->assertAccount1($map["Joe"]); |
|
581
|
|
|
|
|
582
|
|
|
$this->assertIdentical(1, $map["Joe"]->getID()); |
|
583
|
|
|
$this->assertIdentical(2, $map["Averel"]->getID()); |
|
584
|
|
|
$this->assertIdentical(3, $map["William"]->getID()); |
|
585
|
|
|
$this->assertIdentical(4, $map["Jack"]->getID()); |
|
586
|
|
|
$this->assertIdentical(5, $map["Gilles"]->getID()); |
|
587
|
|
|
} |
|
588
|
|
|
|
|
589
|
|
|
/** |
|
590
|
|
|
* Test ExecuteQueryForMap : Hashtable. |
|
591
|
|
|
* |
|
592
|
|
|
* If the keyProperty is an integer, you must acces the map |
|
593
|
|
|
* by map[integer] and not by map["integer"] |
|
594
|
|
|
*/ |
|
595
|
|
|
function testExecuteQueryForMap2() |
|
596
|
|
|
{ |
|
597
|
|
|
$map = $this->sqlmap->QueryForMap("GetAllOrderWithLineItems", null, "PostalCode"); |
|
598
|
|
|
|
|
599
|
|
|
$this->assertIdentical(11, count($map)); |
|
600
|
|
|
$order = $map["T4H 9G4"]; |
|
601
|
|
|
|
|
602
|
|
|
$this->assertIdentical(2, $order->getLineItemsList()->getCount()); |
|
603
|
|
|
} |
|
604
|
|
|
|
|
605
|
|
|
/** |
|
606
|
|
|
* Test ExecuteQueryForMap with value property : |
|
607
|
|
|
* "FirstName" as key, "EmailAddress" as value |
|
608
|
|
|
*/ |
|
609
|
|
|
function testExecuteQueryForMapWithValueProperty() |
|
610
|
|
|
{ |
|
611
|
|
|
$map = $this->sqlmap->QueryForMap("GetAllAccountsViaResultClass", null, |
|
612
|
|
|
"FirstName", "EmailAddress"); |
|
613
|
|
|
|
|
614
|
|
|
$this->assertIdentical(5, count($map)); |
|
615
|
|
|
|
|
616
|
|
|
$this->assertIdentical("[email protected]", $map["Joe"]); |
|
617
|
|
|
$this->assertIdentical("[email protected]", $map["Averel"]); |
|
618
|
|
|
$this->assertNull($map["William"]); |
|
619
|
|
|
$this->assertIdentical("[email protected]", $map["Jack"]); |
|
620
|
|
|
$this->assertNull($map["Gilles"]); |
|
621
|
|
|
} |
|
622
|
|
|
|
|
623
|
|
|
/** |
|
624
|
|
|
* Test ExecuteQueryForWithJoined |
|
625
|
|
|
*/ |
|
626
|
|
|
function testExecuteQueryForWithJoined() |
|
627
|
|
|
{ |
|
628
|
|
|
$order = $this->sqlmap->QueryForObject("GetOrderJoinWithAccount",10); |
|
629
|
|
|
|
|
630
|
|
|
$this->assertNotNull($order->getAccount()); |
|
631
|
|
|
|
|
632
|
|
|
$order = $this->sqlmap->QueryForObject("GetOrderJoinWithAccount",11); |
|
633
|
|
|
|
|
634
|
|
|
$this->assertNull($order->getAccount()); |
|
635
|
|
|
} |
|
636
|
|
|
|
|
637
|
|
|
/** |
|
638
|
|
|
* Test ExecuteQueryFor With Complex Joined |
|
639
|
|
|
* |
|
640
|
|
|
* A->B->C |
|
641
|
|
|
* ->E |
|
642
|
|
|
* ->F |
|
643
|
|
|
*/ |
|
644
|
|
|
function testExecuteQueryForWithComplexJoined() |
|
645
|
|
|
{ |
|
646
|
|
|
$a = $this->sqlmap->QueryForObject("SelectComplexJoined"); |
|
647
|
|
|
$this->assertNotNull($a); |
|
648
|
|
|
$this->assertNotNull($a->getB()); |
|
649
|
|
|
$this->assertNotNull($a->getB()->getC()); |
|
650
|
|
|
$this->assertNull($a->getB()->getD()); |
|
651
|
|
|
$this->assertNotNull($a->getE()); |
|
652
|
|
|
$this->assertNull($a->getF()); |
|
653
|
|
|
} |
|
654
|
|
|
#endregion |
|
|
|
|
|
|
655
|
|
|
|
|
656
|
|
|
#region Extends statement |
|
|
|
|
|
|
657
|
|
|
|
|
658
|
|
|
/** |
|
659
|
|
|
* Test base Extends statement |
|
660
|
|
|
*/ |
|
661
|
|
|
function testExtendsGetAllAccounts() |
|
662
|
|
|
{ |
|
663
|
|
|
$list = $this->sqlmap->QueryForList("GetAllAccounts"); |
|
664
|
|
|
|
|
665
|
|
|
$this->assertAccount1($list[0]); |
|
666
|
|
|
$this->assertIdentical(5, count($list)); |
|
667
|
|
|
$this->assertIdentical(1, $list[0]->getID()); |
|
668
|
|
|
$this->assertIdentical(2, $list[1]->getID()); |
|
669
|
|
|
$this->assertIdentical(3, $list[2]->getID()); |
|
670
|
|
|
$this->assertIdentical(4, $list[3]->getID()); |
|
671
|
|
|
$this->assertIdentical(5, $list[4]->getID()); |
|
672
|
|
|
} |
|
673
|
|
|
|
|
674
|
|
|
/** |
|
675
|
|
|
* Test Extends statement GetAllAccountsOrderByName extends GetAllAccounts |
|
676
|
|
|
*/ |
|
677
|
|
|
function testExtendsGetAllAccountsOrderByName() |
|
678
|
|
|
{ |
|
679
|
|
|
$list = $this->sqlmap->QueryForList("GetAllAccountsOrderByName"); |
|
680
|
|
|
|
|
681
|
|
|
$this->assertAccount1($list[3]); |
|
682
|
|
|
$this->assertIdentical(5, count($list)); |
|
683
|
|
|
|
|
684
|
|
|
$this->assertIdentical(2, $list[0]->getID()); |
|
685
|
|
|
$this->assertIdentical(5, $list[1]->getID()); |
|
686
|
|
|
$this->assertIdentical(4, $list[2]->getID()); |
|
687
|
|
|
$this->assertIdentical(1, $list[3]->getID()); |
|
688
|
|
|
$this->assertIdentical(3, $list[4]->getID()); |
|
689
|
|
|
} |
|
690
|
|
|
|
|
691
|
|
|
/** |
|
692
|
|
|
* Test Extends statement GetOneAccount extends GetAllAccounts |
|
693
|
|
|
*/ |
|
694
|
|
|
function testExtendsGetOneAccount() |
|
695
|
|
|
{ |
|
696
|
|
|
$account= $this->sqlmap->QueryForObject("GetOneAccount", 1); |
|
697
|
|
|
$this->assertAccount1($account); |
|
698
|
|
|
} |
|
699
|
|
|
|
|
700
|
|
|
/** |
|
701
|
|
|
* Test Extends statement GetSomeAccount extends GetAllAccounts |
|
702
|
|
|
*/ |
|
703
|
|
|
function testExtendsGetSomeAccount() |
|
704
|
|
|
{ |
|
705
|
|
|
$param["lowID"] = 2; |
|
|
|
|
|
|
706
|
|
|
$param["hightID"] = 4; |
|
707
|
|
|
|
|
708
|
|
|
$list = $this->sqlmap->QueryForList("GetSomeAccount", $param); |
|
709
|
|
|
|
|
710
|
|
|
$this->assertIdentical(3, count($list)); |
|
711
|
|
|
|
|
712
|
|
|
$this->assertIdentical(2, $list[0]->getID()); |
|
713
|
|
|
$this->assertIdentical(3, $list[1]->getID()); |
|
714
|
|
|
$this->assertIdentical(4, $list[2]->getID()); |
|
715
|
|
|
} |
|
716
|
|
|
|
|
717
|
|
|
#endregion |
|
|
|
|
|
|
718
|
|
|
|
|
719
|
|
|
#region Update tests |
|
|
|
|
|
|
720
|
|
|
|
|
721
|
|
|
|
|
722
|
|
|
/** |
|
723
|
|
|
* Test Insert account via public fields |
|
724
|
|
|
*/ |
|
725
|
|
|
function testInsertAccountViaPublicFields() |
|
726
|
|
|
{ |
|
727
|
|
|
$this->initScript('account-init.sql'); |
|
728
|
|
|
|
|
729
|
|
|
$account = new AccountBis(); |
|
730
|
|
|
|
|
731
|
|
|
$account->Id = 10; |
|
732
|
|
|
$account->FirstName = "Luky"; |
|
733
|
|
|
$account->LastName = "Luke"; |
|
734
|
|
|
$account->EmailAddress = "[email protected]"; |
|
735
|
|
|
|
|
736
|
|
|
$this->sqlmap->Insert("InsertAccountViaPublicFields", $account); |
|
737
|
|
|
|
|
738
|
|
|
$testAccount = $this->sqlmap->QueryForObject("GetAccountViaColumnName", 10); |
|
739
|
|
|
|
|
740
|
|
|
$this->assertNotNull($testAccount); |
|
741
|
|
|
|
|
742
|
|
|
$this->assertIdentical(10, $testAccount->getID()); |
|
743
|
|
|
|
|
744
|
|
|
$this->initScript('account-init.sql'); |
|
745
|
|
|
} |
|
746
|
|
|
|
|
747
|
|
|
/** |
|
748
|
|
|
* |
|
749
|
|
|
*/ |
|
750
|
|
|
function testInsertOrderViaProperties() |
|
751
|
|
|
{ |
|
752
|
|
|
$this->initScript('account-init.sql'); |
|
753
|
|
|
$this->initScript('order-init.sql'); |
|
754
|
|
|
$account= $this->NewAccount6(); |
|
755
|
|
|
|
|
756
|
|
|
$this->sqlmap->Insert("InsertAccountViaParameterMap", $account); |
|
757
|
|
|
|
|
758
|
|
|
$order = new Order(); |
|
759
|
|
|
$order->setId(99); |
|
760
|
|
|
$order->setCardExpiry("09/11"); |
|
761
|
|
|
$order->setAccount($account); |
|
762
|
|
|
$order->setCardNumber("154564656"); |
|
763
|
|
|
$order->setCardType("Visa"); |
|
764
|
|
|
$order->setCity("Lyon"); |
|
765
|
|
|
$order->setDate('2005-05-20'); |
|
766
|
|
|
$order->setPostalCode("69004"); |
|
767
|
|
|
$order->setProvince("Rhone"); |
|
768
|
|
|
$order->setStreet("rue Durand"); |
|
769
|
|
|
|
|
770
|
|
|
$this->sqlmap->Insert("InsertOrderViaPublicFields", $order); |
|
771
|
|
|
|
|
772
|
|
|
$this->initScript('account-init.sql'); |
|
773
|
|
|
$this->initScript('order-init.sql'); |
|
774
|
|
|
} |
|
775
|
|
|
|
|
776
|
|
|
|
|
777
|
|
|
/** |
|
778
|
|
|
* Test Insert account via inline parameters |
|
779
|
|
|
*/ |
|
780
|
|
|
function testInsertAccountViaInlineParameters() |
|
781
|
|
|
{ |
|
782
|
|
|
$this->initScript('account-init.sql'); |
|
783
|
|
|
$account= new Account(); |
|
784
|
|
|
|
|
785
|
|
|
$account->setId(10); |
|
786
|
|
|
$account->setFirstName("Luky"); |
|
787
|
|
|
$account->setLastName("Luke"); |
|
788
|
|
|
$account->setEmailAddress("[email protected]"); |
|
789
|
|
|
|
|
790
|
|
|
$this->sqlmap->Insert("InsertAccountViaInlineParameters", $account); |
|
791
|
|
|
|
|
792
|
|
|
$testAccount = $this->sqlmap->QueryForObject("GetAccountViaColumnIndex", 10); |
|
793
|
|
|
|
|
794
|
|
|
$this->assertNotNull($testAccount); |
|
795
|
|
|
$this->assertIdentical(10, $testAccount->getId()); |
|
796
|
|
|
$this->initScript('account-init.sql'); |
|
797
|
|
|
} |
|
798
|
|
|
|
|
799
|
|
|
/** |
|
800
|
|
|
* Test Insert account via parameterMap |
|
801
|
|
|
*/ |
|
802
|
|
|
function testInsertAccountViaParameterMap() |
|
803
|
|
|
{ |
|
804
|
|
|
$this->initScript('account-init.sql'); |
|
805
|
|
|
$account= $this->NewAccount6(); |
|
806
|
|
|
$this->sqlmap->Insert("InsertAccountViaParameterMap", $account); |
|
807
|
|
|
|
|
808
|
|
|
$account = $this->sqlmap->QueryForObject("GetAccountNullableEmail", 6); |
|
809
|
|
|
$this->AssertAccount6($account); |
|
810
|
|
|
|
|
811
|
|
|
$this->initScript('account-init.sql'); |
|
812
|
|
|
} |
|
813
|
|
|
|
|
814
|
|
|
/** |
|
815
|
|
|
* Test Update via parameterMap |
|
816
|
|
|
*/ |
|
817
|
|
|
function testUpdateViaParameterMap() |
|
818
|
|
|
{ |
|
819
|
|
|
$this->initScript('account-init.sql'); |
|
820
|
|
|
$account= $this->sqlmap->QueryForObject("GetAccountViaColumnName", 1); |
|
821
|
|
|
|
|
822
|
|
|
$account->setEmailAddress("[email protected]"); |
|
823
|
|
|
$this->sqlmap->Update("UpdateAccountViaParameterMap", $account); |
|
824
|
|
|
|
|
825
|
|
|
$account = $this->sqlmap->QueryForObject("GetAccountViaColumnName", 1); |
|
826
|
|
|
|
|
827
|
|
|
$this->assertIdentical("[email protected]", $account->getEmailAddress()); |
|
828
|
|
|
$this->initScript('account-init.sql'); |
|
829
|
|
|
} |
|
830
|
|
|
|
|
831
|
|
|
/** |
|
832
|
|
|
* Test Update via parameterMap V2 |
|
833
|
|
|
*/ |
|
834
|
|
|
function testUpdateViaParameterMap2() |
|
835
|
|
|
{ |
|
836
|
|
|
$this->initScript('account-init.sql'); |
|
837
|
|
|
$account= $this->sqlmap->QueryForObject("GetAccountViaColumnName", 1); |
|
838
|
|
|
|
|
839
|
|
|
$account->setEmailAddress("[email protected]"); |
|
840
|
|
|
$this->sqlmap->Update("UpdateAccountViaParameterMap2", $account); |
|
841
|
|
|
|
|
842
|
|
|
$account = $this->sqlmap->QueryForObject("GetAccountViaColumnName", 1); |
|
843
|
|
|
|
|
844
|
|
|
$this->assertIdentical("[email protected]", $account->getEmailAddress()); |
|
845
|
|
|
$this->initScript('account-init.sql'); |
|
846
|
|
|
} |
|
847
|
|
|
|
|
848
|
|
|
/** |
|
849
|
|
|
* Test Update with inline parameters |
|
850
|
|
|
*/ |
|
851
|
|
|
function testUpdateWithInlineParameters() |
|
852
|
|
|
{ |
|
853
|
|
|
$this->initScript('account-init.sql'); |
|
854
|
|
|
$account= $this->sqlmap->QueryForObject("GetAccountViaColumnName", 1); |
|
855
|
|
|
|
|
856
|
|
|
$account->setEmailAddress("[email protected]"); |
|
857
|
|
|
$this->sqlmap->Update("UpdateAccountViaInlineParameters", $account); |
|
858
|
|
|
|
|
859
|
|
|
$account = $this->sqlmap->QueryForObject("GetAccountViaColumnName", 1); |
|
860
|
|
|
|
|
861
|
|
|
$this->assertIdentical("[email protected]", $account->getEmailAddress()); |
|
862
|
|
|
$this->initScript('account-init.sql'); |
|
863
|
|
|
} |
|
864
|
|
|
|
|
865
|
|
|
/** |
|
866
|
|
|
* Test Execute Update With Parameter Class |
|
867
|
|
|
*/ |
|
868
|
|
|
function testExecuteUpdateWithParameterClass() |
|
869
|
|
|
{ |
|
870
|
|
|
$this->initScript('account-init.sql'); |
|
871
|
|
|
$account= $this->NewAccount6(); |
|
872
|
|
|
|
|
873
|
|
|
$this->sqlmap->Insert("InsertAccountViaParameterMap", $account); |
|
874
|
|
|
|
|
875
|
|
|
$noRowsDeleted = $this->sqlmap->Update("DeleteAccount", null); |
|
876
|
|
|
|
|
877
|
|
|
$this->sqlmap->Update("DeleteAccount", $account); |
|
878
|
|
|
|
|
879
|
|
|
$account = $this->sqlmap->QueryForObject("GetAccountViaColumnName", 6); |
|
880
|
|
|
|
|
881
|
|
|
$this->assertNull($account); |
|
882
|
|
|
$this->assertIdentical(0, $noRowsDeleted); |
|
883
|
|
|
$this->initScript('account-init.sql'); |
|
884
|
|
|
} |
|
885
|
|
|
|
|
886
|
|
|
/** |
|
887
|
|
|
* Test Execute Delete |
|
888
|
|
|
*/ |
|
889
|
|
|
function testExecuteDelete() |
|
890
|
|
|
{ |
|
891
|
|
|
$this->initScript('account-init.sql'); |
|
892
|
|
|
$account= $this->NewAccount6(); |
|
893
|
|
|
|
|
894
|
|
|
$this->sqlmap->Insert("InsertAccountViaParameterMap", $account); |
|
895
|
|
|
|
|
896
|
|
|
$account = null; |
|
|
|
|
|
|
897
|
|
|
$account = $this->sqlmap->QueryForObject("GetAccountViaColumnName", 6); |
|
898
|
|
|
|
|
899
|
|
|
$this->assertTrue($account->getId() == 6); |
|
900
|
|
|
|
|
901
|
|
|
$rowNumber = $this->sqlmap->Delete("DeleteAccount", $account); |
|
902
|
|
|
$this->assertTrue($rowNumber == 1); |
|
903
|
|
|
|
|
904
|
|
|
$account = $this->sqlmap->QueryForObject("GetAccountViaColumnName", 6); |
|
905
|
|
|
|
|
906
|
|
|
$this->assertNull($account); |
|
907
|
|
|
$this->initScript('account-init.sql'); |
|
908
|
|
|
} |
|
909
|
|
|
|
|
910
|
|
|
/** |
|
911
|
|
|
* Test Execute Delete |
|
912
|
|
|
*/ |
|
913
|
|
|
function testDeleteWithComments() |
|
914
|
|
|
{ |
|
915
|
|
|
$this->initScript('line-item-init.sql'); |
|
916
|
|
|
$rowNumber = $this->sqlmap->Delete("DeleteWithComments"); |
|
917
|
|
|
|
|
918
|
|
|
$this->assertIdentical($rowNumber, 2); |
|
919
|
|
|
$this->initScript('line-item-init.sql'); |
|
920
|
|
|
} |
|
921
|
|
|
|
|
922
|
|
|
|
|
923
|
|
|
|
|
924
|
|
|
#endregion |
|
|
|
|
|
|
925
|
|
|
|
|
926
|
|
|
#region Row delegate |
|
|
|
|
|
|
927
|
|
|
|
|
928
|
|
|
private $_index = 0; |
|
|
|
|
|
|
929
|
|
|
|
|
930
|
|
|
function RowHandler($sender, $paramterObject, $list) |
|
931
|
|
|
{ |
|
932
|
|
|
//_index++; |
|
933
|
|
|
//$this->assertIdentical(_index, (($account) obj).Id); |
|
934
|
|
|
//$list->Add(obj); |
|
935
|
|
|
} |
|
936
|
|
|
|
|
937
|
|
|
#endregion |
|
|
|
|
|
|
938
|
|
|
|
|
939
|
|
|
#region JIRA Tests |
|
|
|
|
|
|
940
|
|
|
|
|
941
|
|
|
/** |
|
942
|
|
|
* Test JIRA 30 (repeating property) |
|
943
|
|
|
*/ |
|
944
|
|
|
function testJIRA30() |
|
945
|
|
|
{ |
|
946
|
|
|
$account= new Account(); |
|
947
|
|
|
$account->setId(1); |
|
948
|
|
|
$account->setFirstName("Joe"); |
|
949
|
|
|
$account->setLastName("Dalton"); |
|
950
|
|
|
$account->setEmailAddress("[email protected]"); |
|
951
|
|
|
|
|
952
|
|
|
$result = $this->sqlmap->QueryForObject("GetAccountWithRepeatingProperty", $account); |
|
953
|
|
|
|
|
954
|
|
|
$this->assertAccount1($result); |
|
955
|
|
|
} |
|
956
|
|
|
|
|
957
|
|
|
/** |
|
958
|
|
|
* Test Bit column |
|
959
|
|
|
*/ |
|
960
|
|
|
function testJIRA42() |
|
961
|
|
|
{ |
|
962
|
|
|
$other = new Other(); |
|
963
|
|
|
|
|
964
|
|
|
$other->setInt(100); |
|
965
|
|
|
$other->setBool(true); |
|
966
|
|
|
$other->setLong(789456321); |
|
967
|
|
|
|
|
968
|
|
|
$this->sqlmap->Insert("InsertBool", $other); |
|
969
|
|
|
} |
|
970
|
|
|
|
|
971
|
|
|
/** |
|
972
|
|
|
* Test for access a result map in a different namespace |
|
973
|
|
|
*/ |
|
974
|
|
|
function testJIRA45() |
|
975
|
|
|
{ |
|
976
|
|
|
$account= $this->sqlmap->QueryForObject("GetAccountJIRA45", 1); |
|
977
|
|
|
$this->assertAccount1($account); |
|
978
|
|
|
} |
|
979
|
|
|
|
|
980
|
|
|
/** |
|
981
|
|
|
* Test : Whitespace is not maintained properly when CDATA tags are used |
|
982
|
|
|
*/ |
|
983
|
|
|
function testJIRA110() |
|
984
|
|
|
{ |
|
985
|
|
|
$account= $this->sqlmap->QueryForObject("Get1Account"); |
|
986
|
|
|
$this->assertAccount1($account); |
|
987
|
|
|
} |
|
988
|
|
|
|
|
989
|
|
|
/** |
|
990
|
|
|
* Test : Whitespace is not maintained properly when CDATA tags are used |
|
991
|
|
|
*/ |
|
992
|
|
|
function testJIRA110Bis() |
|
993
|
|
|
{ |
|
994
|
|
|
$list = $this->sqlmap->QueryForList("GetAccounts"); |
|
995
|
|
|
|
|
996
|
|
|
$this->assertAccount1($list[0]); |
|
997
|
|
|
$this->assertIdentical(5, count($list)); |
|
998
|
|
|
} |
|
999
|
|
|
|
|
1000
|
|
|
/** |
|
1001
|
|
|
* Test for cache stats only being calculated on CachingStatments |
|
1002
|
|
|
*/ |
|
1003
|
|
|
function testJIRA113() |
|
1004
|
|
|
{ |
|
1005
|
|
|
// $this->sqlmap->FlushCaches(); |
|
1006
|
|
|
|
|
1007
|
|
|
// taken from TestFlushDataCache() |
|
1008
|
|
|
// first query is not cached, second query is: 50% cache hit |
|
1009
|
|
|
/*$list = $this->sqlmap->QueryForList("GetCachedAccountsViaResultMap"); |
|
1010
|
|
|
$firstId = HashCodeProvider.GetIdentityHashCode(list); |
|
1011
|
|
|
list = $this->sqlmap->QueryForList("GetCachedAccountsViaResultMap"); |
|
1012
|
|
|
int secondId = HashCodeProvider.GetIdentityHashCode(list); |
|
1013
|
|
|
$this->assertIdentical(firstId, secondId); |
|
1014
|
|
|
|
|
1015
|
|
|
string cacheStats = $this->sqlmap->GetDataCacheStats(); |
|
1016
|
|
|
|
|
1017
|
|
|
$this->assertNotNull(cacheStats);*/ |
|
1018
|
|
|
} |
|
1019
|
|
|
|
|
1020
|
|
|
#endregion |
|
|
|
|
|
|
1021
|
|
|
|
|
1022
|
|
|
#region CustomTypeHandler tests |
|
|
|
|
|
|
1023
|
|
|
|
|
1024
|
|
|
/** |
|
1025
|
|
|
* Test CustomTypeHandler |
|
1026
|
|
|
*/ |
|
1027
|
|
|
function testExecuteQueryWithCustomTypeHandler() |
|
1028
|
|
|
{ |
|
1029
|
|
|
$this->sqlmap->registerTypeHandler(new HundredsBool()); |
|
1030
|
|
|
$this->sqlmap->registerTypeHandler(new OuiNonBool()); |
|
1031
|
|
|
|
|
1032
|
|
|
$list = $this->sqlmap->QueryForList("GetAllAccountsViaCustomTypeHandler"); |
|
1033
|
|
|
|
|
1034
|
|
|
$this->assertAccount1($list[0]); |
|
1035
|
|
|
$this->assertIdentical(5, count($list)); |
|
1036
|
|
|
$this->assertIdentical(1, $list[0]->getID()); |
|
1037
|
|
|
$this->assertIdentical(2, $list[1]->getID()); |
|
1038
|
|
|
$this->assertIdentical(3, $list[2]->getID()); |
|
1039
|
|
|
$this->assertIdentical(4, $list[3]->getID()); |
|
1040
|
|
|
$this->assertIdentical(5, $list[4]->getID()); |
|
1041
|
|
|
|
|
1042
|
|
|
$this->assertFalse($list[0]->getCartOptions()); |
|
1043
|
|
|
$this->assertFalse($list[1]->getCartOptions()); |
|
1044
|
|
|
$this->assertTrue($list[2]->getCartOptions()); |
|
1045
|
|
|
$this->assertTrue($list[3]->getCartOptions()); |
|
1046
|
|
|
$this->assertTrue($list[4]->getCartOptions()); |
|
1047
|
|
|
|
|
1048
|
|
|
$this->assertTrue($list[0]->getBannerOptions()); |
|
1049
|
|
|
$this->assertTrue($list[1]->getBannerOptions()); |
|
1050
|
|
|
$this->assertFalse($list[2]->getBannerOptions()); |
|
1051
|
|
|
$this->assertFalse($list[3]->getBannerOptions()); |
|
1052
|
|
|
$this->assertTrue($list[4]->getBannerOptions()); |
|
1053
|
|
|
} |
|
1054
|
|
|
|
|
1055
|
|
|
/** |
|
1056
|
|
|
* Test CustomTypeHandler Oui/Non |
|
1057
|
|
|
*/ |
|
1058
|
|
|
function testCustomTypeHandler() |
|
1059
|
|
|
{ |
|
1060
|
|
|
$this->initScript('other-init.sql'); |
|
1061
|
|
|
$this->initScript('account-init.sql'); |
|
1062
|
|
|
|
|
1063
|
|
|
$this->sqlmap->registerTypeHandler(new OuiNonBool()); |
|
1064
|
|
|
|
|
1065
|
|
|
$other = new Other(); |
|
1066
|
|
|
$other->setInt(99); |
|
1067
|
|
|
$other->setLong(1966); |
|
1068
|
|
|
$other->setBool(true); |
|
1069
|
|
|
$other->setBool2(false); |
|
1070
|
|
|
$this->sqlmap->Insert("InsertCustomTypeHandler", $other); |
|
1071
|
|
|
|
|
1072
|
|
|
$anOther = $this->sqlmap->QueryForObject("SelectByInt", 99); |
|
1073
|
|
|
$this->assertNotNull( $anOther ); |
|
1074
|
|
|
$this->assertIdentical(99, (int)$anOther->getInt()); |
|
1075
|
|
|
$this->assertIdentical(1966, (int)$anOther->getLong()); |
|
1076
|
|
|
$this->assertIdentical(true, (boolean)$anOther->getBool()); |
|
1077
|
|
|
$this->assertIdentical(false, (boolean)$anOther->getBool2()); |
|
1078
|
|
|
|
|
1079
|
|
|
} |
|
1080
|
|
|
|
|
1081
|
|
|
/** |
|
1082
|
|
|
* Test CustomTypeHandler Oui/Non |
|
1083
|
|
|
*/ |
|
1084
|
|
|
function testInsertInlineCustomTypeHandlerV1() |
|
1085
|
|
|
{ |
|
1086
|
|
|
$this->initScript('other-init.sql'); |
|
1087
|
|
|
$this->initScript('account-init.sql'); |
|
1088
|
|
|
|
|
1089
|
|
|
$other = new Other(); |
|
1090
|
|
|
$other->setInt(99); |
|
1091
|
|
|
$other->setLong(1966); |
|
1092
|
|
|
$other->setBool(true); |
|
1093
|
|
|
$other->setBool2(false); |
|
1094
|
|
|
|
|
1095
|
|
|
$this->sqlmap->Insert("InsertInlineCustomTypeHandlerV1", $other); |
|
1096
|
|
|
|
|
1097
|
|
|
$anOther = $this->sqlmap->QueryForObject("SelectByIntV1", 99); |
|
1098
|
|
|
|
|
1099
|
|
|
$this->assertNotNull( $anOther ); |
|
1100
|
|
|
$this->assertIdentical(99, (int)$anOther->getInt()); |
|
1101
|
|
|
$this->assertIdentical(1966, (int)$anOther->getLong()); |
|
1102
|
|
|
$this->assertIdentical(true, (boolean)$anOther->getBool()); |
|
1103
|
|
|
$this->assertIdentical(false, (boolean)$anOther->getBool2()); |
|
1104
|
|
|
|
|
1105
|
|
|
} |
|
1106
|
|
|
|
|
1107
|
|
|
/** |
|
1108
|
|
|
* Test CustomTypeHandler Oui/Non |
|
1109
|
|
|
*/ |
|
1110
|
|
|
function testInsertInlineCustomTypeHandlerV2() |
|
1111
|
|
|
{ |
|
1112
|
|
|
$this->initScript('other-init.sql'); |
|
1113
|
|
|
$this->initScript('account-init.sql'); |
|
1114
|
|
|
|
|
1115
|
|
|
$other = new Other(); |
|
1116
|
|
|
$other->setInt(99); |
|
1117
|
|
|
$other->setLong(1966); |
|
1118
|
|
|
$other->setBool(true); |
|
1119
|
|
|
$other->setBool2(false); |
|
1120
|
|
|
|
|
1121
|
|
|
$this->sqlmap->Insert("InsertInlineCustomTypeHandlerV2", $other); |
|
1122
|
|
|
|
|
1123
|
|
|
$anOther = $this->sqlmap->QueryForObject("SelectByInt", 99); |
|
1124
|
|
|
|
|
1125
|
|
|
$this->assertNotNull( $anOther ); |
|
1126
|
|
|
$this->assertIdentical(99, (int)$anOther->getInt()); |
|
1127
|
|
|
$this->assertIdentical(1966, (int)$anOther->getLong()); |
|
1128
|
|
|
$this->assertIdentical(true, (boolean)$anOther->getBool()); |
|
1129
|
|
|
$this->assertIdentical(false, (boolean)$anOther->getBool2()); |
|
1130
|
|
|
} |
|
1131
|
|
|
#endregion |
|
|
|
|
|
|
1132
|
|
|
/**/ |
|
1133
|
|
|
} |
|
1134
|
|
|
|
Let’s take a look at an example: