public function CourseObjectAccessTimeTestCase::testCourseObjectRestrictByExpiration in Course 8.3
Same name and namespace in other branches
- 8.2 tests/src/Functional/CourseObjectAccessTimeTestCase.php \Drupal\Tests\course\Functional\CourseObjectAccessTimeTestCase::testCourseObjectRestrictByExpiration()
Test course object expiration date.
File
- tests/
src/ Functional/ CourseObjectAccessTimeTestCase.php, line 38
Class
- CourseObjectAccessTimeTestCase
- 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.');
}