New get_nextid() method

This is useful for generating artificial database records ids.
This commit is contained in:
David Mudrak
2011-05-20 10:19:27 +02:00
parent dbf6843a72
commit 6700d288b3
2 changed files with 22 additions and 0 deletions
+10
View File
@@ -455,6 +455,16 @@ class moodle1_converter extends base_converter {
}
}
/**
* Simple autoincrement generator
*
* @return int the next number in a row of numbers
*/
public function get_nextid() {
static $autoincrement = 0;
return ++$autoincrement;
}
/**
* @see parent::description()
*/
@@ -154,6 +154,18 @@ class moodle1_converter_test extends UnitTestCase {
$converter->drop_stash_storage();
}
public function test_get_nextid() {
$converter = convert_factory::get_converter('moodle1', $this->tempdir);
$id1 = $converter->get_nextid();
$id2 = $converter->get_nextid();
$id3 = $converter->get_nextid();
$this->assertTrue(0 < $id1);
$this->assertTrue($id1 < $id2);
$this->assertTrue($id2 < $id3);
}
public function test_convert_run_convert() {
$converter = convert_factory::get_converter('moodle1', $this->tempdir);
$converter->convert();