You are here

public function QuizTakingTestCase::testQuizAvailability in Quiz 7.5

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

Test the quiz availability tests.

File

tests/QuizTakingTestCase.test, line 153

Class

QuizTakingTestCase

Code

public function testQuizAvailability() {

  // Anonymous doesn't have 'access quiz' permissions, so login a user that
  // has that permission.
  $this
    ->drupalLogin($this->user);
  $future = REQUEST_TIME + 86400;
  $past = REQUEST_TIME - 86400;

  // Within range.
  $quiz_node = $this
    ->drupalCreateQuiz(array(
    'quiz_always' => 0,
    'quiz_open' => $past,
    'quiz_close' => $future,
  ));
  $this
    ->drupalGet("node/{$quiz_node->nid}");
  $this
    ->assertNoText(t('This @quiz is closed.', array(
    '@quiz' => QUIZ_NAME,
  )));
  $this
    ->assertNoText(t('You are not allowed to take this @quiz.', array(
    '@quiz' => QUIZ_NAME,
  )));

  // Starts in the future.
  $quiz_node = $this
    ->drupalCreateQuiz(array(
    'quiz_always' => 0,
    'quiz_open' => $future,
    'quiz_close' => $future + 1,
  ));
  $this
    ->drupalGet("node/{$quiz_node->nid}");
  $this
    ->assertText(t('This @quiz is not yet open.', array(
    '@quiz' => QUIZ_NAME,
  )));
  $this
    ->assertNoText(t('You are not allowed to take this @quiz.', array(
    '@quiz' => QUIZ_NAME,
  )));
  $this
    ->drupalGet("node/{$quiz_node->nid}/take");
  $this
    ->assertText(t('This @quiz is not yet open.', array(
    '@quiz' => QUIZ_NAME,
  )));

  // Ends in the past.
  $quiz_node = $this
    ->drupalCreateQuiz(array(
    'quiz_always' => 0,
    'quiz_open' => $past,
    'quiz_close' => $past + 1,
  ));
  $this
    ->drupalGet("node/{$quiz_node->nid}");
  $this
    ->assertText(t('This @quiz is closed.', array(
    '@quiz' => QUIZ_NAME,
  )));
  $this
    ->assertNoText(t('You are not allowed to take this @quiz.', array(
    '@quiz' => QUIZ_NAME,
  )));
  $this
    ->drupalGet("node/{$quiz_node->nid}/take");
  $this
    ->assertText(t('This @quiz is closed.', array(
    '@quiz' => QUIZ_NAME,
  )));

  // Always available.
  $quiz_node = $this
    ->drupalCreateQuiz(array(
    'quiz_always' => 1,
    'quiz_open' => $future,
    'quiz_close' => $past,
  ));
  $this
    ->drupalGet("node/{$quiz_node->nid}");
  $this
    ->assertNoText(t('This @quiz is closed.', array(
    '@quiz' => QUIZ_NAME,
  )));
  $this
    ->assertNoText(t('You are not allowed to take this @quiz.', array(
    '@quiz' => QUIZ_NAME,
  )));
}