From ff9a0f8289b4bf6e8d5e873a93bba957c5e6783c Mon Sep 17 00:00:00 2001 From: Damyon Wiese Date: Wed, 9 Jan 2019 14:59:32 +0800 Subject: [PATCH] MDL-63578 assign: Better page titles Use the context function get_context_name() to set the page title. This will change it from "Assignment" to "C1: Important foods to eat". The get_context_name() for activity modules is updated to include the course short name (not the name of the activity type). --- mod/assign/lang/en/assign.php | 1 + mod/assign/locallib.php | 9 ++++- mod/assign/renderer.php | 10 ++++-- mod/assign/tests/behat/page_titles.feature | 38 ++++++++++++++++++++++ 4 files changed, 55 insertions(+), 3 deletions(-) create mode 100644 mod/assign/tests/behat/page_titles.feature diff --git a/mod/assign/lang/en/assign.php b/mod/assign/lang/en/assign.php index 6ecb1e2f110..53a5134fead 100644 --- a/mod/assign/lang/en/assign.php +++ b/mod/assign/lang/en/assign.php @@ -553,6 +553,7 @@ $string['submittedearly'] = 'Assignment was submitted {$a} early'; $string['submittedlate'] = 'Assignment was submitted {$a} late'; $string['submittedlateshort'] = '{$a} late'; $string['submitted'] = 'Submitted'; +$string['subpagetitle'] = '{$a->contextname} - {$a->subpage}'; $string['subplugintype_assignsubmission'] = 'Submission plugin'; $string['subplugintype_assignsubmission_plural'] = 'Submission plugins'; $string['subplugintype_assignfeedback'] = 'Feedback plugin'; diff --git a/mod/assign/locallib.php b/mod/assign/locallib.php index c2a9d0d6d0d..4af6984ab59 100644 --- a/mod/assign/locallib.php +++ b/mod/assign/locallib.php @@ -4448,7 +4448,14 @@ class assign { $PAGE->set_pagelayout('embedded'); - $PAGE->set_title($this->get_context()->get_context_name()); + $courseshortname = $this->get_context()->get_course_context()->get_context_name(false, true); + $args = [ + 'contextname' => $this->get_context()->get_context_name(false, true), + 'subpage' => get_string('grading', 'assign') + ]; + $title = get_string('subpagetitle', 'assign', $args); + $title = $courseshortname . ': ' . $title; + $PAGE->set_title($title); $o .= $this->get_renderer()->header(); diff --git a/mod/assign/renderer.php b/mod/assign/renderer.php index 858f9519f6d..51e57864996 100644 --- a/mod/assign/renderer.php +++ b/mod/assign/renderer.php @@ -220,13 +220,19 @@ class mod_assign_renderer extends plugin_renderer_base { if ($header->subpage) { $this->page->navbar->add($header->subpage); + $args = ['contextname' => $header->context->get_context_name(false, true), 'subpage' => $header->subpage]; + $title = get_string('subpagetitle', 'assign', $args); + } else { + $title = $header->context->get_context_name(false, true); } + $courseshortname = $header->context->get_course_context()->get_context_name(false, true); + $title = $courseshortname . ': ' . $title; + $heading = format_string($header->assign->name, false, array('context' => $header->context)); - $this->page->set_title(get_string('pluginname', 'assign')); + $this->page->set_title($title); $this->page->set_heading($this->page->course->fullname); $o .= $this->output->header(); - $heading = format_string($header->assign->name, false, array('context' => $header->context)); $o .= $this->output->heading($heading); if ($header->preface) { $o .= $header->preface; diff --git a/mod/assign/tests/behat/page_titles.feature b/mod/assign/tests/behat/page_titles.feature new file mode 100644 index 00000000000..cee78934c59 --- /dev/null +++ b/mod/assign/tests/behat/page_titles.feature @@ -0,0 +1,38 @@ +@mod @mod_assign +Feature: In an assignment, page titles are informative + In order to know I am viewing the correct page + The page titles need to reflect the current assignment and action + + Background: + Given the following "courses" exist: + | fullname | shortname | category | groupmode | + | Course 1 | C1 | 0 | 1 | + And the following "users" exist: + | username | firstname | lastname | email | + | teacher1 | Teacher | 1 | teacher1@example.com | + | student1 | Student | 1 | student1@example.com | + And the following "course enrolments" exist: + | user | course | role | + | teacher1 | C1 | editingteacher | + | student1 | C1 | student | + And the following "activities" exist: + | activity | course | idnumber | name | intro | assignsubmission_onlinetext_enabled | + | assign | C1 | ants1 | History of ants | Tell me the history of ants | 1 | + + Scenario: I view an assignment as a student and take an action + When I log in as "student1" + And I am on "Course 1" course homepage + Then I follow "History of ants" + And "title[text() = 'C1: History of ants']" "xpath_element" should exist in the "head" "css_element" + And I press "Add submission" + And "title[text() = 'C1: History of ants - Edit submission']" "xpath_element" should exist in the "head" "css_element" + + Scenario: I view an assignment as a teacher and take an action + When I log in as "teacher1" + And I am on "Course 1" course homepage + Then I follow "History of ants" + And "title[text() = 'C1: History of ants']" "xpath_element" should exist in the "head" "css_element" + And I navigate to "View all submissions" in current page administration + And "title[text() = 'C1: History of ants - Grading']" "xpath_element" should exist in the "head" "css_element" + And I click on "Grade" "link" in the "Student 1" "table_row" + And "title[text() = 'C1: History of ants - Grading']" "xpath_element" should exist in the "head" "css_element"