Skip to content

Commit

Permalink
MDL-84000 reportbuilder: move testcase helper to autoloaded namespace.
Browse files Browse the repository at this point in the history
Clean up some class imports while we're at it.
  • Loading branch information
paulholden committed Dec 13, 2024
1 parent a97ddeb commit f52d1fd
Show file tree
Hide file tree
Showing 31 changed files with 290 additions and 406 deletions.
9 changes: 9 additions & 0 deletions .upgradenotes/MDL-84000-2024121209313638.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
issueNumber: MDL-84000
notes:
core_reportbuilder:
- message: >-
The `core_reportbuilder_testcase` class has been moved to new autoloaded
`core_reportbuilder\tests\core_reportbuilder_testcase` location,
affected tests no longer have to manually require
`/reportbuilder/tests/helpers.php`
type: improved
7 changes: 1 addition & 6 deletions admin/roles/tests/reportbuilder/datasource/roles_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,8 @@

use core\context\course;
use core_reportbuilder_generator;
use core_reportbuilder_testcase;
use core_reportbuilder\local\filters\{date, select, text};

defined('MOODLE_INTERNAL') || die();

global $CFG;
require_once("{$CFG->dirroot}/reportbuilder/tests/helpers.php");
use core_reportbuilder\tests\core_reportbuilder_testcase;

/**
* Unit tests for roles datasource
Expand Down
7 changes: 1 addition & 6 deletions admin/tests/reportbuilder/datasource/task_logs_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,9 @@

use core\task\database_logger;
use core_reportbuilder_generator;
use core_reportbuilder_testcase;
use core_reportbuilder\local\filters\{date, duration, number, select, text};
use core_reportbuilder\task\send_schedules;

defined('MOODLE_INTERNAL') || die();

global $CFG;
require_once("{$CFG->dirroot}/reportbuilder/tests/helpers.php");
use core_reportbuilder\tests\core_reportbuilder_testcase;

/**
* Unit tests for task logs datasource
Expand Down
5 changes: 2 additions & 3 deletions badges/tests/reportbuilder/datasource/badges_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,13 @@

use core_badges_generator;
use core_reportbuilder_generator;
use core_reportbuilder_testcase;
use core_reportbuilder\local\filters\{boolean_select, date, select, tags, text};
use core_reportbuilder\manager;
use core_reportbuilder\tests\core_reportbuilder_testcase;

defined('MOODLE_INTERNAL') || die();

global $CFG;
require_once("{$CFG->dirroot}/reportbuilder/tests/helpers.php");
require_once("{$CFG->libdir}/badgeslib.php");

/**
Expand Down Expand Up @@ -377,7 +376,7 @@ public function test_datasource_filters(string $filtername, array $filtervalues,
$generator = $this->getDataGenerator()->get_plugin_generator('core_reportbuilder');

// Create report containing single username column, and given filter.
$report = $generator->create_report(['name' => 'My report', 'source' => badges::class, 'default' => 0]);
$report = $generator->create_report(['name' => 'Badges', 'source' => badges::class, 'default' => 0]);
$generator->create_column(['reportid' => $report->get('id'), 'uniqueidentifier' => 'badge:name']);

// Add filter, set it's values.
Expand Down
5 changes: 2 additions & 3 deletions badges/tests/reportbuilder/datasource/users_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,12 @@

use core_badges_generator;
use core_reportbuilder_generator;
use core_reportbuilder_testcase;
use core_reportbuilder\local\filters\{boolean_select, date, select, tags, text};
use core_reportbuilder\tests\core_reportbuilder_testcase;

defined('MOODLE_INTERNAL') || die();

global $CFG;
require_once("{$CFG->dirroot}/reportbuilder/tests/helpers.php");
require_once("{$CFG->libdir}/badgeslib.php");

/**
Expand Down Expand Up @@ -337,7 +336,7 @@ public function test_datasource_filters(string $filtername, array $filtervalues,
$generator = $this->getDataGenerator()->get_plugin_generator('core_reportbuilder');

// Create report containing single username column, and given filter.
$report = $generator->create_report(['name' => 'My report', 'source' => users::class, 'default' => 0]);
$report = $generator->create_report(['name' => 'Badges', 'source' => users::class, 'default' => 0]);
$generator->create_column(['reportid' => $report->get('id'), 'uniqueidentifier' => 'user:username']);

// Add filter, set it's values.
Expand Down
14 changes: 4 additions & 10 deletions blog/tests/reportbuilder/datasource/blogs_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,18 +18,12 @@

namespace core_blog\reportbuilder\datasource;

use context_system;
use context_user;
use core_blog_generator;
use core_comment_generator;
use core\context\{system, user};
use core_reportbuilder_generator;
use core_reportbuilder_testcase;
use core_reportbuilder\local\filters\{boolean_select, date, select, text};

defined('MOODLE_INTERNAL') || die();

global $CFG;
require_once("{$CFG->dirroot}/reportbuilder/tests/helpers.php");
use core_reportbuilder\tests\core_reportbuilder_testcase;

/**
* Unit tests for blogs datasource
Expand Down Expand Up @@ -98,7 +92,7 @@ public function test_datasource_non_default_columns(): void {
// Add an attachment.
$blog->attachment = 1;
get_file_storage()->create_file_from_string([
'contextid' => context_system::instance()->id,
'contextid' => system::instance()->id,
'component' => 'blog',
'filearea' => 'attachment',
'itemid' => $blog->id,
Expand All @@ -109,7 +103,7 @@ public function test_datasource_non_default_columns(): void {
/** @var core_comment_generator $generator */
$generator = $this->getDataGenerator()->get_plugin_generator('core_comment');
$generator->create_comment([
'context' => context_user::instance($user->id),
'context' => user::instance($user->id),
'component' => 'blog',
'area' => 'format_blog',
'itemid' => $blog->id,
Expand Down
16 changes: 5 additions & 11 deletions cohort/tests/reportbuilder/datasource/cohorts_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,11 @@

namespace core_cohort\reportbuilder\datasource;

use context_coursecat;
use context_system;
use core\context\{coursecat, system};
use core_customfield_generator;
use core_reportbuilder_generator;
use core_reportbuilder_testcase;
use core_reportbuilder\local\filters\{boolean_select, date, select, text};

defined('MOODLE_INTERNAL') || die();

global $CFG;
require_once("{$CFG->dirroot}/reportbuilder/tests/helpers.php");
use core_reportbuilder\tests\core_reportbuilder_testcase;

/**
* Unit tests for cohorts datasource
Expand All @@ -47,7 +41,7 @@ public function test_datasource_default(): void {
$this->resetAfterTest();

// Test subject.
$contextsystem = context_system::instance();
$contextsystem = system::instance();
$cohortone = $this->getDataGenerator()->create_cohort([
'contextid' => $contextsystem->id,
'name' => 'Legends',
Expand All @@ -56,7 +50,7 @@ public function test_datasource_default(): void {
]);

$category = $this->getDataGenerator()->create_category();
$contextcategory = context_coursecat::instance($category->id);
$contextcategory = coursecat::instance($category->id);
$cohorttwo = $this->getDataGenerator()->create_cohort([
'contextid' => $contextcategory->id,
'name' => 'Category cohort',
Expand Down Expand Up @@ -153,7 +147,7 @@ public static function datasource_filters_provider(): array {
], false],
'Filter context' => ['cohort:context', [
'cohort:context_operator' => select::EQUAL_TO,
'cohort:context_value' => context_system::instance()->id,
'cohort:context_value' => system::instance()->id,
], true],
'Filter content (no match)' => ['cohort:context', [
'cohort:context_operator' => select::EQUAL_TO,
Expand Down
34 changes: 13 additions & 21 deletions comment/tests/reportbuilder/datasource/comments_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,11 @@

namespace core_comment\reportbuilder\datasource;

use context_course;
use core_comment_generator;
use core\context\{block, course};
use core_reportbuilder_generator;
use core_reportbuilder_testcase;
use core_reportbuilder\local\filters\{date, select, text};

defined('MOODLE_INTERNAL') || die();

global $CFG;
require_once("{$CFG->dirroot}/reportbuilder/tests/helpers.php");
use core_reportbuilder\tests\core_reportbuilder_testcase;

/**
* Unit tests for comments datasource
Expand All @@ -46,7 +41,7 @@ public function test_datasource_default(): void {
$this->resetAfterTest();

$course = $this->getDataGenerator()->create_course();
$coursecontext = context_course::instance($course->id);
$coursecontext = course::instance($course->id);

/** @var core_comment_generator $generator */
$generator = $this->getDataGenerator()->get_plugin_generator('core_comment');
Expand Down Expand Up @@ -78,7 +73,7 @@ public function test_datasource_default(): void {

/** @var core_reportbuilder_generator $generator */
$generator = $this->getDataGenerator()->get_plugin_generator('core_reportbuilder');
$report = $generator->create_report(['name' => 'Blogs', 'source' => comments::class, 'default' => 1]);
$report = $generator->create_report(['name' => 'Comments', 'source' => comments::class, 'default' => 1]);

$content = $this->get_custom_report_content($report->get('id'));

Expand All @@ -99,8 +94,7 @@ public function test_datasource_non_default_columns(): void {
$this->setAdminUser();

$course = $this->getDataGenerator()->create_course();
$courseurl = course_get_url($course);
$coursecontext = context_course::instance($course->id);
$coursecontext = course::instance($course->id);

/** @var core_comment_generator $generator */
$generator = $this->getDataGenerator()->get_plugin_generator('core_comment');
Expand All @@ -113,9 +107,9 @@ public function test_datasource_non_default_columns(): void {

/** @var core_reportbuilder_generator $generator */
$generator = $this->getDataGenerator()->get_plugin_generator('core_reportbuilder');
$report = $generator->create_report(['name' => 'Blogs', 'source' => comments::class, 'default' => 0]);
$report = $generator->create_report(['name' => 'Comments', 'source' => comments::class, 'default' => 0]);

$generator->create_column(['reportid' => $report->get('id'), 'uniqueidentifier' => 'context:link']);
$generator->create_column(['reportid' => $report->get('id'), 'uniqueidentifier' => 'context:name']);
$generator->create_column(['reportid' => $report->get('id'), 'uniqueidentifier' => 'comment:component']);
$generator->create_column(['reportid' => $report->get('id'), 'uniqueidentifier' => 'comment:area']);
$generator->create_column(['reportid' => $report->get('id'), 'uniqueidentifier' => 'comment:itemid']);
Expand All @@ -124,7 +118,7 @@ public function test_datasource_non_default_columns(): void {
$this->assertCount(1, $content);

$this->assertEquals([
"<a href=\"{$courseurl}\">{$coursecontext->get_context_name()}</a>",
$coursecontext->get_context_name(),
'block_comments',
'page_comments',
0,
Expand Down Expand Up @@ -159,11 +153,11 @@ public static function datasource_filters_provider(): array {
// Context.
'Context level' => ['context:level', [
'context:level_operator' => select::EQUAL_TO,
'context:level_value' => CONTEXT_COURSE,
'context:level_value' => course::LEVEL,
], true],
'Context level (no match)' => ['context:level', [
'context:level_operator' => select::EQUAL_TO,
'context:level_value' => CONTEXT_BLOCK,
'context:level_value' => block::LEVEL,
], false],

// User.
Expand Down Expand Up @@ -196,12 +190,11 @@ public function test_datasource_filters(
$this->setAdminUser();

$course = $this->getDataGenerator()->create_course();
$coursecontext = context_course::instance($course->id);

/** @var core_comment_generator $generator */
$generator = $this->getDataGenerator()->get_plugin_generator('core_comment');
$generator->create_comment([
'context' => $coursecontext,
'context' => course::instance($course->id),
'component' => 'block_comments',
'area' => 'page_comments',
'content' => 'Cool',
Expand All @@ -211,7 +204,7 @@ public function test_datasource_filters(
$generator = $this->getDataGenerator()->get_plugin_generator('core_reportbuilder');

// Create report containing single column, and given filter.
$report = $generator->create_report(['name' => 'Tasks', 'source' => comments::class, 'default' => 0]);
$report = $generator->create_report(['name' => 'Comments', 'source' => comments::class, 'default' => 0]);
$generator->create_column(['reportid' => $report->get('id'), 'uniqueidentifier' => 'comment:component']);

// Add filter, set it's values.
Expand Down Expand Up @@ -240,12 +233,11 @@ public function test_stress_datasource(): void {
$this->setAdminUser();

$course = $this->getDataGenerator()->create_course();
$coursecontext = context_course::instance($course->id);

/** @var core_comment_generator $generator */
$generator = $this->getDataGenerator()->get_plugin_generator('core_comment');
$generator->create_comment([
'context' => $coursecontext,
'context' => course::instance($course->id),
'component' => 'block_comments',
'area' => 'page_comments',
'content' => 'Cool',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,8 @@
use core_competency_generator;
use core_competency\user_competency;
use core_reportbuilder_generator;
use core_reportbuilder_testcase;
use core_reportbuilder\local\filters\{boolean_select, date, select, text};

defined('MOODLE_INTERNAL') || die();

global $CFG;
require_once("{$CFG->dirroot}/reportbuilder/tests/helpers.php");
use core_reportbuilder\tests\core_reportbuilder_testcase;

/**
* Unit tests for comptencies datasource
Expand Down
7 changes: 1 addition & 6 deletions course/tests/reportbuilder/datasource/categories_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,8 @@

use core_course_category;
use core_reportbuilder_generator;
use core_reportbuilder_testcase;
use core_reportbuilder\local\filters\{category, select, text};

defined('MOODLE_INTERNAL') || die();

global $CFG;
require_once("{$CFG->dirroot}/reportbuilder/tests/helpers.php");
use core_reportbuilder\tests\core_reportbuilder_testcase;

/**
* Unit tests for course categories datasource
Expand Down
19 changes: 5 additions & 14 deletions course/tests/reportbuilder/datasource/courses_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,19 +18,10 @@

namespace core_course\reportbuilder\datasource;

use context_course;
use core_reportbuilder_testcase;
use core\context\course;
use core_reportbuilder_generator;
use core_reportbuilder\local\filters\boolean_select;
use core_reportbuilder\local\filters\date;
use core_reportbuilder\local\filters\select;
use core_reportbuilder\local\filters\tags;
use core_reportbuilder\local\filters\text;

defined('MOODLE_INTERNAL') || die();

global $CFG;
require_once("{$CFG->dirroot}/reportbuilder/tests/helpers.php");
use core_reportbuilder\local\filters\{boolean_select, date, select, tags, text};
use core_reportbuilder\tests\core_reportbuilder_testcase;

/**
* Unit tests for courses datasources
Expand Down Expand Up @@ -97,7 +88,7 @@ public function test_datasource_non_default_columns(): void {

// Add a course image.
get_file_storage()->create_file_from_string([
'contextid' => context_course::instance($course->id)->id,
'contextid' => course::instance($course->id)->id,
'component' => 'course',
'filearea' => 'overviewfiles',
'itemid' => 0,
Expand Down Expand Up @@ -416,7 +407,7 @@ public function test_datasource_filters(string $filtername, array $filtervalues,
$generator = $this->getDataGenerator()->get_plugin_generator('core_reportbuilder');

// Create report containing single column, and given filter.
$report = $generator->create_report(['name' => 'Tasks', 'source' => courses::class, 'default' => 0]);
$report = $generator->create_report(['name' => 'Courses', 'source' => courses::class, 'default' => 0]);
$generator->create_column(['reportid' => $report->get('id'), 'uniqueidentifier' => 'course:fullname']);

// Add filter, set it's values.
Expand Down
Loading

0 comments on commit f52d1fd

Please sign in to comment.