Skip to content

Commit

Permalink
MDL-72090 navigation: New unit and behat tests for navigation.
Browse files Browse the repository at this point in the history
This adds new tests for functions that impact the more menu and
the course administration overflow.
  • Loading branch information
abgreeve committed Dec 9, 2021
1 parent d022741 commit 89d749f
Show file tree
Hide file tree
Showing 2 changed files with 141 additions and 0 deletions.
99 changes: 99 additions & 0 deletions lib/tests/navigation/views/secondary_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

use navigation_node;
use ReflectionMethod;
use moodle_url;

/**
* Class core_secondary_testcase
Expand Down Expand Up @@ -738,6 +739,8 @@ public function test_get_additional_child_nodes_provider(): array {
*/
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' => [
Expand All @@ -752,6 +755,11 @@ public function test_get_overflow_menu_data(string $selectedurl, bool $expectedn
],
'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');
Expand Down Expand Up @@ -815,4 +823,95 @@ public function test_get_overflow_menu_data_provider(): array {
],
];
}

/**
* 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 changes: 42 additions & 0 deletions theme/boost/tests/behat/course_administration.feature
Original file line number Diff line number Diff line change
@@ -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"

0 comments on commit 89d749f

Please sign in to comment.