mirror of
https://github.com/moodle/moodle.git
synced 2025-08-04 16:36:37 +02:00
MDL-19057 improved recordset testing
This commit is contained in:
parent
dec3252935
commit
8efd88650e
1 changed files with 36 additions and 1 deletions
|
@ -626,9 +626,9 @@ class dml_test extends UnitTestCase {
|
||||||
$DB->insert_record($tablename, $record);
|
$DB->insert_record($tablename, $record);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// standard recordset iteration
|
||||||
$rs = $DB->get_recordset($tablename);
|
$rs = $DB->get_recordset($tablename);
|
||||||
$this->assertTrue($rs instanceof moodle_recordset);
|
$this->assertTrue($rs instanceof moodle_recordset);
|
||||||
|
|
||||||
reset($data);
|
reset($data);
|
||||||
foreach($rs as $record) {
|
foreach($rs as $record) {
|
||||||
$data_record = current($data);
|
$data_record = current($data);
|
||||||
|
@ -639,6 +639,41 @@ class dml_test extends UnitTestCase {
|
||||||
}
|
}
|
||||||
$rs->close();
|
$rs->close();
|
||||||
|
|
||||||
|
// iterator style usage
|
||||||
|
$rs = $DB->get_recordset($tablename);
|
||||||
|
$this->assertTrue($rs instanceof moodle_recordset);
|
||||||
|
reset($data);
|
||||||
|
while ($rs->valid()) {
|
||||||
|
$record = $rs->current();
|
||||||
|
$data_record = current($data);
|
||||||
|
foreach ($record as $k => $v) {
|
||||||
|
$this->assertEqual($data_record[$k], $v);
|
||||||
|
}
|
||||||
|
next($data);
|
||||||
|
$rs->next();
|
||||||
|
}
|
||||||
|
$rs->close();
|
||||||
|
|
||||||
|
// make sure rewind is ignored
|
||||||
|
$rs = $DB->get_recordset($tablename);
|
||||||
|
$this->assertTrue($rs instanceof moodle_recordset);
|
||||||
|
reset($data);
|
||||||
|
$i = 0;
|
||||||
|
foreach($rs as $record) {
|
||||||
|
$i++;
|
||||||
|
$rs->rewind();
|
||||||
|
if ($i > 10) {
|
||||||
|
$this->fail('revind not ignored in recordsets');
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
$data_record = current($data);
|
||||||
|
foreach ($record as $k => $v) {
|
||||||
|
$this->assertEqual($data_record[$k], $v);
|
||||||
|
}
|
||||||
|
next($data);
|
||||||
|
}
|
||||||
|
$rs->close();
|
||||||
|
|
||||||
// notes:
|
// notes:
|
||||||
// * limits are tested in test_get_recordset_sql()
|
// * limits are tested in test_get_recordset_sql()
|
||||||
// * where_clause() is used internally and is tested in test_get_records()
|
// * where_clause() is used internally and is tested in test_get_records()
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue