mirror of
https://github.com/moodle/moodle.git
synced 2025-04-16 14:02:32 +02:00
Merge branch 'MDL-65204-master' of git://github.com/junpataleta/moodle
This commit is contained in:
commit
1b011cdbda
@ -100,6 +100,6 @@ class tool_dataprivacy_metadata_registry_testcase extends advanced_testcase {
|
||||
$this->assertEquals(1, $corerating['compliant']);
|
||||
$this->assertNotEmpty($corerating['metadata']);
|
||||
$this->assertEquals('database_table', $corerating['metadata'][0]['type']);
|
||||
$this->assertNotEmpty('database_table', $corerating['metadata'][0]['fields']);
|
||||
$this->assertNotEmpty($corerating['metadata'][0]['fields']);
|
||||
}
|
||||
}
|
||||
|
@ -66,7 +66,7 @@ class tool_log_privacy_testcase extends provider_testcase {
|
||||
$manager = get_log_manager(true);
|
||||
|
||||
$this->setUser($u1);
|
||||
$this->assertEmpty(provider::get_contexts_for_userid($u1->id)->get_contextids(), []);
|
||||
$this->assertEmpty(provider::get_contexts_for_userid($u1->id)->get_contextids());
|
||||
$e = \logstore_standard\event\unittest_executed::create(['context' => $c1ctx]);
|
||||
$e->trigger();
|
||||
$this->assertEquals($c1ctx->id, provider::get_contexts_for_userid($u1->id)->get_contextids()[0]);
|
||||
|
@ -5,8 +5,8 @@
|
||||
"type": "project",
|
||||
"homepage": "https://moodle.org",
|
||||
"require-dev": {
|
||||
"phpunit/phpunit": "6.5.*",
|
||||
"phpunit/dbunit": "3.0.*",
|
||||
"phpunit/phpunit": "7.5.*",
|
||||
"phpunit/dbunit": "4.0.*",
|
||||
"moodlehq/behat-extension": "3.37.0",
|
||||
"mikey179/vfsstream": "^1.6"
|
||||
}
|
||||
|
446
composer.lock
generated
446
composer.lock
generated
File diff suppressed because it is too large
Load Diff
@ -63,7 +63,7 @@ abstract class advanced_testcase extends base_testcase {
|
||||
* Runs the bare test sequence.
|
||||
* @return void
|
||||
*/
|
||||
final public function runBare() {
|
||||
final public function runBare(): void {
|
||||
global $DB;
|
||||
|
||||
if (phpunit_util::$lastdbwrites != $DB->perf_get_writes()) {
|
||||
|
@ -43,7 +43,7 @@
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
class phpunit_autoloader implements \PHPUnit\Runner\TestSuiteLoader {
|
||||
public function load($suiteClassName, $suiteClassFile = '') {
|
||||
public function load(string $suiteClassName, string $suiteClassFile = ''): ReflectionClass {
|
||||
global $CFG;
|
||||
|
||||
// Let's guess what user entered on the commandline...
|
||||
@ -197,7 +197,7 @@ class phpunit_autoloader implements \PHPUnit\Runner\TestSuiteLoader {
|
||||
return new ReflectionClass($classname);
|
||||
}
|
||||
|
||||
public function reload(ReflectionClass $aClass) {
|
||||
public function reload(ReflectionClass $aClass): ReflectionClass {
|
||||
return $aClass;
|
||||
}
|
||||
}
|
||||
|
@ -57,7 +57,7 @@ abstract class basic_testcase extends base_testcase {
|
||||
* Runs the bare test sequence and log any changes in global state or database.
|
||||
* @return void
|
||||
*/
|
||||
final public function runBare() {
|
||||
final public function runBare(): void {
|
||||
global $DB;
|
||||
|
||||
try {
|
||||
|
@ -39,6 +39,20 @@ class phpunit_constraint_object_is_equal_with_exceptions extends PHPUnit\Framewo
|
||||
*/
|
||||
protected $keys = array();
|
||||
|
||||
/**
|
||||
* @var mixed $value Need to keep it here because it became private for PHPUnit 7.x and up
|
||||
*/
|
||||
protected $capturedvalue;
|
||||
|
||||
/**
|
||||
* Override constructor to capture value
|
||||
*/
|
||||
public function __construct($value, float $delta = 0.0, int $maxDepth = 10, bool $canonicalize = false,
|
||||
bool $ignoreCase = false) {
|
||||
parent::__construct($value, $delta, $maxDepth, $canonicalize, $ignoreCase);
|
||||
$this->capturedvalue = $value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add an exception for the named key to use a different comparison
|
||||
* method. Any assertion provided by PHPUnit\Framework\Assert is
|
||||
@ -69,13 +83,13 @@ class phpunit_constraint_object_is_equal_with_exceptions extends PHPUnit\Framewo
|
||||
*/
|
||||
public function evaluate($other, $description = '', $shouldreturnesult = false) {
|
||||
foreach ($this->keys as $key => $comparison) {
|
||||
if (isset($other->$key) || isset($this->value->$key)) {
|
||||
if (isset($other->$key) || isset($this->capturedvalue->$key)) {
|
||||
// One of the keys is present, therefore run the comparison.
|
||||
PHPUnit\Framework\Assert::$comparison($this->value->$key, $other->$key);
|
||||
PHPUnit\Framework\Assert::$comparison($this->capturedvalue->$key, $other->$key);
|
||||
|
||||
// Unset the keys, otherwise the standard evaluation will take place.
|
||||
unset($other->$key);
|
||||
unset($this->value->$key);
|
||||
unset($this->capturedvalue->$key);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -138,7 +138,7 @@ abstract class database_driver_testcase extends base_testcase {
|
||||
* Runs the bare test sequence.
|
||||
* @return void
|
||||
*/
|
||||
public function runBare() {
|
||||
public function runBare(): void {
|
||||
try {
|
||||
parent::runBare();
|
||||
|
||||
|
@ -48,7 +48,7 @@ class Hint_ResultPrinter extends PHPUnit\TextUI\ResultPrinter {
|
||||
parent::__construct(null, false, self::COLOR_DEFAULT, false);
|
||||
}
|
||||
|
||||
protected function printDefectTrace(PHPUnit\Framework\TestFailure $defect) {
|
||||
protected function printDefectTrace(PHPUnit\Framework\TestFailure $defect): void {
|
||||
global $CFG;
|
||||
|
||||
parent::printDefectTrace($defect);
|
||||
|
@ -76,7 +76,8 @@ class core_completionlib_testcase extends advanced_testcase {
|
||||
* @param boolean $canonicalize
|
||||
* @param boolean $ignoreCase
|
||||
*/
|
||||
public static function assertEquals($expected, $actual, $message = '', $delta = 0, $maxDepth = 10, $canonicalize = FALSE, $ignoreCase = FALSE) {
|
||||
public static function assertEquals($expected, $actual, string $message = '', float $delta = 0, int $maxDepth = 10,
|
||||
bool $canonicalize = false, bool $ignoreCase = false): void {
|
||||
// Nasty cheating hack: prevent random failures on timemodified field.
|
||||
if (is_object($expected) and is_object($actual)) {
|
||||
if (property_exists($expected, 'timemodified') and property_exists($actual, 'timemodified')) {
|
||||
|
@ -629,7 +629,7 @@ class assign_events_testcase extends advanced_testcase {
|
||||
);
|
||||
$assign->testable_process_save_quick_grades($data);
|
||||
$grade = $assign->get_user_grade($student->id, false);
|
||||
$this->assertEquals('60.0', $grade->grade);
|
||||
$this->assertEquals(60.0, $grade->grade);
|
||||
|
||||
$events = $sink->get_events();
|
||||
$this->assertCount(3, $events);
|
||||
@ -655,7 +655,7 @@ class assign_events_testcase extends advanced_testcase {
|
||||
$data->grade = '50.0';
|
||||
$assign->update_grade($data);
|
||||
$grade = $assign->get_user_grade($student->id, false, 0);
|
||||
$this->assertEquals('50.0', $grade->grade);
|
||||
$this->assertEquals(50.0, $grade->grade);
|
||||
$events = $sink->get_events();
|
||||
|
||||
$this->assertCount(3, $events);
|
||||
|
@ -1134,7 +1134,7 @@ class mod_assign_external_testcase extends externallib_advanced_testcase {
|
||||
$result = mod_assign_external::get_grades(array($instance->id));
|
||||
$result = external_api::clean_returnvalue(mod_assign_external::get_grades_returns(), $result);
|
||||
|
||||
$this->assertEquals($result['assignments'][0]['grades'][0]['grade'], '50.0');
|
||||
$this->assertEquals((float)$result['assignments'][0]['grades'][0]['grade'], '50.0');
|
||||
}
|
||||
|
||||
/**
|
||||
@ -1284,13 +1284,13 @@ class mod_assign_external_testcase extends externallib_advanced_testcase {
|
||||
array('userid' => $student1->id, 'assignment' => $instance->id),
|
||||
'*',
|
||||
MUST_EXIST);
|
||||
$this->assertEquals($student1grade->grade, '50.0');
|
||||
$this->assertEquals((float)$student1grade->grade, '50.0');
|
||||
|
||||
$student2grade = $DB->get_record('assign_grades',
|
||||
array('userid' => $student2->id, 'assignment' => $instance->id),
|
||||
'*',
|
||||
MUST_EXIST);
|
||||
$this->assertEquals($student2grade->grade, '100.0');
|
||||
$this->assertEquals((float)$student2grade->grade, '100.0');
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -3640,7 +3640,7 @@ Anchor link 2:<a title=\"bananas\" href=\"../logo-240x60.gif\">Link text</a>
|
||||
$result = $assign->testable_process_save_quick_grades($data);
|
||||
$this->assertContains(get_string('quickgradingchangessaved', 'assign'), $result);
|
||||
$grade = $assign->get_user_grade($student->id, false);
|
||||
$this->assertEquals('60.0', $grade->grade);
|
||||
$this->assertEquals(60.0, $grade->grade);
|
||||
|
||||
// Attempt to grade with a past attempts grade info.
|
||||
$assign->testable_process_add_attempt($student->id);
|
||||
@ -3664,7 +3664,7 @@ Anchor link 2:<a title=\"bananas\" href=\"../logo-240x60.gif\">Link text</a>
|
||||
$result = $assign->testable_process_save_quick_grades($data);
|
||||
$this->assertContains(get_string('quickgradingchangessaved', 'assign'), $result);
|
||||
$grade = $assign->get_user_grade($student->id, false);
|
||||
$this->assertEquals('40.0', $grade->grade);
|
||||
$this->assertEquals(40.0, $grade->grade);
|
||||
|
||||
// Catch grade update conflicts.
|
||||
// Save old data for later.
|
||||
@ -3678,13 +3678,13 @@ Anchor link 2:<a title=\"bananas\" href=\"../logo-240x60.gif\">Link text</a>
|
||||
$result = $assign->testable_process_save_quick_grades($data);
|
||||
$this->assertContains(get_string('quickgradingchangessaved', 'assign'), $result);
|
||||
$grade = $assign->get_user_grade($student->id, false);
|
||||
$this->assertEquals('30.0', $grade->grade);
|
||||
$this->assertEquals(30.0, $grade->grade);
|
||||
|
||||
// Now update using 'old' data. Should fail.
|
||||
$result = $assign->testable_process_save_quick_grades($pastdata);
|
||||
$this->assertContains(get_string('errorrecordmodified', 'assign'), $result);
|
||||
$grade = $assign->get_user_grade($student->id, false);
|
||||
$this->assertEquals('30.0', $grade->grade);
|
||||
$this->assertEquals(30.0, $grade->grade);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -315,8 +315,8 @@ class mod_assign_privacy_testcase extends provider_testcase {
|
||||
$this->assertEquals(1, $writer->get_data(['attempt 1', 'submission'])->attemptnumber);
|
||||
$this->assertEquals(2, $writer->get_data(['attempt 2', 'submission'])->attemptnumber);
|
||||
// Check grades.
|
||||
$this->assertEquals($grade1, $writer->get_data(['attempt 1', 'grade'])->grade);
|
||||
$this->assertEquals($grade2, $writer->get_data(['attempt 2', 'grade'])->grade);
|
||||
$this->assertEquals((float)$grade1, $writer->get_data(['attempt 1', 'grade'])->grade);
|
||||
$this->assertEquals((float)$grade2, $writer->get_data(['attempt 2', 'grade'])->grade);
|
||||
// Check feedback.
|
||||
$this->assertContains($teachercommenttext, $writer->get_data(['attempt 1', 'Feedback comments'])->commenttext);
|
||||
$this->assertContains($teachercommenttext2, $writer->get_data(['attempt 2', 'Feedback comments'])->commenttext);
|
||||
@ -425,11 +425,11 @@ class mod_assign_privacy_testcase extends provider_testcase {
|
||||
|
||||
// Check for student grades given.
|
||||
$student1grade = $writer->get_data(['studentsubmissions', $user1->id, 'attempt 1', 'grade']);
|
||||
$this->assertEquals($grade1, $student1grade->grade);
|
||||
$this->assertEquals((float)$grade1, $student1grade->grade);
|
||||
$student2grade1 = $writer->get_data(['studentsubmissions', $user2->id, 'attempt 1', 'grade']);
|
||||
$this->assertEquals($grade2, $student2grade1->grade);
|
||||
$this->assertEquals((float)$grade2, $student2grade1->grade);
|
||||
$student2grade2 = $writer->get_data(['studentsubmissions', $user2->id, 'attempt 2', 'grade']);
|
||||
$this->assertEquals($grade3, $student2grade2->grade);
|
||||
$this->assertEquals((float)$grade3, $student2grade2->grade);
|
||||
// Check for feedback given to students.
|
||||
$this->assertContains($teachercommenttext, $writer->get_data(['studentsubmissions', $user1->id, 'attempt 1',
|
||||
'Feedback comments'])->commenttext);
|
||||
|
@ -338,7 +338,8 @@ class mod_quiz_attempt_walkthrough_from_csv_testcase extends advanced_testcase {
|
||||
$this->assertEquals((bool)$value, $attemptobj->is_finished());
|
||||
break;
|
||||
case 'summarks' :
|
||||
$this->assertEquals($value, $attemptobj->get_sum_marks(), "Sum of marks of attempt {$result['quizattempt']}.");
|
||||
$this->assertEquals((float)$value, $attemptobj->get_sum_marks(),
|
||||
"Sum of marks of attempt {$result['quizattempt']}.");
|
||||
break;
|
||||
case 'quizgrade' :
|
||||
// Check quiz grades.
|
||||
|
@ -189,19 +189,19 @@ class mod_workshop_privacy_provider_testcase extends advanced_testcase {
|
||||
// Student1 has data in workshop11 (author + self reviewer), workshop12 (author) and workshop21 (reviewer).
|
||||
$contextlist = \mod_workshop\privacy\provider::get_contexts_for_userid($this->student1->id);
|
||||
$this->assertInstanceOf(\core_privacy\local\request\contextlist::class, $contextlist);
|
||||
$this->assertEquals([$context11->id, $context12->id, $context21->id], $contextlist->get_contextids(), null, 0.0, 10, true);
|
||||
$this->assertEquals([$context11->id, $context12->id, $context21->id], $contextlist->get_contextids(), '', 0.0, 10, true);
|
||||
|
||||
// Student2 has data in workshop11 (reviewer), workshop12 (reviewer) and workshop21 (author).
|
||||
$contextlist = \mod_workshop\privacy\provider::get_contexts_for_userid($this->student2->id);
|
||||
$this->assertEquals([$context11->id, $context12->id, $context21->id], $contextlist->get_contextids(), null, 0.0, 10, true);
|
||||
$this->assertEquals([$context11->id, $context12->id, $context21->id], $contextlist->get_contextids(), '', 0.0, 10, true);
|
||||
|
||||
// Student3 has data in workshop11 (reviewer).
|
||||
$contextlist = \mod_workshop\privacy\provider::get_contexts_for_userid($this->student3->id);
|
||||
$this->assertEquals([$context11->id], $contextlist->get_contextids(), null, 0.0, 10, true);
|
||||
$this->assertEquals([$context11->id], $contextlist->get_contextids(), '', 0.0, 10, true);
|
||||
|
||||
// Teacher4 has data in workshop12 (gradeoverby) and workshop21 (gradinggradeoverby).
|
||||
$contextlist = \mod_workshop\privacy\provider::get_contexts_for_userid($this->teacher4->id);
|
||||
$this->assertEquals([$context21->id, $context12->id], $contextlist->get_contextids(), null, 0.0, 10, true);
|
||||
$this->assertEquals([$context21->id, $context12->id], $contextlist->get_contextids(), '', 0.0, 10, true);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -80,7 +80,7 @@ class qtype_multichoice_test_helper extends question_test_helper {
|
||||
'id' => 13,
|
||||
'answer' => 'One',
|
||||
'answerformat' => FORMAT_PLAIN,
|
||||
'fraction' => '0.5',
|
||||
'fraction' => 0.5,
|
||||
'feedback' => 'One is odd.',
|
||||
'feedbackformat' => FORMAT_HTML,
|
||||
),
|
||||
@ -88,7 +88,7 @@ class qtype_multichoice_test_helper extends question_test_helper {
|
||||
'id' => 14,
|
||||
'answer' => 'Two',
|
||||
'answerformat' => FORMAT_PLAIN,
|
||||
'fraction' => '0.0',
|
||||
'fraction' => 0.0,
|
||||
'feedback' => 'Two is even.',
|
||||
'feedbackformat' => FORMAT_HTML,
|
||||
),
|
||||
@ -96,7 +96,7 @@ class qtype_multichoice_test_helper extends question_test_helper {
|
||||
'id' => 15,
|
||||
'answer' => 'Three',
|
||||
'answerformat' => FORMAT_PLAIN,
|
||||
'fraction' => '0.5',
|
||||
'fraction' => 0.5,
|
||||
'feedback' => 'Three is odd.',
|
||||
'feedbackformat' => FORMAT_HTML,
|
||||
),
|
||||
@ -104,7 +104,7 @@ class qtype_multichoice_test_helper extends question_test_helper {
|
||||
'id' => 16,
|
||||
'answer' => 'Four',
|
||||
'answerformat' => FORMAT_PLAIN,
|
||||
'fraction' => '0.0',
|
||||
'fraction' => 0.0,
|
||||
'feedback' => 'Four is even.',
|
||||
'feedbackformat' => FORMAT_HTML,
|
||||
),
|
||||
@ -261,7 +261,7 @@ class qtype_multichoice_test_helper extends question_test_helper {
|
||||
'id' => 13,
|
||||
'answer' => 'One',
|
||||
'answerformat' => FORMAT_PLAIN,
|
||||
'fraction' => '1',
|
||||
'fraction' => 1,
|
||||
'feedback' => 'One is the oddest.',
|
||||
'feedbackformat' => FORMAT_HTML,
|
||||
),
|
||||
@ -269,7 +269,7 @@ class qtype_multichoice_test_helper extends question_test_helper {
|
||||
'id' => 14,
|
||||
'answer' => 'Two',
|
||||
'answerformat' => FORMAT_PLAIN,
|
||||
'fraction' => '0.0',
|
||||
'fraction' => 0.0,
|
||||
'feedback' => 'Two is even.',
|
||||
'feedbackformat' => FORMAT_HTML,
|
||||
),
|
||||
@ -277,7 +277,7 @@ class qtype_multichoice_test_helper extends question_test_helper {
|
||||
'id' => 15,
|
||||
'answer' => 'Three',
|
||||
'answerformat' => FORMAT_PLAIN,
|
||||
'fraction' => '0',
|
||||
'fraction' => 0,
|
||||
'feedback' => 'Three is odd.',
|
||||
'feedbackformat' => FORMAT_HTML,
|
||||
),
|
||||
@ -285,7 +285,7 @@ class qtype_multichoice_test_helper extends question_test_helper {
|
||||
'id' => 16,
|
||||
'answer' => 'Four',
|
||||
'answerformat' => FORMAT_PLAIN,
|
||||
'fraction' => '0.0',
|
||||
'fraction' => 0.0,
|
||||
'feedback' => 'Four is even.',
|
||||
'feedbackformat' => FORMAT_HTML,
|
||||
),
|
||||
|
@ -266,7 +266,7 @@ class qtype_multichoice_attempt_upgrader_test extends question_attempt_upgrader_
|
||||
'fraction' => 0.9,
|
||||
'timecreated' => 1278604597,
|
||||
'userid' => null,
|
||||
'data' => array('-comment' => 'Well done!', '-mark' => '0.9', '-maxmark' => '1'),
|
||||
'data' => array('-comment' => 'Well done!', '-mark' => '0.9', '-maxmark' => 1),
|
||||
),
|
||||
),
|
||||
);
|
||||
|
Loading…
x
Reference in New Issue
Block a user