You are here

public function MultichoiceTestCase::testCreateQuizQuestion in Quiz 7.6

Same name and namespace in other branches
  1. 7.5 question_types/multichoice/multichoice.test \MultichoiceTestCase::testCreateQuizQuestion()

Create a default MCQ with default settings.

Overrides QuizQuestionTestCase::testCreateQuizQuestion

5 calls to MultichoiceTestCase::testCreateQuizQuestion()
MultichoiceTestCase::testMultipleAnswers in question_types/multichoice/multichoice.test
Test multiple answers.
MultichoiceTestCase::testQuestionFeedback in question_types/multichoice/multichoice.test
MultichoiceTestCase::testRandomOrder in question_types/multichoice/multichoice.test
Test random order of choices. @todo I don't know how we would test random questions.
MultichoiceTestCase::testReorderingUI in question_types/multichoice/multichoice.test
Test the reordering UI.
MultichoiceTestCase::testSimpleScoring in question_types/multichoice/multichoice.test
Test simple scoring.

File

question_types/multichoice/multichoice.test, line 30
Test suite for choice Questions type module.

Class

MultichoiceTestCase
Test class for multichoice questions.

Code

public function testCreateQuizQuestion($settings = array()) {
  $settings += array(
    'title' => 'MCQ 1 Title',
    'type' => 'multichoice',
    'choice_multi' => 0,
    'choice_random' => 0,
    'choice_boolean' => 0,
    'body' => array(
      LANGUAGE_NONE => array(
        array(
          'value' => 'MCQ 1 body text',
        ),
      ),
    ),
  );

  // Set up some alternatives.
  $settings['alternatives'][0]['answer']['value'] = 'A';
  $settings['alternatives'][0]['answer']['format'] = 'filtered_html';
  $settings['alternatives'][0]['feedback_if_chosen']['value'] = 'You chose A';
  $settings['alternatives'][0]['feedback_if_chosen']['format'] = 'filtered_html';
  $settings['alternatives'][0]['feedback_if_not_chosen']['value'] = 'You did not choose A';
  $settings['alternatives'][0]['feedback_if_not_chosen']['format'] = 'filtered_html';
  $settings['alternatives'][0]['score_if_chosen'] = 1;
  $settings['alternatives'][0]['score_if_not_chosen'] = 0;
  $settings['alternatives'][1]['answer']['value'] = 'B';
  $settings['alternatives'][1]['answer']['format'] = 'filtered_html';
  $settings['alternatives'][1]['feedback_if_chosen']['value'] = 'You chose B';
  $settings['alternatives'][1]['feedback_if_chosen']['format'] = 'filtered_html';
  $settings['alternatives'][1]['feedback_if_not_chosen']['value'] = 'You did not choose B';
  $settings['alternatives'][1]['feedback_if_not_chosen']['format'] = 'filtered_html';
  $settings['alternatives'][1]['score_if_chosen'] = 0;
  $settings['alternatives'][1]['score_if_not_chosen'] = 0;
  $settings['alternatives'][2]['answer']['value'] = 'C';
  $settings['alternatives'][2]['answer']['format'] = 'filtered_html';
  $settings['alternatives'][2]['feedback_if_chosen']['value'] = 'You chose C';
  $settings['alternatives'][2]['feedback_if_chosen']['format'] = 'filtered_html';
  $settings['alternatives'][2]['feedback_if_not_chosen']['value'] = 'You did not choose C';
  $settings['alternatives'][2]['feedback_if_not_chosen']['format'] = 'filtered_html';
  $settings['alternatives'][2]['score_if_chosen'] = 0;
  $settings['alternatives'][2]['score_if_not_chosen'] = 0;
  $node = $this
    ->drupalCreateNode($settings);
  $node = node_load($node->nid);
  $this
    ->assertNotNull($node->alternatives[0]['id'], 'Alternative A was created as part of question save.');
  $this
    ->assertNotNull($node->alternatives[1]['id'], 'Alternative B was created as part of question save.');
  $this
    ->assertNotNull($node->alternatives[2]['id'], 'Alternative C was created as part of question save.');
  $this
    ->assertEqual($node->alternatives[0]['answer']['value'], 'A', 'Alternative text A was saved and loaded correctly.');
  $this
    ->assertEqual($node->alternatives[1]['answer']['value'], 'B', 'Alternative text B was saved and loaded correctly.');
  $this
    ->assertEqual($node->alternatives[2]['answer']['value'], 'C', 'Alternative text C was saved and loaded correctly.');
  $this
    ->assertEqual($node->alternatives[0]['answer']['format'], 'filtered_html', 'Alternative format A was saved and loaded correctly.');
  $this
    ->assertEqual($node->alternatives[1]['answer']['format'], 'filtered_html', 'Alternative format B was saved and loaded correctly.');
  $this
    ->assertEqual($node->alternatives[1]['answer']['format'], 'filtered_html', 'Alternative format C was saved and loaded correctly.');
  return $node;
}