View source
<?php
namespace Drupal\Tests\quiz\Functional;
class QuizRandomTest extends QuizTestBase {
protected static $modules = [
'quiz_truefalse',
];
public function testRandomQuestions() {
$this
->drupalLogin($this->admin);
$quiz = $this
->createQuiz([
'randomization' => 2,
'number_of_random_questions' => 2,
]);
$question = $this
->createQuestion([
'type' => 'truefalse',
'truefalse_correct' => 1,
'body' => 'TF 1 body text',
]);
$question2 = $this
->createQuestion([
'type' => 'truefalse',
'truefalse_correct' => 1,
'body' => 'TF 2 body text',
]);
$question3 = $this
->createQuestion([
'type' => 'truefalse',
'truefalse_correct' => 1,
'body' => 'TF 3 body text',
]);
$question4 = $this
->createQuestion([
'type' => 'truefalse',
'truefalse_correct' => 1,
'body' => 'TF 4 body text',
]);
$question5 = $this
->createQuestion([
'type' => 'truefalse',
'truefalse_correct' => 1,
'body' => 'TF 5 body text',
]);
$this
->linkQuestionToQuiz($question, $quiz);
$this
->linkQuestionToQuiz($question2, $quiz);
$this
->linkQuestionToQuiz($question3, $quiz);
$this
->linkQuestionToQuiz($question4, $quiz);
$this
->linkQuestionToQuiz($question5, $quiz);
$this
->drupalGet("quiz/{$quiz->id()}/questions");
$this
->drupalPostForm(NULL, [
"question_list[1][question_status]" => TRUE,
], t('Submit'));
for ($i = 1; $i <= 10; $i++) {
$questions = $quiz
->buildLayout();
$this
->assertEqual(count($questions), 3, t('Quiz has 3 questions.'));
$out[$i] = '';
foreach ($questions as $question) {
$out[$i] .= $question['qqid'];
}
$this
->assert(strpos($out[$i], $question['qqid']) !== FALSE, t('Quiz always contains required question 1'));
}
$this
->assertNotEqual(count(array_unique($out)), 1, t('At least one set of questions were different.'));
$num_questions = $quiz
->getNumberOfQuestions();
$this
->assertEqual($num_questions, 3);
$this
->drupalLogin($this->user);
$this
->drupalGet("quiz/{$quiz->id()}");
}
}