public function QuizShuffleTest::testShuffleInPages in Quiz 6.x
Same name and namespace in other branches
- 8.6 tests/src/Functional/QuizShuffleTest.php \Drupal\Tests\quiz\Functional\QuizShuffleTest::testShuffleInPages()
- 8.5 tests/src/Functional/QuizShuffleTest.php \Drupal\Tests\quiz\Functional\QuizShuffleTest::testShuffleInPages()
Test that questions inside of pages are shuffled.
File
- tests/
src/ Functional/ QuizShuffleTest.php, line 77
Class
- QuizShuffleTest
- Tests for random questions.
Namespace
Drupal\Tests\quiz\FunctionalCode
public function testShuffleInPages() {
$this
->drupalLogin($this->admin);
$quiz = $this
->createQuiz([
'randomization' => 1,
]);
// Create the questions.
$question1 = $this
->createQuestion([
'type' => 'truefalse',
'truefalse_correct' => 1,
'body' => 'TF 1 body text',
]);
$this
->linkQuestionToQuiz($question1, $quiz);
$question2 = $this
->createQuestion([
'type' => 'truefalse',
'truefalse_correct' => 1,
'body' => 'TF 2 body text',
]);
$this
->linkQuestionToQuiz($question2, $quiz);
$question3 = $this
->createQuestion([
'type' => 'truefalse',
'truefalse_correct' => 1,
'body' => 'TF 3 body text',
]);
$this
->linkQuestionToQuiz($question3, $quiz);
$question4 = $this
->createQuestion([
'type' => 'truefalse',
'truefalse_correct' => 1,
'body' => 'TF 4 body text',
]);
$this
->linkQuestionToQuiz($question4, $quiz);
$question5 = $this
->createQuestion([
'type' => 'truefalse',
'truefalse_correct' => 1,
'body' => 'TF 5 body text',
]);
$this
->linkQuestionToQuiz($question5, $quiz);
// Create the pages.
$page1 = $this
->createQuestion([
'type' => 'page',
]);
$this
->linkQuestionToQuiz($page1, $quiz);
$page2 = $this
->createQuestion([
'type' => 'page',
]);
$this
->linkQuestionToQuiz($page2, $quiz);
// Go to the manage questions form.
$this
->drupalGet("quiz/{$quiz->id()}/questions");
$post = [
// Make the questions have parents.
"question_list[1][qqr_pid]" => 6,
// Page 1
"question_list[2][qqr_pid]" => 6,
// Page 1
"question_list[3][qqr_pid]" => 6,
// Page 1
"question_list[4][qqr_pid]" => 7,
// Page 2
"question_list[5][qqr_pid]" => 7,
// Page 2
// Adjust weight of pages.
"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'];
}
}
// 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, make sure the questions stayed put on their pages.
$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');
// We know the 3 questions on the page.
$this
->drupalPostForm(NULL, [
"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');
}