matching.test in Quiz 7.6
Unit tests for the matching Module.
File
question_types/matching/matching.testView source
<?php
/**
* @file
* Unit tests for the matching Module.
*/
/**
* Test class for matching questions.
*/
class MatchingTestCase extends QuizQuestionTestCase {
// initializing attributes
var $question_node_type = 'matching';
var $title = '';
var $body = '';
public static function getInfo() {
return array(
'name' => t('Matching'),
'description' => t('Unit test for matching question type.'),
'group' => t('Quiz'),
);
}
function setUp($modules = array(), $admin_permissions = array(), $user_permissions = array()) {
parent::setUp(array(
'matching',
));
}
/**
* Test adding and taking a matching question.
*/
function testCreateQuizQuestion() {
// Login as our privileged user.
$this
->drupalLogin($this->admin);
$match = array();
for ($i = 0; $i <= 2; $i++) {
$match[$i]['question'] = "MAQ " . ($i + 1);
$match[$i]['answer'] = "MAA " . ($i + 1);
$match[$i]['feedback'] = "MAF " . ($i + 1);
}
$question_node = $this
->drupalCreateNode(array(
'type' => $this->question_node_type,
'title' => 'MA 1 title',
'body' => array(
LANGUAGE_NONE => array(
array(
'value' => 'MA 1 body text',
),
),
),
'match' => $match,
'choice_penalty' => 0,
));
return $question_node;
}
function testTakeQuestion() {
$quiz_node = $this
->drupalCreateQuiz(array(
'review_options' => array(
'end' => drupal_map_assoc(array(
'answer_feedback',
'score',
)),
),
));
$question_node = $this
->testCreateQuizQuestion();
// Link the question.
$this
->linkQuestionToQuiz($question_node, $quiz_node);
// Test that question appears in lists.
$this
->drupalGet("node/{$quiz_node->nid}/quiz/questions");
$this
->assertText('MA 1 title');
// Login as non-admin.
$this
->drupalLogin($this->user);
// Take the quiz.
$this
->drupalGet("node/{$quiz_node->nid}/take");
$this
->assertNoText('MA 1 title');
$this
->assertText('MA 1 body text');
$this
->assertText('MAQ 1');
$this
->assertText('MAQ 2');
$this
->assertText('MAQ 3');
$this
->assertText('MAA 1');
$this
->assertText('MAA 2');
$this
->assertText('MAA 3');
// Test validation.
$this
->drupalPost(NULL, array(), t('Finish'));
$this
->assertText('You need to match at least one of the items.');
// Test correct question.
$this
->drupalGet("node/{$quiz_node->nid}/take");
$this
->drupalPost(NULL, array(
"question[2][answer][1]" => 1,
"question[2][answer][2]" => 2,
"question[2][answer][3]" => 3,
), t('Finish'));
$this
->assertText('MAF 1');
$this
->assertText('MAF 2');
$this
->assertText('MAF 3');
$this
->assertText('You got 3 of 3 possible points.');
// Test incorrect question.
$this
->drupalGet("node/{$quiz_node->nid}/take");
$this
->drupalPost(NULL, array(
"question[2][answer][1]" => 1,
"question[2][answer][2]" => 2,
"question[2][answer][3]" => 2,
), t('Finish'));
$this
->assertText('MAF 1');
$this
->assertText('MAF 2');
// The behavior right now is that all the feedback shows.
$this
->assertText('MAF 3');
$this
->assertText('You got 2 of 3 possible points.');
}
function testChoicePenalty() {
$quiz_node = $this
->drupalCreateQuiz(array(
'review_options' => array(
'end' => drupal_map_assoc(array(
'answer_feedback',
'score',
)),
),
));
$question_node = $this
->testCreateQuizQuestion();
$question_node->choice_penalty = 1;
node_save($question_node);
// Link the question.
$this
->linkQuestionToQuiz($question_node, $quiz_node);
// Login as non-admin.
$this
->drupalLogin($this->user);
// Test penalty
$this
->drupalGet("node/{$quiz_node->nid}/take");
$this
->drupalPost(NULL, array(
"question[{$question_node->nid}][answer][4]" => 4,
"question[{$question_node->nid}][answer][5]" => 5,
"question[{$question_node->nid}][answer][6]" => 4,
), t('Finish'));
$this
->assertText('You got 1 of 3 possible points.');
}
}
Classes
Name | Description |
---|---|
MatchingTestCase | Test class for matching questions. |