View source
<?php
namespace Drupal\Tests\quiz\Functional;
class QuizShuffleTest extends QuizTestBase {
public static $modules = array(
'quiz_page',
'quiz_truefalse',
);
public function testShuffle() {
$this
->drupalLogin($this->admin);
$quiz = $this
->createQuiz(array(
'randomization' => 1,
));
$question1 = $this
->createQuestion(array(
'type' => 'truefalse',
'truefalse_correct' => 1,
'body' => 'TF 1 body text',
));
$question2 = $this
->createQuestion(array(
'type' => 'truefalse',
'truefalse_correct' => 1,
'body' => 'TF 2 body text',
));
$question3 = $this
->createQuestion(array(
'type' => 'truefalse',
'truefalse_correct' => 1,
'body' => 'TF 3 body text',
));
$question4 = $this
->createQuestion(array(
'type' => 'truefalse',
'truefalse_correct' => 1,
'body' => 'TF 4 body text',
));
$question5 = $this
->createQuestion(array(
'type' => 'truefalse',
'truefalse_correct' => 1,
'body' => 'TF 5 body text',
));
$this
->linkQuestionToQuiz($question1, $quiz);
$this
->linkQuestionToQuiz($question2, $quiz);
$this
->linkQuestionToQuiz($question3, $quiz);
$this
->linkQuestionToQuiz($question4, $quiz);
$this
->linkQuestionToQuiz($question5, $quiz);
for ($i = 1; $i <= 10; $i++) {
$questions = $quiz
->buildLayout();
$out[$i] = '';
foreach ($questions as $question) {
$out[$i] .= $question['qqid'];
}
}
$this
->assertNotEqual(count(array_unique($out)), 1, t('At least one set of questions was different.'));
$this
->drupalLogin($this->user);
$this
->drupalGet("quiz/{$quiz->id()}");
}
public function testShuffleInPages() {
$this
->drupalLogin($this->admin);
$quiz = $this
->createQuiz(array(
'randomization' => 1,
));
$question1 = $this
->createQuestion(array(
'type' => 'truefalse',
'truefalse_correct' => 1,
'body' => 'TF 1 body text',
));
$this
->linkQuestionToQuiz($question1, $quiz);
$question2 = $this
->createQuestion(array(
'type' => 'truefalse',
'truefalse_correct' => 1,
'body' => 'TF 2 body text',
));
$this
->linkQuestionToQuiz($question2, $quiz);
$question3 = $this
->createQuestion(array(
'type' => 'truefalse',
'truefalse_correct' => 1,
'body' => 'TF 3 body text',
));
$this
->linkQuestionToQuiz($question3, $quiz);
$question4 = $this
->createQuestion(array(
'type' => 'truefalse',
'truefalse_correct' => 1,
'body' => 'TF 4 body text',
));
$this
->linkQuestionToQuiz($question4, $quiz);
$question5 = $this
->createQuestion(array(
'type' => 'truefalse',
'truefalse_correct' => 1,
'body' => 'TF 5 body text',
));
$this
->linkQuestionToQuiz($question5, $quiz);
$page1 = $this
->createQuestion(array(
'type' => 'page',
));
$this
->linkQuestionToQuiz($page1, $quiz);
$page2 = $this
->createQuestion(array(
'type' => 'page',
));
$this
->linkQuestionToQuiz($page2, $quiz);
$this
->drupalGet("quiz/{$quiz->id()}/questions");
$post = array(
"question_list[1][qqr_pid]" => 6,
"question_list[2][qqr_pid]" => 6,
"question_list[3][qqr_pid]" => 6,
"question_list[4][qqr_pid]" => 7,
"question_list[5][qqr_pid]" => 7,
"question_list[6][weight]" => 1,
"question_list[7][weight]" => 2,
);
$this
->drupalPostForm(NULL, $post, t('Submit'));
for ($i = 1; $i <= 10; $i++) {
$questions = $quiz
->buildLayout();
$out[$i] = '';
foreach ($questions as $question) {
$out[$i] .= $question['qqid'];
}
}
$this
->assertNotEqual(count(array_unique($out)), 1, t('At least one set of questions was different.'));
$this
->drupalLogin($this->user);
$this
->drupalGet("quiz/{$quiz->id()}/take");
$this
->assertText('TF 1 body text');
$this
->assertText('TF 2 body text');
$this
->assertText('TF 3 body text');
$this
->assertNoText('TF 4 body text');
$this
->assertNoText('TF 5 body text');
$this
->drupalPostForm(NULL, array(
"question[{$question1->id()}][answer]" => TRUE,
"question[{$question2->id()}][answer]" => TRUE,
"question[{$question3->id()}][answer]" => TRUE,
), t('Next'));
$this
->assertNoText('TF 1 body text');
$this
->assertNoText('TF 2 body text');
$this
->assertNoText('TF 3 body text');
$this
->assertText('TF 4 body text');
$this
->assertText('TF 5 body text');
}
}