Skip to content

Commit

Permalink
MDL-72930 navigation: Changes to the secondary view unit tests.
Browse files Browse the repository at this point in the history
The display of the arrays has been changed and so updates were
necessary for the unit tests as well due to changing output.
  • Loading branch information
abgreeve committed Jan 4, 2022
1 parent 060e5de commit f85662d
Showing 1 changed file with 6 additions and 84 deletions.
90 changes: 6 additions & 84 deletions lib/tests/navigation/views/secondary_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -514,9 +514,7 @@ public function test_get_menu_array(string $selected, array $expected) {
$secondary = new secondary($PAGE);
$secondary->add_node($this->generate_node_tree_construct($structure, 'primarynode'));
$selectednode = $secondary->find($selected, null);
$method = new ReflectionMethod('core\navigation\views\secondary', 'get_menu_array');
$method->setAccessible(true);
$response = $method->invoke($secondary, $selectednode);
$response = \core\navigation\views\secondary::create_menu_element([$selectednode]);

$this->assertSame($expected, $response);
}
Expand Down Expand Up @@ -544,7 +542,7 @@ public function test_get_menu_array_provider(): array {
"Fetch information from a node with children" => [
'child2',
[
'https://www.example.com/moodle/test.php' => 'child2',
'https://www.example.com/moodle/test.php' => 'child2.3',
'https://www.example.com/moodle/view/course.php?child=2' => 'child2.1',
'https://www.example.com/moodle/view/admin.php?child=2' => 'child2.2'
],
Expand All @@ -557,22 +555,18 @@ public function test_get_menu_array_provider(): array {
'parentnode1',
[
[
'parentnode1' => [
'https://www.example.com/moodle/my' => 'child1'
],
'child2' => [
'https://www.example.com/moodle/test.php' => 'child2',
'https://www.example.com/moodle/view/course.php?child=2' => 'child2.1',
'https://www.example.com/moodle/view/admin.php?child=2' => 'child2.2',
]
],
[
],
'child3' => [
'https://www.example.com/moodle/view/course.php?child=3' => 'child3.1',
'https://www.example.com/moodle/view/admin.php?child=3' => 'child3.2'
]
],
[
'parentnode1' => [
'https://www.example.com/moodle/my' => 'child1'
]
]
],
],
Expand Down Expand Up @@ -657,78 +651,6 @@ public function test_get_node_with_first_action_provider(): array {
];
}

/**
* Test for get_additional_child_nodes
*
* @param string $selectedkey
* @param array $expected
* @dataProvider test_get_additional_child_nodes_provider
*/
public function test_get_additional_child_nodes(string $selectedkey, array $expected) {
global $PAGE;
$structure = [
'parentnode1' => [
'child1' => '/my',
'child2' => [
'action' => '/test.php',
'children' => [
'child2.1' => '/view/course.php?child=2',
'child2.2' => '/view/admin.php?child=2',
]
],
'child3' => [
'child3.1' => '/view/course.php?child=3',
'child3.2' => '/view/admin.php?child=3',
]
],
'parentnode2' => "/view/module.php"
];

$secondary = new secondary($PAGE);
$nodes = $this->generate_node_tree_construct($structure, 'primarynode');
$selectednode = $nodes->find($selectedkey, null);
$method = new ReflectionMethod('core\navigation\views\secondary', 'get_additional_child_nodes');
$method->setAccessible(true);
$response = $method->invoke($secondary, $selectednode);

$this->assertSame($expected, $response);
}

/**
* Provider for test_get_additional_child_nodes
*
* @return array[]
*/
public function test_get_additional_child_nodes_provider(): array {
return [
"Get nodes with deep nested children" => [
"parentnode1",
[
'https://www.example.com/moodle/my' => 'child1',
'https://www.example.com/moodle/test.php' => 'child2',
'https://www.example.com/moodle/view/course.php?child=2' => 'child2.1',
'https://www.example.com/moodle/view/admin.php?child=2' => 'child2.2',
'https://www.example.com/moodle/view/course.php?child=3' => 'child3.1',
'https://www.example.com/moodle/view/admin.php?child=3' => 'child3.2',
]
],
"Get children from parent without action " => [
"child3",
[
'https://www.example.com/moodle/view/course.php?child=3' => 'child3.1',
'https://www.example.com/moodle/view/admin.php?child=3' => 'child3.2'
]
],
"Get children from parent with action " => [
"child2",
[
'https://www.example.com/moodle/view/course.php?child=2' => 'child2.1',
'https://www.example.com/moodle/view/admin.php?child=2' => 'child2.2'
]
],
];
}

/**
* Test the get_overflow_menu_data function
*
Expand Down

0 comments on commit f85662d

Please sign in to comment.