Skip to content

Commit

Permalink
MDL-32251 E_STRICT fixes part 3
Browse files Browse the repository at this point in the history
  • Loading branch information
skodak committed Mar 29, 2012
1 parent 0bb48cc commit caee6e6
Show file tree
Hide file tree
Showing 43 changed files with 236 additions and 185 deletions.
8 changes: 4 additions & 4 deletions admin/tool/generator/locallib.php
Original file line number Diff line number Diff line change
Expand Up @@ -348,7 +348,7 @@ public function generate_courses() {
$base_course->summary = 'Blah Blah';
$base_course->format = 'weeks';
$base_course->numsections = '10';
$base_course->startdate = mktime();
$base_course->startdate = time();
$base_course->id = '0';

$courses_count = 0;
Expand Down Expand Up @@ -461,7 +461,7 @@ public function generate_modules($courses) {
case 'assignment':
$module->intro = $description;
$module->assignmenttype = $this->get_module_type('assignment');
$module->timedue = mktime() + 89487321;
$module->timedue = time() + 89487321;
$module->grade = rand(50,100);
break;
case 'chat':
Expand Down Expand Up @@ -505,8 +505,8 @@ public function generate_modules($courses) {
break;
case 'lesson':
$module->lessondefault = 1;
$module->available = mktime();
$module->deadline = mktime() + 719891987;
$module->available = time();
$module->deadline = time() + 719891987;
$module->grade = 100;
break;
case 'quiz':
Expand Down
4 changes: 0 additions & 4 deletions admin/tool/unittest/dbtest.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,6 @@
require(dirname(__FILE__) . '/../../../config.php');
require_once($CFG->libdir.'/adminlib.php');

// unfortunately outdated SimpleTest is not E_STRICT compatible
$CFG->debug = ($CFG->debug & ~E_STRICT);
error_reporting($CFG->debug);

require_once('simpletestlib.php');
require_once('simpletestcoveragelib.php');
require_once('ex_simple_test.php');
Expand Down
9 changes: 2 additions & 7 deletions admin/tool/unittest/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,6 @@

require(dirname(__FILE__) . '/../../../config.php');
require_once($CFG->libdir.'/adminlib.php');

// Always run the unit tests in developer debug mode.
// unfortunately outdated SimpleTest is not E_STRICT compatible
$CFG->debug = (DEBUG_DEVELOPER & ~E_STRICT);
error_reporting($CFG->debug);
raise_memory_limit(MEMORY_EXTRA);

require_once('simpletestlib.php');
require_once('simpletestcoveragelib.php');
require_once('ex_simple_test.php');
Expand All @@ -48,6 +41,8 @@

admin_externalpage_setup('toolsimpletest', '', array('showpasses'=>$showpasses, 'showsearch'=>$showsearch));

raise_memory_limit(MEMORY_EXTRA);

$unittest = true;

global $UNITTEST;
Expand Down
1 change: 1 addition & 0 deletions admin/tool/unittest/simpletestcoveragelib.php
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,7 @@ public function run($simpletestreporter) {
$covrecorder->start_instrumentation();
parent::run($simpletestreporter);
$covrecorder->stop_instrumentation();
set_time_limit(60*10); // it may take a long time to generate the report
$covrecorder->generate_report();
moodle_coverage_reporter::print_summary_info(basename($this->coveragedir));
} else {
Expand Down
2 changes: 1 addition & 1 deletion auth/cas/auth.php
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ function loginpage_hook() {
function prelogout_hook() {
global $CFG;

if ($this->config->logoutcas) {
if (!empty($this->config->logoutcas)) {
$backurl = $CFG->wwwroot;
$this->connectCAS();
phpCAS::logoutWithURL($backurl);
Expand Down
2 changes: 1 addition & 1 deletion auth/shibboleth/config.html
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@

?>
</td>
<td><?php print_string("auth_shib_convert_data_description", "auth_shibboleth"); echo $config->alt_login ?></td>
<td><?php print_string("auth_shib_convert_data_description", "auth_shibboleth"); echo (isset($config->alt_login) ? $config->alt_login : '') ?></td>
</tr>

<tr valign="top">
Expand Down
3 changes: 2 additions & 1 deletion backup/converter/convertlib.php
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,8 @@ public function get_id() {
* @return string the system name of the converter
*/
public function get_name() {
return array_shift(explode('_', get_class($this)));
$parts = explode('_', get_class($this));
return array_shift($parts);
}

/**
Expand Down
5 changes: 3 additions & 2 deletions backup/converter/moodle1/handlerlib.php
Original file line number Diff line number Diff line change
Expand Up @@ -863,6 +863,7 @@ public function process_course_module($data, $raw) {
// host...
$versionfile = $CFG->dirroot.'/mod/'.$data['modulename'].'/version.php';
if (file_exists($versionfile)) {
$module = new stdClass();
include($versionfile);
$data['version'] = $module->version;
} else {
Expand Down Expand Up @@ -1852,7 +1853,7 @@ final public function get_paths() {
/**
* Question type handlers cannot open the xml_writer
*/
final protected function open_xml_writer() {
final protected function open_xml_writer($filename) {
throw new moodle1_convert_exception('opening_xml_writer_forbidden');
}

Expand Down Expand Up @@ -1971,7 +1972,7 @@ final public function get_paths() {
* @param array $data pre-cooked legacy resource data
* @param array $raw raw legacy resource data
*/
public function process_legacy_resource(array $data, array $raw) {
public function process_legacy_resource(array $data, array $raw = null) {
}

/**
Expand Down
3 changes: 2 additions & 1 deletion backup/util/structure/simpletest/testbackupstructures.php
Original file line number Diff line number Diff line change
Expand Up @@ -337,7 +337,8 @@ function test_backup_structure_construct() {
$this->assertEqual($inventeds->get_counter(), 2); // Array

// Perform some validations with the generated XML
$dom = DOMDocument::loadXML($xo->get_allcontents());
$dom = new DomDocument();
$dom->loadXML($xo->get_allcontents());
$xpath = new DOMXPath($dom);
// Some more counters
$query = '/forum/discussions/discussion/posts/post';
Expand Down
4 changes: 2 additions & 2 deletions blog/external_blog_edit.php
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@
$newexternal->userid = $USER->id;
$newexternal->url = $data->url;
$newexternal->filtertags = $data->filtertags;
$newexternal->timemodified = mktime();
$newexternal->timemodified = time();

$newexternal->id = $DB->insert_record('blog_external', $newexternal);
blog_sync_external_entries($newexternal);
Expand All @@ -99,7 +99,7 @@
$external->userid = $USER->id;
$external->url = $data->url;
$external->filtertags = $data->filtertags;
$external->timemodified = mktime();
$external->timemodified = time();

$DB->update_record('blog_external', $external);
tag_set('blog_external', $external->id, explode(',', $data->autotags));
Expand Down
6 changes: 3 additions & 3 deletions blog/locallib.php
Original file line number Diff line number Diff line change
Expand Up @@ -1132,13 +1132,13 @@ public function __construct($id) {
}

/**
* This filter restricts the results to a time interval in seconds up to mktime()
* This filter restricts the results to a time interval in seconds up to time()
*/
class blog_filter_since extends blog_filter {
public function __construct($interval) {
$this->conditions[] = 'p.lastmodified >= ? AND p.lastmodified <= ?';
$this->params[] = mktime() - $interval;
$this->params[] = mktime();
$this->params[] = time() - $interval;
$this->params[] = time();
}
}

Expand Down
8 changes: 4 additions & 4 deletions lib/completionlib.php
Original file line number Diff line number Diff line change
Expand Up @@ -1116,7 +1116,7 @@ public function generate_tracked_user_sql($groupid = 0) {
$groupjoin = "JOIN {groups_members} gm
ON gm.userid = u.id";
$groupselect = " AND gm.groupid = :groupid ";

$return->data['groupid'] = $groupid;
}

Expand Down Expand Up @@ -1249,9 +1249,9 @@ public function inform_grade_changed($cm, $item, $grade, $deleted) {
// Grade being deleted, so only change could be to make it incomplete
$possibleresult = COMPLETION_INCOMPLETE;
} else {
$possibleresult = $this->internal_get_grade_state($item, $grade);
$possibleresult = self::internal_get_grade_state($item, $grade);
}

// OK, let's update state based on this
$this->update_state($cm, $possibleresult, $grade->userid);
}
Expand All @@ -1267,7 +1267,7 @@ public function inform_grade_changed($cm, $item, $grade, $deleted) {
* @param grade_grade $grade an instance of grade_grade
* @return int Completion state e.g. COMPLETION_INCOMPLETE
*/
public function internal_get_grade_state($item, $grade) {
public static function internal_get_grade_state($item, $grade) {
if (!$grade) {
return COMPLETION_INCOMPLETE;
}
Expand Down
4 changes: 2 additions & 2 deletions lib/dml/simpletest/testdml.php
Original file line number Diff line number Diff line change
Expand Up @@ -2284,13 +2284,13 @@ public function test_update_record_raw() {
$this->assertEqual(1, $DB->count_records($tablename, array('course' => 2)));
$this->assertEqual(1, $DB->count_records($tablename, array('course' => 3)));

$record = $DB->get_record($tablename, array('course' => 1));
$record = $DB->get_record($tablename, array('course' => 3));
$record->xxxxx = 2;
try {
$DB->update_record_raw($tablename, $record);
$this->fail("Expecting an exception, none occurred");
} catch (Exception $e) {
$this->assertTrue($e instanceof coding_exception);
$this->assertTrue($e instanceof moodle_exception);
}

$record = $DB->get_record($tablename, array('course' => 3));
Expand Down
42 changes: 21 additions & 21 deletions lib/grade/simpletest/testgradecategory.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public function __construct() {
public function __destruct() {
$this->endtime = time();
//var_dump($this->endtime-$this->starttime);

parent::__destruct();
}

Expand Down Expand Up @@ -118,7 +118,7 @@ function sub_test_grade_category_construct() {
$grade_category = new grade_category($params, false);
$grade_category->insert();
$this->grade_categories[50] = $grade_category;//going to delete this one later hence the special index

$this->assertEqual(4, $grade_category->depth);
$this->assertEqual($parentpath.$grade_category->id."/", $grade_category->path);
}
Expand Down Expand Up @@ -251,7 +251,7 @@ function sub_test_grade_category_force_regrading() {
/**
* Tests the calculation of grades using the various aggregation methods with and without hidden grades
* This will not work entirely until MDL-11837 is done
* @global type $DB
* @global type $DB
*/
function sub_test_grade_category_generate_grades() {
global $DB;
Expand Down Expand Up @@ -286,13 +286,13 @@ function sub_test_grade_category_generate_grades() {
$grade_items[$i]->grademin = 0;
$grade_items[$i]->grademax = 10;
$grade_items[$i]->iteminfo = 'Manual grade item used for unit testing';
$grade_items[$i]->timecreated = mktime();
$grade_items[$i]->timemodified = mktime();
$grade_items[$i]->timecreated = time();
$grade_items[$i]->timemodified = time();

//used as the weight by weighted mean and as extra credit by mean with extra credit
//Will be 0, 1 and 2
$grade_items[$i]->aggregationcoef = $i;

$grade_items[$i]->insert();
}

Expand All @@ -304,8 +304,8 @@ function sub_test_grade_category_generate_grades() {
$grade_grades[$i]->userid = $this->userid;
$grade_grades[$i]->rawgrade = ($i+1)*2;//produce grade grades of 2, 4 and 6
$grade_grades[$i]->finalgrade = ($i+1)*2;
$grade_grades[$i]->timecreated = mktime();
$grade_grades[$i]->timemodified = mktime();
$grade_grades[$i]->timecreated = time();
$grade_grades[$i]->timemodified = time();
$grade_grades[$i]->information = '1 of 2 grade_grades';
$grade_grades[$i]->informationformat = FORMAT_PLAIN;
$grade_grades[$i]->feedback = 'Good, but not good enough..';
Expand All @@ -316,14 +316,14 @@ function sub_test_grade_category_generate_grades() {

//3 grade items with 1 grade_grade each.
//grade grades have the values 2, 4 and 6

//First correct answer is the aggregate with all 3 grades
//Second correct answer is with the first grade (value 2) hidden

$this->helper_test_grade_agg_method($grade_category, $grade_items, $grade_grades, GRADE_AGGREGATE_MEDIAN, 'GRADE_AGGREGATE_MEDIAN', 8, 8);
$this->helper_test_grade_agg_method($grade_category, $grade_items, $grade_grades, GRADE_AGGREGATE_MAX, 'GRADE_AGGREGATE_MAX', 12, 12);
$this->helper_test_grade_agg_method($grade_category, $grade_items, $grade_grades, GRADE_AGGREGATE_MODE, 'GRADE_AGGREGATE_MODE', 12, 12);

//weighted mean. note grade totals are rounded to an int to prevent rounding discrepancies. correct final grade isnt actually exactly 10
//3 items with grades 2, 4 and 6 with weights 0, 1 and 2 and all out of 10. then doubled to be out of 20.
$this->helper_test_grade_agg_method($grade_category, $grade_items, $grade_grades, GRADE_AGGREGATE_WEIGHTED_MEAN, 'GRADE_AGGREGATE_WEIGHTED_MEAN', 10, 10);
Expand All @@ -335,16 +335,16 @@ function sub_test_grade_category_generate_grades() {
//mean of grades with extra credit
//3 items with grades 2, 4 and 6 with extra credit 0, 1 and 2 equally weighted and all out of 10. then doubled to be out of 20.
$this->helper_test_grade_agg_method($grade_category, $grade_items, $grade_grades, GRADE_AGGREGATE_EXTRACREDIT_MEAN, 'GRADE_AGGREGATE_EXTRACREDIT_MEAN', 10, 13);

//aggregation tests the are affected by a hidden grade currently dont work as we dont store the altered grade in the database
//instead an in memory recalculation is done. This should be remedied by MDL-11837

//fails with 1 grade hidden. still reports 8 as being correct
$this->helper_test_grade_agg_method($grade_category, $grade_items, $grade_grades, GRADE_AGGREGATE_MEAN, 'GRADE_AGGREGATE_MEAN', 8, 10);

//fails with 1 grade hidden. still reports 4 as being correct
$this->helper_test_grade_agg_method($grade_category, $grade_items, $grade_grades, GRADE_AGGREGATE_MIN, 'GRADE_AGGREGATE_MIN', 4, 8);

//fails with 1 grade hidden. still reports 12 as being correct
$this->helper_test_grade_agg_method($grade_category, $grade_items, $grade_grades, GRADE_AGGREGATE_SUM, 'GRADE_AGGREGATE_SUM', 12, 10);
}
Expand Down Expand Up @@ -384,27 +384,27 @@ function helper_test_grade_agg_method($grade_category, $grade_items, $grade_grad
*/
function helper_test_grade_aggregation_result($grade_category, $correctgrade, $msg) {
global $DB;

$category_grade_item = $grade_category->get_grade_item();

//this creates all the grade_grades we need
grade_regrade_final_grades($this->courseid);

$grade = $DB->get_record('grade_grades', array('itemid'=>$category_grade_item->id, 'userid'=>$this->userid));
$this->assertWithinMargin($grade->rawgrade, $grade->rawgrademin, $grade->rawgrademax);
$this->assertEqual(intval($correctgrade), intval($grade->finalgrade), $msg);

/*
* TODO this doesnt work as the grade_grades created by $grade_category->generate_grades(); dont
* observe the category's max grade
//delete the grade_grades for the category itself and check they get recreated correctly
$DB->delete_records('grade_grades', array('itemid'=>$category_grade_item->id));
$grade_category->generate_grades();
$grade = $DB->get_record('grade_grades', array('itemid'=>$category_grade_item->id, 'userid'=>$this->userid));
$this->assertWithinMargin($grade->rawgrade, $grade->rawgrademin, $grade->rawgrademax);
$this->assertEqual(intval($correctgrade), intval($grade->finalgrade), $msg);
*
*
*/
}

Expand Down
2 changes: 1 addition & 1 deletion lib/grade/simpletest/testgradescale.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ function sub_test_scale_construct() {
$params->userid = $this->userid;
$params->scale = 'Distinction, Very Good, Good, Pass, Fail';
$params->description = 'This scale is used to mark standard assignments.';
$params->timemodified = mktime();
$params->timemodified = time();

$scale = new grade_scale($params, false);

Expand Down
Loading

0 comments on commit caee6e6

Please sign in to comment.