Skip to content

Commit

Permalink
Merge branch 'MDL-74030' of https://github.com/roland04/moodle
Browse files Browse the repository at this point in the history
  • Loading branch information
vmdef committed Mar 14, 2022
2 parents 5195ac0 + d2acd08 commit e95d99e
Show file tree
Hide file tree
Showing 9 changed files with 91 additions and 12 deletions.
3 changes: 2 additions & 1 deletion admin/settings/appearance.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@
'profile,moodle|/user/profile.php
grades,grades|/grade/report/mygrades.php
calendar,core_calendar|/calendar/view.php?view=month
privatefiles,moodle|/user/files.php',
privatefiles,moodle|/user/files.php
reports,core_reportbuilder|/reportbuilder/index.php',
PARAM_RAW,
'50',
'10'
Expand Down
1 change: 1 addition & 0 deletions lang/en/reportbuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,7 @@
$string['reportbuilder'] = 'Report builder';
$string['reportcreated'] = 'Report created';
$string['reportdeleted'] = 'Report deleted';
$string['reports'] = 'Reports';
$string['reportsource'] = 'Report source';
$string['reportsource_help'] = 'The report source defines where the data for the report will come from.';
$string['reportupdated'] = 'Report updated';
Expand Down
7 changes: 7 additions & 0 deletions lib/db/upgrade.php
Original file line number Diff line number Diff line change
Expand Up @@ -4246,5 +4246,12 @@ function xmldb_main_upgrade($oldversion) {
upgrade_main_savepoint(true, 2022030100.00);
}

if ($oldversion < 2022031100.01) {
$reportsusermenuitem = 'reports,core_reportbuilder|/reportbuilder/index.php';
upgrade_add_item_to_usermenu($reportsusermenuitem);
// Main savepoint reached.
upgrade_main_savepoint(true, 2022031100.01);
}

return true;
}
20 changes: 20 additions & 0 deletions lib/db/upgradelib.php
Original file line number Diff line number Diff line change
Expand Up @@ -1408,3 +1408,23 @@ function upgrade_migrate_question_table(): void {

$transaction->allow_commit();
}

/**
* Add a new item at the end of the usermenu.
*
* @param string $menuitem
*/
function upgrade_add_item_to_usermenu(string $menuitem): void {
global $CFG;

// Get current configuration data.
$currentcustomusermenuitems = str_replace(["\r\n", "\r"], "\n", $CFG->customusermenuitems);
$lines = preg_split('/\n/', $currentcustomusermenuitems, -1, PREG_SPLIT_NO_EMPTY);
$lines = array_map('trim', $lines);

if (!in_array($menuitem, $lines)) {
// Add the item to the menu.
$lines[] = $menuitem;
set_config('customusermenuitems', implode("\n", $lines));
}
}
1 change: 1 addition & 0 deletions lib/tests/behat/behat_navigation.php
Original file line number Diff line number Diff line change
Expand Up @@ -1018,6 +1018,7 @@ public function i_select_from_primary_navigation(string $link) {
/**
* Clicks link with specified id|title|alt|text in the secondary navigation
*
* @When I select :link from secondary navigation
* @throws ElementNotFoundException Thrown by behat_base::find
* @param string $link
*/
Expand Down
52 changes: 52 additions & 0 deletions lib/tests/upgradelib_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -1619,4 +1619,56 @@ public function test_check_xmlrpc_mahara_portfolios_is_set(): void {
$this->assertEquals('xmlrpc_mahara_usage', $result->getInfo());
$this->assertFalse($result->getStatus());
}

/**
* Data provider of usermenu items.
*
* @return array
*/
public function usermenu_items_dataprovider(): array {
return [
'Add new item to empty usermenu' => [
'',
'reports,core_reportbuilder|/reportbuilder/index.php',
'reports,core_reportbuilder|/reportbuilder/index.php',
],
'Add new item to usermenu' => [
'profile,moodle|/user/profile.php
grades,grades|/grade/report/mygrades.php',
'reports,core_reportbuilder|/reportbuilder/index.php',
'profile,moodle|/user/profile.php
grades,grades|/grade/report/mygrades.php
reports,core_reportbuilder|/reportbuilder/index.php',
],
'Add existing item to usermenu' => [
'profile,moodle|/user/profile.php
reports,core_reportbuilder|/reportbuilder/index.php
calendar,core_calendar|/calendar/view.php?view=month',
'reports,core_reportbuilder|/reportbuilder/index.php',
'profile,moodle|/user/profile.php
reports,core_reportbuilder|/reportbuilder/index.php
calendar,core_calendar|/calendar/view.php?view=month',
],
];
}

/**
* Test the functionality of the {@link upgrade_add_item_to_usermenu()} function.
*
* @covers ::upgrade_add_item_to_usermenu
* @dataProvider usermenu_items_dataprovider
*/
public function test_upgrade_add_item_to_usermenu(string $initialmenu, string $newmenuitem, string $expectedmenu) {
global $CFG;

$this->resetAfterTest();
// Set the base user menu.
$CFG->customusermenuitems = $initialmenu;

// Add the new item to the user menu.
upgrade_add_item_to_usermenu($newmenuitem);
$newcustomusermenu = $CFG->customusermenuitems;

$this->assertEquals($expectedmenu, $newcustomusermenu);
}
}
4 changes: 2 additions & 2 deletions mod/lesson/tests/behat/lesson_report.feature
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ Feature: In a lesson activity, teachers can review student attempts
Then I log in as "teacher1"
And I am on "Course 1" course homepage
And I follow "Test lesson name"
And I follow "Reports"
And I select "Reports" from secondary navigation
And I should see "Student 1"
And I should see "100%"
And I should see "High score"
Expand Down Expand Up @@ -158,7 +158,7 @@ Feature: In a lesson activity, teachers can review student attempts
Then I log in as "teacher1"
And I am on "Course 1" course homepage
And I follow "Test lesson name"
And I follow "Reports"
And I select "Reports" from secondary navigation
And I should see "Student 1"
And I should not see "High score"
And I should not see "Average score"
Expand Down
13 changes: 5 additions & 8 deletions reportbuilder/tests/behat/audience.feature
Original file line number Diff line number Diff line change
Expand Up @@ -137,9 +137,8 @@ Feature: Configure access to reports based on intended audience
| moodle/reportbuilder:editall | Prohibit | viewreportsrole | System | |
| moodle/reportbuilder:edit | Prohibit | viewreportsrole | System | |
| moodle/reportbuilder:view | Allow | viewreportsrole | System | |
| moodle/site:configview | Allow | viewreportsrole | System | |
When I log in as "user1"
And I navigate to "Reports > Report builder > Custom reports" in site administration
And I follow "Reports" in the user menu
And I should see "Custom reports"
And I should not see "My report"
And I should not see "My second report"
Expand All @@ -154,7 +153,7 @@ Feature: Configure access to reports based on intended audience
And I press "Save changes"
And I log out
And I log in as "user1"
And I navigate to "Reports > Report builder > Custom reports" in site administration
And I follow "Reports" in the user menu
And I should not see "My second report"
And I click on "My report" "link" in the "My report" "table_row"

Expand All @@ -173,9 +172,8 @@ Feature: Configure access to reports based on intended audience
| moodle/reportbuilder:editall | Prohibit | viewreportsrole | System | |
| moodle/reportbuilder:edit | Allow | viewreportsrole | System | |
| moodle/reportbuilder:view | Prohibit | viewreportsrole | System | |
| moodle/site:configview | Allow | viewreportsrole | System | |
When I log in as "user1"
And I navigate to "Reports > Report builder > Custom reports" in site administration
And I follow "Reports" in the user menu
And I should see "Custom reports"
And I should not see "My report"
And I should not see "My second report"
Expand All @@ -198,7 +196,7 @@ Feature: Configure access to reports based on intended audience
And I press "Save changes"
And I log out
And I log in as "user1"
And I navigate to "Reports > Report builder > Custom reports" in site administration
And I follow "Reports" in the user menu
And I should not see "My second report"
And I should see "My user1 report"
And I click on "My report" "link" in the "My report" "table_row"
Expand All @@ -218,9 +216,8 @@ Feature: Configure access to reports based on intended audience
| moodle/reportbuilder:editall | Allow | viewreportsrole | System | |
| moodle/reportbuilder:edit | Prohibit | viewreportsrole | System | |
| moodle/reportbuilder:view | Prohibit | viewreportsrole | System | |
| moodle/site:configview | Allow | viewreportsrole | System | |
When I log in as "user1"
And I navigate to "Reports > Report builder > Custom reports" in site administration
And I follow "Reports" in the user menu
And I should see "Custom reports"
And I should see "My report"
Then I click on "My second report" "link" in the "My second report" "table_row"
Expand Down
2 changes: 1 addition & 1 deletion version.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@

defined('MOODLE_INTERNAL') || die();

$version = 2022031100.00; // YYYYMMDD = weekly release date of this DEV branch.
$version = 2022031100.01; // YYYYMMDD = weekly release date of this DEV branch.
// RR = release increments - 00 in DEV branches.
// .XX = incremental changes.
$release = '4.0beta+ (Build: 20220311)'; // Human-friendly version name
Expand Down

0 comments on commit e95d99e

Please sign in to comment.