Skip to content

Commit

Permalink
MDL-45884 navigation: tidied up code and added behat tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Sam Hemelryk committed Jun 12, 2014
1 parent 4d378e9 commit aab6438
Show file tree
Hide file tree
Showing 4 changed files with 66 additions and 11 deletions.
2 changes: 1 addition & 1 deletion admin/settings/appearance.php
Expand Up @@ -122,7 +122,7 @@
$temp->add(new admin_setting_configcheckbox('navshowcategories', new lang_string('navshowcategories', 'admin'), new lang_string('confignavshowcategories', 'admin'), 1));
$temp->add(new admin_setting_configcheckbox('navshowmycoursecategories', new lang_string('navshowmycoursecategories', 'admin'), new lang_string('navshowmycoursecategories_help', 'admin'), 0));
$temp->add(new admin_setting_configcheckbox('navshowallcourses', new lang_string('navshowallcourses', 'admin'), new lang_string('confignavshowallcourses', 'admin'), 0));
$temp->add(new admin_setting_configcheckbox('navcollapsemycourses', new lang_string('navcollapsemycourses', 'admin'), new lang_string('confignavcollapsemycourses', 'admin'), 0));
$temp->add(new admin_setting_configcheckbox('navcollapsemycourses', new lang_string('navcollapsemycourses', 'admin'), new lang_string('navcollapsemycourses_desc', 'admin'), 0));
$sortoptions = array(
'sortorder' => new lang_string('sort_sortorder', 'admin'),
'fullname' => new lang_string('sort_fullname', 'admin'),
Expand Down
55 changes: 55 additions & 0 deletions blocks/navigation/tests/behat/collapse_my_courses_setting.feature
@@ -0,0 +1,55 @@
@block @block_navigation
Feature: Test collapse my courses navigation setting
As a student
I visit my My Moodle page and observe the the My Courses branch

Background:
Given the following "users" exist:
| username | firstname | lastname | email |
| student1 | Student | 1 | student1@asd.com |
And the following "categories" exist:
| name | category | idnumber |
| cat1 | 0 | cat1 |
And the following "courses" exist:
| fullname | shortname | category |
| Course1 | c1 | cat1 |
| Course2 | c2 | cat1 |
| Course3 | c3 | cat1 |
And the following "course enrolments" exist:
| user | course | role |
| student1 | c1 | student |
| student1 | c2 | student |

Scenario: The My Courses branch is expanded on the My Moodle page by default
When I log in as "student1"
And I follow "My home"
Then I should see "c1" in the "Navigation" "block"
And I should see "c2" in the "Navigation" "block"
And I should not see "c3" in the "Navigation" "block"

Scenario: The My Courses branch is collapsed when collapse my courses is on
Given I log in as "admin"
And I set the following administration settings values:
| Keep My Courses collapsed initially | 1 |
And I log out
Given I log in as "student1"
And I follow "My home"
Then I should not see "c1" in the "Navigation" "block"
And I should not see "c2" in the "Navigation" "block"
And I should not see "c3" in the "Navigation" "block"

@javascript
Scenario: My Courses can be expanded on the My Moodle page when collapse my courses is on
Given I log in as "admin"
And I set the following administration settings values:
| Keep My Courses collapsed initially | 1 |
And I log out
Given I log in as "student1"
And I follow "My home"
And I should not see "c1" in the "Navigation" "block"
And I should not see "c2" in the "Navigation" "block"
And I should not see "c3" in the "Navigation" "block"
And I expand "My courses" node
Then I should see "c1" in the "Navigation" "block"
And I should see "c2" in the "Navigation" "block"
And I should not see "c3" in the "Navigation" "block"
4 changes: 2 additions & 2 deletions lang/en/admin.php
Expand Up @@ -271,7 +271,6 @@
$string['confignavshowallcourses'] = 'This setting determines whether users who are enrolled in courses can see Courses (listing all courses) in the navigation, in addition to My Courses (listing courses in which they are enrolled).';
$string['confignavshowcategories'] = 'Show course categories in the navigation bar and navigation blocks. This does not occur with courses the user is currently enrolled in, they will still be listed under mycourses without categories.';
$string['confignotifyloginfailures'] = 'Send login failure notification messages to these selected users. This requires an internal logstore (eg Standard Logstore) to be enabled.';
$string['confignavcollapsemycourses'] = 'Show the My Courses area as collapsed.';
$string['confignotifyloginthreshold'] = 'If notifications about failed logins are active, how many failed login attempts by one user or one IP address is it worth notifying about?';
$string['confignotloggedinroleid'] = 'Users who are not logged in to the site will be treated as if they have this role granted to them at the site context. Guest is almost always what you want here, but you might want to create roles that are less or more restrictive. Things like creating posts still require the user to log in properly.';
$string['configopentogoogle'] = 'If you enable this setting, then Google will be allowed to enter your site as a Guest. In addition, people coming in to your site via a Google search will automatically be logged in as a Guest. Note that this only provides transparent access to courses that already allow guest access.';
Expand Down Expand Up @@ -740,7 +739,8 @@
$string['navshowallcourses'] = 'Show all courses';
$string['navshowcategories'] = 'Show course categories';
$string['navshowmycoursecategories'] = 'Show my course categories';
$string['navcollapsemycourses'] = 'Show My Courses as collapsed';
$string['navcollapsemycourses'] = 'Keep My Courses collapsed initially';
$string['navcollapsemycourses_desc'] = 'When enabled the My Courses branch will never be expanded initially. The user will need to click to expand it. At present the My Courses branch is only expanded initially when on the My Moodle page.';
$string['navshowmycoursecategories_help'] = 'If enabled courses in the users my courses branch will be shown in categories.';
$string['navsortmycoursessort'] = 'Sort my courses';
$string['navsortmycoursessort_help'] = 'This determines whether courses are listed under My courses according to the sort order (i.e. the order set in Site administration > Courses > Manage courses and categories) or alphabetically by course setting.';
Expand Down
16 changes: 8 additions & 8 deletions lib/navigationlib.php
Expand Up @@ -979,7 +979,7 @@ class global_navigation extends navigation_node {
protected $initialised = false;
/** @var array An array of course information */
protected $mycourses = array();
/** @var array An array for containing root navigation nodes */
/** @var navigation_node[] An array for containing root navigation nodes */
protected $rootnodes = array();
/** @var bool A switch for whether to show empty sections in the navigation */
protected $showemptysections = true;
Expand Down Expand Up @@ -1133,13 +1133,13 @@ public function initialise() {
$this->rootnodes['courses']->isexpandable = true;
}

if (empty($CFG->navcollapsemycourses)){
if ($this->rootnodes['mycourses']->isactive) {
$this->load_courses_enrolled();
}
} else {
$this->rootnodes['mycourses']->collapse = true;
$this->rootnodes['mycourses']->make_inactive();
// Load the users enrolled courses if they are viewing the My Moodle page AND the admin has not
// set that they wish to keep the My Courses branch collapsed by default.
if (empty($CFG->navcollapsemycourses) && $this->rootnodes['mycourses']->isactive){
$this->load_courses_enrolled();
} else {
$this->rootnodes['mycourses']->collapse = true;
$this->rootnodes['mycourses']->make_inactive();
}

$canviewcourseprofile = true;
Expand Down

0 comments on commit aab6438

Please sign in to comment.