Merge branch 'MDL-84967-M501_recordset-not-closed-in-core_analytics_local_analyser_by_course_get_analysables_iterator' of https://github.com/ziegenberg/moodle into MOODLE_501_STABLE

This commit is contained in:
Huong Nguyen
2025-11-13 08:47:26 +07:00
2 changed files with 22 additions and 0 deletions
@@ -53,6 +53,7 @@ abstract class by_course extends base {
if (!$recordset->valid()) {
$this->add_log(get_string('nocourses', 'analytics'));
$recordset->close();
return new \ArrayIterator([]);
}
+21
View File
@@ -16,6 +16,7 @@
namespace core;
use core\context\coursecat;
use test_target_course_level_shortname;
use test_target_shortname;
@@ -32,6 +33,8 @@ require_once(__DIR__ . '/../../lib/enrollib.php');
* @category test
* @copyright 2017 David Monllaó {@link http://www.davidmonllao.com}
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*
* @covers \core\analytics\analyser\courses
*/
final class analysers_test extends \advanced_testcase {
@@ -81,6 +84,24 @@ final class analysers_test extends \advanced_testcase {
}
/**
* Test analyser iterator status with invalid course data.
*/
public function test_no_courses_analyser(): void {
$this->resetAfterTest(true);
$target = new test_target_shortname();
$analyser = new \core\analytics\analyser\courses(1, $target, [], [], []);
$category = $this->getDataGenerator()->create_category();
$categorycontext = coursecat::instance($category->id);
// No courses.
$this->assertCount(0, $analyser->get_analysables_iterator(null, [$categorycontext]));
$this->assertCount(1, $analyser->get_logs());
$this->assertEquals(get_string('nocourses', 'analytics'), $analyser->get_logs()[0]);
}
/**
* test_site_courses_analyser
*