-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathclozeq.test
174 lines (145 loc) · 5.03 KB
/
clozeq.test
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
<?php
/**
* @file
* Unit tests for the clozeq Module.
*/
/**
* Test class for clozeq questions.
*/
class clozeqTestCase extends QuizQuestionTestCase {
// Initializing attributes.
var $question_node_type = 'clozeq';
var $title = '';
var $body = '';
public static function getInfo() {
return array(
'name' => t('clozeq'),
'description' => t('Unit test for clozeq question type.'),
'group' => t('Quiz'),
);
}
public function setUp($modules = array(), $admin_permissions = array(), $user_permissions = array()) {
parent::setUp(array('clozeq'));
}
/**
* Test adding and taking a clozeq question.
*/
public 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;
}
/**
* Test using a clozeq question inside a quiz.
*/
public 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.');
}
/**
* Test if the penalty system for guessing wrong work.
*/
public 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.');
}
/**
* Test that the question response can be edited.
*/
public function testEditQuestionResponse() {
// Create & link a question.
$question_node = $this->testCreateQuizQuestion();
$quiz_node = $this->linkQuestionToQuiz($question_node);
$question_node2 = $this->testCreateQuizQuestion();
$this->linkQuestionToQuiz($question_node2, $quiz_node);
// Login as non-admin.
$this->drupalLogin($this->user);
// Take the quiz.
$this->drupalGet("node/$quiz_node->nid/take");
// Test editing a question.
$this->drupalGet("node/$quiz_node->nid/take");
$this->drupalGet("node/$quiz_node->nid/take/1");
$this->drupalPost(NULL, array(
"question[$question_node->nid][answer][1]" => 1,
), t('Next'));
$this->drupalGet("node/$quiz_node->nid/take/1");
$this->drupalPost(NULL, array(
"question[$question_node->nid][answer][1]" => 0,
"question[$question_node->nid][answer][2]" => 2,
), t('Next'));
}
}