public function QuizCreationTest::testQuizDefaults in Quiz 8.5
Same name and namespace in other branches
- 8.6 tests/src/Functional/QuizCreationTest.php \Drupal\Tests\quiz\Functional\QuizCreationTest::testQuizDefaults()
Test system, global, and user defaults.
File
- tests/
src/ Functional/ QuizCreationTest.php, line 30
Class
- QuizCreationTest
- Test aspects of quiz creation including global and user defaults.
Namespace
Drupal\Tests\quiz\FunctionalCode
public function testQuizDefaults() {
// We need another admin user here.
$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");
// 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
->drupalPostForm(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("quiz/add/quiz");
$this
->assertNoFieldChecked('edit-allow-resume');
$this
->assertFieldChecked('edit-allow-skipping');
// Check defaults for another user.
$this
->drupalLogin($this->admin2);
$this
->drupalGet("quiz/add/quiz");
$this
->assertNoFieldChecked('edit-allow-resume');
$this
->assertFieldChecked('edit-allow-skipping');
// Set allow skipping to off as a user default.
$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');
// Ensure it didn't affect another user.
$this
->drupalLogin($this->admin);
$this
->drupalGet("quiz/add/quiz");
$this
->assertNoFieldChecked('edit-allow-resume');
$this
->assertFieldChecked('edit-allow-skipping');
}