mirror of
https://github.com/moodle/moodle.git
synced 2025-04-13 12:32:08 +02:00
MDL-72090 navigation: New unit and behat tests for navigation.
This adds new tests for functions that impact the more menu and the course administration overflow.
This commit is contained in:
parent
d02274137a
commit
89d749fda6
@ -18,6 +18,7 @@ namespace core\navigation\views;
|
||||
|
||||
use navigation_node;
|
||||
use ReflectionMethod;
|
||||
use moodle_url;
|
||||
|
||||
/**
|
||||
* Class core_secondary_testcase
|
||||
@ -738,6 +739,8 @@ class secondary_test extends \advanced_testcase {
|
||||
*/
|
||||
public function test_get_overflow_menu_data(string $selectedurl, bool $expectednull, bool $emptynode = false) {
|
||||
global $PAGE;
|
||||
|
||||
$this->resetAfterTest();
|
||||
// Custom nodes - mimicing nodes added via 3rd party plugins.
|
||||
$structure = [
|
||||
'parentnode1' => [
|
||||
@ -752,6 +755,11 @@ class secondary_test extends \advanced_testcase {
|
||||
],
|
||||
'parentnode2' => "/view/module.php"
|
||||
];
|
||||
|
||||
$course = $this->getDataGenerator()->create_course();
|
||||
$context = \context_course::instance($course->id);
|
||||
$PAGE->set_context($context);
|
||||
|
||||
$PAGE->set_url($selectedurl);
|
||||
navigation_node::override_active_url(new \moodle_url($selectedurl));
|
||||
$node = $this->generate_node_tree_construct($structure, 'primarynode');
|
||||
@ -815,4 +823,95 @@ class secondary_test extends \advanced_testcase {
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Test the course administration settings return an overflow menu.
|
||||
*
|
||||
* @dataProvider test_get_overflow_menu_data_course_admin_provider
|
||||
* @param string $url Url of the page we are testing.
|
||||
* @param string $contextidentifier id or contextid or something similar.
|
||||
* @param bool $expected The expected return. True to return the overflow menu otherwise false for nothing.
|
||||
*/
|
||||
public function test_get_overflow_menu_data_course_admin(string $url, string $contextidentifier, bool $expected): void {
|
||||
global $PAGE;
|
||||
$this->resetAfterTest();
|
||||
$this->setAdminUser();
|
||||
|
||||
$pagecourse = $this->getDataGenerator()->create_course();
|
||||
$contextrecord = \context_course::instance($pagecourse->id, MUST_EXIST);
|
||||
|
||||
$id = ($contextidentifier == 'contextid') ? $contextrecord->id : $pagecourse->id;
|
||||
|
||||
$pageurl = new \moodle_url($url, [$contextidentifier => $id]);
|
||||
$PAGE->set_url($pageurl);
|
||||
navigation_node::override_active_url($pageurl);
|
||||
$PAGE->set_course($pagecourse);
|
||||
$PAGE->set_context($contextrecord);
|
||||
|
||||
$node = new secondary($PAGE);
|
||||
$node->initialise();
|
||||
$result = $node->get_overflow_menu_data();
|
||||
if ($expected) {
|
||||
$this->assertInstanceOf('url_select', $result);
|
||||
$this->assertTrue($pageurl->compare($result->selected));
|
||||
} else {
|
||||
$this->assertNull($result);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Data provider for the other half of the method thing
|
||||
*
|
||||
* @return array Provider information.
|
||||
*/
|
||||
public function test_get_overflow_menu_data_course_admin_provider(): array {
|
||||
return [
|
||||
"Backup page returns overflow" => [
|
||||
'/backup/backup.php',
|
||||
'id',
|
||||
true
|
||||
],
|
||||
"Restore course page returns overflow" => [
|
||||
'/backup/restorefile.php',
|
||||
'contextid',
|
||||
true
|
||||
],
|
||||
"Import course page returns overflow" => [
|
||||
'/backup/import.php',
|
||||
'id',
|
||||
true
|
||||
],
|
||||
"Course copy page returns overflow" => [
|
||||
'/backup/copy.php',
|
||||
'id',
|
||||
true
|
||||
],
|
||||
"Course reset page returns overflow" => [
|
||||
'/course/reset.php',
|
||||
'id',
|
||||
true
|
||||
],
|
||||
// The following pages should not return the overflow menu.
|
||||
"Course page returns nothing" => [
|
||||
'/course/view.php',
|
||||
'id',
|
||||
false
|
||||
],
|
||||
"Question bank should return nothing" => [
|
||||
'/question/edit.php',
|
||||
'courseid',
|
||||
false
|
||||
],
|
||||
"Reports should return nothing" => [
|
||||
'/report/log/index.php',
|
||||
'id',
|
||||
false
|
||||
],
|
||||
"Participants page should return nothing" => [
|
||||
'/user/index.php',
|
||||
'id',
|
||||
false
|
||||
]
|
||||
];
|
||||
}
|
||||
}
|
||||
|
42
theme/boost/tests/behat/course_administration.feature
Normal file
42
theme/boost/tests/behat/course_administration.feature
Normal file
@ -0,0 +1,42 @@
|
||||
@javascript @theme_boost
|
||||
Feature: Course administration navigation
|
||||
As a teacher
|
||||
I can navigate to course administration pages
|
||||
|
||||
Background:
|
||||
Given the following "courses" exist:
|
||||
| fullname | shortname | newsitems |
|
||||
| Course 1 | C1 | 5 |
|
||||
And the following "users" exist:
|
||||
| username | firstname | lastname | email |
|
||||
| teacher1 | Teacher | 1 | teacher1@example.com |
|
||||
And the following "course enrolments" exist:
|
||||
| user | course | role |
|
||||
| teacher1 | C1 | editingteacher |
|
||||
|
||||
Scenario: A Teacher can navigate to the course Import page.
|
||||
Given I log in as "teacher1"
|
||||
When I am on "Course 1" course homepage
|
||||
And I navigate to "Course administration" in current page administration
|
||||
Then I should see "Find a course to import data from:"
|
||||
|
||||
Scenario Outline: A Teacher can navigate to other course administration pages.
|
||||
Given I log in as "teacher1"
|
||||
When I am on "Course 1" course homepage
|
||||
And I navigate to "Course administration" in current page administration
|
||||
And I select "<adminpage>" from the "jump" singleselect
|
||||
Then I should see "<title>"
|
||||
|
||||
Examples:
|
||||
| adminpage | title |
|
||||
| Backup | Backup settings |
|
||||
| Restore | Import a backup file |
|
||||
| Import | Find a course to import data from: |
|
||||
| Reset | Reset course |
|
||||
|
||||
Scenario: An Administrator can view the course copy page.
|
||||
Given I log in as "admin"
|
||||
When I am on "Course 1" course homepage
|
||||
And I navigate to "Course administration" in current page administration
|
||||
And I select "Copy course" from the "jump" singleselect
|
||||
Then I should see "This course will be duplicated and put into the selected course category"
|
Loading…
x
Reference in New Issue
Block a user