public function QuizShuffleTest::testShuffle in Quiz 6.x
Same name and namespace in other branches
- 8.6 tests/src/Functional/QuizShuffleTest.php \Drupal\Tests\quiz\Functional\QuizShuffleTest::testShuffle()
- 8.5 tests/src/Functional/QuizShuffleTest.php \Drupal\Tests\quiz\Functional\QuizShuffleTest::testShuffle()
Test random order of questions.
File
- tests/
src/ Functional/ QuizShuffleTest.php, line 20
Class
- QuizShuffleTest
- Tests for random questions.
Namespace
Drupal\Tests\quiz\FunctionalCode
public function testShuffle() {
$this
->drupalLogin($this->admin);
$quiz = $this
->createQuiz([
'randomization' => 1,
]);
$question1 = $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($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'];
}
}
// Check that at least one of the orders is different.
$this
->assertNotEqual(count(array_unique($out)), 1, t('At least one set of questions was different.'));
// Start the quiz.
$this
->drupalLogin($this->user);
$this
->drupalGet("quiz/{$quiz->id()}");
}