Skip to content

Commit

Permalink
Merge branch 'MDL-33020' of git://github.com/timhunt/moodle
Browse files Browse the repository at this point in the history
  • Loading branch information
danpoltawski committed May 25, 2012
2 parents 494573d + 5ef18d8 commit 8119141
Showing 1 changed file with 18 additions and 12 deletions.
30 changes: 18 additions & 12 deletions question/engine/tests/helpers.php
Original file line number Diff line number Diff line change
Expand Up @@ -423,33 +423,38 @@ public function build_db_records(array $table) {

abstract class question_testcase extends advanced_testcase {

public function assert($expectation, $compare, $message = '') {
$message = (isset($expectation->message) and $expectation->message !== '') ? $expectation->message : $message;
public function assert($expectation, $compare, $notused = '') {

if (get_class($expectation) === 'question_pattern_expectation') {
$this->assertRegExp($expectation->pattern, $compare, $message);
$this->assertRegExp($expectation->pattern, $compare,
'Expected regex ' . $expectation->pattern . ' not found in ' . $compare);
return;

} else if (get_class($expectation) === 'question_no_pattern_expectation') {
$this->assertNotRegExp($expectation->pattern, $compare, $message);
$this->assertNotRegExp($expectation->pattern, $compare,
'Unexpected regex ' . $expectation->pattern . ' found in ' . $compare);
return;

} else if (get_class($expectation) === 'question_contains_tag_with_attributes') {
$this->assertTag(array('tag'=>$expectation->tag, 'attributes'=>$expectation->expectedvalues), $compare, $message);
$this->assertTag(array('tag'=>$expectation->tag, 'attributes'=>$expectation->expectedvalues), $compare,
'Looking for a ' . $expectation->tag . ' with attributes ' . html_writer::attributes($expectation->expectedvalues) . ' in ' . $compare);
foreach ($expectation->forbiddenvalues as $k=>$v) {
$attr = $expectation->expectedvalues;
$attr[$k] = $v;
$this->assertNotTag(array('tag'=>$expectation->tag, 'attributes'=>$attr), $compare, $message);
$this->assertNotTag(array('tag'=>$expectation->tag, 'attributes'=>$attr), $compare,
$expectation->tag . ' had a ' . $k . ' attribute that should not be there in ' . $compare);
}
return;

} else if (get_class($expectation) === 'question_contains_tag_with_attribute') {
$attr = array($expectation->attribute=>$expectation->value);
$this->assertTag(array('tag'=>$expectation->tag, 'attributes'=>$attr), $compare, $message);
$this->assertTag(array('tag'=>$expectation->tag, 'attributes'=>$attr), $compare,
'Looking for a ' . $expectation->tag . ' with attribute ' . html_writer::attributes($attr) . ' in ' . $compare);
return;

} else if (get_class($expectation) === 'question_does_not_contain_tag_with_attributes') {
$this->assertNotTag(array('tag'=>$expectation->tag, 'attributes'=>$expectation->attributes), $compare, $message);
$this->assertNotTag(array('tag'=>$expectation->tag, 'attributes'=>$expectation->attributes), $compare,
'Unexpected ' . $expectation->tag . ' with attributes ' . html_writer::attributes($expectation->attributes) . ' found in ' . $compare);
return;

} else if (get_class($expectation) === 'question_contains_select_expectation') {
Expand Down Expand Up @@ -492,7 +497,8 @@ public function assert($expectation, $compare, $message = '') {
return;

} else if (get_class($expectation) === 'question_contains_tag_with_contents') {
$this->assertTag(array('tag'=>$expectation->tag, 'content'=>$expectation->content), $compare, $message);
$this->assertTag(array('tag'=>$expectation->tag, 'content'=>$expectation->content), $compare,
'Looking for a ' . $expectation->tag . ' with content ' . $expectation->content . ' in ' . $compare);
return;
}

Expand Down Expand Up @@ -652,8 +658,8 @@ protected function manual_grade($comment, $mark) {
}

protected function check_current_state($state) {
$this->assertEquals($this->quba->get_question_state($this->slot), $state,
'Questions is in the wrong state: %s.');
$this->assertEquals($state, $this->quba->get_question_state($this->slot),
'Questions is in the wrong state.');
}

protected function check_current_mark($mark) {
Expand All @@ -666,7 +672,7 @@ protected function check_current_mark($mark) {
$this->assertNotNull($this->quba->get_question_mark($this->slot));
}
$this->assertEquals($mark, $this->quba->get_question_mark($this->slot),
'Expected mark and actual mark differ: %s.', 0.000001);
'Expected mark and actual mark differ.', 0.000001);
}
}

Expand Down

0 comments on commit 8119141

Please sign in to comment.