mirror of
https://github.com/moodle/moodle.git
synced 2025-01-18 05:58:34 +01:00
Merge branch 'MDL-79979-main' of https://github.com/aanabit/moodle
This commit is contained in:
commit
9cb654b356
@ -216,7 +216,7 @@ class tool_generator_course_backend extends tool_generator_backend {
|
||||
* @return int Course id
|
||||
*/
|
||||
public function make() {
|
||||
global $DB, $CFG;
|
||||
global $DB, $CFG, $USER;
|
||||
require_once($CFG->dirroot . '/lib/phpunit/classes/util.php');
|
||||
|
||||
raise_memory_limit(MEMORY_EXTRA);
|
||||
@ -252,6 +252,12 @@ class tool_generator_course_backend extends tool_generator_backend {
|
||||
}
|
||||
}
|
||||
|
||||
// We are checking 'enroladminnewcourse' setting to decide to enrol admins or not.
|
||||
if (!empty($CFG->creatornewroleid) && !empty($CFG->enroladminnewcourse) && is_siteadmin($USER->id)) {
|
||||
// Deal with course creators - enrol them internally with default role.
|
||||
enrol_try_internal_enrol($this->course->id, $USER->id, $CFG->creatornewroleid);
|
||||
}
|
||||
|
||||
// Log total time.
|
||||
$this->log('coursecompleted', round(microtime(true) - $entirestart, 1));
|
||||
|
||||
|
33
admin/tool/generator/tests/behat/make_test_course.feature
Normal file
33
admin/tool/generator/tests/behat/make_test_course.feature
Normal file
@ -0,0 +1,33 @@
|
||||
@core @core_course @tool_generator
|
||||
Feature: Admins can create test courses
|
||||
In order to create testing information
|
||||
As an admin
|
||||
I need to create testing courses quickly
|
||||
|
||||
@javascript
|
||||
Scenario: 'Auto-enrol admin in new courses' setting when creating a test course as admin
|
||||
Given I log in as "admin"
|
||||
And the following config values are set as admin:
|
||||
| enroladminnewcourse | 0 |
|
||||
And I navigate to "Development > Make test course" in site administration
|
||||
And I set the following fields to these values:
|
||||
| Size of course | XS |
|
||||
| Course full name | Fake course for testing |
|
||||
| Course short name | fake |
|
||||
And I press "Create course"
|
||||
And I click on "Continue" "link"
|
||||
And I navigate to course participants
|
||||
Then I should not see "Teacher"
|
||||
And I should not see "Nothing to display"
|
||||
And the following config values are set as admin:
|
||||
| enroladminnewcourse | 1 |
|
||||
And I navigate to "Courses > Add a new course" in site administration
|
||||
And I navigate to "Development > Make test course" in site administration
|
||||
And I set the following fields to these values:
|
||||
| Size of course | XS |
|
||||
| Course full name | New fake course for testing |
|
||||
| Course short name | newfake |
|
||||
And I press "Create course"
|
||||
And I click on "Continue" "link"
|
||||
And I navigate to course participants
|
||||
And I should see "Teacher"
|
@ -68,9 +68,14 @@ class maketestcourse_test extends \advanced_testcase {
|
||||
$this->assertEquals(2, count($modinfo->get_section_info_all()));
|
||||
|
||||
// Check user is enrolled.
|
||||
// enroladminnewcourse is enabled by default, so admin is also enrolled as teacher.
|
||||
$users = get_enrolled_users($context);
|
||||
$this->assertEquals(1, count($users));
|
||||
$this->assertEquals('tool_generator_000001', reset($users)->username);
|
||||
$this->assertEquals(2, count($users));
|
||||
$usernames = array_map(function($user) {
|
||||
return $user->username;
|
||||
}, $users);
|
||||
$this->assertTrue(in_array('admin', $usernames));
|
||||
$this->assertTrue(in_array('tool_generator_000001', $usernames));
|
||||
|
||||
// Check there's a page on the course.
|
||||
$pages = $modinfo->get_instances_of('page');
|
||||
|
Loading…
x
Reference in New Issue
Block a user