Skip to content

Commit

Permalink
Merge branch 'MDL-29478' of git://github.com/stronk7/moodle
Browse files Browse the repository at this point in the history
  • Loading branch information
Sam Hemelryk committed Sep 25, 2011
2 parents fea98bd + e437d9f commit 0ebe676
Show file tree
Hide file tree
Showing 4 changed files with 65 additions and 11 deletions.
6 changes: 3 additions & 3 deletions blog/lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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);
Expand Down Expand Up @@ -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'));
Expand Down
3 changes: 2 additions & 1 deletion blog/simpletest/testbloglib.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
4 changes: 2 additions & 2 deletions lib/simpletest/testpagelib_moodlepage.php
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ public function test_set_context() {

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() {
Expand All @@ -239,7 +239,7 @@ public function test_initialise_default_pagetype() {
// 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() {
Expand Down
63 changes: 58 additions & 5 deletions rating/simpletest/testrating.php
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}
}

/**
Expand All @@ -57,7 +92,7 @@ public function setUp() {
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(

Expand Down Expand Up @@ -86,13 +121,13 @@ function test_get_ratings_sql() {

// 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

Expand Down Expand Up @@ -223,3 +258,21 @@ function test_get_ratings_sql() {
$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);
}

}

0 comments on commit 0ebe676

Please sign in to comment.