public function test_sort_behaviours() { $in = array('b1' => 'Behave 1', 'b2' => 'Behave 2', 'b3' => 'Behave 3', 'b4' => 'Behave 4', 'b5' => 'Behave 5', 'b6' => 'Behave 6'); $out = array('b1' => 'Behave 1', 'b2' => 'Behave 2', 'b3' => 'Behave 3', 'b4' => 'Behave 4', 'b5' => 'Behave 5', 'b6' => 'Behave 6'); $this->assertSame($out, question_engine::sort_behaviours($in, '', '', '')); $this->assertSame($out, question_engine::sort_behaviours($in, '', 'b4', 'b4')); $out = array('b4' => 'Behave 4', 'b5' => 'Behave 5', 'b6' => 'Behave 6'); $this->assertSame($out, question_engine::sort_behaviours($in, '', 'b1,b2,b3,b4', 'b4')); $out = array('b6' => 'Behave 6', 'b1' => 'Behave 1', 'b4' => 'Behave 4'); $this->assertSame($out, question_engine::sort_behaviours($in, 'b6,b1,b4', 'b2,b3,b4,b5', 'b4')); $out = array('b6' => 'Behave 6', 'b5' => 'Behave 5', 'b4' => 'Behave 4'); $this->assertSame($out, question_engine::sort_behaviours($in, 'b6,b5,b4', 'b1,b2,b3', 'b4')); $out = array('b6' => 'Behave 6', 'b5' => 'Behave 5', 'b4' => 'Behave 4'); $this->assertSame($out, question_engine::sort_behaviours($in, 'b1,b6,b5', 'b1,b2,b3,b4', 'b4')); $out = array('b2' => 'Behave 2', 'b4' => 'Behave 4', 'b6' => 'Behave 6'); $this->assertSame($out, question_engine::sort_behaviours($in, 'b2,b4,b6', 'b1,b3,b5', 'b2')); // Ignore unknown input in the order argument. $this->assertSame($in, question_engine::sort_behaviours($in, 'unknown', '', '')); // Ignore unknown input in the disabled argument. $this->assertSame($in, question_engine::sort_behaviours($in, '', 'unknown', '')); }
$archetypal[$behaviour] = question_engine::is_behaviour_archetypal($behaviour); } foreach ($counts as $behaviour => $count) { if (!array_key_exists($behaviour, $behaviours)) { $counts['missing'] += $count; } } $needed['missing'] = true; // Work of the correct sort order. $config = get_config('question'); $sortedbehaviours = array(); foreach ($behaviours as $behaviour => $notused) { $sortedbehaviours[$behaviour] = question_engine::get_behaviour_name($behaviour); } if (!empty($config->behavioursortorder)) { $sortedbehaviours = question_engine::sort_behaviours($sortedbehaviours, $config->behavioursortorder, ''); } if (!empty($config->disabledbehaviours)) { $disabledbehaviours = explode(',', $config->disabledbehaviours); } else { $disabledbehaviours = array(); } // Process actions ============================================================ // Disable. if (($disable = optional_param('disable', '', PARAM_PLUGIN)) && confirm_sesskey()) { if (!isset($behaviours[$disable])) { print_error('unknownbehaviour', 'question', $thispageurl, $disable); } if (array_search($disable, $disabledbehaviours) === false) { $disabledbehaviours[] = $disable; set_config('disabledbehaviours', implode(',', $disabledbehaviours), 'question');