View source
<?php
require_once drupal_get_path('module', 'course') . '/tests/CourseTestCase.test';
class CourseObjectAccessConditionalTestCase extends CourseTestCase {
public static function getInfo() {
return array(
'name' => 'Course object conditional access',
'description' => 'Ensure that the Course object conditional access plugin functions properly.',
'group' => 'Course',
);
}
function testTimeAfterStart() {
$courseNode = $this
->createCourseNode();
$this
->createCourseObject($courseNode);
$this
->createCourseObject($courseNode);
$course = course_get_course($courseNode);
$co = $course
->getObjects();
$co1 = $co[0];
$co2 = $co[1];
$set = array();
$set['plugins']['access']['conditional'] = array(
'conditional_type' => 'started',
'conditional_time' => 300,
'conditional_object' => $co1
->getId(),
'conditional_hidden' => 0,
);
$hidden['plugins']['access']['conditional']['conditional_hidden'] = 1;
$co2
->addOptions($set);
course_enrol($courseNode);
$this
->assertTrue($co1
->access('take'), 'Check that user can access first (depended on) object.');
$co1
->getFulfillment()
->setComplete(1);
$this
->assertFalse($co2
->access('take'), 'Check that user still cannot access second (dependent) object, even though first is complete.');
$this
->assertTrue($co2
->access('see'), 'Check that user can still see pending course object.');
$co2
->addOptions($hidden);
$this
->assertFalse($co2
->access('see'), 'Check that user cannot still see pending course object when hidden is checked.');
$co1
->getFulfillment()
->setOption('date_started', time() - 301);
$this
->assertTrue($co2
->access('take'), 'Check that user can access second course object after time has elapsed.');
}
function testTimeAfterCompletion() {
$courseNode = $this
->createCourseNode();
$this
->createCourseObject($courseNode);
$this
->createCourseObject($courseNode);
$course = course_get_course($courseNode);
$co = $course
->getObjects();
$co1 = $co[0];
$co2 = $co[1];
$set = array();
$set['plugins']['access']['conditional'] = array(
'conditional_type' => 'completed',
'conditional_time' => 300,
'conditional_object' => $co1
->getId(),
'conditional_hidden' => 0,
);
$hidden['plugins']['access']['conditional']['conditional_hidden'] = 1;
$co2
->addOptions($set);
course_enrol($courseNode);
$this
->assertTrue($co1
->access('take'), 'Check that user can access first (depended on) object.');
$co1
->getFulfillment()
->setComplete(1);
$this
->assertFalse($co2
->access('take'), 'Check that user still cannot access second (dependent) object, even though first is complete.');
$this
->assertTrue($co2
->access('see'), 'Check that user can still see pending course object.');
$co2
->addOptions($hidden);
$this
->assertFalse($co2
->access('see'), 'Check that user cannot still see pending course object when hidden is checked.');
$co1
->getFulfillment()
->setOption('date_completed', time() - 301);
$this
->assertTrue($co2
->access('take'), 'Check that user can access second course object after time has elapsed.');
}
}