mirror of
https://github.com/moodle/moodle.git
synced 2025-01-19 14:27:22 +01:00
MDL-17020 dml: native pgsql driver - fixing/improving unittests; fixed column names in indexes
This commit is contained in:
parent
334ce0266d
commit
80ffbad34b
@ -187,8 +187,10 @@ class pgsql_native_moodle_database extends moodle_database {
|
||||
if ($matches[4] === 'id') {
|
||||
continue;
|
||||
}
|
||||
$columns = explode(',', $matches[4]);
|
||||
$columns = array_map('trim', $columns);
|
||||
$indexes[$matches[2]] = array('unique'=>!empty($matches[1]),
|
||||
'columns'=>explode(',', $matches[4]));
|
||||
'columns'=>$columns);
|
||||
}
|
||||
pg_free_result($result);
|
||||
}
|
||||
|
@ -222,23 +222,31 @@ class dml_test extends UnitTestCase {
|
||||
$table = $this->get_test_table($dbman, "testtable");
|
||||
$table->add_field('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null, null, null);
|
||||
$table->add_field('course', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0');
|
||||
$table->add_key('primary', XMLDB_KEY_PRIMARY, array('id'));
|
||||
$table->add_index('course', XMLDB_INDEX_NOTUNIQUE, array('course'));
|
||||
$table->add_index('course-id', XMLDB_INDEX_UNIQUE, array('course', 'id'));
|
||||
$table->add_key('primary', XMLDB_KEY_PRIMARY, array('id'));
|
||||
$dbman->create_table($table);
|
||||
$this->tables[$table->getName()] = $table;
|
||||
|
||||
$this->assertTrue($indices = $DB->get_indexes('testtable'));
|
||||
$this->assertTrue(count($indices) == 2);
|
||||
sort($indices);
|
||||
|
||||
$this->assertFalse($indices[0]['unique']);
|
||||
$this->assertTrue($indices[1]['unique']);
|
||||
$this->assertEqual(1, count($indices[0]['columns']));
|
||||
$this->assertEqual(2, count($indices[1]['columns']));
|
||||
$this->assertEqual('course', $indices[0]['columns'][0]);
|
||||
$this->assertEqual('course', $indices[1]['columns'][0]);
|
||||
$this->assertEqual('id', $indices[1]['columns'][1]);
|
||||
// we do not cvare about index names for now
|
||||
$first = array_shift($indices);
|
||||
$second = array_shift($indices);
|
||||
if (count($first['columns']) == 2) {
|
||||
$composed = $first;
|
||||
$single = $second;
|
||||
} else {
|
||||
$composed = $second;
|
||||
$single = $first;
|
||||
}
|
||||
$this->assertFalse($single['unique']);
|
||||
$this->assertTrue($composed['unique']);
|
||||
$this->assertEqual(1, count($single['columns']));
|
||||
$this->assertEqual(2, count($composed['columns']));
|
||||
$this->assertEqual('course', $single['columns'][0]);
|
||||
$this->assertEqual('course', $composed['columns'][0]);
|
||||
$this->assertEqual('id', $composed['columns'][1]);
|
||||
}
|
||||
|
||||
public function testGetColumns() {
|
||||
|
Loading…
x
Reference in New Issue
Block a user