Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
moodle
moodle
Commits
a5b84589
Commit
a5b84589
authored
Aug 21, 2020
by
Ferran Recio Calderó
Committed by
Jenkins
Oct 30, 2020
Browse files
MDL-69378 tool_uploadcourse: fix enrolment methods uploads
parent
086d433a
Changes
5
Hide whitespace changes
Inline
Side-by-side
admin/tool/uploadcourse/classes/course.php
View file @
a5b84589
...
...
@@ -872,36 +872,31 @@ class tool_uploadcourse_course {
unset
(
$method
[
'delete'
]);
unset
(
$method
[
'disable'
]);
if
(
!
empty
(
$instance
)
&&
$todelete
)
{
if
(
$todelete
)
{
// Remove the enrolment method.
foreach
(
$instances
as
$instance
)
{
if
(
$instance
->
enrol
==
$enrolmethod
)
{
$plugin
=
$enrolmentplugins
[
$instance
->
enrol
];
$plugin
->
delete_instance
(
$instance
);
break
;
}
if
(
$instance
)
{
$plugin
=
$enrolmentplugins
[
$instance
->
enrol
];
$plugin
->
delete_instance
(
$instance
);
}
}
else
if
(
!
empty
(
$instance
)
&&
$todisable
)
{
// Disable the enrolment.
foreach
(
$instances
as
$instance
)
{
if
(
$instance
->
enrol
==
$enrolmethod
)
{
$plugin
=
$enrolmentplugins
[
$instance
->
enrol
];
$plugin
->
update_status
(
$instance
,
ENROL_INSTANCE_DISABLED
);
$enrol_updated
=
true
;
break
;
}
}
$plugin
=
$enrolmentplugins
[
$instance
->
enrol
];
$plugin
->
update_status
(
$instance
,
ENROL_INSTANCE_DISABLED
);
$enrol_updated
=
true
;
}
else
{
$plugin
=
null
;
$status
=
(
$todisable
)
?
ENROL_INSTANCE_DISABLED
:
ENROL_INSTANCE_ENABLED
;
if
(
empty
(
$instance
))
{
$plugin
=
$enrolmentplugins
[
$enrolmethod
];
$instance
=
new
stdClass
(
);
$instance
->
id
=
$plugin
->
add_default_instance
(
$course
);
$instance
id
=
$plugin
->
add_default_instance
(
$course
);
$instance
=
$DB
->
get_record
(
'enrol'
,
[
'id'
=>
$instanceid
]
);
$instance
->
roleid
=
$plugin
->
get_config
(
'roleid'
);
$instance
->
status
=
ENROL_INSTANCE_ENABLED
;
$plugin
->
update_status
(
$instance
,
$
status
)
;
}
else
{
$plugin
=
$enrolmentplugins
[
$instance
->
enrol
];
$plugin
->
update_status
(
$instance
,
ENROL_INSTANCE_ENABLED
);
$plugin
->
update_status
(
$instance
,
$status
);
}
// Now update values.
...
...
admin/tool/uploadcourse/tests/behat/enrolments.feature
0 → 100644
View file @
a5b84589
@tool
@tool_uploadcourse
@_file_upload
Feature
:
An admin can update courses enrolments using a CSV file
In order to update courses enrolments using a CSV file
As an admin
I need to be able to upload a CSV file with enrolment methods for the courses
Background
:
Given the following "courses" exist
:
|
fullname
|
shortname
|
category
|
|
Course
1
|
C1
|
0
|
And
I log in as
"admin"
@javascript
Scenario
:
Creating enrolment method by enable it
Given
I am on
"Course 1"
course homepage
And
I navigate to
"Users > Enrolment methods"
in current page administration
And
I click on
"Delete"
"link"
in the
"Guest access"
"table_row"
And
I click on
"Continue"
"button"
And
I should not see
"Guest access"
in the
"generaltable"
"table"
And
I navigate to
"Courses > Upload courses"
in site administration
And
I upload
"admin/tool/uploadcourse/tests/fixtures/enrolment_enable.csv"
file to
"File"
filemanager
And
I set the field
"Upload mode"
to
"Only update existing courses"
And
I set the field
"Update mode"
to
"Update with CSV data only"
And
I set the field
"Allow deletes"
to
"Yes"
And
I click on
"Preview"
"button"
When
I click on
"Upload courses"
"button"
Then
I should see
"Course updated"
And
I am on
"Course 1"
course homepage
And
I navigate to
"Users > Enrolment methods"
in current page administration
And
"Disable"
"icon"
should exist in the
"Guest access"
"table_row"
@javascript
Scenario
:
Creating enrolment method by disabling it
Given
I am on
"Course 1"
course homepage
And
I navigate to
"Users > Enrolment methods"
in current page administration
And
I click on
"Delete"
"link"
in the
"Guest access"
"table_row"
And
I click on
"Continue"
"button"
And
I should not see
"Guest access"
in the
"generaltable"
"table"
And
I navigate to
"Courses > Upload courses"
in site administration
And
I upload
"admin/tool/uploadcourse/tests/fixtures/enrolment_disable.csv"
file to
"File"
filemanager
And
I set the field
"Upload mode"
to
"Only update existing courses"
And
I set the field
"Update mode"
to
"Update with CSV data only"
And
I set the field
"Allow deletes"
to
"Yes"
And
I click on
"Preview"
"button"
When
I click on
"Upload courses"
"button"
Then
I should see
"Course updated"
And
I am on
"Course 1"
course homepage
And
I navigate to
"Users > Enrolment methods"
in current page administration
And
"Enable"
"icon"
should exist in the
"Guest access"
"table_row"
@javascript
Scenario
:
Enabling enrolment method
Given
I navigate to
"Courses > Upload courses"
in site administration
And
I upload
"admin/tool/uploadcourse/tests/fixtures/enrolment_enable.csv"
file to
"File"
filemanager
And
I set the field
"Upload mode"
to
"Only update existing courses"
And
I set the field
"Update mode"
to
"Update with CSV data only"
And
I set the field
"Allow deletes"
to
"Yes"
And
I click on
"Preview"
"button"
When
I click on
"Upload courses"
"button"
Then
I should see
"Course updated"
And
I am on
"Course 1"
course homepage
And
I navigate to
"Users > Enrolment methods"
in current page administration
And
"Disable"
"icon"
should exist in the
"Guest access"
"table_row"
@javascript
Scenario
:
Disable an enrolment method
Given
I am on
"Course 1"
course homepage
And
I navigate to
"Users > Enrolment methods"
in current page administration
And
I click on
"Enable"
"link"
in the
"Guest access"
"table_row"
And
"Disable"
"icon"
should exist in the
"Guest access"
"table_row"
And
I navigate to
"Courses > Upload courses"
in site administration
And
I upload
"admin/tool/uploadcourse/tests/fixtures/enrolment_disable.csv"
file to
"File"
filemanager
And
I set the field
"Upload mode"
to
"Only update existing courses"
And
I set the field
"Update mode"
to
"Update with CSV data only"
And
I set the field
"Allow deletes"
to
"Yes"
And
I click on
"Preview"
"button"
When
I click on
"Upload courses"
"button"
Then
I should see
"Course updated"
And
I am on
"Course 1"
course homepage
And
I navigate to
"Users > Enrolment methods"
in current page administration
And
"Enable"
"icon"
should exist in the
"Guest access"
"table_row"
@javascript
Scenario
:
Delete an enrolment method
Given
I navigate to
"Courses > Upload courses"
in site administration
And
I upload
"admin/tool/uploadcourse/tests/fixtures/enrolment_delete.csv"
file to
"File"
filemanager
And
I set the field
"Upload mode"
to
"Only update existing courses"
And
I set the field
"Update mode"
to
"Update with CSV data only"
And
I set the field
"Allow deletes"
to
"Yes"
And
I click on
"Preview"
"button"
When
I click on
"Upload courses"
"button"
Then
I should see
"Course updated"
And
I am on
"Course 1"
course homepage
And
I navigate to
"Users > Enrolment methods"
in current page administration
And
I should not see
"Guest access"
in the
"generaltable"
"table"
@javascript
Scenario
:
Delete an unexistent enrolment method (nothing should change)
Given
I am on
"Course 1"
course homepage
And
I navigate to
"Users > Enrolment methods"
in current page administration
And
I click on
"Delete"
"link"
in the
"Guest access"
"table_row"
And
I click on
"Continue"
"button"
And
I should not see
"Guest access"
in the
"generaltable"
"table"
And
I navigate to
"Courses > Upload courses"
in site administration
And
I upload
"admin/tool/uploadcourse/tests/fixtures/enrolment_delete.csv"
file to
"File"
filemanager
And
I set the field
"Upload mode"
to
"Only update existing courses"
And
I set the field
"Update mode"
to
"Update with CSV data only"
And
I set the field
"Allow deletes"
to
"Yes"
And
I click on
"Preview"
"button"
When
I click on
"Upload courses"
"button"
Then
I should see
"Course updated"
And
I am on
"Course 1"
course homepage
And
I navigate to
"Users > Enrolment methods"
in current page administration
And
I should not see
"Guest access"
in the
"generaltable"
"table"
admin/tool/uploadcourse/tests/fixtures/enrolment_delete.csv
0 → 100644
View file @
a5b84589
shortname,category,enrolment_1,enrolment_1_delete
C1,1,guest,1
\ No newline at end of file
admin/tool/uploadcourse/tests/fixtures/enrolment_disable.csv
0 → 100644
View file @
a5b84589
shortname,category,enrolment_1,enrolment_1_disable
C1,1,guest,1
\ No newline at end of file
admin/tool/uploadcourse/tests/fixtures/enrolment_enable.csv
0 → 100644
View file @
a5b84589
shortname,category,enrolment_1,enrolment_1_disable
C1,1,guest,0
\ No newline at end of file
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment