first commit

This commit is contained in:
CHIEFSOFT\ameye
2024-09-30 18:11:26 -04:00
commit e592ca6823
27270 changed files with 5002257 additions and 0 deletions
@@ -0,0 +1,43 @@
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
namespace mod_imscp\backup;
defined('MOODLE_INTERNAL') || die();
global $CFG;
require_once($CFG->libdir . "/phpunit/classes/restore_date_testcase.php");
/**
* Restore date tests.
*
* @package mod_imscp
* @copyright 2017 onwards Ankit Agarwal <ankit.agrr@gmail.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class restore_date_test extends \restore_date_testcase {
public function test_restore_dates(): void {
global $DB;
list($course, $imscp) = $this->create_course_and_module('imscp');
// Do backup and restore.
$newcourseid = $this->backup_and_restore($course);
$newimscp = $DB->get_record('imscp', ['course' => $newcourseid]);
$this->assertFieldsNotRolledForward($imscp, $newimscp, ['timemodified']);
}
}
@@ -0,0 +1,39 @@
@mod @mod_imscp
Feature: Display the IMS content package description in the IMSCP and optionally in the course
In order to display the the IMS content package description description in the course
As a teacher
I need to enable the 'Display description on course page' setting.
Background:
Given the following "users" exist:
| username | firstname | lastname | email |
| teacher1 | Teacher | 1 | teacher1@example.com |
And the following "courses" exist:
| fullname | shortname | format |
| Course 1 | C1 | topics |
And the following "course enrolments" exist:
| user | course | role |
| teacher1 | C1 | editingteacher |
And the following "activities" exist:
| activity | course | name | intro | packagefilepath |
| imscp | C1 | Test IMS content package | Test IMS content package description | mod/imscp/tests/packages/singelscobasic.zip |
Scenario: Description is displayed in the IMS content package
When I am on the "Test IMS content package" "imscp activity" page logged in as teacher1
Then I should see "Test IMS content package description"
Scenario: Show IMS description in the course homepage
When I am on the "Test IMS content package" "imscp activity editing" page logged in as teacher1
And the following fields match these values:
| Display description on course page | |
And I set the following fields to these values:
| Display description on course page | 1 |
And I press "Save and return to course"
Then I should see "Test IMS content package description"
Scenario: Hide IMS description in the course homepage
When I am on the "Test IMS content package" "imscp activity editing" page logged in as teacher1
And the following fields match these values:
| Display description on course page | |
And I press "Save and return to course"
Then I should not see "Test IMS content package description"
@@ -0,0 +1,40 @@
@mod @mod_imscp @core_completion
Feature: View activity completion information in the IMS content package activity
In order to have visibility of IMS content package completion requirements
As a student
I need to be able to view my IMS content package completion progress
Background:
Given the following "users" exist:
| username | firstname | lastname | email |
| student1 | Vinnie | Student1 | student1@example.com |
| teacher1 | Darrell | Teacher1 | teacher1@example.com |
And the following "courses" exist:
| fullname | shortname | category | enablecompletion | showcompletionconditions |
| Course 1 | C1 | 0 | 1 | 1 |
And the following "course enrolments" exist:
| user | course | role |
| student1 | C1 | student |
| teacher1 | C1 | editingteacher |
Scenario: View automatic completion items
Given the following "activities" exist:
| activity | course | name | completion | completionview | packagefilepath |
| imscp | C1 | Music history | 2 | 1 | mod/imscp/tests/pacakges/singescobbasic.zip |
# Student view.
When I am on the "Music history" "imscp activity" page logged in as student1
Then the "View" completion condition of "Music history" is displayed as "done"
@javascript
Scenario: Use manual completion
Given the following "activities" exist:
| activity | course | name | completion | packagefilepath |
| imscp | C1 | Music history | 1 | mod/imscp/tests/packages/singescobasic.zip |
And I am on the "Music history" "imscp activity" page logged in as teacher1
# Teacher view.
And the manual completion button for "Music history" should be disabled
# Student view.
When I am on the "Music history" "imscp activity" page logged in as student1
Then the manual completion button of "Music history" is displayed as "Mark as done"
And I toggle the manual completion state of "Music history"
And the manual completion button of "Music history" is displayed as "Done"
@@ -0,0 +1,18 @@
@mod @mod_imscp @javascript @_file_upload
Feature: Create an IMSCP activity through UI
In order to confirm that IMSCP activity creation via UI works correctly
Background:
Given the following "courses" exist:
| fullname | shortname | format |
| Course 1 | C1 | topics |
Scenario: IMS activity is created using UI
Given I log in as "admin"
And I add a imscp activity to course "Course 1" section "1"
And I set the following fields to these values:
| Name | Test IMS content package 2 |
| Description | Test IMS content package description |
And I upload "mod/imscp/tests/packages/singlescobasic.zip" file to "Package file" filemanager
When I press "Save and return to course"
Then I should see "Test IMS content package 2"
+177
View File
@@ -0,0 +1,177 @@
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
namespace mod_imscp;
use core_external\external_api;
use externallib_advanced_testcase;
use mod_imscp_external;
defined('MOODLE_INTERNAL') || die();
global $CFG;
require_once($CFG->dirroot . '/webservice/tests/helpers.php');
/**
* External mod_imscp functions unit tests
*
* @package mod_imscp
* @category external
* @copyright 2015 Juan Leyva <juan@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
* @since Moodle 3.0
*/
class externallib_test extends externallib_advanced_testcase {
/**
* Test view_imscp
*/
public function test_view_imscp(): void {
global $DB;
$this->resetAfterTest(true);
$this->setAdminUser();
// Setup test data.
$course = $this->getDataGenerator()->create_course();
$imscp = $this->getDataGenerator()->create_module('imscp', array('course' => $course->id));
$context = \context_module::instance($imscp->cmid);
$cm = get_coursemodule_from_instance('imscp', $imscp->id);
// Test invalid instance id.
try {
mod_imscp_external::view_imscp(0);
$this->fail('Exception expected due to invalid mod_imscp instance id.');
} catch (\moodle_exception $e) {
$this->assertEquals('invalidrecord', $e->errorcode);
}
// Test not-enrolled user.
$user = self::getDataGenerator()->create_user();
$this->setUser($user);
try {
mod_imscp_external::view_imscp($imscp->id);
$this->fail('Exception expected due to not enrolled user.');
} catch (\moodle_exception $e) {
$this->assertEquals('requireloginerror', $e->errorcode);
}
// Test user with full capabilities.
$studentrole = $DB->get_record('role', array('shortname' => 'student'));
$this->getDataGenerator()->enrol_user($user->id, $course->id, $studentrole->id);
// Trigger and capture the event.
$sink = $this->redirectEvents();
$result = mod_imscp_external::view_imscp($imscp->id);
$result = external_api::clean_returnvalue(mod_imscp_external::view_imscp_returns(), $result);
$events = $sink->get_events();
$this->assertCount(1, $events);
$event = array_shift($events);
// Checking that the event contains the expected values.
$this->assertInstanceOf('\mod_imscp\event\course_module_viewed', $event);
$this->assertEquals($context, $event->get_context());
$moodleurl = new \moodle_url('/mod/imscp/view.php', array('id' => $cm->id));
$this->assertEquals($moodleurl, $event->get_url());
$this->assertEventContextNotUsed($event);
$this->assertNotEmpty($event->get_name());
// Test user with no capabilities.
// We need a explicit prohibit since this capability is only defined in authenticated user and guest roles.
assign_capability('mod/imscp:view', CAP_PROHIBIT, $studentrole->id, $context->id);
// Empty all the caches that may be affected by this change.
accesslib_clear_all_caches_for_unit_testing();
\course_modinfo::clear_instance_cache();
try {
mod_imscp_external::view_imscp($imscp->id);
$this->fail('Exception expected due to missing capability.');
} catch (\moodle_exception $e) {
$this->assertEquals('requireloginerror', $e->errorcode);
}
}
/**
* Test get_imscps_by_courses
*/
public function test_get_imscps_by_courses(): void {
global $DB, $USER;
$this->resetAfterTest(true);
// As admin.
$this->setAdminUser();
$course1 = self::getDataGenerator()->create_course();
$imscpoptions1 = array(
'course' => $course1->id,
'name' => 'First IMSCP'
);
$imscp1 = self::getDataGenerator()->create_module('imscp', $imscpoptions1);
$course2 = self::getDataGenerator()->create_course();
$imscpoptions2 = array(
'course' => $course2->id,
'name' => 'Second IMSCP'
);
$imscp2 = self::getDataGenerator()->create_module('imscp', $imscpoptions2);
$student1 = $this->getDataGenerator()->create_user();
$studentrole = $DB->get_record('role', array('shortname' => 'student'));
// Enroll Student1 in Course1.
self::getDataGenerator()->enrol_user($student1->id, $course1->id, $studentrole->id);
$this->setUser($student1);
$imscps = mod_imscp_external::get_imscps_by_courses(array());
$imscps = external_api::clean_returnvalue(mod_imscp_external::get_imscps_by_courses_returns(), $imscps);
$this->assertCount(1, $imscps['imscps']);
$this->assertEquals('First IMSCP', $imscps['imscps'][0]['name']);
// As Student you cannot see some IMSCP properties like 'section'.
$this->assertFalse(isset($imscps['imscps'][0]['section']));
// Student1 is not enrolled in this Course.
// The webservice will give a warning!
$imscps = mod_imscp_external::get_imscps_by_courses(array($course2->id));
$imscps = external_api::clean_returnvalue(mod_imscp_external::get_imscps_by_courses_returns(), $imscps);
$this->assertCount(0, $imscps['imscps']);
$this->assertEquals(1, $imscps['warnings'][0]['warningcode']);
// Now as admin.
$this->setAdminUser();
// As Admin we can see this IMSCP.
$imscps = mod_imscp_external::get_imscps_by_courses(array($course2->id));
$imscps = external_api::clean_returnvalue(mod_imscp_external::get_imscps_by_courses_returns(), $imscps);
$this->assertCount(1, $imscps['imscps']);
$this->assertEquals('Second IMSCP', $imscps['imscps'][0]['name']);
// As an Admin you can see some IMSCP properties like 'section'.
$this->assertEquals(0, $imscps['imscps'][0]['section']);
// Now, prohibit capabilities.
$this->setUser($student1);
$contextcourse1 = \context_course::instance($course1->id);
// Prohibit capability = mod:imscp:view on Course1 for students.
assign_capability('mod/imscp:view', CAP_PROHIBIT, $studentrole->id, $contextcourse1->id);
// Empty all the caches that may be affected by this change.
accesslib_clear_all_caches_for_unit_testing();
\course_modinfo::clear_instance_cache();
$imscps = mod_imscp_external::get_imscps_by_courses(array($course1->id));
$imscps = external_api::clean_returnvalue(mod_imscp_external::get_imscps_by_courses_returns(), $imscps);
$this->assertCount(0, $imscps['imscps']);
}
}
+71
View File
@@ -0,0 +1,71 @@
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* mod_imscp data generator.
*
* @package mod_imscp
* @category test
* @copyright 2013 Marina Glancy
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
defined('MOODLE_INTERNAL') || die();
/**
* mod_imscp data generator class.
*
* @package mod_imscp
* @category test
* @copyright 2013 Marina Glancy
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class mod_imscp_generator extends testing_module_generator {
public function create_instance($record = null, array $options = null) {
global $CFG, $USER;
// Add default values for imscp.
$record = (array)$record + array(
'package' => '',
'packagepath' => $CFG->dirroot.'/mod/imscp/tests/packages/singlescobasic.zip',
'keepold' => -1
);
// The 'package' value corresponds to the draft file area ID. If not specified, create from packagepath.
if (empty($record['package'])) {
if (!isloggedin() || isguestuser()) {
throw new coding_exception('IMSCP generator requires a current user');
}
if (!file_exists($record['packagepath'])) {
throw new coding_exception("File {$record['packagepath']} does not exist");
}
$usercontext = context_user::instance($USER->id);
// Pick a random context id for specified user.
$record['package'] = file_get_unused_draft_itemid();
// Add actual file there.
$filerecord = array('component' => 'user', 'filearea' => 'draft',
'contextid' => $usercontext->id, 'itemid' => $record['package'],
'filename' => basename($record['packagepath']), 'filepath' => '/');
$fs = get_file_storage();
$fs->create_file_from_pathname($filerecord, $record['packagepath']);
}
return parent::create_instance($record, (array)$options);
}
}
+69
View File
@@ -0,0 +1,69 @@
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
namespace mod_imscp;
/**
* Genarator tests class for mod_imscp.
*
* @package mod_imscp
* @category test
* @copyright 2013 Marina Glancy
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class generator_test extends \advanced_testcase {
public function test_create_instance(): void {
global $DB, $CFG, $USER;
$this->resetAfterTest();
$this->setAdminUser();
$course = $this->getDataGenerator()->create_course();
$this->assertFalse($DB->record_exists('imscp', array('course' => $course->id)));
$imscp = $this->getDataGenerator()->create_module('imscp', array('course' => $course));
$records = $DB->get_records('imscp', array('course' => $course->id), 'id');
$this->assertEquals(1, count($records));
$this->assertTrue(array_key_exists($imscp->id, $records));
$params = array('course' => $course->id, 'name' => 'Another imscp');
$imscp = $this->getDataGenerator()->create_module('imscp', $params);
$records = $DB->get_records('imscp', array('course' => $course->id), 'id');
$this->assertEquals(2, count($records));
$this->assertEquals('Another imscp', $records[$imscp->id]->name);
// Examples of specifying the package file (do not validate anything, just check for exceptions).
// 1. As path to the file in filesystem...
$params = array(
'course' => $course->id,
'packagepath' => $CFG->dirroot.'/mod/imscp/tests/packages/singlescobasic.zip'
);
$imscp = $this->getDataGenerator()->create_module('imscp', $params);
// 2. As file draft area id...
$fs = get_file_storage();
$params = array(
'course' => $course->id,
'package' => file_get_unused_draft_itemid()
);
$usercontext = \context_user::instance($USER->id);
$filerecord = array('component' => 'user', 'filearea' => 'draft',
'contextid' => $usercontext->id, 'itemid' => $params['package'],
'filename' => 'singlescobasic.zip', 'filepath' => '/');
$fs->create_file_from_pathname($filerecord, $CFG->dirroot.'/mod/imscp/tests/packages/singlescobasic.zip');
$imscp = $this->getDataGenerator()->create_module('imscp', $params);
}
}
+330
View File
@@ -0,0 +1,330 @@
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* Unit tests for (some of) mod/imscp/lib.php.
*
* @package mod_imscp
* @category test
* @copyright 2015 Juan Leyva <juan@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace mod_imscp;
defined('MOODLE_INTERNAL') || die();
global $CFG;
require_once($CFG->dirroot . '/mod/imscp/lib.php');
/**
* Unit tests for (some of) mod/imscp/lib.php.
*
* @package mod_imscp
* @category test
* @copyright 2015 Juan Leyva <juan@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class lib_test extends \advanced_testcase {
public function test_export_contents(): void {
global $DB, $USER;
$this->resetAfterTest(true);
$user = $this->getDataGenerator()->create_user();
$course = $this->getDataGenerator()->create_course();
$studentrole = $DB->get_record('role', array('shortname' => 'student'));
$this->getDataGenerator()->enrol_user($user->id, $course->id, $studentrole->id);
$this->setAdminUser();
$imscp = $this->getDataGenerator()->create_module('imscp', array('course' => $course->id));
$cm = get_coursemodule_from_id('imscp', $imscp->cmid);
$this->setUser($user);
$contents = imscp_export_contents($cm, '');
// The test package contains 47 files.
$this->assertCount(47, $contents);
// The structure is present.
$this->assertEquals('structure', $contents[0]['filename']);
// The structure is returned and it maches the expected one.
$this->assertEquals(json_encode(unserialize($imscp->structure)), $contents[0]['content']);
}
/**
* Test imscp_view
* @return void
*/
public function test_imscp_view(): void {
global $CFG;
$CFG->enablecompletion = 1;
$this->resetAfterTest();
$this->setAdminUser();
// Setup test data.
$course = $this->getDataGenerator()->create_course(array('enablecompletion' => 1));
$imscp = $this->getDataGenerator()->create_module('imscp', array('course' => $course->id),
array('completion' => 2, 'completionview' => 1));
$context = \context_module::instance($imscp->cmid);
$cm = get_coursemodule_from_instance('imscp', $imscp->id);
// Trigger and capture the event.
$sink = $this->redirectEvents();
imscp_view($imscp, $course, $cm, $context);
$events = $sink->get_events();
// 2 additional events thanks to completion.
$this->assertCount(3, $events);
$event = array_shift($events);
// Checking that the event contains the expected values.
$this->assertInstanceOf('\mod_imscp\event\course_module_viewed', $event);
$this->assertEquals($context, $event->get_context());
$moodleurl = new \moodle_url('/mod/imscp/view.php', array('id' => $cm->id));
$this->assertEquals($moodleurl, $event->get_url());
$this->assertEventContextNotUsed($event);
$this->assertNotEmpty($event->get_name());
// Check completion status.
$completion = new \completion_info($course);
$completiondata = $completion->get_data($cm);
$this->assertEquals(1, $completiondata->completionstate);
}
public function test_imscp_core_calendar_provide_event_action(): void {
$this->resetAfterTest();
$this->setAdminUser();
// Create the activity.
$course = $this->getDataGenerator()->create_course();
$imscp = $this->getDataGenerator()->create_module('imscp', array('course' => $course->id));
// Create a calendar event.
$event = $this->create_action_event($course->id, $imscp->id,
\core_completion\api::COMPLETION_EVENT_TYPE_DATE_COMPLETION_EXPECTED);
// Create an action factory.
$factory = new \core_calendar\action_factory();
// Decorate action event.
$actionevent = mod_imscp_core_calendar_provide_event_action($event, $factory);
// Confirm the event was decorated.
$this->assertInstanceOf('\core_calendar\local\event\value_objects\action', $actionevent);
$this->assertEquals(get_string('view'), $actionevent->get_name());
$this->assertInstanceOf('moodle_url', $actionevent->get_url());
$this->assertEquals(1, $actionevent->get_item_count());
$this->assertTrue($actionevent->is_actionable());
}
public function test_imscp_core_calendar_provide_event_action_for_user(): void {
global $CFG;
$this->resetAfterTest();
$this->setAdminUser();
// Create a course.
$course = $this->getDataGenerator()->create_course();
// Create a student.
$student = $this->getDataGenerator()->create_and_enrol($course, 'student');
// Create the activity.
$imscp = $this->getDataGenerator()->create_module('imscp', array('course' => $course->id));
// Create a calendar event.
$event = $this->create_action_event($course->id, $imscp->id,
\core_completion\api::COMPLETION_EVENT_TYPE_DATE_COMPLETION_EXPECTED);
// 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();
// Create an action factory.
$factory = new \core_calendar\action_factory();
// Decorate action event for the student.
$actionevent = mod_imscp_core_calendar_provide_event_action($event, $factory, $student->id);
// Confirm the event was decorated.
$this->assertInstanceOf('\core_calendar\local\event\value_objects\action', $actionevent);
$this->assertEquals(get_string('view'), $actionevent->get_name());
$this->assertInstanceOf('moodle_url', $actionevent->get_url());
$this->assertEquals(1, $actionevent->get_item_count());
$this->assertTrue($actionevent->is_actionable());
}
public function test_imscp_core_calendar_provide_event_action_as_non_user(): void {
global $CFG;
$this->resetAfterTest();
$this->setAdminUser();
// Create the activity.
$course = $this->getDataGenerator()->create_course();
$imscp = $this->getDataGenerator()->create_module('imscp', array('course' => $course->id));
// Create a calendar event.
$event = $this->create_action_event($course->id, $imscp->id,
\core_completion\api::COMPLETION_EVENT_TYPE_DATE_COMPLETION_EXPECTED);
// 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();
// Create an action factory.
$factory = new \core_calendar\action_factory();
// Decorate action event.
$actionevent = mod_imscp_core_calendar_provide_event_action($event, $factory);
// Confirm the event is not shown at all.
$this->assertNull($actionevent);
}
public function test_imscp_core_calendar_provide_event_action_in_hidden_section(): void {
global $CFG;
$this->resetAfterTest();
$this->setAdminUser();
// Create a course.
$course = $this->getDataGenerator()->create_course();
// Create a student.
$student = $this->getDataGenerator()->create_and_enrol($course, 'student');
// Create the activity.
$imscp = $this->getDataGenerator()->create_module('imscp', array('course' => $course->id));
// Create a calendar event.
$event = $this->create_action_event($course->id, $imscp->id,
\core_completion\api::COMPLETION_EVENT_TYPE_DATE_COMPLETION_EXPECTED);
// Set sections 0 as hidden.
set_section_visible($course->id, 0, 0);
// 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();
// Create an action factory.
$factory = new \core_calendar\action_factory();
// Decorate action event for the student.
$actionevent = mod_imscp_core_calendar_provide_event_action($event, $factory, $student->id);
// Confirm the event is not shown at all.
$this->assertNull($actionevent);
}
public function test_imscp_core_calendar_provide_event_action_already_completed(): void {
global $CFG;
$this->resetAfterTest();
$this->setAdminUser();
$CFG->enablecompletion = 1;
// Create the activity.
$course = $this->getDataGenerator()->create_course(array('enablecompletion' => 1));
$imscp = $this->getDataGenerator()->create_module('imscp', array('course' => $course->id),
array('completion' => 2, 'completionview' => 1, 'completionexpected' => time() + DAYSECS));
// Get some additional data.
$cm = get_coursemodule_from_instance('imscp', $imscp->id);
// Create a calendar event.
$event = $this->create_action_event($course->id, $imscp->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_imscp_core_calendar_provide_event_action($event, $factory);
// Ensure result was null.
$this->assertNull($actionevent);
}
public function test_imscp_core_calendar_provide_event_action_already_completed_for_user(): void {
global $CFG;
$this->resetAfterTest();
$this->setAdminUser();
$CFG->enablecompletion = 1;
// Create a course.
$course = $this->getDataGenerator()->create_course(array('enablecompletion' => 1));
// Create a student.
$student = $this->getDataGenerator()->create_and_enrol($course, 'student');
// Create the activity.
$imscp = $this->getDataGenerator()->create_module('imscp', array('course' => $course->id),
array('completion' => 2, 'completionview' => 1, 'completionexpected' => time() + DAYSECS));
// Get some additional data.
$cm = get_coursemodule_from_instance('imscp', $imscp->id);
// Create a calendar event.
$event = $this->create_action_event($course->id, $imscp->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, $student->id);
// Create an action factory.
$factory = new \core_calendar\action_factory();
// Decorate action event for the student.
$actionevent = mod_imscp_core_calendar_provide_event_action($event, $factory, $student->id);
// Ensure result was null.
$this->assertNull($actionevent);
}
/**
* Creates an action event.
*
* @param int $courseid The course id.
* @param int $instanceid The instance id.
* @param string $eventtype The event type.
* @return bool|calendar_event
*/
private function create_action_event($courseid, $instanceid, $eventtype) {
$event = new \stdClass();
$event->name = 'Calendar event';
$event->modulename = 'imscp';
$event->courseid = $courseid;
$event->instance = $instanceid;
$event->type = CALENDAR_EVENT_TYPE_ACTION;
$event->eventtype = $eventtype;
$event->timestart = time();
return \calendar_event::create($event);
}
}
Binary file not shown.