Merge branch 'MDL-29478' of git://github.com/stronk7/moodle
This commit is contained in:
+3
-3
@@ -844,7 +844,7 @@ function blog_get_headers($courseid=null, $groupid=null, $userid=null, $tagid=nu
|
||||
|
||||
$a = new stdClass();
|
||||
$a->user = fullname($user);
|
||||
$a->course = format_string($course->fullname, true, array('context' => get_context_instance(CONTEXT_COURSE, $courseid)));
|
||||
$a->course = format_string($course->fullname, true, array('context' => get_context_instance(CONTEXT_COURSE, $course->id)));
|
||||
$a->type = get_string('course');
|
||||
$headers['heading'] = get_string('blogentriesbyuseraboutcourse', 'blog', $a);
|
||||
$headers['stradd'] = get_string('blogaboutthis', 'blog', $a);
|
||||
@@ -870,7 +870,7 @@ function blog_get_headers($courseid=null, $groupid=null, $userid=null, $tagid=nu
|
||||
|
||||
$a = new stdClass();
|
||||
$a->group = $group->name;
|
||||
$a->course = format_string($course->fullname, true, array('context' => get_context_instance(CONTEXT_COURSE, $courseid)));
|
||||
$a->course = format_string($course->fullname, true, array('context' => get_context_instance(CONTEXT_COURSE, $course->id)));
|
||||
$a->type = get_string('course');
|
||||
$headers['heading'] = get_string('blogentriesbygroupaboutcourse', 'blog', $a);
|
||||
$headers['stradd'] = get_string('blogaboutthis', 'blog', $a);
|
||||
@@ -927,7 +927,7 @@ function blog_get_headers($courseid=null, $groupid=null, $userid=null, $tagid=nu
|
||||
$PAGE->set_heading("$siteshortname: $courseshortname: " . get_string('blogentries', 'blog'));
|
||||
$a = new stdClass();
|
||||
$a->type = get_string('course');
|
||||
$headers['heading'] = get_string('blogentriesabout', 'blog', format_string($course->fullname, true, array('context' => get_context_instance(CONTEXT_COURSE, $courseid))));
|
||||
$headers['heading'] = get_string('blogentriesabout', 'blog', format_string($course->fullname, true, array('context' => get_context_instance(CONTEXT_COURSE, $course->id))));
|
||||
$headers['stradd'] = get_string('blogaboutthis', 'blog', $a);
|
||||
$headers['strview'] = get_string('viewblogentries', 'blog', $a);
|
||||
$blogurl->remove_params(array('userid'));
|
||||
|
||||
@@ -26,13 +26,14 @@
|
||||
*/
|
||||
|
||||
require_once($CFG->dirroot . '/blog/locallib.php');
|
||||
require_once($CFG->dirroot . '/blog/lib.php');
|
||||
|
||||
/**
|
||||
* Test functions that rely on the DB tables
|
||||
*/
|
||||
class bloglib_test extends UnitTestCaseUsingDatabase {
|
||||
|
||||
public static $includecoverage = array('blog/locallib.php');
|
||||
public static $includecoverage = array('blog/locallib.php', 'blog/lib.php');
|
||||
|
||||
private $courseid; // To store important ids to be used in tests
|
||||
private $groupid;
|
||||
|
||||
@@ -225,7 +225,7 @@ class moodle_page_test extends UnitTestCase {
|
||||
|
||||
public function test_pagetype_defaults_to_script() {
|
||||
// Exercise SUT and validate
|
||||
$this->assertEqual('admin-report-unittest-index', $this->testpage->pagetype);
|
||||
$this->assertEqual('admin-tool-unittest-index', $this->testpage->pagetype);
|
||||
}
|
||||
|
||||
public function test_set_pagetype() {
|
||||
@@ -239,7 +239,7 @@ class moodle_page_test extends UnitTestCase {
|
||||
// Exercise SUT
|
||||
$this->testpage->initialise_default_pagetype('admin/tool/unittest/index.php');
|
||||
// Validate
|
||||
$this->assertEqual('admin-report-unittest-index', $this->testpage->pagetype);
|
||||
$this->assertEqual('admin-tool-unittest-index', $this->testpage->pagetype);
|
||||
}
|
||||
|
||||
public function test_initialise_default_pagetype_fp() {
|
||||
|
||||
@@ -39,16 +39,51 @@ class rating_db_test extends UnitTestCaseUsingDatabase {
|
||||
|
||||
protected $testtables = array(
|
||||
'lib' => array(
|
||||
'rating', 'scale'));
|
||||
'rating', 'scale', 'context', 'capabilities', 'role_assignments', 'role_capabilities', 'course'));
|
||||
|
||||
protected $syscontext;
|
||||
protected $neededcaps = array('view', 'viewall', 'viewany', 'rate');
|
||||
protected $originaldefaultfrontpageroleid;
|
||||
|
||||
public function setUp() {
|
||||
global $CFG;
|
||||
parent::setUp();
|
||||
|
||||
$this->switch_to_test_db(); // Switch to test DB for all the execution
|
||||
// Make sure accesslib has cached a sensible system context object
|
||||
// before we switch to the test DB.
|
||||
$this->syscontext = get_context_instance(CONTEXT_SYSTEM);
|
||||
|
||||
foreach ($this->testtables as $dir => $tables) {
|
||||
$this->create_test_tables($tables, $dir); // Create tables
|
||||
}
|
||||
|
||||
$this->switch_to_test_db(); // Switch to test DB for all the execution
|
||||
|
||||
$this->fill_records();
|
||||
|
||||
// Ignore any frontpageroleid, that would require to crete more contexts
|
||||
$this->originaldefaultfrontpageroleid = $CFG->defaultfrontpageroleid;
|
||||
$CFG->defaultfrontpageroleid = null;
|
||||
}
|
||||
|
||||
public function tearDown() {
|
||||
global $CFG;
|
||||
// Recover original frontpageroleid
|
||||
$CFG->defaultfrontpageroleid = $this->originaldefaultfrontpageroleid;
|
||||
parent::tearDown();
|
||||
}
|
||||
|
||||
private function fill_records() {
|
||||
global $DB;
|
||||
|
||||
// Set up systcontext in the test database.
|
||||
$this->syscontext->id = $this->testdb->insert_record('context', $this->syscontext);
|
||||
|
||||
// Add the capabilities used by ratings
|
||||
foreach ($this->neededcaps as $neededcap) {
|
||||
$this->testdb->insert_record('capabilities', (object)array('name' => 'moodle/rating:' . $neededcap,
|
||||
'contextlevel' => CONTEXT_COURSE));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -57,7 +92,7 @@ class rating_db_test extends UnitTestCaseUsingDatabase {
|
||||
function test_get_ratings_sql() {
|
||||
|
||||
// We load 3 items. Each is rated twice. For simplicity itemid == user id of the item owner
|
||||
$ctxid = SYSCONTEXTID;
|
||||
$ctxid = $this->syscontext->id;
|
||||
$this->load_test_data('rating',
|
||||
array('contextid', 'component', 'ratingarea', 'itemid', 'scaleid', 'rating', 'userid', 'timecreated', 'timemodified'), array(
|
||||
|
||||
@@ -86,13 +121,13 @@ class rating_db_test extends UnitTestCaseUsingDatabase {
|
||||
|
||||
// Prepare the default options
|
||||
$defaultoptions = array (
|
||||
'context' => get_context_instance(CONTEXT_SYSTEM),
|
||||
'context' => $this->syscontext,
|
||||
'component' => 'mod_forum',
|
||||
'ratingarea' => 'post',
|
||||
'scaleid' => 10,
|
||||
'aggregate' => RATING_AGGREGATE_AVERAGE);
|
||||
|
||||
$rm = new rating_manager();
|
||||
$rm = new mockup_rating_manager();
|
||||
|
||||
// STEP 1: Retreive ratings using the current user
|
||||
|
||||
@@ -223,3 +258,21 @@ class rating_db_test extends UnitTestCaseUsingDatabase {
|
||||
$this->assertEqual($result[0]->rating->aggregate, 3);//should still get the aggregate
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* rating_manager subclass for unit testing without requiring capabilities to be loaded
|
||||
*/
|
||||
class mockup_rating_manager extends rating_manager {
|
||||
|
||||
/**
|
||||
* Overwrite get_plugin_permissions_array() so it always return granted perms for unit testing
|
||||
*/
|
||||
public function get_plugin_permissions_array($contextid, $component, $ratingarea) {
|
||||
return array(
|
||||
'rate' => true,
|
||||
'view' => true,
|
||||
'viewany' => true,
|
||||
'viewall' => true);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user