Merge branch 'MDL-71084-master' of git://github.com/peterRd/moodle

This commit is contained in:
Travis CI 2021-03-23 13:57:13 +08:00
commit fa7c534032
4 changed files with 33 additions and 13 deletions

View file

@ -35,6 +35,7 @@ $string['activities_help'] = 'Activities, such as forums, quizzes and wikis, ena
$string['activity'] = 'Activity'; $string['activity'] = 'Activity';
$string['activityclipboard'] = 'Moving this activity: {$a}'; $string['activityclipboard'] = 'Moving this activity: {$a}';
$string['activityiscurrentlyhidden'] = 'Sorry, this activity is currently hidden'; $string['activityiscurrentlyhidden'] = 'Sorry, this activity is currently hidden';
$string['activityheader'] = 'Activity menu';
$string['activitymodule'] = 'Activity module'; $string['activitymodule'] = 'Activity module';
$string['activitymodules'] = 'Activity modules'; $string['activitymodules'] = 'Activity modules';
$string['activityreport'] = 'Activity report'; $string['activityreport'] = 'Activity report';
@ -310,6 +311,7 @@ $string['costdefault'] = 'Default cost';
$string['counteditems'] = '{$a->count} {$a->items}'; $string['counteditems'] = '{$a->count} {$a->items}';
$string['country'] = 'Country'; $string['country'] = 'Country';
$string['course'] = 'Course'; $string['course'] = 'Course';
$string['courseheader'] = 'Course menu';
$string['courseadministration'] = 'Course administration'; $string['courseadministration'] = 'Course administration';
$string['courseapprovedemail'] = 'Your requested course, {$a->name}, has been approved and you have been made a {$a->teacher}. To access your new course, go to {$a->url}'; $string['courseapprovedemail'] = 'Your requested course, {$a->name}, has been approved and you have been made a {$a->teacher}. To access your new course, go to {$a->url}';
$string['courseapprovedemail2'] = 'Your requested course, {$a->name}, has been approved. To access your new course, go to {$a->url}'; $string['courseapprovedemail2'] = 'Your requested course, {$a->name}, has been approved. To access your new course, go to {$a->url}';
@ -1195,6 +1197,7 @@ $string['logs'] = 'Logs';
$string['logtoomanycourses'] = '[ <a href="{$a->url}">more</a> ]'; $string['logtoomanycourses'] = '[ <a href="{$a->url}">more</a> ]';
$string['logtoomanyusers'] = '[ <a href="{$a->url}">more</a> ]'; $string['logtoomanyusers'] = '[ <a href="{$a->url}">more</a> ]';
$string['lookback'] = 'Look back'; $string['lookback'] = 'Look back';
$string['menu'] = 'Menu';
$string['mailadmins'] = 'Inform admins'; $string['mailadmins'] = 'Inform admins';
$string['mailstudents'] = 'Inform students'; $string['mailstudents'] = 'Inform students';
$string['mailteachers'] = 'Inform teachers'; $string['mailteachers'] = 'Inform teachers';

View file

@ -30,6 +30,8 @@ use navigation_node;
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/ */
class secondary extends view { class secondary extends view {
/** @var string $headertitle The header for this particular menu*/
public $headertitle;
/** /**
* Defines the default structure for the secondary nav in a course context. * Defines the default structure for the secondary nav in a course context.
* *
@ -116,14 +118,17 @@ class secondary extends view {
} }
$this->id = 'secondary_navigation'; $this->id = 'secondary_navigation';
$context = $this->context; $context = $this->context;
$this->headertitle = get_string('menu');
switch ($context->contextlevel) { switch ($context->contextlevel) {
case CONTEXT_COURSE: case CONTEXT_COURSE:
if ($this->page->course->id != $SITE->id) { if ($this->page->course->id != $SITE->id) {
$this->headertitle = get_string('courseheader');
$this->load_course_navigation(); $this->load_course_navigation();
} }
break; break;
case CONTEXT_MODULE: case CONTEXT_MODULE:
$this->headertitle = get_string('activityheader');
$this->load_module_navigation(); $this->load_module_navigation();
break; break;
case CONTEXT_SYSTEM: case CONTEXT_SYSTEM:

View file

@ -36,6 +36,8 @@ abstract class view extends navigation_node {
protected $page; protected $page;
/** @var bool $initialised A switch to see if the navigation node is initialised */ /** @var bool $initialised A switch to see if the navigation node is initialised */
protected $initialised = false; protected $initialised = false;
/** @var navigation_node $activenode A string identifier for the active node*/
public $activenode;
/** /**
* Function to initialise the respective view * Function to initialise the respective view
@ -116,7 +118,9 @@ abstract class view extends navigation_node {
$child->make_inactive(); $child->make_inactive();
} else { } else {
$child->make_active(); $child->make_active();
$this->activenode = $child;
} }
return $node; // We have found the active node, set the parent status, no need to continue. return $node; // We have found the active node, set the parent status, no need to continue.
} }
} }

View file

@ -14,7 +14,10 @@
// You should have received a copy of the GNU General Public License // You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>. // along with Moodle. If not, see <http://www.gnu.org/licenses/>.
use core\navigation\views\secondary; namespace core\navigation\views;
use navigation_node;
use ReflectionMethod;
/** /**
* Class core_secondary_testcase * Class core_secondary_testcase
@ -26,7 +29,7 @@ use core\navigation\views\secondary;
* @copyright 2021 onwards Peter Dias * @copyright 2021 onwards Peter Dias
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/ */
class core_secondary_testcase extends advanced_testcase { class secondary_test extends \advanced_testcase {
/** /**
* Test the get_leaf_nodes function * Test the get_leaf_nodes function
* @param float $siteorder The order for the siteadmin node * @param float $siteorder The order for the siteadmin node
@ -81,9 +84,12 @@ class core_secondary_testcase extends advanced_testcase {
* *
* @param string $context The context to setup for - course, module, system * @param string $context The context to setup for - course, module, system
* @param string $expectedfirstnode The expected first node * @param string $expectedfirstnode The expected first node
* @param string $header The expected string
* @param string $activenode The expected active node
* @dataProvider test_setting_initialise_provider * @dataProvider test_setting_initialise_provider
*/ */
public function test_setting_initialise(string $context, string $expectedfirstnode) { public function test_setting_initialise(string $context, string $expectedfirstnode,
string $header, string $activenode) {
global $PAGE, $SITE; global $PAGE, $SITE;
$this->resetAfterTest(); $this->resetAfterTest();
$this->setAdminUser(); $this->setAdminUser();
@ -92,21 +98,21 @@ class core_secondary_testcase extends advanced_testcase {
switch ($context) { switch ($context) {
case 'course': case 'course':
$pagecourse = $this->getDataGenerator()->create_course(); $pagecourse = $this->getDataGenerator()->create_course();
$contextrecord = context_course::instance($pagecourse->id, MUST_EXIST); $contextrecord = \context_course::instance($pagecourse->id, MUST_EXIST);
$pageurl = new moodle_url('/course/view.php', ['id' => $pagecourse->id]); $pageurl = new \moodle_url('/course/view.php', ['id' => $pagecourse->id]);
break; break;
case 'module': case 'module':
$pagecourse = $this->getDataGenerator()->create_course(); $pagecourse = $this->getDataGenerator()->create_course();
$assign = $this->getDataGenerator()->create_module('assign', ['course' => $pagecourse->id]); $assign = $this->getDataGenerator()->create_module('assign', ['course' => $pagecourse->id]);
$cm = get_coursemodule_from_id('assign', $assign->cmid); $cm = get_coursemodule_from_id('assign', $assign->cmid);
$contextrecord = context_module::instance($cm->id); $contextrecord = \context_module::instance($cm->id);
$pageurl = new moodle_url('/mod/assign/view.php', ['id' => $cm->instance]); $pageurl = new \moodle_url('/mod/assign/view.php', ['id' => $cm->instance]);
$PAGE->set_cm($cm); $PAGE->set_cm($cm);
break; break;
case 'system': case 'system':
$contextrecord = context_system::instance(); $contextrecord = \context_system::instance();
$PAGE->set_pagelayout('admin'); $PAGE->set_pagelayout('admin');
$pageurl = new moodle_url('/admin/index.php'); $pageurl = new \moodle_url('/admin/index.php');
} }
$PAGE->set_url($pageurl); $PAGE->set_url($pageurl);
@ -116,7 +122,9 @@ class core_secondary_testcase extends advanced_testcase {
$node = new secondary($PAGE); $node = new secondary($PAGE);
$node->initialise(); $node->initialise();
$children = $node->get_children_key_list(); $children = $node->get_children_key_list();
$this->assertEquals($children[0], $expectedfirstnode); $this->assertEquals($expectedfirstnode, $children[0]);
$this->assertEquals(get_string($header), $node->headertitle);
$this->assertEquals($activenode, $node->activenode->text);
} }
/** /**
@ -125,9 +133,9 @@ class core_secondary_testcase extends advanced_testcase {
*/ */
public function test_setting_initialise_provider(): array { public function test_setting_initialise_provider(): array {
return [ return [
'Testing in a course context' => ['course', 'coursehome'], 'Testing in a course context' => ['course', 'coursehome', 'courseheader', 'Course Page'],
'Testing in a module context' => ['module', 'modulepage'], 'Testing in a module context' => ['module', 'modulepage', 'activityheader', 'Activity'],
'Testing in a site admin' => ['system', 'siteadminnode'], 'Testing in a site admin' => ['system', 'siteadminnode', 'menu', 'Site administration'],
]; ];
} }
} }