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
+82
View File
@@ -0,0 +1,82 @@
<?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_lti\external;
use core_external\external_api;
defined('MOODLE_INTERNAL') || die();
global $CFG;
require_once($CFG->dirroot . '/mod/lti/tests/mod_lti_testcase.php');
/**
* PHPUnit tests for delete_course_tool_type external function.
*
* @package mod_lti
* @copyright 2023 Jake Dallimore <jrhdallimore@gmail.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
* @coversDefaultClass \mod_lti\external\delete_course_tool_type
*/
class delete_course_tool_type_test extends \mod_lti_testcase {
/**
* Test delete_course_tool() for a course tool.
* @covers ::execute
*/
public function test_delete_course_tool(): void {
$this->resetAfterTest();
$course = $this->getDataGenerator()->create_course();
$editingteacher = $this->getDataGenerator()->create_and_enrol($course, 'editingteacher');
$this->setUser($editingteacher);
$typeid = lti_add_type(
(object) [
'state' => LTI_TOOL_STATE_CONFIGURED,
'course' => $course->id
],
(object) [
'lti_typename' => "My course tool",
'lti_toolurl' => 'http://example.com',
'lti_ltiversion' => 'LTI-1p0'
]
);
$data = delete_course_tool_type::execute($typeid);
$data = external_api::clean_returnvalue(delete_course_tool_type::execute_returns(), $data);
$this->assertTrue($data);
}
/**
* Test delete_course_tool() for a site tool, which is forbidden.
* @covers ::execute
*/
public function test_delete_course_tool_site_tool(): void {
$this->resetAfterTest();
$course = $this->getDataGenerator()->create_course();
$editingteacher = $this->getDataGenerator()->create_and_enrol($course, 'editingteacher');
$this->setUser($editingteacher);
$type = $this->generate_tool_type(123); // Creates a site tool.
$this->expectException(\invalid_parameter_exception::class);
delete_course_tool_type::execute($type->id);
}
}
@@ -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_lti\external;
use core_external\external_api;
defined('MOODLE_INTERNAL') || die();
global $CFG;
require_once($CFG->dirroot . '/mod/lti/tests/mod_lti_testcase.php');
/**
* PHPUnit tests for get_tool_types_and_proxies_count external function.
*
* @package mod_lti
* @author Andrew Madden <andrewmadden@catalyst-au.net>
* @copyright 2021 Catalyst IT
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class get_tool_types_and_proxies_count_test extends \mod_lti_testcase {
/**
* This method runs before every test.
*/
public function setUp(): void {
$this->resetAfterTest();
$this->setAdminUser();
}
/**
* Test get_tool_types_and_proxies_count returns the correct number.
*/
public function test_mod_lti_get_tool_types_and_proxies_count(): void {
for ($i = 0; $i < 10; $i++) {
$proxy = $this->generate_tool_proxy($i);
$this->generate_tool_type($i, $proxy->id);
}
$data = \mod_lti\external\get_tool_types_and_proxies_count::execute(0, false);
$data = external_api::clean_returnvalue(\mod_lti\external\get_tool_types_and_proxies_count::execute_returns(), $data);
$this->assertEquals(20, $data['count']);
}
/**
* Test get_tool_types_and_proxies_count returns the correct number.
*/
public function test_mod_lti_get_tool_types_and_proxies_count_with_no_tools_configured(): void {
$data = \mod_lti\external\get_tool_types_and_proxies_count::execute(0, false);
$data = external_api::clean_returnvalue(\mod_lti\external\get_tool_types_and_proxies_count::execute_returns(), $data);
$this->assertEquals(0, $data['count']);
}
}
@@ -0,0 +1,117 @@
<?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_lti\external;
use core_external\external_api;
defined('MOODLE_INTERNAL') || die();
global $CFG;
require_once($CFG->dirroot . '/mod/lti/tests/mod_lti_testcase.php');
/**
* PHPUnit tests for get_tool_types_and_proxies external function.
*
* @package mod_lti
* @author Andrew Madden <andrewmadden@catalyst-au.net>
* @copyright 2021 Catalyst IT
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class get_tool_types_and_proxies_test extends \mod_lti_testcase {
/**
* This method runs before every test.
*/
public function setUp(): void {
$this->resetAfterTest();
$this->setAdminUser();
}
/**
* Test get_tool_types_and_proxies.
*/
public function test_mod_lti_get_tool_types_and_proxies(): void {
$proxy = $this->generate_tool_proxy(1);
$this->generate_tool_type(1, $proxy->id);
$data = get_tool_types_and_proxies::execute(0, false, 50, 0);
$data = external_api::clean_returnvalue(get_tool_types_and_proxies::execute_returns(), $data);
$this->assertCount(1, $data['types']);
$type = $data['types'][0];
$this->assertEquals('Test tool 1', $type['name']);
$this->assertEquals('Example description 1', $type['description']);
$this->assertCount(1, $data['proxies']);
$proxy = $data['proxies'][0];
$this->assertEquals('Test proxy 1', $proxy['name']);
$this->assertEquals(50, $data['limit']);
$this->assertEquals(0, $data['offset']);
}
/**
* Test get_tool_types_and_proxies with multiple pages of tool types.
*/
public function test_mod_lti_get_tool_types_and_proxies_with_multiple_pages(): void {
for ($i = 0; $i < 3; $i++) {
$proxy = $this->generate_tool_proxy($i);
$this->generate_tool_type($i, $proxy->id);
}
$data = get_tool_types_and_proxies::execute(0, false, 5, 0);
$data = external_api::clean_returnvalue(get_tool_types_and_proxies::execute_returns(), $data);
$this->assertCount(2, $data['types']);
$this->assertCount(3, $data['proxies']);
$this->assertEquals(5, $data['limit']);
$this->assertEquals(0, $data['offset']);
}
/**
* Test get_tool_types_and_proxies with multiple pages of tool types and offset.
*/
public function test_mod_lti_get_tool_types_and_proxies_with_multiple_pages_last_page(): void {
for ($i = 0; $i < 6; $i++) {
$proxy = $this->generate_tool_proxy($i);
$this->generate_tool_type($i, $proxy->id);
}
$data = get_tool_types_and_proxies::execute(0, false, 5, 10);
$data = external_api::clean_returnvalue(get_tool_types_and_proxies::execute_returns(), $data);
$this->assertCount(2, $data['types']);
$this->assertCount(0, $data['proxies']);
$this->assertEquals(5, $data['limit']);
$this->assertEquals(10, $data['offset']);
}
/**
* Test get_tool_types_and_proxies without pagination.
*/
public function test_mod_lti_get_tool_types_and_proxies_without_pagination(): void {
for ($i = 0; $i < 10; $i++) {
$proxy = $this->generate_tool_proxy($i);
$this->generate_tool_type($i, $proxy->id);
}
$data = get_tool_types_and_proxies::execute(0, false, 0, 0);
$data = external_api::clean_returnvalue(get_tool_types_and_proxies::execute_returns(), $data);
$this->assertCount(10, $data['types']);
$this->assertCount(10, $data['proxies']);
}
}
@@ -0,0 +1,162 @@
<?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_lti\external;
use core_external\external_api;
defined('MOODLE_INTERNAL') || die();
global $CFG;
require_once($CFG->dirroot . '/mod/lti/tests/mod_lti_testcase.php');
/**
* PHPUnit tests for toggle_showinactivitychooser external function.
*
* @package mod_lti
* @copyright 2023 Ilya Tregubov <ilya.a.tregubov@gmail.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
* @coversDefaultClass \mod_lti\external\toggle_showinactivitychooser
*/
class toggle_showinactivitychooser_test extends \mod_lti_testcase {
/**
* Test toggle_showinactivitychooser for course tool.
* @covers ::execute
*/
public function test_toggle_showinactivitychooser_course_tool(): void {
global $DB;
$this->resetAfterTest();
$course = $this->getDataGenerator()->create_course();
$editingteacher = $this->getDataGenerator()->create_and_enrol($course, 'editingteacher');
$this->setUser($editingteacher);
$typeid = lti_add_type(
(object) [
'state' => LTI_TOOL_STATE_CONFIGURED,
'course' => $course->id,
'coursevisible' => LTI_COURSEVISIBLE_ACTIVITYCHOOSER
],
(object) [
'lti_typename' => "My course tool",
'lti_toolurl' => 'http://example.com',
'lti_ltiversion' => 'LTI-1p0',
'lti_coursevisible' => LTI_COURSEVISIBLE_ACTIVITYCHOOSER
]
);
$result = toggle_showinactivitychooser::execute($typeid, $course->id, false);
$result = external_api::clean_returnvalue(toggle_showinactivitychooser::execute_returns(), $result);
$this->assertTrue($result);
$sql = "SELECT lt.coursevisible coursevisible
FROM {lti_types} lt
WHERE lt.id = ?";
$actual = $DB->get_record_sql($sql, [$typeid]);
$this->assertEquals(LTI_COURSEVISIBLE_PRECONFIGURED, $actual->coursevisible);
$result = toggle_showinactivitychooser::execute($typeid, $course->id, true);
$result = external_api::clean_returnvalue(toggle_showinactivitychooser::execute_returns(), $result);
$this->assertTrue($result);
$actual = $DB->get_record_sql($sql, [$typeid]);
$this->assertEquals(LTI_COURSEVISIBLE_ACTIVITYCHOOSER, $actual->coursevisible);
}
/**
* Test toggle_showinactivitychooser for site tool.
* @covers ::execute
*/
public function test_toggle_showinactivitychooser_site_tool(): void {
global $DB;
$this->resetAfterTest();
$coursecat1 = $this->getDataGenerator()->create_category();
$coursecat2 = $this->getDataGenerator()->create_category();
$course = $this->getDataGenerator()->create_course(['category' => $coursecat1->id]);
$editingteacher = $this->getDataGenerator()->create_and_enrol($course, 'editingteacher');
$this->setUser($editingteacher);
$type = $this->generate_tool_type(123); // Creates a site tool.
$result = toggle_showinactivitychooser::execute($type->id, $course->id, false);
$result = external_api::clean_returnvalue(toggle_showinactivitychooser::execute_returns(), $result);
$this->assertTrue($result);
$sql = "SELECT lt.coursevisible coursevisible1, lc.coursevisible AS coursevisible2
FROM {lti_types} lt
LEFT JOIN {lti_coursevisible} lc ON lt.id = lc.typeid
WHERE lt.id = ?
AND lc.courseid = ?";
$actual = $DB->get_record_sql($sql, [$type->id, $course->id]);
$this->assertEquals(LTI_COURSEVISIBLE_ACTIVITYCHOOSER, $actual->coursevisible1);
$this->assertEquals(LTI_COURSEVISIBLE_PRECONFIGURED, $actual->coursevisible2);
$result = toggle_showinactivitychooser::execute($type->id, $course->id, true);
$result = external_api::clean_returnvalue(toggle_showinactivitychooser::execute_returns(), $result);
$this->assertTrue($result);
$actual = $DB->get_record_sql($sql, [$type->id, $course->id]);
$this->assertEquals(LTI_COURSEVISIBLE_ACTIVITYCHOOSER, $actual->coursevisible1);
$this->assertEquals(LTI_COURSEVISIBLE_ACTIVITYCHOOSER, $actual->coursevisible2);
$ltigenerator = $this->getDataGenerator()->get_plugin_generator('mod_lti');
$ltigenerator->create_tool_types([
'name' => 'site tool preconfigured and activity chooser, restricted to category 1',
'baseurl' => 'http://example.com/tool/1',
'coursevisible' => LTI_COURSEVISIBLE_ACTIVITYCHOOSER,
'state' => LTI_TOOL_STATE_CONFIGURED,
'lti_coursecategories' => $coursecat1->id
]);
$tool = $DB->get_record('lti_types', ['name' => 'site tool preconfigured and activity chooser, restricted to category 1']);
$result = toggle_showinactivitychooser::execute($tool->id, $course->id, false);
$result = external_api::clean_returnvalue(toggle_showinactivitychooser::execute_returns(), $result);
$this->assertTrue($result);
$actual = $DB->get_record_sql($sql, [$tool->id, $course->id]);
$this->assertEquals(LTI_COURSEVISIBLE_ACTIVITYCHOOSER, $actual->coursevisible1);
$this->assertEquals(LTI_COURSEVISIBLE_PRECONFIGURED, $actual->coursevisible2);
$ltigenerator = $this->getDataGenerator()->get_plugin_generator('mod_lti');
$ltigenerator->create_tool_types([
'name' => 'site tool preconfigured and activity chooser, restricted to category 2',
'baseurl' => 'http://example.com/tool/1',
'coursevisible' => LTI_COURSEVISIBLE_ACTIVITYCHOOSER,
'state' => LTI_TOOL_STATE_CONFIGURED,
'lti_coursecategories' => $coursecat2->id
]);
$tool = $DB->get_record('lti_types', ['name' => 'site tool preconfigured and activity chooser, restricted to category 2']);
$this->expectException('moodle_exception');
$this->expectExceptionMessage('You are not allowed to change this setting for this tool.');
toggle_showinactivitychooser::execute($tool->id, $course->id, true);
$ltigenerator = $this->getDataGenerator()->get_plugin_generator('mod_lti');
$ltigenerator->create_tool_types([
'name' => 'site tool dont show',
'baseurl' => 'http://example.com/tool/1',
'coursevisible' => LTI_COURSEVISIBLE_NO,
'state' => LTI_TOOL_STATE_CONFIGURED,
]);
$tool = $DB->get_record('lti_types', ['name' => 'site tool dont show']);
$result = toggle_showinactivitychooser::execute($tool->id, $course->id, false);
$result = external_api::clean_returnvalue(toggle_showinactivitychooser::execute_returns(), $result);
$this->assertFalse($result);
}
}