diff --git a/mod/assign/lib.php b/mod/assign/lib.php index 36971fded7f..5c30ab02dee 100644 --- a/mod/assign/lib.php +++ b/mod/assign/lib.php @@ -1879,6 +1879,14 @@ function mod_assign_core_calendar_provide_event_action(calendar_event $event, $cm = get_fast_modinfo($event->courseid, $userid)->instances['assign'][$event->instance]; $context = context_module::instance($cm->id); + $completion = new \completion_info($cm->get_course()); + + $completiondata = $completion->get_data($cm, false, $userid); + + if ($completiondata->completionstate != COMPLETION_INCOMPLETE) { + return null; + } + $assign = new assign($context, $cm, null); // Apply overrides. diff --git a/mod/assign/tests/lib_test.php b/mod/assign/tests/lib_test.php index 759f534818a..caf600f638f 100644 --- a/mod/assign/tests/lib_test.php +++ b/mod/assign/tests/lib_test.php @@ -800,6 +800,71 @@ class mod_assign_lib_testcase extends advanced_testcase { $this->assertNull($actionevent); } + public function test_assign_core_calendar_provide_event_action_already_completed() { + $this->resetAfterTest(); + set_config('enablecompletion', 1); + $this->setAdminUser(); + + // Create the activity. + $course = $this->getDataGenerator()->create_course(array('enablecompletion' => 1)); + $assign = $this->create_instance($course, + ['completion' => 2, 'completionview' => 1, 'completionexpected' => time() + DAYSECS]); + + // Get some additional data. + $cm = get_coursemodule_from_instance('assign', $assign->get_instance()->id); + + // Create a calendar event. + $event = $this->create_action_event($course, $assign, + \core_completion\api::COMPLETION_EVENT_TYPE_DATE_COMPLETION_EXPECTED); + + // Mark the activity as completed. + $completion = new completion_info($course); + $completion->set_module_viewed($cm); + + // Create an action factory. + $factory = new \core_calendar\action_factory(); + + // Decorate action event. + $actionevent = mod_assign_core_calendar_provide_event_action($event, $factory); + + // Ensure result was null. + $this->assertNull($actionevent); + } + + public function test_assign_core_calendar_provide_event_action_already_completed_for_user() { + $this->resetAfterTest(); + set_config('enablecompletion', 1); + $this->setAdminUser(); + + // Create the activity. + $course = $this->getDataGenerator()->create_course(array('enablecompletion' => 1)); + $assign = $this->create_instance($course, + ['completion' => 2, 'completionview' => 1, 'completionexpected' => time() + DAYSECS]); + + // Enrol a student in the course. + $student = $this->getDataGenerator()->create_and_enrol($course, 'student'); + + // Get some additional data. + $cm = get_coursemodule_from_instance('assign', $assign->get_instance()->id); + + // Create a calendar event. + $event = $this->create_action_event($course, $assign, + \core_completion\api::COMPLETION_EVENT_TYPE_DATE_COMPLETION_EXPECTED); + + // Mark the activity as completed for the student. + $completion = new completion_info($course); + $completion->set_module_viewed($cm, $student->id); + + // Create an action factory. + $factory = new \core_calendar\action_factory(); + + // Decorate action event for the student. + $actionevent = mod_assign_core_calendar_provide_event_action($event, $factory, $student->id); + + // Ensure result was null. + $this->assertNull($actionevent); + } + /** * Creates an action event. * diff --git a/mod/chat/lib.php b/mod/chat/lib.php index 0db27f2be45..f112ce9a0d9 100644 --- a/mod/chat/lib.php +++ b/mod/chat/lib.php @@ -1470,6 +1470,14 @@ function mod_chat_core_calendar_provide_event_action(calendar_event $event, return null; } + $completion = new \completion_info($cm->get_course()); + + $completiondata = $completion->get_data($cm, false, $userid); + + if ($completiondata->completionstate != COMPLETION_INCOMPLETE) { + return null; + } + $chattime = $DB->get_field('chat', 'chattime', array('id' => $event->instance)); $usertimezone = core_date::get_user_timezone($user); $chattimemidnight = usergetmidnight($chattime, $usertimezone); diff --git a/mod/chat/tests/lib_test.php b/mod/chat/tests/lib_test.php index fa7ad53c378..7a864cfecb3 100644 --- a/mod/chat/tests/lib_test.php +++ b/mod/chat/tests/lib_test.php @@ -635,6 +635,69 @@ class mod_chat_lib_testcase extends advanced_testcase { } } + public function test_chat_core_calendar_provide_event_action_already_completed() { + set_config('enablecompletion', 1); + $this->setAdminUser(); + + // Create the activity. + $course = $this->getDataGenerator()->create_course(array('enablecompletion' => 1)); + $chat = $this->getDataGenerator()->create_module('chat', array('course' => $course->id), + array('completion' => 2, 'completionview' => 1, 'completionexpected' => time() + DAYSECS)); + + // Get some additional data. + $cm = get_coursemodule_from_instance('chat', $chat->id); + + // Create a calendar event. + $event = $this->create_action_event($course->id, $chat->id, + \core_completion\api::COMPLETION_EVENT_TYPE_DATE_COMPLETION_EXPECTED); + + // Mark the activity as completed. + $completion = new completion_info($course); + $completion->set_module_viewed($cm); + + // Create an action factory. + $factory = new \core_calendar\action_factory(); + + // Decorate action event. + $actionevent = mod_chat_core_calendar_provide_event_action($event, $factory); + + // Ensure result was null. + $this->assertNull($actionevent); + } + + public function test_chat_core_calendar_provide_event_action_already_completed_for_user() { + set_config('enablecompletion', 1); + $this->setAdminUser(); + + // Create the activity. + $course = $this->getDataGenerator()->create_course(array('enablecompletion' => 1)); + $chat = $this->getDataGenerator()->create_module('chat', array('course' => $course->id), + array('completion' => 2, 'completionview' => 1, 'completionexpected' => time() + DAYSECS)); + + // Enrol a student in the course. + $student = $this->getDataGenerator()->create_and_enrol($course, 'student'); + + // Get some additional data. + $cm = get_coursemodule_from_instance('chat', $chat->id); + + // Create a calendar event. + $event = $this->create_action_event($course->id, $chat->id, + \core_completion\api::COMPLETION_EVENT_TYPE_DATE_COMPLETION_EXPECTED); + + // Mark the activity as completed for the student. + $completion = new completion_info($course); + $completion->set_module_viewed($cm, $student->id); + + // Create an action factory. + $factory = new \core_calendar\action_factory(); + + // Decorate action event for the student. + $actionevent = mod_chat_core_calendar_provide_event_action($event, $factory, $student->id); + + // Ensure result was null. + $this->assertNull($actionevent); + } + /** * Creates an action event. * diff --git a/mod/choice/lib.php b/mod/choice/lib.php index c6704c7cabe..e971bab0125 100644 --- a/mod/choice/lib.php +++ b/mod/choice/lib.php @@ -1239,6 +1239,14 @@ function mod_choice_core_calendar_provide_event_action(calendar_event $event, return null; } + $completion = new \completion_info($cm->get_course()); + + $completiondata = $completion->get_data($cm, false, $userid); + + if ($completiondata->completionstate != COMPLETION_INCOMPLETE) { + return null; + } + $now = time(); if (!empty($cm->customdata['timeclose']) && $cm->customdata['timeclose'] < $now) { diff --git a/mod/choice/tests/lib_test.php b/mod/choice/tests/lib_test.php index 316e0a6dba1..ff4b5ba8b22 100644 --- a/mod/choice/tests/lib_test.php +++ b/mod/choice/tests/lib_test.php @@ -714,6 +714,71 @@ class mod_choice_lib_testcase extends externallib_advanced_testcase { $this->assertTrue($actionevent->is_actionable()); } + public function test_choice_core_calendar_provide_event_action_already_completed() { + $this->resetAfterTest(); + set_config('enablecompletion', 1); + $this->setAdminUser(); + + // Create the activity. + $course = $this->getDataGenerator()->create_course(array('enablecompletion' => 1)); + $choice = $this->getDataGenerator()->create_module('choice', array('course' => $course->id), + array('completion' => 2, 'completionview' => 1, 'completionexpected' => time() + DAYSECS)); + + // Get some additional data. + $cm = get_coursemodule_from_instance('choice', $choice->id); + + // Create a calendar event. + $event = $this->create_action_event($course->id, $choice->id, + \core_completion\api::COMPLETION_EVENT_TYPE_DATE_COMPLETION_EXPECTED); + + // Mark the activity as completed. + $completion = new completion_info($course); + $completion->set_module_viewed($cm); + + // Create an action factory. + $factory = new \core_calendar\action_factory(); + + // Decorate action event. + $actionevent = mod_choice_core_calendar_provide_event_action($event, $factory); + + // Ensure result was null. + $this->assertNull($actionevent); + } + + public function test_choice_core_calendar_provide_event_action_already_completed_for_user() { + $this->resetAfterTest(); + set_config('enablecompletion', 1); + $this->setAdminUser(); + + // Create the activity. + $course = $this->getDataGenerator()->create_course(array('enablecompletion' => 1)); + $choice = $this->getDataGenerator()->create_module('choice', array('course' => $course->id), + array('completion' => 2, 'completionview' => 1, 'completionexpected' => time() + DAYSECS)); + + // Enrol a student in the course. + $student = $this->getDataGenerator()->create_and_enrol($course, 'student'); + + // Get some additional data. + $cm = get_coursemodule_from_instance('choice', $choice->id); + + // Create a calendar event. + $event = $this->create_action_event($course->id, $choice->id, + \core_completion\api::COMPLETION_EVENT_TYPE_DATE_COMPLETION_EXPECTED); + + // Mark the activity as completed for the student. + $completion = new completion_info($course); + $completion->set_module_viewed($cm, $student->id); + + // Create an action factory. + $factory = new \core_calendar\action_factory(); + + // Decorate action event for the student. + $actionevent = mod_choice_core_calendar_provide_event_action($event, $factory, $student->id); + + // Ensure result was null. + $this->assertNull($actionevent); + } + /** * Creates an action event. * diff --git a/mod/feedback/lib.php b/mod/feedback/lib.php index b680dd0532b..ecef901e970 100644 --- a/mod/feedback/lib.php +++ b/mod/feedback/lib.php @@ -3011,6 +3011,14 @@ function mod_feedback_core_calendar_provide_event_action(calendar_event $event, return null; } + $completion = new \completion_info($cm->get_course()); + + $completiondata = $completion->get_data($cm, false, $userid); + + if ($completiondata->completionstate != COMPLETION_INCOMPLETE) { + return null; + } + $feedbackcompletion = new mod_feedback_completion(null, $cm, 0, false, null, null, $userid); if (!empty($cm->customdata['timeclose']) && $cm->customdata['timeclose'] < time()) { diff --git a/mod/feedback/tests/lib_test.php b/mod/feedback/tests/lib_test.php index a890ace137f..62c522a58ba 100644 --- a/mod/feedback/tests/lib_test.php +++ b/mod/feedback/tests/lib_test.php @@ -541,6 +541,71 @@ class mod_feedback_lib_testcase extends advanced_testcase { $this->assertNull($actionevent); } + public function test_feedback_core_calendar_provide_event_action_already_completed() { + $this->resetAfterTest(); + set_config('enablecompletion', 1); + $this->setAdminUser(); + + // Create the activity. + $course = $this->getDataGenerator()->create_course(array('enablecompletion' => 1)); + $feedback = $this->getDataGenerator()->create_module('feedback', array('course' => $course->id), + array('completion' => 2, 'completionview' => 1, 'completionexpected' => time() + DAYSECS)); + + // Get some additional data. + $cm = get_coursemodule_from_instance('feedback', $feedback->id); + + // Create a calendar event. + $event = $this->create_action_event($course->id, $feedback->id, + \core_completion\api::COMPLETION_EVENT_TYPE_DATE_COMPLETION_EXPECTED); + + // Mark the activity as completed. + $completion = new completion_info($course); + $completion->set_module_viewed($cm); + + // Create an action factory. + $factory = new \core_calendar\action_factory(); + + // Decorate action event. + $actionevent = mod_feedback_core_calendar_provide_event_action($event, $factory); + + // Ensure result was null. + $this->assertNull($actionevent); + } + + public function test_feedback_core_calendar_provide_event_action_already_completed_for_user() { + $this->resetAfterTest(); + set_config('enablecompletion', 1); + $this->setAdminUser(); + + // Create the activity. + $course = $this->getDataGenerator()->create_course(array('enablecompletion' => 1)); + $feedback = $this->getDataGenerator()->create_module('feedback', array('course' => $course->id), + array('completion' => 2, 'completionview' => 1, 'completionexpected' => time() + DAYSECS)); + + // Enrol a student in the course. + $student = $this->getDataGenerator()->create_and_enrol($course, 'student'); + + // Get some additional data. + $cm = get_coursemodule_from_instance('feedback', $feedback->id); + + // Create a calendar event. + $event = $this->create_action_event($course->id, $feedback->id, + \core_completion\api::COMPLETION_EVENT_TYPE_DATE_COMPLETION_EXPECTED); + + // Mark the activity as completed for the student. + $completion = new completion_info($course); + $completion->set_module_viewed($cm, $student->id); + + // Create an action factory. + $factory = new \core_calendar\action_factory(); + + // Decorate action event for the student. + $actionevent = mod_feedback_core_calendar_provide_event_action($event, $factory, $student->id); + + // Ensure result was null. + $this->assertNull($actionevent); + } + /** * Creates an action event. * diff --git a/mod/lesson/lib.php b/mod/lesson/lib.php index 9f5d1bc512a..c92c647cb55 100644 --- a/mod/lesson/lib.php +++ b/mod/lesson/lib.php @@ -1674,6 +1674,14 @@ function mod_lesson_core_calendar_provide_event_action(calendar_event $event, return null; } + $completion = new \completion_info($cm->get_course()); + + $completiondata = $completion->get_data($cm, false, $userid); + + if ($completiondata->completionstate != COMPLETION_INCOMPLETE) { + return null; + } + $lesson = new lesson($DB->get_record('lesson', array('id' => $cm->instance), '*', MUST_EXIST)); if ($lesson->count_user_retries($userid)) { diff --git a/mod/lesson/tests/lib_test.php b/mod/lesson/tests/lib_test.php index ed6a7db532a..06502139a6c 100644 --- a/mod/lesson/tests/lib_test.php +++ b/mod/lesson/tests/lib_test.php @@ -648,6 +648,71 @@ class mod_lesson_lib_testcase extends advanced_testcase { $this->assertNull($action); } + public function test_lesson_core_calendar_provide_event_action_already_completed() { + $this->resetAfterTest(); + set_config('enablecompletion', 1); + $this->setAdminUser(); + + // Create the activity. + $course = $this->getDataGenerator()->create_course(array('enablecompletion' => 1)); + $lesson = $this->getDataGenerator()->create_module('lesson', array('course' => $course->id), + array('completion' => 2, 'completionview' => 1, 'completionexpected' => time() + DAYSECS)); + + // Get some additional data. + $cm = get_coursemodule_from_instance('lesson', $lesson->id); + + // Create a calendar event. + $event = $this->create_action_event($course->id, $lesson->id, + \core_completion\api::COMPLETION_EVENT_TYPE_DATE_COMPLETION_EXPECTED); + + // Mark the activity as completed. + $completion = new completion_info($course); + $completion->set_module_viewed($cm); + + // Create an action factory. + $factory = new \core_calendar\action_factory(); + + // Decorate action event. + $actionevent = mod_lesson_core_calendar_provide_event_action($event, $factory); + + // Ensure result was null. + $this->assertNull($actionevent); + } + + public function test_lesson_core_calendar_provide_event_action_already_completed_for_user() { + $this->resetAfterTest(); + set_config('enablecompletion', 1); + $this->setAdminUser(); + + // Create the activity. + $course = $this->getDataGenerator()->create_course(array('enablecompletion' => 1)); + $lesson = $this->getDataGenerator()->create_module('lesson', array('course' => $course->id), + array('completion' => 2, 'completionview' => 1, 'completionexpected' => time() + DAYSECS)); + + // Enrol a student in the course. + $student = $this->getDataGenerator()->create_and_enrol($course, 'student'); + + // Get some additional data. + $cm = get_coursemodule_from_instance('lesson', $lesson->id); + + // Create a calendar event. + $event = $this->create_action_event($course->id, $lesson->id, + \core_completion\api::COMPLETION_EVENT_TYPE_DATE_COMPLETION_EXPECTED); + + // Mark the activity as completed for the student. + $completion = new completion_info($course); + $completion->set_module_viewed($cm, $student->id); + + // Create an action factory. + $factory = new \core_calendar\action_factory(); + + // Decorate action event for the student. + $actionevent = mod_lesson_core_calendar_provide_event_action($event, $factory, $student->id); + + // Ensure result was null. + $this->assertNull($actionevent); + } + /** * Creates an action event. * diff --git a/mod/quiz/lib.php b/mod/quiz/lib.php index c9b5c02df79..6f6dc11791b 100644 --- a/mod/quiz/lib.php +++ b/mod/quiz/lib.php @@ -2192,6 +2192,14 @@ function mod_quiz_core_calendar_provide_event_action(calendar_event $event, return null; } + $completion = new \completion_info($cm->get_course()); + + $completiondata = $completion->get_data($cm, false, $userid); + + if ($completiondata->completionstate != COMPLETION_INCOMPLETE) { + return null; + } + quiz_update_effective_access($quiz, $userid); // Check if quiz is closed, if so don't display it. diff --git a/mod/quiz/tests/lib_test.php b/mod/quiz/tests/lib_test.php index df77dee1286..cccfed7e693 100644 --- a/mod/quiz/tests/lib_test.php +++ b/mod/quiz/tests/lib_test.php @@ -846,6 +846,71 @@ class mod_quiz_lib_testcase extends advanced_testcase { $this->assertNull(mod_quiz_core_calendar_provide_event_action($event, $factory, $student->id)); } + public function test_quiz_core_calendar_provide_event_action_already_completed() { + $this->resetAfterTest(); + set_config('enablecompletion', 1); + $this->setAdminUser(); + + // Create the activity. + $course = $this->getDataGenerator()->create_course(array('enablecompletion' => 1)); + $quiz = $this->getDataGenerator()->create_module('quiz', array('course' => $course->id), + array('completion' => 2, 'completionview' => 1, 'completionexpected' => time() + DAYSECS)); + + // Get some additional data. + $cm = get_coursemodule_from_instance('quiz', $quiz->id); + + // Create a calendar event. + $event = $this->create_action_event($course->id, $quiz->id, + \core_completion\api::COMPLETION_EVENT_TYPE_DATE_COMPLETION_EXPECTED); + + // Mark the activity as completed. + $completion = new completion_info($course); + $completion->set_module_viewed($cm); + + // Create an action factory. + $factory = new \core_calendar\action_factory(); + + // Decorate action event. + $actionevent = mod_quiz_core_calendar_provide_event_action($event, $factory); + + // Ensure result was null. + $this->assertNull($actionevent); + } + + public function test_quiz_core_calendar_provide_event_action_already_completed_for_user() { + $this->resetAfterTest(); + set_config('enablecompletion', 1); + $this->setAdminUser(); + + // Create the activity. + $course = $this->getDataGenerator()->create_course(array('enablecompletion' => 1)); + $quiz = $this->getDataGenerator()->create_module('quiz', array('course' => $course->id), + array('completion' => 2, 'completionview' => 1, 'completionexpected' => time() + DAYSECS)); + + // Enrol a student in the course. + $student = $this->getDataGenerator()->create_and_enrol($course, 'student'); + + // Get some additional data. + $cm = get_coursemodule_from_instance('quiz', $quiz->id); + + // Create a calendar event. + $event = $this->create_action_event($course->id, $quiz->id, + \core_completion\api::COMPLETION_EVENT_TYPE_DATE_COMPLETION_EXPECTED); + + // Mark the activity as completed for the student. + $completion = new completion_info($course); + $completion->set_module_viewed($cm, $student->id); + + // Create an action factory. + $factory = new \core_calendar\action_factory(); + + // Decorate action event for the student. + $actionevent = mod_quiz_core_calendar_provide_event_action($event, $factory, $student->id); + + // Ensure result was null. + $this->assertNull($actionevent); + } + /** * Creates an action event. * diff --git a/mod/scorm/lib.php b/mod/scorm/lib.php index ae9672e885e..0c49fe3f533 100644 --- a/mod/scorm/lib.php +++ b/mod/scorm/lib.php @@ -1709,6 +1709,14 @@ function mod_scorm_core_calendar_provide_event_action(calendar_event $event, return null; } + $completion = new \completion_info($cm->get_course()); + + $completiondata = $completion->get_data($cm, false, $userid); + + if ($completiondata->completionstate != COMPLETION_INCOMPLETE) { + return null; + } + if (!empty($cm->customdata['timeclose']) && $cm->customdata['timeclose'] < time()) { // The scorm has closed so the user can no longer submit anything. return null; diff --git a/mod/scorm/tests/lib_test.php b/mod/scorm/tests/lib_test.php index b41bb3f6bba..bc6971f34fe 100644 --- a/mod/scorm/tests/lib_test.php +++ b/mod/scorm/tests/lib_test.php @@ -408,6 +408,71 @@ class mod_scorm_lib_testcase extends externallib_advanced_testcase { $this->assertTrue($actionevent->is_actionable()); } + public function test_scorm_core_calendar_provide_event_action_already_completed() { + $this->resetAfterTest(); + set_config('enablecompletion', 1); + $this->setAdminUser(); + + // Create the activity. + $course = $this->getDataGenerator()->create_course(array('enablecompletion' => 1)); + $scorm = $this->getDataGenerator()->create_module('scorm', array('course' => $course->id), + array('completion' => 2, 'completionview' => 1, 'completionexpected' => time() + DAYSECS)); + + // Get some additional data. + $cm = get_coursemodule_from_instance('scorm', $scorm->id); + + // Create a calendar event. + $event = $this->create_action_event($course->id, $scorm->id, + \core_completion\api::COMPLETION_EVENT_TYPE_DATE_COMPLETION_EXPECTED); + + // Mark the activity as completed. + $completion = new completion_info($course); + $completion->set_module_viewed($cm); + + // Create an action factory. + $factory = new \core_calendar\action_factory(); + + // Decorate action event. + $actionevent = mod_scorm_core_calendar_provide_event_action($event, $factory); + + // Ensure result was null. + $this->assertNull($actionevent); + } + + public function test_scorm_core_calendar_provide_event_action_already_completed_for_user() { + $this->resetAfterTest(); + set_config('enablecompletion', 1); + $this->setAdminUser(); + + // Create the activity. + $course = $this->getDataGenerator()->create_course(array('enablecompletion' => 1)); + $scorm = $this->getDataGenerator()->create_module('scorm', array('course' => $course->id), + array('completion' => 2, 'completionview' => 1, 'completionexpected' => time() + DAYSECS)); + + // Enrol a student in the course. + $student = $this->getDataGenerator()->create_and_enrol($course, 'student'); + + // Get some additional data. + $cm = get_coursemodule_from_instance('scorm', $scorm->id); + + // Create a calendar event. + $event = $this->create_action_event($course->id, $scorm->id, + \core_completion\api::COMPLETION_EVENT_TYPE_DATE_COMPLETION_EXPECTED); + + // Mark the activity as completed for the student. + $completion = new completion_info($course); + $completion->set_module_viewed($cm, $student->id); + + // Create an action factory. + $factory = new \core_calendar\action_factory(); + + // Decorate action event for the student. + $actionevent = mod_scorm_core_calendar_provide_event_action($event, $factory, $student->id); + + // Ensure result was null. + $this->assertNull($actionevent); + } + /** * Creates an action event. * diff --git a/mod/workshop/lib.php b/mod/workshop/lib.php index d63573a7692..ef8668b4c3b 100644 --- a/mod/workshop/lib.php +++ b/mod/workshop/lib.php @@ -1857,6 +1857,14 @@ function mod_workshop_core_calendar_provide_event_action(calendar_event $event, return null; } + $completion = new \completion_info($cm->get_course()); + + $completiondata = $completion->get_data($cm, false, $userid); + + if ($completiondata->completionstate != COMPLETION_INCOMPLETE) { + return null; + } + return $factory->create_instance( get_string('viewworkshopsummary', 'workshop'), new \moodle_url('/mod/workshop/view.php', array('id' => $cm->id)), diff --git a/mod/workshop/tests/lib_test.php b/mod/workshop/tests/lib_test.php index 7f417ec27f8..67a89e9aed4 100644 --- a/mod/workshop/tests/lib_test.php +++ b/mod/workshop/tests/lib_test.php @@ -309,6 +309,71 @@ class mod_workshop_lib_testcase extends advanced_testcase { $this->assertNull($actionevent); } + public function test_workshop_core_calendar_provide_event_action_already_completed() { + $this->resetAfterTest(); + set_config('enablecompletion', 1); + $this->setAdminUser(); + + // Create the activity. + $course = $this->getDataGenerator()->create_course(array('enablecompletion' => 1)); + $workshop = $this->getDataGenerator()->create_module('workshop', array('course' => $course->id), + array('completion' => 2, 'completionview' => 1, 'completionexpected' => time() + DAYSECS)); + + // Get some additional data. + $cm = get_coursemodule_from_instance('workshop', $workshop->id); + + // Create a calendar event. + $event = $this->create_action_event($course->id, $workshop->id, + \core_completion\api::COMPLETION_EVENT_TYPE_DATE_COMPLETION_EXPECTED); + + // Mark the activity as completed. + $completion = new completion_info($course); + $completion->set_module_viewed($cm); + + // Create an action factory. + $factory = new \core_calendar\action_factory(); + + // Decorate action event. + $actionevent = mod_workshop_core_calendar_provide_event_action($event, $factory); + + // Ensure result was null. + $this->assertNull($actionevent); + } + + public function test_workshop_core_calendar_provide_event_action_already_completed_for_user() { + $this->resetAfterTest(); + set_config('enablecompletion', 1); + $this->setAdminUser(); + + // Create the activity. + $course = $this->getDataGenerator()->create_course(array('enablecompletion' => 1)); + $workshop = $this->getDataGenerator()->create_module('workshop', array('course' => $course->id), + array('completion' => 2, 'completionview' => 1, 'completionexpected' => time() + DAYSECS)); + + // Enrol a student in the course. + $student = $this->getDataGenerator()->create_and_enrol($course, 'student'); + + // Get some additional data. + $cm = get_coursemodule_from_instance('workshop', $workshop->id); + + // Create a calendar event. + $event = $this->create_action_event($course->id, $workshop->id, + \core_completion\api::COMPLETION_EVENT_TYPE_DATE_COMPLETION_EXPECTED); + + // Mark the activity as completed for the student. + $completion = new completion_info($course); + $completion->set_module_viewed($cm, $student->id); + + // Create an action factory. + $factory = new \core_calendar\action_factory(); + + // Decorate action event for the student. + $actionevent = mod_workshop_core_calendar_provide_event_action($event, $factory, $student->id); + + // Ensure result was null. + $this->assertNull($actionevent); + } + /** * Creates an action event. *