mirror of
https://github.com/moodle/moodle.git
synced 2025-08-05 08:56:36 +02:00
Merge branch 'MDL-63152-master' of git://github.com/rezaies/moodle
This commit is contained in:
commit
67481bef21
2 changed files with 201 additions and 6 deletions
|
@ -1789,12 +1789,23 @@ function workshop_calendar_update(stdClass $workshop, $cmid) {
|
|||
*
|
||||
* @param calendar_event $event
|
||||
* @param \core_calendar\action_factory $factory
|
||||
* @param int $userid User id to use for all capability checks, etc. Set to 0 for current user (default).
|
||||
* @return \core_calendar\local\event\entities\action_interface|null
|
||||
*/
|
||||
function mod_workshop_core_calendar_provide_event_action(calendar_event $event,
|
||||
\core_calendar\action_factory $factory) {
|
||||
\core_calendar\action_factory $factory, int $userid = 0) {
|
||||
global $USER;
|
||||
|
||||
$cm = get_fast_modinfo($event->courseid)->instances['workshop'][$event->instance];
|
||||
if (!$userid) {
|
||||
$userid = $USER->id;
|
||||
}
|
||||
|
||||
$cm = get_fast_modinfo($event->courseid, $userid)->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'),
|
||||
|
|
|
@ -56,6 +56,62 @@ class mod_workshop_lib_testcase extends advanced_testcase {
|
|||
$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 open when user id is provided.
|
||||
*/
|
||||
public function test_workshop_core_calendar_provide_event_action_open_for_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);
|
||||
$student = $this->getDataGenerator()->create_and_enrol($course, 'student');
|
||||
|
||||
// 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, $student->id);
|
||||
|
||||
$this->assertInstanceOf('\core_calendar\local\event\value_objects\action', $actionevent);
|
||||
$this->assertEquals(get_string('viewworkshopsummary', 'workshop'), $actionevent->get_name());
|
||||
$this->assertInstanceOf('moodle_url', $actionevent->get_url());
|
||||
$this->assertEquals(1, $actionevent->get_item_count());
|
||||
$this->assertTrue($actionevent->is_actionable());
|
||||
}
|
||||
|
||||
/**
|
||||
* Test calendar event provide action closed.
|
||||
*/
|
||||
|
@ -78,10 +134,62 @@ class mod_workshop_lib_testcase extends advanced_testcase {
|
|||
$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 provide action closed when user id is provided.
|
||||
*/
|
||||
public function test_workshop_core_calendar_provide_event_action_closed_for_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);
|
||||
$student = $this->getDataGenerator()->create_and_enrol($course, 'student');
|
||||
|
||||
// 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, $student->id);
|
||||
|
||||
$this->assertInstanceOf('\core_calendar\local\event\value_objects\action', $actionevent);
|
||||
$this->assertEquals(get_string('viewworkshopsummary', 'workshop'), $actionevent->get_name());
|
||||
$this->assertInstanceOf('moodle_url', $actionevent->get_url());
|
||||
$this->assertEquals(1, $actionevent->get_item_count());
|
||||
$this->assertTrue($actionevent->is_actionable());
|
||||
}
|
||||
|
||||
/**
|
||||
* Test calendar event action open in future.
|
||||
*
|
||||
* @throws coding_exception
|
||||
*/
|
||||
public function test_workshop_core_calendar_provide_event_action_open_in_future() {
|
||||
$this->resetAfterTest();
|
||||
|
@ -102,10 +210,62 @@ class mod_workshop_lib_testcase extends advanced_testcase {
|
|||
$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 action open in future when user id is provided.
|
||||
*/
|
||||
public function test_workshop_core_calendar_provide_event_action_open_in_future_for_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);
|
||||
$student = $this->getDataGenerator()->create_and_enrol($course, 'student');
|
||||
|
||||
// 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, $student->id);
|
||||
|
||||
$this->assertInstanceOf('\core_calendar\local\event\value_objects\action', $actionevent);
|
||||
$this->assertEquals(get_string('viewworkshopsummary', 'workshop'), $actionevent->get_name());
|
||||
$this->assertInstanceOf('moodle_url', $actionevent->get_url());
|
||||
$this->assertEquals(1, $actionevent->get_item_count());
|
||||
$this->assertTrue($actionevent->is_actionable());
|
||||
}
|
||||
|
||||
/**
|
||||
* Test calendar event with no time specified.
|
||||
*
|
||||
* @throws coding_exception
|
||||
*/
|
||||
public function test_workshop_core_calendar_provide_event_action_no_time_specified() {
|
||||
$this->resetAfterTest();
|
||||
|
@ -125,6 +285,30 @@ class mod_workshop_lib_testcase extends advanced_testcase {
|
|||
$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.
|
||||
*
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue