| Línea 35... |
Línea 35... |
| 35 |
* @copyright 2011 The Open University
|
35 |
* @copyright 2011 The Open University
|
| 36 |
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
36 |
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
| 37 |
*/
|
37 |
*/
|
| 38 |
class questionbank_test extends \advanced_testcase {
|
38 |
class questionbank_test extends \advanced_testcase {
|
| Línea 39... |
Línea 39... |
| 39 |
|
39 |
|
| 40 |
public function test_sort_qtype_array() {
|
40 |
public function test_sort_qtype_array(): void {
|
| 41 |
$config = new \stdClass();
|
41 |
$config = new \stdClass();
|
| 42 |
$config->multichoice_sortorder = '1';
|
42 |
$config->multichoice_sortorder = '1';
|
| 43 |
$config->calculated_sortorder = '2';
|
43 |
$config->calculated_sortorder = '2';
|
| 44 |
$qtypes = array(
|
44 |
$qtypes = array(
|
| Línea 51... |
Línea 51... |
| 51 |
'calculated' => 'newt',
|
51 |
'calculated' => 'newt',
|
| 52 |
'frog' => 'toad',
|
52 |
'frog' => 'toad',
|
| 53 |
));
|
53 |
));
|
| 54 |
}
|
54 |
}
|
| Línea 55... |
Línea 55... |
| 55 |
|
55 |
|
| 56 |
public function test_fraction_options() {
|
56 |
public function test_fraction_options(): void {
|
| 57 |
$fractions = question_bank::fraction_options();
|
57 |
$fractions = question_bank::fraction_options();
|
| 58 |
$this->assertSame(get_string('none'), reset($fractions));
|
58 |
$this->assertSame(get_string('none'), reset($fractions));
|
| 59 |
$this->assertSame('0.0', key($fractions));
|
59 |
$this->assertSame('0.0', key($fractions));
|
| 60 |
$this->assertSame('5%', end($fractions));
|
60 |
$this->assertSame('5%', end($fractions));
|
| Línea 66... |
Línea 66... |
| 66 |
$this->assertSame('1.0', key($fractions));
|
66 |
$this->assertSame('1.0', key($fractions));
|
| 67 |
$this->assertSame('11.11111%', end($fractions));
|
67 |
$this->assertSame('11.11111%', end($fractions));
|
| 68 |
$this->assertSame('0.1111111', key($fractions));
|
68 |
$this->assertSame('0.1111111', key($fractions));
|
| 69 |
}
|
69 |
}
|
| Línea 70... |
Línea 70... |
| 70 |
|
70 |
|
| 71 |
public function test_fraction_options_full() {
|
71 |
public function test_fraction_options_full(): void {
|
| 72 |
$fractions = question_bank::fraction_options_full();
|
72 |
$fractions = question_bank::fraction_options_full();
|
| 73 |
$this->assertSame(get_string('none'), reset($fractions));
|
73 |
$this->assertSame(get_string('none'), reset($fractions));
|
| 74 |
$this->assertSame('0.0', key($fractions));
|
74 |
$this->assertSame('0.0', key($fractions));
|
| 75 |
$this->assertSame('-100%', end($fractions));
|
75 |
$this->assertSame('-100%', end($fractions));
|
| Línea 81... |
Línea 81... |
| 81 |
$this->assertSame('1.0', key($fractions));
|
81 |
$this->assertSame('1.0', key($fractions));
|
| 82 |
$this->assertSame('-83.33333%', end($fractions));
|
82 |
$this->assertSame('-83.33333%', end($fractions));
|
| 83 |
$this->assertSame('-0.8333333', key($fractions));
|
83 |
$this->assertSame('-0.8333333', key($fractions));
|
| 84 |
}
|
84 |
}
|
| Línea 85... |
Línea 85... |
| 85 |
|
85 |
|
| 86 |
public function test_load_many_for_cache() {
|
86 |
public function test_load_many_for_cache(): void {
|
| 87 |
$this->resetAfterTest();
|
87 |
$this->resetAfterTest();
|
| 88 |
$generator = $this->getDataGenerator()->get_plugin_generator('core_question');
|
88 |
$generator = $this->getDataGenerator()->get_plugin_generator('core_question');
|
| 89 |
$cat = $generator->create_question_category();
|
89 |
$cat = $generator->create_question_category();
|
| Línea 90... |
Línea 90... |
| 90 |
$q1 = $generator->create_question('shortanswer', null, ['category' => $cat->id]);
|
90 |
$q1 = $generator->create_question('shortanswer', null, ['category' => $cat->id]);
|
| 91 |
|
91 |
|
| 92 |
$qs = question_finder::get_instance()->load_many_for_cache([$q1->id]);
|
92 |
$qs = question_finder::get_instance()->load_many_for_cache([$q1->id]);
|
| Línea 93... |
Línea 93... |
| 93 |
$this->assertArrayHasKey($q1->id, $qs);
|
93 |
$this->assertArrayHasKey($q1->id, $qs);
|
| 94 |
}
|
94 |
}
|
| 95 |
|
95 |
|
| 96 |
public function test_load_many_for_cache_missing_id() {
|
96 |
public function test_load_many_for_cache_missing_id(): void {
|
| 97 |
// Try to load a non-existent question.
|
97 |
// Try to load a non-existent question.
|