public function QuizTakingTest::testQuizAvailability in Quiz 8.6
Same name and namespace in other branches
- 8.5 tests/src/Functional/QuizTakingTest.php \Drupal\Tests\quiz\Functional\QuizTakingTest::testQuizAvailability()
- 6.x tests/src/Functional/QuizTakingTest.php \Drupal\Tests\quiz\Functional\QuizTakingTest::testQuizAvailability()
Test the quiz availability tests.
File
- tests/
src/ Functional/ QuizTakingTest.php, line 17
Class
- QuizTakingTest
- Test quiz taking behavior.
Namespace
Drupal\Tests\quiz\FunctionalCode
public function testQuizAvailability() {
// Anonymous doesn't have 'access quiz' permissions, so login a user that
// has that permission.
$this
->drupalLogin($this->user);
$future = \Drupal::time()
->getRequestTime() + 86400;
$past = \Drupal::time()
->getRequestTime() - 86400;
// Within range.
$quiz_node_open = $this
->createQuiz(array(
'quiz_date' => [
'value' => date('Y-m-d\\TH:i:s', $past),
'end_value' => date('Y-m-d\\TH:i:s', $future),
],
));
$this
->drupalGet("quiz/{$quiz_node_open->id()}");
$this
->assertNoText(t('This @quiz is closed.', array(
'@quiz' => _quiz_get_quiz_name(),
)));
$this
->assertNoText(t('You are not allowed to take this @quiz.', array(
'@quiz' => _quiz_get_quiz_name(),
)));
// Starts in the future.
$quiz_node_future = $this
->createQuiz(array(
'quiz_date' => [
'value' => date('Y-m-d\\TH:i:s', $future),
'end_value' => date('Y-m-d\\TH:i:s', $future + 1),
],
));
$this
->drupalGet("quiz/{$quiz_node_future->id()}");
$this
->assertText(t('This @quiz is not yet open.', array(
'@quiz' => _quiz_get_quiz_name(),
)));
$this
->assertNoText(t('You are not allowed to take this @quiz.', array(
'@quiz' => _quiz_get_quiz_name(),
)));
$this
->drupalGet("quiz/{$quiz_node_future->id()}/take");
$this
->assertText(t('This @quiz is not yet open.', array(
'@quiz' => _quiz_get_quiz_name(),
)));
// Ends in the past.
$quiz_node_past = $this
->createQuiz(array(
'quiz_date' => [
'value' => date('Y-m-d\\TH:i:s', $past),
'end_value' => date('Y-m-d\\TH:i:s', $past + 1),
],
));
$this
->drupalGet("quiz/{$quiz_node_past->id()}");
$this
->assertText(t('This @quiz is closed.', array(
'@quiz' => _quiz_get_quiz_name(),
)));
$this
->assertNoText(t('You are not allowed to take this @quiz.', array(
'@quiz' => _quiz_get_quiz_name(),
)));
$this
->drupalGet("quiz/{$quiz_node_past->id()}/take");
$this
->assertText(t('This @quiz is closed.', array(
'@quiz' => _quiz_get_quiz_name(),
)));
// Always available.
$quiz = $this
->createQuiz(array());
$this
->drupalGet("quiz/{$quiz->id()}");
$this
->assertNoText(t('This @quiz is closed.', array(
'@quiz' => _quiz_get_quiz_name(),
)));
$this
->assertNoText(t('You are not allowed to take this @quiz.', array(
'@quiz' => _quiz_get_quiz_name(),
)));
}