diff --git a/cloze.classes.inc b/cloze.classes.inc
index c4699b3..0d9586c 100644
--- a/cloze.classes.inc
+++ b/cloze.classes.inc
@@ -354,7 +354,9 @@ class ClozeResponse extends QuizQuestionResponse {
*/
public function getReportForm($showpoints = TRUE, $showfeedback = TRUE, $allow_scoring = FALSE) {
$form = parent::getReportForm($showpoints, $showfeedback, $allow_scoring);
- $question = strip_tags($form['question']['#markup']);
+ $question_node = node_load($form['nid']['#value'], $form['vid']['#value']);
+ $body = field_get_items('node', $question_node, 'body');
+ $question = strip_tags($body[0]['value']);
$question_form['open_wrapper'] = array(
'#markup' => '
',
);
@@ -395,7 +397,10 @@ class ClozeResponse extends QuizQuestionResponse {
$question_form['close_wrapper'] = array(
'#markup' => '
',
);
- $form['question']['#markup'] = drupal_render($question_form);
+ $form['question']['cloze'] = array(
+ '#type' => 'item',
+ '#markup' => drupal_render($question_form)
+ );
return $form;
}
diff --git a/cloze.info b/cloze.info
index 2d4327c..f6e359e 100644
--- a/cloze.info
+++ b/cloze.info
@@ -5,6 +5,7 @@ core = 7.x
php = 5.1
dependencies[] = quiz
dependencies[] = quiz_question
+files[] = cloze.test
files[] = cloze.classes.inc
files[] = cloze.admin.inc
diff --git a/cloze.test b/cloze.test
new file mode 100644
index 0000000..97345be
--- /dev/null
+++ b/cloze.test
@@ -0,0 +1,100 @@
+ 'Cloze tests',
+ 'description' => 'Test creating and answering to Cloze quiz questions.',
+ 'group' => 'quiz',
+ );
+ }
+
+ /**
+ * Enable Cloze module
+ */
+ public function setUp() {
+ parent::setUp('cloze');
+ }
+
+ /**
+ * Helper function to create a new quiz node.
+ *
+ * @param $questions
+ * (optional) an array of question nodes to add to this quiz
+ */
+ public function createQuiz($questions = array()) {
+ $settings = array(
+ 'aid' => 0,
+ 'type' => 'quiz',
+ );
+ // create a test drupal node
+ $quiz = $this->drupalCreateNode($settings);
+ $this->assertTrue(quiz_set_questions($quiz, $questions));
+ return $quiz;
+ }
+
+ /**
+ * Helper function to create quiz questions.
+ *
+ * @param $settings
+ * (optional) node settings array, some defaults are automatically added
+ * if not defined in this array.
+ */
+ public function createClozeNode($settings = array()) {
+ $settings += array(
+ 'type' => 'cloze',
+ 'body' => array(LANGUAGE_NONE => array(array('value' => 'Text cloze [123].'))),
+ 'learning_mode' => 0,
+ 'state' => QUESTION_ALWAYS,
+ 'max_score' => 1,
+ 'auto_update_max_score' => TRUE,
+ 'refresh' => FALSE,
+ 'weight' => 0,
+ 'add_directly' => array('new' => FALSE)
+ );
+ // create a test drupal node
+ return $this->drupalCreateNode($settings);
+ }
+
+ /**
+ * Test Cloze answering / view results forms.
+ */
+ public function testAnsweringClozeQuestion() {
+ $cloze = $this->createClozeNode();
+ $quiz = $this->createQuiz(array($cloze));
+ $this->user = $this->drupalCreateUser(array('access quiz'));
+ $this->drupalLogin($this->user);
+
+ // Take quiz, add wrong answer to cloze
+ $this->drupalGet('node/' . $quiz->nid . '/take');
+ $this->assertFieldByName('tries[1]', NULL, 'Cloze field found.');
+ $edit = array(
+ 'tries[1]' => '1234'
+ );
+ $this->drupalPost(NULL, $edit, t('Finish'));
+ $this->assertText('0 of 1');
+ $this->assertPattern('/class="[^"]*q-wrong"/');
+
+ // Try again but with correct answer this time.
+ $this->drupalGet('node/' . $quiz->nid . '/take');
+ $edit = array(
+ 'tries[1]' => '123'
+ );
+ $this->drupalPost(NULL, $edit, t('Finish'));
+ $this->assertText('1 of 1');
+ $this->assertPattern('/class="[^"]*q-correct"/');
+ // div.form-item contains input field
+ $this->assertPattern('/