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,49 @@
@tool @tool_licensemanager
Feature: Delete custom licenses
In order to manage custom licenses
As an admin
I need to be able to delete custom licenses but not standard Moodle licenses
@javascript
Scenario: I can delete a custom license
Given I log in as "admin"
And I navigate to "Licence > Licence manager" in site administration
And I click on "Create licence" "link"
And I set the following fields to these values:
| shortname | MIT |
| fullname | MIT Licence |
| source | https://opensource.org/licenses/MIT |
| Licence version | ##1 March 2019## |
And I press "Save changes"
And I click on "Delete" "icon" in the "MIT" "table_row"
When I click on "Yes" "button" in the "Delete licence" "dialogue"
Then I should not see "MIT Licence" in the "manage-licenses" "table"
Scenario: I cannot delete a standard license
Given I log in as "admin"
And I navigate to "Licence > Licence manager" in site administration
Then I should see "Licence not specified" in the "unknown" "table_row"
And I should not see "Delete" in the "unknown" "table_row"
@javascript @_file_upload
Scenario: I cannot delete a custom license in use
Given I log in as "admin"
And I navigate to "Licence > Licence manager" in site administration
And I click on "Create licence" "link"
And I set the following fields to these values:
| shortname | Test licence |
| fullname | Test licence |
| source | https://opensource.org/licenses/MIT |
| Licence version | ##1 March 2019## |
And I press "Save changes"
And I follow "Private files" in the user menu
And I upload "lib/tests/fixtures/gd-logo.png" file to "Files" filemanager
And I click on "gd-logo.png" "link"
And I set the field "Choose licence" to "Test licence"
And I press "Update"
And I press "Save changes"
And I am on site homepage
And I navigate to "Licence > Licence manager" in site administration
And I click on "Delete" "icon" in the "Test licence" "table_row"
When I click on "Yes" "button" in the "Delete licence" "dialogue"
Then I should see "Cannot delete a licence which is currently assigned to one or more files"
@@ -0,0 +1,71 @@
@tool @tool_licensemanager
Feature: Custom licences
In order to use custom licences
As an admin
I need to be able to add custom licences
Scenario: I am able to create custom licences
Given I log in as "admin"
And I navigate to "Licence > Licence manager" in site administration
And I click on "Create licence" "link"
And I set the following fields to these values:
| shortname | MIT |
| fullname | MIT Licence |
| source | https://opensource.org/licenses/MIT |
| Licence version | ##first day of January 2020## |
When I press "Save changes"
Then I should see "Licence manager"
And I should see "MIT Licence" in the "MIT" "table_row"
And I should see "https://opensource.org/licenses/MIT" in the "MIT" "table_row"
Scenario: I am only be able to make custom license with a valid url source (including scheme).
Given I log in as "admin"
And I navigate to "Licence > Licence manager" in site administration
And I click on "Create licence" "link"
And I set the following fields to these values:
| shortname | MIT |
| fullname | MIT Licence |
| source | opensource.org/licenses/MIT |
| Licence version | ##2020-01-01## |
When I press "Save changes"
Then I should see "Invalid source URL"
And I set the following fields to these values:
| source | mailto:tomdickman@catalyst-au.net |
And I press "Save changes"
And I should see "Invalid source URL"
And I set the following fields to these values:
| source | https://opensource.org/licenses/MIT |
And I press "Save changes"
And I should see "Licence manager"
And I should see "MIT Licence" in the "MIT" "table_row"
And I should see "https://opensource.org/licenses/MIT" in the "MIT" "table_row"
Scenario: Custom license version format must be YYYYMMDD00
Given I log in as "admin"
And I navigate to "Licence > Licence manager" in site administration
And I click on "Create licence" "link"
And I set the following fields to these values:
| shortname | MIT |
| fullname | MIT Licence |
| source | https://opensource.org/licenses/MIT |
| Licence version | ##1 March 2019## |
When I press "Save changes"
Then I should see "Licence manager"
And I should see "2019030100" in the "MIT" "table_row"
@javascript
Scenario: Custom license short name should not be editable after first creation
Given I log in as "admin"
And I navigate to "Licence > Licence manager" in site administration
And I click on "Create licence" "link"
And I set the following fields to these values:
| shortname | MIT |
| fullname | MIT Licence |
| source | https://opensource.org/licenses/MIT |
| Licence version | ##1 Mar 2019## |
And I press "Save changes"
And I should see "Licence manager"
And I should see "MIT Licence" in the "MIT" "table_row"
When I click on "Edit" "icon" in the "MIT" "table_row"
Then I should see "Edit licence"
And the "shortname" "field" should be disabled
@@ -0,0 +1,58 @@
@tool @tool_licensemanager
Feature: Licence manager
In order to manage licences
As an admin
I need to be able to view and alter licence preferences in the licence manager.
Scenario: I should be able to see the default Moodle licences.
Given I log in as "admin"
When I navigate to "Licence > Licence manager" in site administration
Then I should see "Licence not specified" in the "unknown" "table_row"
And I should see "All rights reserved" in the "allrightsreserved" "table_row"
And I should see "Public domain" in the "public" "table_row"
And I should see "Creative Commons - 4.0 International" in the "cc-4.0" "table_row"
And I should see "Creative Commons - NoDerivatives 4.0 International" in the "cc-nd-4.0" "table_row"
And I should see "Creative Commons - NonCommercial-NoDerivatives 4.0 International" in the "cc-nc-nd-4.0" "table_row"
And I should see "Creative Commons - NonCommercial-ShareAlike 4.0 International" in the "cc-nc-sa-4.0" "table_row"
And I should see "Creative Commons - ShareAlike 4.0 International" in the "cc-sa-4.0" "table_row"
And I should see "Creative Commons - NonCommercial 4.0 International" in the "cc-nc-4.0" "table_row"
Scenario: I should be able to enable and disable licences
Given I log in as "admin"
And I navigate to "Licence > Licence settings" in site administration
When I set the field "Default site licence" to "Public domain"
And I press "Save changes"
And I navigate to "Licence > Licence manager" in site administration
Then "This is the site default licence" "icon" should exist in the "public" "table_row"
And "Enable licence" "icon" should not exist in the "public" "table_row"
And "This is the site default licence" "icon" should not exist in the "cc-4.0" "table_row"
And I navigate to "Licence > Licence settings" in site administration
And I set the field "Default site licence" to "Creative Commons"
And I press "Save changes"
And I navigate to "Licence > Licence manager" in site administration
And "This is the site default licence" "icon" should exist in the "cc-4.0" "table_row"
And "Enable licence" "icon" should not exist in the "cc-4.0" "table_row"
And "This is the site default licence" "icon" should not exist in the "public" "table_row"
@javascript @_file_upload
Scenario Outline: User licence preference is remembered depending of setting value
Given the following config values are set as admin:
| sitedefaultlicense | cc-4.0 |
| rememberuserlicensepref | <rememberuserlicensepref> |
And I log in as "admin"
And I follow "Private files" in the user menu
And I follow "Add..."
And I follow "Upload a file"
And the field with xpath "//select[@name='license']" matches value "Creative Commons - 4.0 International"
And I click on "Close" "button" in the "File picker" "dialogue"
When I upload "lib/tests/fixtures/empty.txt" file to "Files" filemanager as:
| Save as | empty_copy.txt |
| license | Public domain |
And I press "Save changes"
And I follow "Add..."
Then the field with xpath "//select[@name='license']" matches value "<expectedlicence>"
Examples:
| rememberuserlicensepref | expectedlicence |
| 0 | Creative Commons - 4.0 International |
| 1 | Public domain |
@@ -0,0 +1,44 @@
<?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/>.
/**
* Tests for tool_licensemanager helper class.
*
* @package tool_licensemanager
* @copyright 2020 Tom Dickman <tom.dickman@catalyst-au.net>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
defined('MOODLE_INTERNAL') || die();
/**
* Tests for tool_licensemanager helper class.
*
* @package tool_licensemanager
* @copyright 2020 Tom Dickman <tom.dickman@catalyst-au.net>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
* @group tool_licensemanager
*/
class helper_test extends advanced_testcase {
public function test_convert_version_to_epoch(): void {
$version = '2020010100';
$expected = strtotime(20200101);
$this->assertEquals($expected, \tool_licensemanager\helper::convert_version_to_epoch($version));
}
}
@@ -0,0 +1,194 @@
<?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/>.
/**
* Tests for tool_licensemanager manager class.
*
* @package tool_licensemanager
* @copyright 2020 Tom Dickman <tom.dickman@catalyst-au.net>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
defined('MOODLE_INTERNAL') || die();
global $CFG;
require_once($CFG->libdir . '/formslib.php');
require_once($CFG->libdir . '/licenselib.php');
/**
* Tests for tool_licensemanager manager class.
*
* @package tool_licensemanager
* @copyright 2020 Tom Dickman <tom.dickman@catalyst-au.net>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
* @group tool_licensemanager
*/
class manager_test extends advanced_testcase {
/**
* Test editing a license.
*/
public function test_edit_existing_license(): void {
$this->resetAfterTest();
// Create initial custom license to edit.
$testlicense = new stdClass();
$testlicense->shortname = 'my-lic';
$testlicense->fullname = 'My License';
$testlicense->source = 'https://fakeurl.net';
$testlicense->version = date('Ymd', time()) . '00';
$testlicense->custom = license_manager::CUSTOM_LICENSE;
license_manager::save($testlicense);
license_manager::enable($testlicense->shortname);
$manager = new \tool_licensemanager\manager();
// Attempt to submit form data with altered details.
$formdata = [
'shortname' => 'new-value',
'fullname' => 'New License Name',
'source' => 'https://updatedfakeurl.net',
'version' => time()
];
// Attempt to submit form data with an altered shortname.
\tool_licensemanager\form\edit_license::mock_submit($formdata);
// We're testing a private method, so we need to setup reflector magic.
$method = new ReflectionMethod('\tool_licensemanager\manager', 'edit');
$method->invoke($manager, \tool_licensemanager\manager::ACTION_UPDATE, $testlicense->shortname);
// Should not create a new license when updating an existing license.
$this->assertEmpty(license_manager::get_license_by_shortname($formdata['shortname']));
$actual = license_manager::get_license_by_shortname('my-lic');
// Should not be able to update the shortname of the license.
$this->assertNotSame($formdata['shortname'], $actual->shortname);
// Should be able to update other details of the license.
$this->assertSame($formdata['fullname'], $actual->fullname);
$this->assertSame($formdata['source'], $actual->source);
$this->assertSame(date('Ymd', $formdata['version']) . '00', $actual->version);
}
public function test_edit_license_not_exists(): void {
$manager = new \tool_licensemanager\manager();
// We're testing a private method, so we need to setup reflector magic.
$method = new ReflectionMethod('\tool_licensemanager\manager', 'edit');
// Attempt to update a license that doesn't exist.
$formdata = [
'shortname' => 'new-value',
'fullname' => 'New License Name',
'source' => 'https://updatedfakeurl.net',
'version' => time()
];
\tool_licensemanager\form\edit_license::mock_submit($formdata);
// Should not be able to update a license with a shortname that doesn't exist.
$this->expectException('moodle_exception');
$method->invoke($manager, \tool_licensemanager\manager::ACTION_UPDATE, $formdata['shortname']);
}
public function test_edit_license_no_shortname(): void {
$manager = new \tool_licensemanager\manager();
// We're testing a private method, so we need to setup reflector magic.
$method = new ReflectionMethod('\tool_licensemanager\manager', 'edit');
// Attempt to update a license without passing license shortname.
$formdata = [
'fullname' => 'New License Name',
'source' => 'https://updatedfakeurl.net',
'version' => time()
];
\tool_licensemanager\form\edit_license::mock_submit($formdata);
// Should not be able to update empty license shortname.
$this->expectException('moodle_exception');
$method->invoke($manager, \tool_licensemanager\manager::ACTION_UPDATE, '');
}
/**
* Test creating a new license.
*/
public function test_edit_create_license(): void {
$this->resetAfterTest();
$licensecount = count(license_manager::get_licenses());
$manager = new \tool_licensemanager\manager();
$formdata = [
'shortname' => 'new-value',
'fullname' => 'My License',
'source' => 'https://fakeurl.net',
'version' => time()
];
// Attempt to submit form data for a new license.
\tool_licensemanager\form\edit_license::mock_submit($formdata);
// We're testing a private method, so we need to setup reflector magic.
$method = new ReflectionMethod('\tool_licensemanager\manager', 'edit');
$method->invoke($manager, \tool_licensemanager\manager::ACTION_CREATE, $formdata['shortname']);
// Should create a new license in database.
$this->assertCount($licensecount + 1, license_manager::get_licenses());
$actual = license_manager::get_license_by_shortname($formdata['shortname']);
$this->assertSame($formdata['shortname'], $actual->shortname);
$this->assertSame($formdata['fullname'], $actual->fullname);
$this->assertSame($formdata['source'], $actual->source);
$this->assertSame(date('Ymd', $formdata['version']) . '00', $actual->version);
// Attempt to submit form data for a duplicate license.
\tool_licensemanager\form\edit_license::mock_submit($formdata);
// Should not be able to create duplicate licenses.
$this->expectException('moodle_exception');
$method->invoke($manager, \tool_licensemanager\manager::ACTION_CREATE, $formdata['shortname']);
}
/**
* Test changing the order of licenses.
*/
public function test_change_license_order(): void {
$this->resetAfterTest();
$licenseorder = array_keys(license_manager::get_licenses());
$initialposition = array_search('cc-nc-4.0', $licenseorder);
$manager = new tool_licensemanager\manager();
// We're testing a private method, so we need to setup reflector magic.
$method = new ReflectionMethod('\tool_licensemanager\manager', 'change_license_order');
$method->invoke($manager, \tool_licensemanager\manager::ACTION_MOVE_UP, 'cc-nc-4.0');
$licenseorder = array_keys(license_manager::get_licenses());
$newposition = array_search('cc-nc-4.0', $licenseorder);
$this->assertLessThan($initialposition, $newposition);
$initialposition = array_search('allrightsreserved', $licenseorder);
$method->invoke($manager, \tool_licensemanager\manager::ACTION_MOVE_DOWN, 'allrightsreserved');
$licenseorder = array_keys(license_manager::get_licenses());
$newposition = array_search('cc-nc-4.0', $licenseorder);
$this->assertGreaterThan($initialposition, $newposition);
}
}