From d2acd08934a73582de41960c0a39784223972e07 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mikel=20Mart=C3=ADn?= Date: Wed, 2 Mar 2022 09:30:19 +0100 Subject: [PATCH] MDL-74030 navigation: Add reports link Add report builder 'Reports' link to the user menu AMOS BEGIN CPY [reports,moodle],[reports,core_reportbuilder] AMOS END --- admin/settings/appearance.php | 3 +- lang/en/reportbuilder.php | 1 + lib/db/upgrade.php | 7 +++ lib/db/upgradelib.php | 20 ++++++++ lib/tests/behat/behat_navigation.php | 1 + lib/tests/upgradelib_test.php | 52 ++++++++++++++++++++ mod/lesson/tests/behat/lesson_report.feature | 4 +- reportbuilder/tests/behat/audience.feature | 13 ++--- version.php | 2 +- 9 files changed, 91 insertions(+), 12 deletions(-) diff --git a/admin/settings/appearance.php b/admin/settings/appearance.php index c63082cf4b9..04350e3642c 100644 --- a/admin/settings/appearance.php +++ b/admin/settings/appearance.php @@ -40,7 +40,8 @@ if ($hassiteconfig or has_any_capability($capabilities, $systemcontext)) { // sp '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' diff --git a/lang/en/reportbuilder.php b/lang/en/reportbuilder.php index e8d3fc36b65..ddae192d8aa 100644 --- a/lang/en/reportbuilder.php +++ b/lang/en/reportbuilder.php @@ -221,6 +221,7 @@ $string['renamefilter'] = 'Rename filter \'{$a}\''; $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'; diff --git a/lib/db/upgrade.php b/lib/db/upgrade.php index eabda1f6ff7..3c2a8ce3ac6 100644 --- a/lib/db/upgrade.php +++ b/lib/db/upgrade.php @@ -4246,5 +4246,12 @@ privatefiles,moodle|/user/files.php'; upgrade_main_savepoint(true, 2022030100.00); } + if ($oldversion < 2022030800.01) { + $reportsusermenuitem = 'reports,core_reportbuilder|/reportbuilder/index.php'; + upgrade_add_item_to_usermenu($reportsusermenuitem); + // Main savepoint reached. + upgrade_main_savepoint(true, 2022030800.01); + } + return true; } diff --git a/lib/db/upgradelib.php b/lib/db/upgradelib.php index e67af9972de..958fcbec092 100644 --- a/lib/db/upgradelib.php +++ b/lib/db/upgradelib.php @@ -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)); + } +} diff --git a/lib/tests/behat/behat_navigation.php b/lib/tests/behat/behat_navigation.php index 9929c4d3885..1b9cd22d3bf 100644 --- a/lib/tests/behat/behat_navigation.php +++ b/lib/tests/behat/behat_navigation.php @@ -1018,6 +1018,7 @@ class behat_navigation extends behat_base { /** * 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 */ diff --git a/lib/tests/upgradelib_test.php b/lib/tests/upgradelib_test.php index 80851dcff6e..9a886e11032 100644 --- a/lib/tests/upgradelib_test.php +++ b/lib/tests/upgradelib_test.php @@ -1619,4 +1619,56 @@ class upgradelib_test extends advanced_testcase { $this->assertEquals('xmlrpc_mahara_usage', $result->getInfo()); $this->assertFalse($result->getStatus()); } + + /** + * Data provider of usermenu items. + * + * @return array + */ + public function usermenu_items_dataprovider() { + 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, $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); + } } diff --git a/mod/lesson/tests/behat/lesson_report.feature b/mod/lesson/tests/behat/lesson_report.feature index d76870dc9ad..56a0e52b06a 100644 --- a/mod/lesson/tests/behat/lesson_report.feature +++ b/mod/lesson/tests/behat/lesson_report.feature @@ -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" @@ -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" diff --git a/reportbuilder/tests/behat/audience.feature b/reportbuilder/tests/behat/audience.feature index cf083a05302..1426c5a6320 100644 --- a/reportbuilder/tests/behat/audience.feature +++ b/reportbuilder/tests/behat/audience.feature @@ -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" @@ -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" @@ -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" @@ -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" @@ -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" diff --git a/version.php b/version.php index 6f70d91473b..5f6c05d78fa 100644 --- a/version.php +++ b/version.php @@ -29,7 +29,7 @@ defined('MOODLE_INTERNAL') || die(); -$version = 2022030800.00; // YYYYMMDD = weekly release date of this DEV branch. +$version = 2022030800.01; // YYYYMMDD = weekly release date of this DEV branch. // RR = release increments - 00 in DEV branches. // .XX = incremental changes. $release = '4.0beta+ (Build: 20220308)'; // Human-friendly version name