From bc05916cbff8a323b0a5f65192175d025284dae8 Mon Sep 17 00:00:00 2001 From: Paul Holden Date: Tue, 8 Mar 2022 09:46:04 +0000 Subject: [PATCH] MDL-74128 reportbuilder: Behat helper for navigating to view page. --- reportbuilder/tests/behat/audience.feature | 108 +++++------------- .../tests/behat/behat_reportbuilder.php | 4 + 2 files changed, 33 insertions(+), 79 deletions(-) diff --git a/reportbuilder/tests/behat/audience.feature b/reportbuilder/tests/behat/audience.feature index 011d2a414a5..47a1fd09c53 100644 --- a/reportbuilder/tests/behat/audience.feature +++ b/reportbuilder/tests/behat/audience.feature @@ -1,6 +1,6 @@ @core_reportbuilder @javascript Feature: Configure access to reports based on intended audience - As a manager + As an admin I want to restrict which users have access to a report Background: @@ -11,24 +11,19 @@ Feature: Configure access to reports based on intended audience | user3 | User | 3 | And the following "core_reportbuilder > Reports" exist: | name | source | default | - | My report | core_user\reportbuilder\datasource\users | 0 | + | My report | core_user\reportbuilder\datasource\users | 1 | Scenario: Configure report audience with manually added users audience type - Given the following "users" exist: - | username | firstname | lastname | - | manager1 | Manager | 1 | - And the following "role assigns" exist: - | user | role | contextlevel | reference | - | manager1 | manager | System | | - And the following "permission overrides" exist: - | capability | permission | role | contextlevel | reference | - | moodle/reportbuilder:editall | Allow | manager | System | | - And I am on the "My report" "reportbuilder > Editor" page logged in as "manager1" + When I log in as "user1" + And I follow "Reports" in the user menu + And I should see "Nothing to display" + And I log out + And I am on the "My report" "reportbuilder > Editor" page logged in as "admin" And I click on the "Access" dynamic tab And I should see "Nothing to display" And I click on the "Audience" dynamic tab And I should see "There are no audiences for this report" - Then I click on "Add audience 'Manually added users'" "link" + And I click on "Add audience 'Manually added users'" "link" And I should see "Added audience 'Manually added users'" And I set the field "Add users manually" to "User 1,User 3" And I press "Save changes" @@ -41,6 +36,12 @@ Feature: Configure access to reports based on intended audience And I should see "User 1" in the "reportbuilder-table" "table" And I should not see "User 2" in the "reportbuilder-table" "table" And I should see "User 3" in the "reportbuilder-table" "table" + And I log out + And I log in as "user1" + And I follow "Reports" in the user menu + Then I should see "My report" in the "reportbuilder-table" "table" + And I click on "My report" "link" in the "My report" "table_row" + And I should see "User 1" in the "reportbuilder-table" "table" Scenario: Configure report audience with has system role audience type Given the following "roles" exist: @@ -62,6 +63,9 @@ Feature: Configure access to reports based on intended audience And I should not see "User 1" in the "reportbuilder-table" "table" And I should see "User 2" in the "reportbuilder-table" "table" And I should not see "User 3" in the "reportbuilder-table" "table" + And I log out + And I am on the "My report" "reportbuilder > View" page logged in as "user2" + And I should see "User 1" in the "reportbuilder-table" "table" Scenario: Configure report audience with Member of cohort audience type Given the following "cohorts" exist: @@ -83,6 +87,9 @@ Feature: Configure access to reports based on intended audience And I should not see "User 1" in the "reportbuilder-table" "table" And I should not see "User 2" in the "reportbuilder-table" "table" And I should see "User 3" in the "reportbuilder-table" "table" + And I log out + And I am on the "My report" "reportbuilder > View" page logged in as "user3" + And I should see "User 1" in the "reportbuilder-table" "table" Scenario: Configure report audience with Member of cohort audience type with no cohorts available Given I am on the "My report" "reportbuilder > Editor" page logged in as "admin" @@ -154,46 +161,8 @@ Feature: Configure access to reports based on intended audience And I should see "User 2" in the "reportbuilder-table" "table" And I should not see "User 3" in the "reportbuilder-table" "table" - Scenario: View report as a user with no edit capability and set in the report audience - Given the following "core_reportbuilder > Reports" exist: - | name | source | - | My second report | core_user\reportbuilder\datasource\users | - And the following "roles" exist: - | shortname | name | archetype | - | viewreportsrole | Test role | | - And the following "role assigns" exist: - | user | role | contextlevel | reference | - | user1 | viewreportsrole | System | | - And the following "permission overrides" exist: - | capability | permission | role | contextlevel | reference | - | moodle/reportbuilder:editall | Prohibit | viewreportsrole | System | | - | moodle/reportbuilder:edit | Prohibit | viewreportsrole | System | | - | moodle/reportbuilder:view | Allow | viewreportsrole | System | | - When I log in as "user1" - 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" - And I log out - And I log in as "admin" - And I navigate to "Reports > Report builder > Custom reports" in site administration - And I click on "My report" "link" in the "My report" "table_row" - And I click on the "Audience" dynamic tab - And I should see "There are no audiences for this report" - Then I click on "Add audience 'Manually added users'" "link" - And I set the field "Add users manually" to "User 1" - And I press "Save changes" - And I log out - And I log in as "user1" - 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" - Scenario: View report as a user with edit capability - Given the following "core_reportbuilder > Reports" exist: - | name | source | - | My second report | core_user\reportbuilder\datasource\users | - And the following "roles" exist: + Given the following "roles" exist: | shortname | name | archetype | | viewreportsrole | Test role | | And the following "role assigns" exist: @@ -206,9 +175,7 @@ Feature: Configure access to reports based on intended audience | moodle/reportbuilder:view | Prohibit | viewreportsrole | System | | When I log in as "user1" 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" + And I should see "Nothing to display" And I click on "New report" "button" And I set the following fields in the "New report" "dialogue" to these values: | Name | My user1 report | @@ -216,28 +183,12 @@ Feature: Configure access to reports based on intended audience | Include default setup | 1 | And I click on "Save" "button" in the "New report" "dialogue" And I click on "Close 'My user1 report' editor" "button" - And I should see "My user1 report" - And I log out - And I log in as "admin" - And I navigate to "Reports > Report builder > Custom reports" in site administration - And I click on "My report" "link" in the "My report" "table_row" - And I click on the "Audience" dynamic tab - And I should see "There are no audiences for this report" - Then I click on "Add audience 'Manually added users'" "link" - And I set the field "Add users manually" to "User 1" - And I press "Save changes" - And I log out - And I log in as "user1" - 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" + And I should see "My user1 report" in the "reportbuilder-table" "table" + And I press "View report" action in the "My user1 report" report row + And I should see "User 1" in the "reportbuilder-table" "table" Scenario: View report as a user with editall capability - Given the following "core_reportbuilder > Reports" exist: - | name | source | - | My second report | core_user\reportbuilder\datasource\users | - And the following "roles" exist: + Given the following "roles" exist: | shortname | name | archetype | | viewreportsrole | Test role | | And the following "role assigns" exist: @@ -250,7 +201,6 @@ Feature: Configure access to reports based on intended audience | moodle/reportbuilder:view | Prohibit | viewreportsrole | System | | When I log in as "user1" 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" - And I should see "Email address" + Then I should see "My report" in the "reportbuilder-table" "table" + And I press "View report" action in the "My report" report row + And I should see "User 1" in the "reportbuilder-table" "table" diff --git a/reportbuilder/tests/behat/behat_reportbuilder.php b/reportbuilder/tests/behat/behat_reportbuilder.php index 93251aa1cf1..10818fbc889 100644 --- a/reportbuilder/tests/behat/behat_reportbuilder.php +++ b/reportbuilder/tests/behat/behat_reportbuilder.php @@ -38,6 +38,7 @@ class behat_reportbuilder extends behat_base { * Recognised page names are: * | type | identifier | description | * | Editor | Report name | Custom report editor | + * | View | Report name | Custom report view | * * @param string $type * @param string $identifier @@ -53,6 +54,9 @@ class behat_reportbuilder extends behat_base { case 'Editor': return new moodle_url('/reportbuilder/edit.php', ['id' => $report->get('id')]); + case 'View': + return new moodle_url('/reportbuilder/view.php', ['id' => $report->get('id')]); + default: throw new Exception("Unrecognised reportbuilder page type '{$type}'"); }