mirror of
https://github.com/moodle/moodle.git
synced 2025-04-21 16:32:18 +02:00
MDL-37506 question code: incorrect preg_quote uses.
For preg_quote to work reliably, you must pass the delimiter you are using for your regular expression. In many places we were failing to do that.
This commit is contained in:
parent
a5ec499521
commit
03cefcc91b
@ -43,35 +43,35 @@ class qbehaviour_adaptive_walkthrough_test extends qbehaviour_walkthrough_test_b
|
||||
protected function get_contains_penalty_info_expectation($penalty) {
|
||||
$penaltyinfo = get_string('gradingdetailspenalty', 'qbehaviour_adaptive',
|
||||
format_float($penalty, $this->displayoptions->markdp));
|
||||
return new question_pattern_expectation('/'.preg_quote($penaltyinfo).'/');
|
||||
return new question_pattern_expectation('/'.preg_quote($penaltyinfo, '/').'/');
|
||||
}
|
||||
|
||||
protected function get_does_not_contain_penalty_info_expectation() {
|
||||
$penaltyinfo = get_string('gradingdetailspenalty', 'qbehaviour_adaptive', 'XXXXX');
|
||||
$penaltypattern = '/'.str_replace('XXXXX', '\\w*', preg_quote($penaltyinfo)).'/';
|
||||
$penaltypattern = '/'.str_replace('XXXXX', '\\w*', preg_quote($penaltyinfo, '/')).'/';
|
||||
return new question_no_pattern_expectation($penaltypattern);
|
||||
}
|
||||
|
||||
protected function get_contains_total_penalty_expectation($penalty) {
|
||||
$penaltyinfo = get_string('gradingdetailspenaltytotal', 'qbehaviour_adaptive',
|
||||
format_float($penalty, $this->displayoptions->markdp));
|
||||
return new question_pattern_expectation('/'.preg_quote($penaltyinfo).'/');
|
||||
return new question_pattern_expectation('/'.preg_quote($penaltyinfo, '/').'/');
|
||||
}
|
||||
|
||||
protected function get_does_not_contain_total_penalty_expectation() {
|
||||
$penaltyinfo = get_string('gradingdetailspenaltytotal', 'qbehaviour_adaptive', 'XXXXX');
|
||||
$penaltypattern = '/'.str_replace('XXXXX', '\\w*', preg_quote($penaltyinfo)).'/';
|
||||
$penaltypattern = '/'.str_replace('XXXXX', '\\w*', preg_quote($penaltyinfo, '/')).'/';
|
||||
return new question_no_pattern_expectation($penaltypattern);
|
||||
}
|
||||
|
||||
protected function get_contains_disregarded_info_expectation() {
|
||||
$penaltyinfo = get_string('disregardedwithoutpenalty', 'qbehaviour_adaptive');
|
||||
return new question_pattern_expectation('/'.preg_quote($penaltyinfo).'/');
|
||||
return new question_pattern_expectation('/'.preg_quote($penaltyinfo, '/').'/');
|
||||
}
|
||||
|
||||
protected function get_does_not_contain_disregarded_info_expectation() {
|
||||
$penaltyinfo = get_string('disregardedwithoutpenalty', 'qbehaviour_adaptive');
|
||||
return new question_no_pattern_expectation('/'.preg_quote($penaltyinfo).'/');
|
||||
return new question_no_pattern_expectation('/'.preg_quote($penaltyinfo, '/').'/');
|
||||
}
|
||||
|
||||
public function test_adaptive_multichoice() {
|
||||
@ -165,7 +165,7 @@ class qbehaviour_adaptive_walkthrough_test extends qbehaviour_walkthrough_test_b
|
||||
$this->check_current_mark(1);
|
||||
$this->check_current_output(
|
||||
$this->get_contains_mark_summary(1),
|
||||
new question_pattern_expectation('/' . preg_quote('Not good enough!') . '/'));
|
||||
new question_pattern_expectation('/' . preg_quote('Not good enough!', '/') . '/'));
|
||||
|
||||
// Now change the correct answer to the question, and regrade.
|
||||
$mc->answers[13]->fraction = -0.33333333;
|
||||
|
@ -131,7 +131,7 @@ class qbehaviour_adaptivenopenalty_walkthrough_test extends qbehaviour_walkthrou
|
||||
$this->check_current_mark(1);
|
||||
$this->check_current_output(
|
||||
$this->get_contains_mark_summary(1),
|
||||
new question_pattern_expectation('/' . preg_quote('Not good enough!') . '/'));
|
||||
new question_pattern_expectation('/' . preg_quote('Not good enough!', '/') . '/'));
|
||||
|
||||
// Now change the correct answer to the question, and regrade.
|
||||
$mc->answers[13]->fraction = -0.33333333;
|
||||
|
@ -101,7 +101,7 @@ class qbehaviour_deferredcbm_walkthrough_test extends qbehaviour_walkthrough_tes
|
||||
$this->check_current_state(question_state::$mangrpartial);
|
||||
$this->check_current_mark(1);
|
||||
$this->check_current_output(new question_pattern_expectation('/' .
|
||||
preg_quote('Not good enough!') . '/'));
|
||||
preg_quote('Not good enough!', '/') . '/'));
|
||||
|
||||
// Now change the correct answer to the question, and regrade.
|
||||
$tf->rightanswer = false;
|
||||
@ -178,7 +178,7 @@ class qbehaviour_deferredcbm_walkthrough_test extends qbehaviour_walkthrough_tes
|
||||
new question_pattern_expectation('/' . preg_quote(
|
||||
get_string('assumingcertainty', 'qbehaviour_deferredcbm',
|
||||
question_cbm::get_string(
|
||||
$qa->get_last_behaviour_var('_assumedcertainty')))) . '/'));
|
||||
$qa->get_last_behaviour_var('_assumedcertainty'))), '/') . '/'));
|
||||
$this->assertEquals(get_string('true', 'qtype_truefalse'),
|
||||
$this->quba->get_response_summary($this->slot));
|
||||
}
|
||||
@ -204,9 +204,9 @@ class qbehaviour_deferredcbm_walkthrough_test extends qbehaviour_walkthrough_tes
|
||||
$this->get_contains_incorrect_expectation());
|
||||
$this->assertEquals('A [' . question_cbm::get_string(question_cbm::HIGH) . ']',
|
||||
$this->quba->get_right_answer_summary($this->slot));
|
||||
$this->assertRegExp('/' . preg_quote($mc->questiontext) . '/',
|
||||
$this->assertRegExp('/' . preg_quote($mc->questiontext, '/') . '/',
|
||||
$this->quba->get_question_summary($this->slot));
|
||||
$this->assertRegExp('/(B|C) \[' . preg_quote(question_cbm::get_string(2)) . '\]/',
|
||||
$this->assertRegExp('/(B|C) \[' . preg_quote(question_cbm::get_string(2), '/') . '\]/',
|
||||
$this->quba->get_response_summary($this->slot));
|
||||
|
||||
// Save the old attempt.
|
||||
@ -228,7 +228,7 @@ class qbehaviour_deferredcbm_walkthrough_test extends qbehaviour_walkthrough_tes
|
||||
$this->get_does_not_contain_correctness_expectation());
|
||||
$this->assertEquals('A [' . question_cbm::get_string(question_cbm::HIGH) . ']',
|
||||
$this->quba->get_right_answer_summary($this->slot));
|
||||
$this->assertRegExp('/' . preg_quote($mc->questiontext) . '/',
|
||||
$this->assertRegExp('/' . preg_quote($mc->questiontext, '/') . '/',
|
||||
$this->quba->get_question_summary($this->slot));
|
||||
$this->assertNull($this->quba->get_response_summary($this->slot));
|
||||
|
||||
@ -243,7 +243,7 @@ class qbehaviour_deferredcbm_walkthrough_test extends qbehaviour_walkthrough_tes
|
||||
$this->get_contains_mc_radio_expectation($rightindex, false, true),
|
||||
$this->get_contains_cbm_radio_expectation(3, false, true),
|
||||
$this->get_contains_correct_expectation());
|
||||
$this->assertRegExp('/(A) \[' . preg_quote(question_cbm::get_string(3)) . '\]/',
|
||||
$this->assertRegExp('/(A) \[' . preg_quote(question_cbm::get_string(3), '/') . '\]/',
|
||||
$this->quba->get_response_summary($this->slot));
|
||||
}
|
||||
|
||||
|
@ -52,7 +52,7 @@ class qbehaviour_deferredfeedback_walkthrough_test extends qbehaviour_walkthroug
|
||||
$this->get_does_not_contain_feedback_expectation());
|
||||
$this->assertEquals(get_string('true', 'qtype_truefalse'),
|
||||
$this->quba->get_right_answer_summary($this->slot));
|
||||
$this->assertRegExp('/' . preg_quote($tf->questiontext) . '/',
|
||||
$this->assertRegExp('/' . preg_quote($tf->questiontext, '/') . '/',
|
||||
$this->quba->get_question_summary($this->slot));
|
||||
$this->assertNull($this->quba->get_response_summary($this->slot));
|
||||
|
||||
@ -97,7 +97,7 @@ class qbehaviour_deferredfeedback_walkthrough_test extends qbehaviour_walkthroug
|
||||
$this->check_current_state(question_state::$mangrpartial);
|
||||
$this->check_current_mark(1);
|
||||
$this->check_current_output(
|
||||
new question_pattern_expectation('/' . preg_quote('Not good enough!') . '/'));
|
||||
new question_pattern_expectation('/' . preg_quote('Not good enough!', '/') . '/'));
|
||||
|
||||
// Now change the correct answer to the question, and regrade.
|
||||
$tf->rightanswer = false;
|
||||
|
@ -60,7 +60,7 @@ class qbehaviour_immediatecbm_walkthrough_test extends qbehaviour_walkthrough_te
|
||||
$this->get_does_not_contain_feedback_expectation());
|
||||
$this->assertEquals('A [' . question_cbm::get_string(question_cbm::HIGH) . ']',
|
||||
$this->quba->get_right_answer_summary($this->slot));
|
||||
$this->assertRegExp('/' . preg_quote($mc->questiontext) . '/',
|
||||
$this->assertRegExp('/' . preg_quote($mc->questiontext, '/') . '/',
|
||||
$this->quba->get_question_summary($this->slot));
|
||||
$this->assertNull($this->quba->get_response_summary($this->slot));
|
||||
|
||||
@ -116,7 +116,7 @@ class qbehaviour_immediatecbm_walkthrough_test extends qbehaviour_walkthrough_te
|
||||
$this->check_current_mark(0.5);
|
||||
$this->check_current_output(
|
||||
$this->get_contains_partcorrect_expectation(),
|
||||
new question_pattern_expectation('/' . preg_quote('Not good enough!') . '/'));
|
||||
new question_pattern_expectation('/' . preg_quote('Not good enough!', '/') . '/'));
|
||||
|
||||
// Now change the correct answer to the question, and regrade.
|
||||
$mc->answers[13]->fraction = -0.33333333;
|
||||
@ -183,7 +183,7 @@ class qbehaviour_immediatecbm_walkthrough_test extends qbehaviour_walkthrough_te
|
||||
$this->check_current_mark(0.5);
|
||||
$this->check_current_output(
|
||||
$this->get_contains_partcorrect_expectation(),
|
||||
new question_pattern_expectation('/' . preg_quote('Not good enough!') . '/'));
|
||||
new question_pattern_expectation('/' . preg_quote('Not good enough!', '/') . '/'));
|
||||
}
|
||||
|
||||
public function test_immediatecbm_feedback_shortanswer_try_to_submit_no_certainty() {
|
||||
|
@ -123,7 +123,7 @@ class qbehaviour_immediatefeedback_walkthrough_test extends qbehaviour_walkthrou
|
||||
$this->check_current_mark(0.5);
|
||||
$this->check_current_output(
|
||||
$this->get_contains_partcorrect_expectation(),
|
||||
new question_pattern_expectation('/' . preg_quote('Not good enough!') . '/'));
|
||||
new question_pattern_expectation('/' . preg_quote('Not good enough!', '/') . '/'));
|
||||
|
||||
// Now change the correct answer to the question, and regrade.
|
||||
$mc->answers[13]->fraction = -0.33333333;
|
||||
@ -192,7 +192,7 @@ class qbehaviour_immediatefeedback_walkthrough_test extends qbehaviour_walkthrou
|
||||
$this->check_current_mark(0.5);
|
||||
$this->check_current_output(
|
||||
$this->get_contains_partcorrect_expectation(),
|
||||
new question_pattern_expectation('/' . preg_quote('Not good enough!') . '/'));
|
||||
new question_pattern_expectation('/' . preg_quote('Not good enough!', '/') . '/'));
|
||||
}
|
||||
|
||||
public function test_immediatefeedback_feedback_multichoice_wrong_on_finish() {
|
||||
|
@ -79,7 +79,7 @@ class qbehaviour_informationitem_walkthrough_test extends qbehaviour_walkthrough
|
||||
$this->check_current_state(question_state::$manfinished);
|
||||
$this->check_current_mark(null);
|
||||
$this->check_current_output(
|
||||
new question_pattern_expectation('/' . preg_quote('Not good enough!') . '/'));
|
||||
new question_pattern_expectation('/' . preg_quote('Not good enough!', '/') . '/'));
|
||||
|
||||
// Check that trying to process a manual comment with a grade causes an exception.
|
||||
$this->setExpectedException('moodle_exception');
|
||||
|
@ -99,7 +99,7 @@ class qbehaviour_interactive_walkthrough_test extends qbehaviour_walkthrough_tes
|
||||
$this->get_contains_try_again_button_expectation(true),
|
||||
$this->get_does_not_contain_correctness_expectation(),
|
||||
new question_pattern_expectation('/' .
|
||||
preg_quote(get_string('notcomplete', 'qbehaviour_interactive')) . '/'),
|
||||
preg_quote(get_string('notcomplete', 'qbehaviour_interactive'), '/') . '/'),
|
||||
$this->get_contains_hint_expectation('This is the first hint'));
|
||||
|
||||
// Check that, if we review in this state, the try again button is disabled.
|
||||
@ -165,7 +165,7 @@ class qbehaviour_interactive_walkthrough_test extends qbehaviour_walkthrough_tes
|
||||
$this->check_current_output(
|
||||
$this->get_contains_mark_summary(0.5),
|
||||
$this->get_contains_partcorrect_expectation(),
|
||||
new question_pattern_expectation('/' . preg_quote('Not good enough!') . '/'));
|
||||
new question_pattern_expectation('/' . preg_quote('Not good enough!', '/') . '/'));
|
||||
|
||||
// Check regrading does not mess anything up.
|
||||
$this->quba->regrade_all_questions();
|
||||
@ -224,7 +224,7 @@ class qbehaviour_interactive_walkthrough_test extends qbehaviour_walkthrough_tes
|
||||
$this->get_contains_try_again_button_expectation(true),
|
||||
$this->get_does_not_contain_correctness_expectation(),
|
||||
new question_pattern_expectation('/' .
|
||||
preg_quote(get_string('notcomplete', 'qbehaviour_interactive')) . '/'),
|
||||
preg_quote(get_string('notcomplete', 'qbehaviour_interactive'), '/') . '/'),
|
||||
$this->get_contains_hint_expectation('This is the first hint'));
|
||||
|
||||
// Finish the attempt.
|
||||
@ -289,7 +289,7 @@ class qbehaviour_interactive_walkthrough_test extends qbehaviour_walkthrough_tes
|
||||
$this->get_does_not_contain_validation_error_expectation(),
|
||||
$this->get_contains_try_again_button_expectation(true),
|
||||
new question_pattern_expectation('/' .
|
||||
preg_quote(get_string('notcomplete', 'qbehaviour_interactive')) . '/'),
|
||||
preg_quote(get_string('notcomplete', 'qbehaviour_interactive'), '/') . '/'),
|
||||
$this->get_contains_hint_expectation('This is the first hint'));
|
||||
$this->assertEquals('newt',
|
||||
$this->quba->get_response_summary($this->slot));
|
||||
@ -387,7 +387,7 @@ class qbehaviour_interactive_walkthrough_test extends qbehaviour_walkthrough_tes
|
||||
$this->get_contains_try_again_button_expectation(true),
|
||||
$this->get_does_not_contain_correctness_expectation(),
|
||||
new question_pattern_expectation('/' .
|
||||
preg_quote(get_string('notcomplete', 'qbehaviour_interactive')) . '/'),
|
||||
preg_quote(get_string('notcomplete', 'qbehaviour_interactive'), '/') . '/'),
|
||||
$this->get_contains_hint_expectation('This is the first hint'),
|
||||
$this->get_contains_num_parts_correct(1),
|
||||
$this->get_contains_standard_incorrect_combined_feedback_expectation(),
|
||||
|
@ -91,7 +91,7 @@ class qbehaviour_interactivecountback_walkthrough_test extends qbehaviour_walkth
|
||||
$this->get_contains_try_again_button_expectation(true),
|
||||
$this->get_does_not_contain_correctness_expectation(),
|
||||
new question_pattern_expectation('/' .
|
||||
preg_quote(get_string('notcomplete', 'qbehaviour_interactive')) . '/'),
|
||||
preg_quote(get_string('notcomplete', 'qbehaviour_interactive'), '/') . '/'),
|
||||
$this->get_contains_hint_expectation('This is the first hint'),
|
||||
$this->get_contains_num_parts_correct(2),
|
||||
$this->get_contains_standard_partiallycorrect_combined_feedback_expectation(),
|
||||
|
@ -96,7 +96,7 @@ class qbehaviour_manualgraded_walkthrough_test extends qbehaviour_walkthrough_te
|
||||
$this->check_current_state(question_state::$mangrright);
|
||||
$this->check_current_mark(10);
|
||||
$this->check_current_output(
|
||||
new question_pattern_expectation('/' . preg_quote('Not good enough!') . '/'));
|
||||
new question_pattern_expectation('/' . preg_quote('Not good enough!', '/') . '/'));
|
||||
|
||||
// Now change the max mark for the question and regrade.
|
||||
$this->quba->regrade_question($this->slot, true, 1);
|
||||
@ -147,7 +147,7 @@ class qbehaviour_manualgraded_walkthrough_test extends qbehaviour_walkthrough_te
|
||||
$this->check_current_output(
|
||||
$this->get_does_not_contain_correctness_expectation(),
|
||||
$this->get_does_not_contain_specific_feedback_expectation(),
|
||||
new question_pattern_expectation('/' . preg_quote('Not good enough!') . '/'));
|
||||
new question_pattern_expectation('/' . preg_quote('Not good enough!', '/') . '/'));
|
||||
}
|
||||
|
||||
public function test_manual_graded_ignore_repeat_sumbission() {
|
||||
@ -194,7 +194,7 @@ class qbehaviour_manualgraded_walkthrough_test extends qbehaviour_walkthrough_te
|
||||
$this->check_current_mark(null);
|
||||
$this->check_current_output(
|
||||
new question_pattern_expectation('/' .
|
||||
preg_quote('I am not sure what grade to award.') . '/'));
|
||||
preg_quote('I am not sure what grade to award.', '/') . '/'));
|
||||
|
||||
// Now grade it.
|
||||
$this->manual_grade('Pretty good!', '9.00000');
|
||||
@ -202,7 +202,7 @@ class qbehaviour_manualgraded_walkthrough_test extends qbehaviour_walkthrough_te
|
||||
$this->check_current_state(question_state::$mangrpartial);
|
||||
$this->check_current_mark(9);
|
||||
$this->check_current_output(
|
||||
new question_pattern_expectation('/' . preg_quote('Pretty good!') . '/'));
|
||||
new question_pattern_expectation('/' . preg_quote('Pretty good!', '/') . '/'));
|
||||
|
||||
// Process the same data again, and make sure it does not add a step.
|
||||
$this->manual_grade('Pretty good!', '9.00000');
|
||||
@ -217,7 +217,7 @@ class qbehaviour_manualgraded_walkthrough_test extends qbehaviour_walkthrough_te
|
||||
$this->check_current_mark(null);
|
||||
$this->check_current_output(
|
||||
new question_pattern_expectation('/' .
|
||||
preg_quote('Actually, I am not sure any more.') . '/'));
|
||||
preg_quote('Actually, I am not sure any more.', '/') . '/'));
|
||||
|
||||
$qa = $this->quba->get_question_attempt($this->slot);
|
||||
$this->assertEquals('Commented: Actually, I am not sure any more.',
|
||||
|
@ -101,9 +101,9 @@ class qbehaviour_missing_test extends advanced_testcase {
|
||||
$this->assertEquals(array('-submit' => '1', 'choice0' => '1'), $step->get_all_data());
|
||||
|
||||
$output = $qa->render(new question_display_options(), '1');
|
||||
$this->assertRegExp('/' . preg_quote($qa->get_question()->questiontext) . '/', $output);
|
||||
$this->assertRegExp('/' . preg_quote($qa->get_question()->questiontext, '/') . '/', $output);
|
||||
$this->assertRegExp('/' . preg_quote(
|
||||
get_string('questionusedunknownmodel', 'qbehaviour_missing')) . '/', $output);
|
||||
get_string('questionusedunknownmodel', 'qbehaviour_missing'), '/') . '/', $output);
|
||||
$this->assertTag(array('tag'=>'div', 'attributes'=>array('class'=>'warning')), $output);
|
||||
}
|
||||
}
|
||||
|
@ -958,7 +958,7 @@ class question_attempt {
|
||||
$postdata = $_POST;
|
||||
}
|
||||
|
||||
$pattern = '/^' . preg_quote($this->get_field_prefix()) . '[^-:]/';
|
||||
$pattern = '/^' . preg_quote($this->get_field_prefix(), '/') . '[^-:]/';
|
||||
$prefixlen = strlen($this->get_field_prefix());
|
||||
|
||||
$submitteddata = array();
|
||||
|
@ -534,7 +534,7 @@ class question_attempt_step_subquestion_adapter extends question_attempt_step {
|
||||
* null if the extre prefix was not present.
|
||||
*/
|
||||
public function remove_prefix($field) {
|
||||
if (preg_match('~^(-?_?)' . preg_quote($this->extraprefix) . '(.*)$~', $field, $matches)) {
|
||||
if (preg_match('~^(-?_?)' . preg_quote($this->extraprefix, '~') . '(.*)$~', $field, $matches)) {
|
||||
return $matches[1] . $matches[2];
|
||||
} else {
|
||||
return null;
|
||||
|
@ -697,11 +697,11 @@ abstract class qbehaviour_walkthrough_test_base extends question_testcase {
|
||||
}
|
||||
|
||||
protected function get_contains_question_text_expectation($question) {
|
||||
return new question_pattern_expectation('/' . preg_quote($question->questiontext) . '/');
|
||||
return new question_pattern_expectation('/' . preg_quote($question->questiontext, '/') . '/');
|
||||
}
|
||||
|
||||
protected function get_contains_general_feedback_expectation($question) {
|
||||
return new question_pattern_expectation('/' . preg_quote($question->generalfeedback) . '/');
|
||||
return new question_pattern_expectation('/' . preg_quote($question->generalfeedback, '/') . '/');
|
||||
}
|
||||
|
||||
protected function get_does_not_contain_correctness_expectation() {
|
||||
@ -709,31 +709,31 @@ abstract class qbehaviour_walkthrough_test_base extends question_testcase {
|
||||
}
|
||||
|
||||
protected function get_contains_correct_expectation() {
|
||||
return new question_pattern_expectation('/' . preg_quote(get_string('correct', 'question')) . '/');
|
||||
return new question_pattern_expectation('/' . preg_quote(get_string('correct', 'question'), '/') . '/');
|
||||
}
|
||||
|
||||
protected function get_contains_partcorrect_expectation() {
|
||||
return new question_pattern_expectation('/' .
|
||||
preg_quote(get_string('partiallycorrect', 'question')) . '/');
|
||||
preg_quote(get_string('partiallycorrect', 'question'), '/') . '/');
|
||||
}
|
||||
|
||||
protected function get_contains_incorrect_expectation() {
|
||||
return new question_pattern_expectation('/' . preg_quote(get_string('incorrect', 'question')) . '/');
|
||||
return new question_pattern_expectation('/' . preg_quote(get_string('incorrect', 'question'), '/') . '/');
|
||||
}
|
||||
|
||||
protected function get_contains_standard_correct_combined_feedback_expectation() {
|
||||
return new question_pattern_expectation('/' .
|
||||
preg_quote(test_question_maker::STANDARD_OVERALL_CORRECT_FEEDBACK) . '/');
|
||||
preg_quote(test_question_maker::STANDARD_OVERALL_CORRECT_FEEDBACK, '/') . '/');
|
||||
}
|
||||
|
||||
protected function get_contains_standard_partiallycorrect_combined_feedback_expectation() {
|
||||
return new question_pattern_expectation('/' .
|
||||
preg_quote(test_question_maker::STANDARD_OVERALL_PARTIALLYCORRECT_FEEDBACK) . '/');
|
||||
preg_quote(test_question_maker::STANDARD_OVERALL_PARTIALLYCORRECT_FEEDBACK, '/') . '/');
|
||||
}
|
||||
|
||||
protected function get_contains_standard_incorrect_combined_feedback_expectation() {
|
||||
return new question_pattern_expectation('/' .
|
||||
preg_quote(test_question_maker::STANDARD_OVERALL_INCORRECT_FEEDBACK) . '/');
|
||||
preg_quote(test_question_maker::STANDARD_OVERALL_INCORRECT_FEEDBACK, '/') . '/');
|
||||
}
|
||||
|
||||
protected function get_does_not_contain_feedback_expectation() {
|
||||
@ -748,7 +748,7 @@ abstract class qbehaviour_walkthrough_test_base extends question_testcase {
|
||||
$a = new stdClass();
|
||||
$a->num = $num;
|
||||
return new question_pattern_expectation('/<div class="numpartscorrect">' .
|
||||
preg_quote(get_string('yougotnright', 'question', $a)) . '/');
|
||||
preg_quote(get_string('yougotnright', 'question', $a), '/') . '/');
|
||||
}
|
||||
|
||||
protected function get_does_not_contain_specific_feedback_expectation() {
|
||||
@ -769,14 +769,14 @@ abstract class qbehaviour_walkthrough_test_base extends question_testcase {
|
||||
$a->max = format_float($this->quba->get_question_max_mark($this->slot),
|
||||
$this->displayoptions->markdp);
|
||||
return new question_pattern_expectation('/' .
|
||||
preg_quote(get_string('markoutofmax', 'question', $a)) . '/');
|
||||
preg_quote(get_string('markoutofmax', 'question', $a), '/') . '/');
|
||||
}
|
||||
|
||||
protected function get_contains_marked_out_of_summary() {
|
||||
$max = format_float($this->quba->get_question_max_mark($this->slot),
|
||||
$this->displayoptions->markdp);
|
||||
return new question_pattern_expectation('/' .
|
||||
preg_quote(get_string('markedoutofmax', 'question', $max)) . '/');
|
||||
preg_quote(get_string('markedoutofmax', 'question', $max), '/') . '/');
|
||||
}
|
||||
|
||||
protected function get_does_not_contain_mark_summary() {
|
||||
@ -894,12 +894,12 @@ abstract class qbehaviour_walkthrough_test_base extends question_testcase {
|
||||
|
||||
protected function get_tries_remaining_expectation($n) {
|
||||
return new question_pattern_expectation('/' .
|
||||
preg_quote(get_string('triesremaining', 'qbehaviour_interactive', $n)) . '/');
|
||||
preg_quote(get_string('triesremaining', 'qbehaviour_interactive', $n), '/') . '/');
|
||||
}
|
||||
|
||||
protected function get_invalid_answer_expectation() {
|
||||
return new question_pattern_expectation('/' .
|
||||
preg_quote(get_string('invalidanswer', 'question')) . '/');
|
||||
preg_quote(get_string('invalidanswer', 'question'), '/') . '/');
|
||||
}
|
||||
|
||||
protected function get_contains_try_again_button_expectation($enabled = null) {
|
||||
|
@ -87,21 +87,21 @@ class question_attempt_test extends advanced_testcase {
|
||||
|
||||
public function test_get_qt_field_name() {
|
||||
$name = $this->qa->get_qt_field_name('test');
|
||||
$this->assertRegExp('/^' . preg_quote($this->qa->get_field_prefix()) . '/', $name);
|
||||
$this->assertRegExp('/^' . preg_quote($this->qa->get_field_prefix(), '/') . '/', $name);
|
||||
$this->assertRegExp('/_test$/', $name);
|
||||
}
|
||||
|
||||
public function test_get_behaviour_field_name() {
|
||||
$name = $this->qa->get_behaviour_field_name('test');
|
||||
$this->assertRegExp('/^' . preg_quote($this->qa->get_field_prefix()) . '/', $name);
|
||||
$this->assertRegExp('/^' . preg_quote($this->qa->get_field_prefix(), '/') . '/', $name);
|
||||
$this->assertRegExp('/_-test$/', $name);
|
||||
}
|
||||
|
||||
public function test_get_field_prefix() {
|
||||
$this->qa->set_slot(7);
|
||||
$name = $this->qa->get_field_prefix();
|
||||
$this->assertRegExp('/' . preg_quote($this->usageid) . '/', $name);
|
||||
$this->assertRegExp('/' . preg_quote($this->qa->get_slot()) . '/', $name);
|
||||
$this->assertRegExp('/' . preg_quote($this->usageid, '/') . '/', $name);
|
||||
$this->assertRegExp('/' . preg_quote($this->qa->get_slot(), '/') . '/', $name);
|
||||
}
|
||||
|
||||
public function test_get_submitted_var_not_present_var_returns_null() {
|
||||
|
@ -86,7 +86,7 @@ class qtype_calculated_walkthrough_test extends qbehaviour_walkthrough_test_base
|
||||
$this->get_does_not_contain_feedback_expectation(),
|
||||
$this->get_contains_validation_error_expectation(),
|
||||
new question_pattern_expectation('/' .
|
||||
preg_quote(get_string('invalidnumber', 'qtype_numerical') . '/')),
|
||||
preg_quote(get_string('invalidnumber', 'qtype_numerical'), '/') . '/'),
|
||||
$this->get_does_not_contain_try_again_button_expectation(),
|
||||
$this->get_no_hint_visible_expectation());
|
||||
|
||||
|
@ -86,7 +86,7 @@ class qtype_calculatedmulti_walkthrough_test extends qbehaviour_walkthrough_test
|
||||
$this->get_does_not_contain_feedback_expectation(),
|
||||
$this->get_contains_validation_error_expectation(),
|
||||
new question_pattern_expectation('/' .
|
||||
preg_quote(get_string('invalidnumber', 'qtype_numerical') . '/')),
|
||||
preg_quote(get_string('invalidnumber', 'qtype_numerical'), '/') . '/'),
|
||||
$this->get_does_not_contain_try_again_button_expectation(),
|
||||
$this->get_no_hint_visible_expectation());
|
||||
|
||||
|
@ -85,7 +85,7 @@ class qtype_calculatedsimple_walkthrough_test extends qbehaviour_walkthrough_tes
|
||||
$this->get_does_not_contain_feedback_expectation(),
|
||||
$this->get_contains_validation_error_expectation(),
|
||||
new question_pattern_expectation('/' .
|
||||
preg_quote(get_string('invalidnumber', 'qtype_numerical') . '/')),
|
||||
preg_quote(get_string('invalidnumber', 'qtype_numerical'), '/') . '/'),
|
||||
$this->get_does_not_contain_try_again_button_expectation(),
|
||||
$this->get_no_hint_visible_expectation());
|
||||
|
||||
|
@ -134,12 +134,12 @@ class qtype_match_question_test extends advanced_testcase {
|
||||
$match = test_question_maker::make_a_matching_question();
|
||||
$match->start_attempt(new question_attempt_step(), 1);
|
||||
$qsummary = $match->get_question_summary();
|
||||
$this->assertRegExp('/' . preg_quote($match->questiontext) . '/', $qsummary);
|
||||
$this->assertRegExp('/' . preg_quote($match->questiontext, '/') . '/', $qsummary);
|
||||
foreach ($match->stems as $stem) {
|
||||
$this->assertRegExp('/' . preg_quote($stem) . '/', $qsummary);
|
||||
$this->assertRegExp('/' . preg_quote($stem, '/') . '/', $qsummary);
|
||||
}
|
||||
foreach ($match->choices as $choice) {
|
||||
$this->assertRegExp('/' . preg_quote($choice) . '/', $qsummary);
|
||||
$this->assertRegExp('/' . preg_quote($choice, '/') . '/', $qsummary);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -107,7 +107,7 @@ class qtype_missing_test extends question_testcase {
|
||||
$this->assertRegExp('/' .
|
||||
preg_quote($qa->get_question()->questiontext, '/') . '/', $output);
|
||||
$this->assertRegExp('/' .
|
||||
preg_quote(get_string('missingqtypewarning', 'qtype_missingtype')) . '/', $output);
|
||||
preg_quote(get_string('missingqtypewarning', 'qtype_missingtype'), '/') . '/', $output);
|
||||
$this->assert(new question_contains_tag_with_attribute(
|
||||
'div', 'class', 'warning missingqtypewarning'), $output);
|
||||
}
|
||||
|
@ -367,7 +367,7 @@ class qtype_multianswer_walkthrough_test extends qbehaviour_walkthrough_test_bas
|
||||
$this->get_contains_try_again_button_expectation(true),
|
||||
$this->get_does_not_contain_correctness_expectation(),
|
||||
new question_pattern_expectation('/' .
|
||||
preg_quote(get_string('notcomplete', 'qbehaviour_interactive')) . '/'),
|
||||
preg_quote(get_string('notcomplete', 'qbehaviour_interactive'), '/') . '/'),
|
||||
$this->get_contains_hint_expectation('This is the first hint.'));
|
||||
|
||||
// Check that extract responses will return the reset data.
|
||||
|
@ -224,9 +224,9 @@ class qtype_multichoice_multi_question_test extends advanced_testcase {
|
||||
|
||||
$qsummary = $mc->get_question_summary();
|
||||
|
||||
$this->assertRegExp('/' . preg_quote($mc->questiontext) . '/', $qsummary);
|
||||
$this->assertRegExp('/' . preg_quote($mc->questiontext, '/') . '/', $qsummary);
|
||||
foreach ($mc->answers as $answer) {
|
||||
$this->assertRegExp('/' . preg_quote($answer->answer) . '/', $qsummary);
|
||||
$this->assertRegExp('/' . preg_quote($answer->answer, '/') . '/', $qsummary);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -85,7 +85,7 @@ class qtype_numerical_walkthrough_test extends qbehaviour_walkthrough_test_base
|
||||
$this->get_does_not_contain_feedback_expectation(),
|
||||
$this->get_contains_validation_error_expectation(),
|
||||
new question_pattern_expectation('/' .
|
||||
preg_quote(get_string('invalidnumber', 'qtype_numerical') . '/')),
|
||||
preg_quote(get_string('invalidnumber', 'qtype_numerical'), '/') . '/'),
|
||||
$this->get_does_not_contain_try_again_button_expectation(),
|
||||
$this->get_no_hint_visible_expectation());
|
||||
|
||||
@ -145,7 +145,7 @@ class qtype_numerical_walkthrough_test extends qbehaviour_walkthrough_test_base
|
||||
$this->get_does_not_contain_feedback_expectation(),
|
||||
$this->get_contains_validation_error_expectation(),
|
||||
new question_pattern_expectation('/' .
|
||||
preg_quote(get_string('invalidnumber', 'qtype_numerical') . '/')),
|
||||
preg_quote(get_string('invalidnumber', 'qtype_numerical'), '/') . '/'),
|
||||
$this->get_does_not_contain_try_again_button_expectation(),
|
||||
$this->get_no_hint_visible_expectation());
|
||||
|
||||
@ -227,7 +227,7 @@ class qtype_numerical_walkthrough_test extends qbehaviour_walkthrough_test_base
|
||||
$this->get_does_not_contain_feedback_expectation(),
|
||||
$this->get_contains_validation_error_expectation(),
|
||||
new question_pattern_expectation('/' .
|
||||
preg_quote(get_string('invalidnumber', 'qtype_numerical') . '/')),
|
||||
preg_quote(get_string('invalidnumber', 'qtype_numerical'), '/') . '/'),
|
||||
$this->get_contains_select_expectation('unit', $unitchoices, 'cm', true),
|
||||
$this->get_does_not_contain_try_again_button_expectation(),
|
||||
$this->get_no_hint_visible_expectation());
|
||||
@ -242,7 +242,7 @@ class qtype_numerical_walkthrough_test extends qbehaviour_walkthrough_test_base
|
||||
$this->get_does_not_contain_feedback_expectation(),
|
||||
$this->get_contains_validation_error_expectation(),
|
||||
new question_pattern_expectation('/' .
|
||||
preg_quote(get_string('unitnotselected', 'qtype_numerical') . '/')),
|
||||
preg_quote(get_string('unitnotselected', 'qtype_numerical'), '/') . '/'),
|
||||
$this->get_contains_select_expectation('unit', $unitchoices, '', true),
|
||||
$this->get_does_not_contain_try_again_button_expectation(),
|
||||
$this->get_no_hint_visible_expectation());
|
||||
|
@ -90,12 +90,12 @@ class qtype_shortanswer_question extends question_graded_by_strategy
|
||||
// Break the string on non-escaped asterisks.
|
||||
$bits = preg_split('/(?<!\\\\)\*/', $pattern);
|
||||
// Escape regexp special characters in the bits.
|
||||
$excapedbits = array();
|
||||
$escapedbits = array();
|
||||
foreach ($bits as $bit) {
|
||||
$excapedbits[] = preg_quote(str_replace('\*', '*', $bit));
|
||||
$escapedbits[] = preg_quote(str_replace('\*', '*', $bit), '|');
|
||||
}
|
||||
// Put it back together to make the regexp.
|
||||
$regexp = '|^' . implode('.*', $excapedbits) . '$|u';
|
||||
$regexp = '|^' . implode('.*', $escapedbits) . '$|u';
|
||||
|
||||
// Make the match insensitive if requested to.
|
||||
if ($ignorecase) {
|
||||
|
@ -54,7 +54,7 @@ class qtype_truefalse_walkthrough_test extends qbehaviour_walkthrough_test_base
|
||||
get_string('questiontext', 'question')));
|
||||
$this->assertEquals(get_string('false', 'qtype_truefalse'),
|
||||
$this->quba->get_right_answer_summary($this->slot));
|
||||
$this->assertRegExp('/' . preg_quote($tf->questiontext) . '/',
|
||||
$this->assertRegExp('/' . preg_quote($tf->questiontext, '/') . '/',
|
||||
$this->quba->get_question_summary($this->slot));
|
||||
$this->assertNull($this->quba->get_response_summary($this->slot));
|
||||
|
||||
@ -69,7 +69,7 @@ class qtype_truefalse_walkthrough_test extends qbehaviour_walkthrough_test_base
|
||||
$this->get_contains_tf_false_radio_expectation(false, false),
|
||||
|
||||
// In particular, check that the false feedback is not displayed.
|
||||
new question_no_pattern_expectation('/' . preg_quote($tf->falsefeedback) . '/'));
|
||||
new question_no_pattern_expectation('/' . preg_quote($tf->falsefeedback, '/') . '/'));
|
||||
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user