Skip to content

Commit

Permalink
MDL-20636 make qe upgrade tests independent of html2text details.
Browse files Browse the repository at this point in the history
Based on Eloy's change, but refactored to be slightly nicer.
  • Loading branch information
timhunt committed Jun 6, 2011
1 parent 0370e3a commit 4c57433
Show file tree
Hide file tree
Showing 14 changed files with 79 additions and 50 deletions.
2 changes: 1 addition & 1 deletion local/qeupgradehelper/locallib.php
Original file line number Diff line number Diff line change
Expand Up @@ -593,7 +593,7 @@ public function test_{$question->qtype}_{$quiz->preferredbehaviour}_{$namesuffix
),
);
$this->assertEqual($expectedqa, $qa);
$this->compare_qas($expectedqa, $qa);
}
</textarea>';
}
Expand Down
29 changes: 29 additions & 0 deletions question/engine/upgrade/simpletest/helper.php
Original file line number Diff line number Diff line change
Expand Up @@ -125,4 +125,33 @@ public function setUp() {
public function tearDown() {
$this->updater = null;
}

/**
* Clear text, bringing independence of html2text results
*
* Some tests performing text comparisons of converted text are too much
* dependent of the behavior of the html2text library. This function is
* aimed to reduce such dependencies that should not affect the results
* of these question attempt upgrade tests.
*/
protected function clear_html2text_dependencies($qa) {
// Cleaning all whitespace should be enough to ignore any html2text dependency
if (property_exists($qa, 'responsesummary')) {
$qa->responsesummary = preg_replace('/\s/', '', $qa->responsesummary);
}
if (property_exists($qa, 'questionsummary')) {
$qa->questionsummary = preg_replace('/\s/', '', $qa->questionsummary);
}
}

/**
* Compare two qas, ignoring inessential differences.
* @param object $expectedqa the expected qa.
* @param object $qa the actual qa.
*/
protected function compare_qas($expectedqa, $qa) {
$this->clear_html2text_dependencies($expectedqa);
$this->clear_html2text_dependencies($qa);
$this->assertEqual($expectedqa, $qa);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ public function test_calculated_adaptive_qsession97() {
),
);

$this->assertEqual($expectedqa, $qa);
$this->compare_qas($expectedqa, $qa);
}

public function test_calculated_adaptive_qsession100() {
Expand Down Expand Up @@ -475,7 +475,7 @@ public function test_calculated_adaptive_qsession100() {
),
);

$this->assertEqual($expectedqa, $qa);
$this->compare_qas($expectedqa, $qa);
}

public function test_calculated_adaptive_qsession103() {
Expand Down Expand Up @@ -695,6 +695,6 @@ public function test_calculated_adaptive_qsession103() {
),
);

$this->assertEqual($expectedqa, $qa);
$this->compare_qas($expectedqa, $qa);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,7 @@ public function test_calculatedmulti_adaptive_qsession96() {
),
);

$this->assertEqual($expectedqa, $qa);
$this->compare_qas($expectedqa, $qa);
}

public function test_calculatedmulti_adaptive_qsession99() {
Expand Down Expand Up @@ -498,7 +498,7 @@ public function test_calculatedmulti_adaptive_qsession99() {
),
);

$this->assertEqual($expectedqa, $qa);
$this->compare_qas($expectedqa, $qa);
}

public function test_calculatedmulti_adaptive_qsession102() {
Expand Down Expand Up @@ -800,6 +800,6 @@ public function test_calculatedmulti_adaptive_qsession102() {
),
);

$this->assertEqual($expectedqa, $qa);
$this->compare_qas($expectedqa, $qa);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ public function test_calculatedsimple_adaptive_qsession95() {
),
);

$this->assertEqual($expectedqa, $qa);
$this->compare_qas($expectedqa, $qa);
}

public function test_calculatedsimple_adaptive_qsession98() {
Expand Down Expand Up @@ -446,7 +446,7 @@ public function test_calculatedsimple_adaptive_qsession98() {
),
);

$this->assertEqual($expectedqa, $qa);
$this->compare_qas($expectedqa, $qa);
}

public function test_calculatedsimple_adaptive_qsession101() {
Expand Down Expand Up @@ -632,6 +632,6 @@ public function test_calculatedsimple_adaptive_qsession101() {
),
);

$this->assertEqual($expectedqa, $qa);
$this->compare_qas($expectedqa, $qa);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ public function test_description_deferredfeedback_history80() {
),
);

$this->assertEqual($expectedqa, $qa);
$this->compare_qas($expectedqa, $qa);
}

public function test_description_deferredfeedback_history70() {
Expand Down Expand Up @@ -327,7 +327,7 @@ public function test_description_deferredfeedback_history70() {
),
);

$this->assertEqual($expectedqa, $qa);
$this->compare_qas($expectedqa, $qa);
}

public function test_description_deferredfeedback_history0() {
Expand Down Expand Up @@ -455,6 +455,6 @@ public function test_description_deferredfeedback_history0() {
),
);

$this->assertEqual($expectedqa, $qa);
$this->compare_qas($expectedqa, $qa);
}
}
6 changes: 3 additions & 3 deletions question/type/essay/db/simpletest/testupgradelibnewqe.php
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,7 @@ public function test_essay_deferredfeedback_history98220() {
),
);

$this->assertEqual($expectedqa, $qa);
$this->compare_qas($expectedqa, $qa);
}

public function test_essay_deferredfeedback_history820() {
Expand Down Expand Up @@ -449,7 +449,7 @@ public function test_essay_deferredfeedback_history820() {
),
);

$this->assertEqual($expectedqa, $qa);
$this->compare_qas($expectedqa, $qa);
}

public function test_essay_deferredfeedback_missing() {
Expand Down Expand Up @@ -561,6 +561,6 @@ public function test_essay_deferredfeedback_missing() {
),
);

$this->assertEqual($expectedqa, $qa);
$this->compare_qas($expectedqa, $qa);
}
}
6 changes: 3 additions & 3 deletions question/type/match/db/simpletest/testupgradelibnewqe.php
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,7 @@ public function test_match_deferredfeedback_history6220() {
}
}

$this->assertEqual($expectedqa, $qa);
$this->compare_qas($expectedqa, $qa);
}

public function test_match_deferredfeedback_history60() {
Expand Down Expand Up @@ -482,7 +482,7 @@ public function test_match_deferredfeedback_history60() {
}
}

$this->assertEqual($expectedqa, $qa);
$this->compare_qas($expectedqa, $qa);
}

public function test_match_deferredfeedback_history622220() {
Expand Down Expand Up @@ -782,6 +782,6 @@ public function test_match_deferredfeedback_history622220() {
}
}

$this->assertEqual($expectedqa, $qa);
$this->compare_qas($expectedqa, $qa);
}
}
12 changes: 6 additions & 6 deletions question/type/multianswer/db/simpletest/testupgradelibnewqe.php
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ public function test_multianswer_adaptivenopenalty_qsession104() {
),
);

$this->assertEqual($expectedqa, $qa);
$this->compare_qas($expectedqa, $qa);
}

public function test_multianswer_adaptivenopenalty_qsession106() {
Expand Down Expand Up @@ -421,7 +421,7 @@ public function test_multianswer_adaptivenopenalty_qsession106() {
),
);

$this->assertEqual($expectedqa, $qa);
$this->compare_qas($expectedqa, $qa);
}

public function test_multianswer_adaptivenopenalty_qsession108() {
Expand Down Expand Up @@ -646,7 +646,7 @@ public function test_multianswer_adaptivenopenalty_qsession108() {
),
);

$this->assertEqual($expectedqa, $qa);
$this->compare_qas($expectedqa, $qa);
}

public function test_multianswer_adaptivenopenalty_qsession105() {
Expand Down Expand Up @@ -1332,7 +1332,7 @@ public function test_multianswer_adaptivenopenalty_qsession105() {
),
);

$this->assertEqual($expectedqa, $qa);
$this->compare_qas($expectedqa, $qa);
}

public function test_multianswer_adaptivenopenalty_qsession107() {
Expand Down Expand Up @@ -1990,7 +1990,7 @@ public function test_multianswer_adaptivenopenalty_qsession107() {
),
);

$this->assertEqual($expectedqa, $qa);
$this->compare_qas($expectedqa, $qa);
}

public function test_multianswer_adaptivenopenalty_qsession109() {
Expand Down Expand Up @@ -2724,6 +2724,6 @@ public function test_multianswer_adaptivenopenalty_qsession109() {
),
);

$this->assertEqual($expectedqa, $qa);
$this->compare_qas($expectedqa, $qa);
}
}
26 changes: 13 additions & 13 deletions question/type/multichoice/db/simpletest/testupgradelibnewqe.php
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,7 @@ public function test_multichoice_deferredfeedback_history960() {
),
);

$this->assertEqual($expectedqa, $qa);
$this->compare_qas($expectedqa, $qa);
}

public function test_multichoice_deferredfeedback_history0() {
Expand Down Expand Up @@ -431,7 +431,7 @@ public function test_multichoice_deferredfeedback_history0() {
),
);

$this->assertEqual($expectedqa, $qa);
$this->compare_qas($expectedqa, $qa);
}

public function test_multichoice_deferredfeedback_history60() {
Expand Down Expand Up @@ -634,7 +634,7 @@ public function test_multichoice_deferredfeedback_history60() {
),
);

$this->assertEqual($expectedqa, $qa);
$this->compare_qas($expectedqa, $qa);
}

public function test_multichoice_deferredfeedback_history6220() {
Expand Down Expand Up @@ -873,7 +873,7 @@ public function test_multichoice_deferredfeedback_history6220() {
),
);

$this->assertEqual($expectedqa, $qa);
$this->compare_qas($expectedqa, $qa);
}

public function test_multichoice_deferredfeedback_missing() {
Expand Down Expand Up @@ -1007,7 +1007,7 @@ public function test_multichoice_deferredfeedback_missing() {
),
);

$this->assertEqual($expectedqa, $qa);
$this->compare_qas($expectedqa, $qa);
}

public function test_multichoice_deferredfeedback_qsession140() {
Expand Down Expand Up @@ -1209,7 +1209,7 @@ public function test_multichoice_deferredfeedback_qsession140() {
),
);

$this->assertEqual($expectedqa, $qa);
$this->compare_qas($expectedqa, $qa);
}

public function test_multichoice_deferredfeedback_qsession2018195() {
Expand Down Expand Up @@ -1455,7 +1455,7 @@ public function test_multichoice_deferredfeedback_qsession2018195() {
),
);

$this->assertEqual($expectedqa, $qa);
$this->compare_qas($expectedqa, $qa);
}

public function test_multichoice_deferredfeedback_qsession2653368() {
Expand Down Expand Up @@ -1679,7 +1679,7 @@ public function test_multichoice_deferredfeedback_qsession2653368() {
),
);

$this->assertEqual($expectedqa, $qa);
$this->compare_qas($expectedqa, $qa);
}

public function test_multichoice_deferredfeedback_qsession3131() {
Expand Down Expand Up @@ -1924,7 +1924,7 @@ public function test_multichoice_deferredfeedback_qsession3131() {
),
);

$this->assertEqual($expectedqa, $qa);
$this->compare_qas($expectedqa, $qa);
}

public function test_multichoice_deferredfeedback_qsession4307870 () {
Expand Down Expand Up @@ -2129,7 +2129,7 @@ public function test_multichoice_deferredfeedback_qsession4307870 () {
),
);

$this->assertEqual($expectedqa, $qa);
$this->compare_qas($expectedqa, $qa);
}

public function test_multichoice_deferredfeedback_qsession49446() {
Expand Down Expand Up @@ -2344,7 +2344,7 @@ public function test_multichoice_deferredfeedback_qsession49446() {
),
);

$this->assertEqual($expectedqa, $qa);
$this->compare_qas($expectedqa, $qa);
}

public function test_multichoice_deferredfeedback_qsession591() {
Expand Down Expand Up @@ -2553,7 +2553,7 @@ public function test_multichoice_deferredfeedback_qsession591() {
),
);

$this->assertEqual($expectedqa, $qa);
$this->compare_qas($expectedqa, $qa);
}

public function test_multichoice_deferredfeedback_qsession594() {
Expand Down Expand Up @@ -2764,6 +2764,6 @@ public function test_multichoice_deferredfeedback_qsession594() {
),
);

$this->assertEqual($expectedqa, $qa);
$this->compare_qas($expectedqa, $qa);
}
}
4 changes: 2 additions & 2 deletions question/type/numerical/db/simpletest/testupgradelibnewqe.php
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,7 @@ public function test_numerical_deferredfeedback_history620() {
),
);

$this->assertEqual($expectedqa, $qa);
$this->compare_qas($expectedqa, $qa);
}

public function test_numerical_deferredfeedback_required_units() {
Expand Down Expand Up @@ -458,6 +458,6 @@ public function test_numerical_deferredfeedback_required_units() {
),
);

$this->assertEqual($expectedqa, $qa);
$this->compare_qas($expectedqa, $qa);
}
}
Loading

0 comments on commit 4c57433

Please sign in to comment.