Skip to content

Commit

Permalink
Merge branch 'MDL-72256' of https://github.com/danmarsden/moodle
Browse files Browse the repository at this point in the history
  • Loading branch information
ilyatregubov committed May 18, 2022
2 parents fa48ab3 + b51d8d9 commit 0829ee7
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 21 deletions.
42 changes: 27 additions & 15 deletions enrol/fee/classes/plugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,32 @@ public function update_instance($instance, $data) {
* @return string html text, usually a form in a text box
*/
public function enrol_page_hook(stdClass $instance) {
global $CFG, $USER, $OUTPUT, $PAGE, $DB;
return $this->show_payment_info($instance);
}

/**
* Returns optional enrolment instance description text.
*
* This is used in detailed course information.
*
*
* @param object $instance
* @return string short html text
*/
public function get_description_text($instance) {
return $this->show_payment_info($instance);
}

/**
* Generates payment information to display on enrol/info page.
*
* @param stdClass $instance
* @return false|string
* @throws coding_exception
* @throws dml_exception
*/
private function show_payment_info(stdClass $instance) {
global $USER, $OUTPUT, $DB;

ob_start();

Expand All @@ -183,19 +208,6 @@ public function enrol_page_hook(stdClass $instance) {
$course = $DB->get_record('course', array('id' => $instance->courseid));
$context = context_course::instance($course->id);

$shortname = format_string($course->shortname, true, array('context' => $context));
$strloginto = get_string("loginto", "", $shortname);
$strcourses = get_string("courses");

// Pass $view=true to filter hidden caps if the user cannot see them.
if ($users = get_users_by_capability($context, 'moodle/course:update', 'u.*', 'u.id ASC',
'', '', '', '', false, true)) {
$users = sort_by_roleassignment_authority($users, $context);
$teacher = array_shift($users);
} else {
$teacher = false;
}

if ( (float) $instance->cost <= 0 ) {
$cost = (float) $this->get_config('cost');
} else {
Expand All @@ -207,7 +219,7 @@ public function enrol_page_hook(stdClass $instance) {
} else {

$data = [
'isguestuser' => isguestuser(),
'isguestuser' => isguestuser() || !isloggedin(),
'cost' => \core_payment\helper::get_cost_as_string($cost, $instance->currency),
'instanceid' => $instance->id,
'description' => get_string('purchasedescription', 'enrol_fee',
Expand Down
20 changes: 14 additions & 6 deletions enrol/fee/tests/behat/fee.feature
Original file line number Diff line number Diff line change
Expand Up @@ -21,23 +21,31 @@ Feature: Signing up for a course with a fee enrolment method
And I navigate to "Plugins > Enrolments > Manage enrol plugins" in site administration
And I click on "Enable" "link" in the "Enrolment on payment" "table_row"
And I log out

@javascript
Scenario: Student can see the payment prompt on the course enrolment page
When I log in as "manager1"
And I am on the "Course 1" "enrolment methods" page
And I log in as "manager1"
And I am on the "Course 1" "enrolment methods" page
And I select "Enrolment on payment" from the "Add method" singleselect
And I set the following fields to these values:
| Payment account | Account1 |
| Enrolment fee | 123.45 |
| Currency | Euro |
And I press "Add method"
And I log out
And I log in as "student1"

@javascript
Scenario: Student can see the payment prompt on the course enrolment page
When I log in as "student1"
And I am on course index
And I follow "Course 1"
Then I should see "This course requires a payment for entry."
And I should see "123.45"
And I press "Select payment type"
And I should see "PayPal" in the "Select payment type" "dialogue"
And I click on "Cancel" "button" in the "Select payment type" "dialogue"

Scenario: Guest can see the login prompt on the course enrolment page
When I log in as "guest"
And I am on course index
And I follow "Course 1"
Then I should see "This course requires a payment for entry."
And I should see "123.45"
And I should see "Log in to the site"

0 comments on commit 0829ee7

Please sign in to comment.