Skip to content

Commit

Permalink
MDL-63152 mod_workshop: check if the module is visible to the user
Browse files Browse the repository at this point in the history
  • Loading branch information
rezaies committed Mar 18, 2019
1 parent ec81914 commit ada27f6
Show file tree
Hide file tree
Showing 2 changed files with 105 additions and 4 deletions.
5 changes: 5 additions & 0 deletions mod/workshop/lib.php
Expand Up @@ -1796,6 +1796,11 @@ function mod_workshop_core_calendar_provide_event_action(calendar_event $event,

$cm = get_fast_modinfo($event->courseid)->instances['workshop'][$event->instance];

if (!$cm->uservisible) {
// The module is not visible to the user for any reason.
return null;
}

return $factory->create_instance(
get_string('viewworkshopsummary', 'workshop'),
new \moodle_url('/mod/workshop/view.php', array('id' => $cm->id)),
Expand Down
104 changes: 100 additions & 4 deletions mod/workshop/tests/lib_test.php
Expand Up @@ -56,6 +56,32 @@ public function test_workshop_core_calendar_provide_event_action_open() {
$this->assertTrue($actionevent->is_actionable());
}

/**
* Test calendar event provide action open for a non user.
*/
public function test_workshop_core_calendar_provide_event_action_open_for_non_user() {
global $CFG;

$this->resetAfterTest();
$this->setAdminUser();

$now = time();
$course = $this->getDataGenerator()->create_course();
$workshop = $this->getDataGenerator()->create_module('workshop', ['course' => $course->id,
'submissionstart' => $now - DAYSECS, 'submissionend' => $now + DAYSECS]);
$event = $this->create_action_event($course->id, $workshop->id, WORKSHOP_EVENT_TYPE_SUBMISSION_OPEN);

// Now, log out.
$CFG->forcelogin = true; // We don't want to be logged in as guest, as guest users might still have some capabilities.
$this->setUser();

$factory = new \core_calendar\action_factory();
$actionevent = mod_workshop_core_calendar_provide_event_action($event, $factory);

// Confirm the event is not shown at all.
$this->assertNull($actionevent);
}

/**
* Test calendar event provide action closed.
*/
Expand All @@ -78,10 +104,33 @@ public function test_workshop_core_calendar_provide_event_action_closed() {
$this->assertTrue($actionevent->is_actionable());
}

/**
* Test calendar event provide action closed for a non user.
*/
public function test_workshop_core_calendar_provide_event_action_closed_for_non_user() {
global $CFG;

$this->resetAfterTest();
$this->setAdminUser();

$course = $this->getDataGenerator()->create_course();
$workshop = $this->getDataGenerator()->create_module('workshop', array('course' => $course->id,
'submissionend' => time() - DAYSECS));
$event = $this->create_action_event($course->id, $workshop->id, WORKSHOP_EVENT_TYPE_SUBMISSION_OPEN);

// Now, log out.
$CFG->forcelogin = true; // We don't want to be logged in as guest, as guest users might still have some capabilities.
$this->setUser();

$factory = new \core_calendar\action_factory();
$actionevent = mod_workshop_core_calendar_provide_event_action($event, $factory);

// Confirm the event is not shown at all.
$this->assertNull($actionevent);
}

/**
* Test calendar event action open in future.
*
* @throws coding_exception
*/
public function test_workshop_core_calendar_provide_event_action_open_in_future() {
$this->resetAfterTest();
Expand All @@ -102,10 +151,33 @@ public function test_workshop_core_calendar_provide_event_action_open_in_future(
$this->assertTrue($actionevent->is_actionable());
}

/**
* Test calendar event action open in future for a non user.
*/
public function test_workshop_core_calendar_provide_event_action_open_in_future_for_non_user() {
global $CFG;

$this->resetAfterTest();
$this->setAdminUser();

$course = $this->getDataGenerator()->create_course();
$workshop = $this->getDataGenerator()->create_module('workshop', ['course' => $course->id,
'submissionstart' => time() + DAYSECS]);
$event = $this->create_action_event($course->id, $workshop->id, WORKSHOP_EVENT_TYPE_SUBMISSION_OPEN);

// Now, log out.
$CFG->forcelogin = true; // We don't want to be logged in as guest, as guest users might still have some capabilities.
$this->setUser();

$factory = new \core_calendar\action_factory();
$actionevent = mod_workshop_core_calendar_provide_event_action($event, $factory);

// Confirm the event is not shown at all.
$this->assertNull($actionevent);
}

/**
* Test calendar event with no time specified.
*
* @throws coding_exception
*/
public function test_workshop_core_calendar_provide_event_action_no_time_specified() {
$this->resetAfterTest();
Expand All @@ -125,6 +197,30 @@ public function test_workshop_core_calendar_provide_event_action_no_time_specifi
$this->assertTrue($actionevent->is_actionable());
}

/**
* Test calendar event with no time specified for a non user.
*/
public function test_workshop_core_calendar_provide_event_action_no_time_specified_for_non_user() {
global $CFG;

$this->resetAfterTest();
$this->setAdminUser();

$course = $this->getDataGenerator()->create_course();
$workshop = $this->getDataGenerator()->create_module('workshop', ['course' => $course->id]);
$event = $this->create_action_event($course->id, $workshop->id, WORKSHOP_EVENT_TYPE_SUBMISSION_OPEN);

// Now, log out.
$CFG->forcelogin = true; // We don't want to be logged in as guest, as guest users might still have some capabilities.
$this->setUser();

$factory = new \core_calendar\action_factory();
$actionevent = mod_workshop_core_calendar_provide_event_action($event, $factory);

// Confirm the event is not shown at all.
$this->assertNull($actionevent);
}

/**
* Creates an action event.
*
Expand Down

0 comments on commit ada27f6

Please sign in to comment.