Skip to content

Commit fd25251

Browse files
committed
add some tests
1 parent e59e2bd commit fd25251

File tree

2 files changed

+35
-0
lines changed

2 files changed

+35
-0
lines changed

tests/backup_restore_test.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -284,6 +284,7 @@ public function test_restore_quiz_with_same_stamp_questions(string $questionname
284284
*/
285285
public static function provide_xml_keys_to_remove(): array {
286286
return [
287+
['emptyallowed'],
287288
['answernotunique'],
288289
['partindex'],
289290
];

tests/evaluator_test.php

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2024,6 +2024,40 @@ public function test_export_import_variable_context(): void {
20242024
self::assertNotNull($e);
20252025
}
20262026

2027+
public function test_import_single_variable(): void {
2028+
// Prepare an empty evaluator.
2029+
$evaluator = new evaluator();
2030+
2031+
// Add variables.
2032+
$evaluator->import_single_variable('_foo', new variable('_foo', 'value', token::STRING));
2033+
$evaluator->import_single_variable('bar', new variable('bar', 1234, token::NUMBER));
2034+
2035+
// Verify the evaluator contains the correct variables with the correct values.
2036+
$variables = $evaluator->export_variable_list();
2037+
self::assertCount(2, $variables);
2038+
self::assertContains('_foo', $variables);
2039+
self::assertContains('bar', $variables);
2040+
2041+
$foo = $evaluator->export_single_variable('_foo');
2042+
self::assertEquals(token::STRING, $foo->type);
2043+
self::assertEquals('value', $foo->value);
2044+
2045+
$bar = $evaluator->export_single_variable('bar');
2046+
self::assertEquals(token::NUMBER, $bar->type);
2047+
self::assertEquals(1234, $bar->value);
2048+
2049+
// Try to set variable again without specifying the overwrite parameter. The value should not change.
2050+
$evaluator->import_single_variable('bar', new variable('bar', 5678, token::NUMBER));
2051+
$bar = $evaluator->export_single_variable('bar');
2052+
self::assertEquals(1234, $bar->value);
2053+
2054+
// Try again, forcing overwrite this time. The value should thus change.
2055+
$evaluator->import_single_variable('bar', new variable('bar', 5678, token::NUMBER), true);
2056+
$bar = $evaluator->export_single_variable('bar');
2057+
self::assertEquals(5678, $bar->value);
2058+
}
2059+
2060+
20272061
/**
20282062
* Provide answers of answer type number.
20292063
*

0 commit comments

Comments
 (0)