You are here

public function QuizCreationTestCase::testQuizDefaults in Quiz 7.5

Same name and namespace in other branches
  1. 7.6 tests/QuizCreationTestCase.test \QuizCreationTestCase::testQuizDefaults()

Test system, global, and user defaults.

File

tests/QuizCreationTestCase.test, line 42
Unit tests for the quiz question Module.

Class

QuizCreationTestCase
Test aspects of quiz creation including global and user defaults.

Code

public function testQuizDefaults() {

  // We need another admin user here.
  $admin_permissions = array();
  $admin_permissions[] = 'administer quiz configuration';
  $admin_permissions[] = 'create quiz content';
  $admin_permissions[] = 'edit any quiz content';
  $admin_permissions[] = 'edit question titles';
  $admin_permissions[] = 'access quiz';
  $this->admin2 = $this
    ->drupalCreateUser(array_unique($admin_permissions));
  $this
    ->drupalLogin($this->admin);
  $this
    ->drupalGet("node/add/quiz");

  // These are the basic system defaults.
  $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');

  // Verify the same ones show up.
  $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');

  // Change a default.
  $this
    ->drupalPost(NULL, array(
    'allow_resume' => FALSE,
  ), t('Save'));
  $this
    ->drupalGet('admin/quiz/settings/quiz-form');
  $this
    ->assertNoFieldChecked('edit-allow-resume');

  // Check that the default carried over. Check that other options remained
  // set.
  $this
    ->drupalGet("node/add/quiz");
  $this
    ->assertNoFieldChecked('edit-allow-resume');
  $this
    ->assertFieldChecked('edit-allow-skipping');

  // Check defaults for another user.
  $this
    ->drupalLogin($this->admin2);
  $this
    ->drupalGet("node/add/quiz");
  $this
    ->assertNoFieldChecked('edit-allow-resume');
  $this
    ->assertFieldChecked('edit-allow-skipping');

  // Set allow skipping to off as a user default.
  $this
    ->drupalGet("node/add/quiz");
  $this
    ->drupalPost(NULL, array(
    'title' => 'Test quiz',
    'allow_skipping' => FALSE,
    'remember_settings' => TRUE,
  ), t('Save'));
  $this
    ->drupalGet("node/add/quiz");
  $this
    ->assertNoFieldChecked('edit-allow-resume');
  $this
    ->assertNoFieldChecked('edit-allow-skipping');

  // Ensure it didn't affect another user.
  $this
    ->drupalLogin($this->admin);
  $this
    ->drupalGet("node/add/quiz");
  $this
    ->assertNoFieldChecked('edit-allow-resume');
  $this
    ->assertFieldChecked('edit-allow-skipping');
}