View source
<?php
namespace Drupal\Tests\quiz\Functional;
class QuizCreationTest extends QuizTestBase {
public static $modules = array(
'quiz_truefalse',
);
public function testQuizCreation() {
$this
->drupalLogin($this->admin);
$this
->drupalGet("quiz/add/quiz");
$this
->drupalPostForm(NULL, array(
'title[0][value]' => 'Test quiz creation',
'body[0][value]' => 'Test quiz description',
), t('Save'));
$this
->assertText('Manage questions');
}
public function testQuizDefaults() {
$admin_permissions = array();
$admin_permissions[] = 'administer quiz configuration';
$admin_permissions[] = 'create quiz quiz';
$admin_permissions[] = 'update any quiz quiz';
$admin_permissions[] = 'edit question titles';
$admin_permissions[] = 'access quiz';
$this->admin2 = $this
->drupalCreateUser(array_unique($admin_permissions));
$this
->drupalLogin($this->admin);
$this
->drupalGet("quiz/add/quiz");
$this
->assertFieldChecked('edit-allow-resume');
$this
->assertFieldChecked('edit-allow-skipping');
$this
->assertNoFieldChecked('edit-allow-jumping');
$this
->assertFieldChecked('edit-allow-change');
$this
->assertFieldChecked('edit-backwards-navigation');
$this
->assertNoFieldChecked('edit-repeat-until-correct');
$this
->assertNoFieldChecked('edit-mark-doubtful');
$this
->assertFieldChecked('edit-show-passed');
$this
->drupalGet('admin/quiz/settings/quiz-form');
$this
->assertFieldChecked('edit-allow-resume');
$this
->assertFieldChecked('edit-allow-skipping');
$this
->assertNoFieldChecked('edit-allow-jumping');
$this
->assertFieldChecked('edit-allow-change');
$this
->assertFieldChecked('edit-backwards-navigation');
$this
->assertNoFieldChecked('edit-repeat-until-correct');
$this
->assertNoFieldChecked('edit-mark-doubtful');
$this
->assertFieldChecked('edit-show-passed');
$this
->drupalPostForm(NULL, array(
'allow_resume' => FALSE,
), t('Save'));
$this
->drupalGet('admin/quiz/settings/quiz-form');
$this
->assertNoFieldChecked('edit-allow-resume');
$this
->drupalGet("quiz/add/quiz");
$this
->assertNoFieldChecked('edit-allow-resume');
$this
->assertFieldChecked('edit-allow-skipping');
$this
->drupalLogin($this->admin2);
$this
->drupalGet("quiz/add/quiz");
$this
->assertNoFieldChecked('edit-allow-resume');
$this
->assertFieldChecked('edit-allow-skipping');
$this
->drupalGet("quiz/add/quiz");
$this
->drupalPostForm(NULL, array(
'title' => 'Test quiz',
'allow_skipping' => FALSE,
'remember_settings' => TRUE,
), t('Save'));
$this
->drupalGet("quiz/add/quiz");
$this
->assertNoFieldChecked('edit-allow-resume');
$this
->assertNoFieldChecked('edit-allow-skipping');
$this
->drupalLogin($this->admin);
$this
->drupalGet("quiz/add/quiz");
$this
->assertNoFieldChecked('edit-allow-resume');
$this
->assertFieldChecked('edit-allow-skipping');
}
public function testCloneQuiz() {
$this
->drupalLogin($this->admin);
$question = $this
->createQuestion(array(
'title' => 'TF 1',
'body' => 'TF 1',
'type' => 'truefalse',
'truefalse_correct' => 1,
));
$quiz = $this
->linkQuestionToQuiz($question);
$quiz
->save();
$new_quiz = $quiz
->createDuplicate();
$new_quiz
->save();
$this
->assertNotEquals($new_quiz
->id(), $quiz
->id());
$this
->drupalLogin($this->user);
$this
->drupalGet("quiz/{$quiz->id()}/take");
$this
->assertText('TF 1');
$this
->drupalGet("quiz/{$new_quiz->id()}/take");
$this
->assertText('TF 1');
}
public function testQuestionRevisionActions() {
$this
->drupalLogin($this->admin);
$question_node = $this
->createQuestion(array(
'title' => 'Revision 1',
'body' => 'Revision 1',
'type' => 'truefalse',
'truefalse_correct' => 1,
));
$quiz_node = $this
->linkQuestionToQuiz($question_node);
$this
->drupalGet("quiz/{$quiz_node->id()}/take");
$this
->assertText("Revision 1");
$this
->drupalGet("quiz/{$question_node->nid}/edit");
$this
->drupalPostForm(NULL, array(), t('Save'));
$this
->assertText(t('Revision actions'));
$this
->assertNoText(t('Update (no revision)'));
$this
->assertText(t('Create new revision'));
$this
->assertText(t('Do nothing'));
$this
->assertText(t('Leave published'));
$this
->drupalGet("quiz/{$quiz_node->id()}/questions");
$this
->assertField("edit-revision-{$question_node->nid}-{$question_node->vid}");
$this
->drupalGet("quiz/{$question_node->nid}/question-revision-actions");
$this
->drupalPostForm(NULL, array(
"quizzes[{$quiz_node->nid}][revise]" => 'revise',
), t('Submit'));
$this
->assertText('succesfully revised');
$this
->drupalGet("quiz/{$question_node->nid}/question-revision-actions");
$this
->drupalPostForm(NULL, array(
"quizzes[{$quiz_node->nid}][revise]" => 'nothing',
), t('Submit'));
$this
->assertText('Quiz not updated, please use the Quiz question listing to if you decide to update the quiz manually.');
$this
->drupalGet("quiz/{$quiz_node->id()}/questions");
$this
->assertNoField("edit-revision-{$question_node->nid}-{$question_node->vid}");
$better_admin = $this
->drupalCreateUser(array(
'edit any truefalse content',
'update any quiz quiz',
'manual quiz revisioning',
));
$this
->drupalLogin($better_admin);
$this
->drupalGet("quiz/{$question_node->nid}/question-revision-actions");
$this
->drupalPostForm(NULL, array(
"quizzes[{$quiz_node->nid}][revise]" => 'update',
), t('Submit'));
$this
->assertText('succesfully updated');
}
}