Merge branch 'wip-MDL-27809-master-r7' of git://github.com/samhemelryk/moodle

This commit is contained in:
Eloy Lafuente (stronk7)
2011-06-27 10:11:02 +02:00
3 changed files with 427 additions and 355 deletions
+16 -12
View File
@@ -33,9 +33,9 @@
require_once('../config.php');
require_once($CFG->dirroot.'/course/lib.php');
$id = required_param('id', PARAM_INT);
$switchrole = optional_param('switchrole',-1, PARAM_INT);
$returnurlkey = optional_param('returnurl', false, PARAM_INT);
$id = required_param('id', PARAM_INT);
$switchrole = optional_param('switchrole',-1, PARAM_INT);
$returnurl = optional_param('returnurl', false, PARAM_URL);
$PAGE->set_url('/course/switchrole.php', array('id'=>$id));
@@ -69,17 +69,21 @@ if ($switchrole > 0 && has_capability('moodle/role:switchroles', $context)) {
}
}
$returnurl = false;
if ($returnurlkey && !empty($SESSION->returnurl) && strpos($SESSION->returnurl, 'moodle_url')!==false) {
$returnurl = @unserialize($SESSION->returnurl);
if (!($returnurl instanceof moodle_url)) {
$returnurl = false;
// TODO: Using SESSION->returnurl is deprecated and should be removed in the future.
// Till then this code remains to support any external applications calling this script.
if (!empty($returnurl) && is_numeric($returnurl)) {
$returnurl = false;
if (!empty($SESSION->returnurl) && strpos($SESSION->returnurl, 'moodle_url')!==false) {
debugging('Code calling switchrole should be passing a URL as a param.', DEBUG_DEVELOPER);
$returnurl = @unserialize($SESSION->returnurl);
if (!($returnurl instanceof moodle_url)) {
$returnurl = false;
}
}
unset($SESSION->returnurl);
}
if ($returnurl===false) {
$returnurl = new moodle_url('/course/view.php', array('id'=>$course->id));
if ($returnurl === false) {
$returnurl = new moodle_url('/course/view.php', array('id' => $course->id));
}
redirect($returnurl);
redirect($returnurl);
+406 -314
View File
File diff suppressed because it is too large Load Diff
+5 -29
View File
@@ -316,14 +316,10 @@ class global_navigation_test extends UnitTestCase {
* @var global_navigation
*/
public $node;
protected $cache;
protected $modinfo5 = 'O:6:"object":6:{s:8:"courseid";s:1:"5";s:6:"userid";s:1:"2";s:8:"sections";a:1:{i:0;a:1:{i:0;s:3:"288";}}s:3:"cms";a:1:{i:288;O:6:"object":17:{s:2:"id";s:3:"288";s:8:"instance";s:2:"19";s:6:"course";s:1:"5";s:7:"modname";s:5:"forum";s:4:"name";s:10:"News forum";s:7:"visible";s:1:"1";s:10:"sectionnum";s:1:"0";s:9:"groupmode";s:1:"0";s:10:"groupingid";s:1:"0";s:16:"groupmembersonly";s:1:"0";s:6:"indent";s:1:"0";s:10:"completion";s:1:"0";s:5:"extra";s:0:"";s:4:"icon";s:0:"";s:11:"uservisible";b:1;s:9:"modplural";s:6:"Forums";s:9:"available";b:1;}}s:9:"instances";a:1:{s:5:"forum";a:1:{i:19;R:8;}}s:6:"groups";N;}';
protected $coursesections5 = 'a:5:{i:0;O:8:"stdClass":6:{s:7:"section";s:1:"0";s:2:"id";s:2:"14";s:6:"course";s:1:"5";s:7:"summary";N;s:8:"sequence";s:3:"288";s:7:"visible";s:1:"1";}i:1;O:8:"stdClass":6:{s:7:"section";s:1:"1";s:2:"id";s:2:"97";s:6:"course";s:1:"5";s:7:"summary";s:0:"";s:8:"sequence";N;s:7:"visible";s:1:"1";}i:2;O:8:"stdClass":6:{s:7:"section";s:1:"2";s:2:"id";s:2:"98";s:6:"course";s:1:"5";s:7:"summary";s:0:"";s:8:"sequence";N;s:7:"visible";s:1:"1";}i:3;O:8:"stdClass":6:{s:7:"section";s:1:"3";s:2:"id";s:2:"99";s:6:"course";s:1:"5";s:7:"summary";s:0:"";s:8:"sequence";N;s:7:"visible";s:1:"1";}i:4;O:8:"stdClass":6:{s:7:"section";s:1:"4";s:2:"id";s:3:"100";s:6:"course";s:1:"5";s:7:"summary";s:0:"";s:8:"sequence";N;s:7:"visible";s:1:"1";}}';
public static $includecoverage = array('./lib/navigationlib.php');
public static $excludecoverage = array();
public function setUp() {
$this->cache = new navigation_cache('simpletest_nav');
$this->node = new exposed_global_navigation();
// Create an initial tree structure to work with
$cat1 = $this->node->add('category 1', null, navigation_node::TYPE_CATEGORY, null, 'cat1');
@@ -335,45 +331,25 @@ class global_navigation_test extends UnitTestCase {
$course1 = $sub2->add('course 1', null, navigation_node::TYPE_COURSE, null, 'course1');
$course2 = $sub2->add('course 2', null, navigation_node::TYPE_COURSE, null, 'course2');
$course3 = $sub2->add('course 3', null, navigation_node::TYPE_COURSE, null, 'course3');
$section1 = $course2->add('section 1', null, navigation_node::TYPE_COURSE, null, 'sec1');
$section2 = $course2->add('section 2', null, navigation_node::TYPE_COURSE, null, 'sec2');
$section3 = $course2->add('section 3', null, navigation_node::TYPE_COURSE, null, 'sec3');
$section1 = $course2->add('section 1', null, navigation_node::TYPE_SECTION, null, 'sec1');
$section2 = $course2->add('section 2', null, navigation_node::TYPE_SECTION, null, 'sec2');
$section3 = $course2->add('section 3', null, navigation_node::TYPE_SECTION, null, 'sec3');
$act1 = $section2->add('activity 1', null, navigation_node::TYPE_ACTIVITY, null, 'act1');
$act2 = $section2->add('activity 2', null, navigation_node::TYPE_ACTIVITY, null, 'act2');
$act3 = $section2->add('activity 3', null, navigation_node::TYPE_ACTIVITY, null, 'act3');
$res1 = $section2->add('resource 1', null, navigation_node::TYPE_RESOURCE, null, 'res1');
$res2 = $section2->add('resource 2', null, navigation_node::TYPE_RESOURCE, null, 'res2');
$res3 = $section2->add('resource 3', null, navigation_node::TYPE_RESOURCE, null, 'res3');
}
$this->cache->clear();
$this->cache->modinfo5 = unserialize($this->modinfo5);
$this->cache->coursesections5 = unserialize($this->coursesections5);
$this->cache->canviewhiddenactivities = true;
$this->cache->canviewhiddensections = true;
$this->cache->canviewhiddencourses = true;
$sub2->add('Test Course 5', new moodle_url('http://moodle.org'),navigation_node::TYPE_COURSE,null,'5');
}
public function test_load_generic_course_sections() {
$coursenode = $this->node->find('5', navigation_node::TYPE_COURSE);
$course = new stdClass;
$course->id = '5';
$course->numsections = 10;
$course->modinfo = $this->modinfo5;
$this->node->load_generic_course_sections($course, $coursenode, 'topic', 'topic');
$this->assertEqual($coursenode->children->count(),1);
}
public function test_format_display_course_content() {
$this->assertTrue($this->node->exposed_format_display_course_content('topic'));
$this->assertFalse($this->node->exposed_format_display_course_content('scorm'));
$this->assertTrue($this->node->exposed_format_display_course_content('dummy'));
}
public function test_module_extends_navigation() {
$this->cache->test1_extends_navigation = true;
$this->cache->test2_extends_navigation = false;
$this->assertTrue($this->node->exposed_module_extends_navigation('data'));
$this->assertTrue($this->node->exposed_module_extends_navigation('test1'));
$this->assertFalse($this->node->exposed_module_extends_navigation('test2'));
$this->assertFalse($this->node->exposed_module_extends_navigation('test3'));
$this->assertFalse($this->node->exposed_module_extends_navigation('test1'));
}
}