MDL-44682 fix bug in decompose_update_into_safe_changes

This commit is contained in:
Tim Hunt 2014-03-18 17:55:58 +00:00
parent 9b8555fbea
commit c35cf42e55
2 changed files with 9 additions and 1 deletions

View File

@ -2036,7 +2036,7 @@ function decompose_update_into_safe_changes(array $newvalues, $unusedvalue) {
$next = $nontrivialmap[$current];
unset($nontrivialmap[$current]);
$current = $next;
} while ($current !== $cyclestart);
} while ($current != $cyclestart);
// Now convert it to a sequence of safe renames by using a temp.
$safechanges[] = array($cyclestart, $unusedvalue);

View File

@ -77,6 +77,14 @@ class datalib_update_with_unique_index_testcase extends advanced_testcase {
}
}
public function test_decompose_update_into_safe_changes_string_values() {
// Sometimes this happens when data has been loaded from the database.
$this->assertEquals(array(array(1, -1), array(2, 1),
array(3, 2), array(4, 3), array(-1, 4)),
decompose_update_into_safe_changes(
array(1 => '4', 2 => '1', 3 => '2', 4 => '3'), -1));
}
public function test_reorder_rows() {
global $DB;
$dbman = $DB->get_manager();