public function CourseObjectAccessTimeTest::testCourseObjectRestrictByExpiration in Course 3.x
Test course object expiration date.
File
- tests/
src/ Functional/ CourseObjectAccessTimeTest.php, line 38
Class
- CourseObjectAccessTimeTest
- Tests for course object access based on time.
Namespace
Drupal\Tests\course\FunctionalCode
public function testCourseObjectRestrictByExpiration() {
$now = \Drupal::time()
->getRequestTime();
$course = $this
->createCourse();
$options = array();
// Test restricting by expiration.
$o2 = $this
->createCourseObject($course);
// Set the expiration to 10 seconds ago.
$options['plugins']['access']['timing']['expiration'] = gmdate('c', $now - 100);
$o2
->addOptions($options)
->save();
$this
->assertFalse($o2
->access('take', $this->student_user), 'Check that user cannot take expired course object.');
$this
->assertTrue($o2
->access('see', $this->student_user), 'Check that user can see expired course object.');
// Set the hide when expired option.
$options['plugins']['access']['timing']['expiration_hidden'] = 1;
$o2
->addOptions($options)
->save();
$this
->assertFalse($o2
->access('see', $this->student_user), 'Check that object is hidden if hidden is checked and object is expired.');
}