Merge branch 'MDL-86283-main-v02' of https://github.com/ferranrecio/moodle

This commit is contained in:
Amaia Anabitarte
2025-09-15 10:30:02 +02:00
28 changed files with 2105 additions and 2215 deletions
@@ -16,8 +16,6 @@
namespace core_courseformat;
use core_courseformat\local\overview\overviewfactory;
/**
* Tests for course
*
@@ -25,8 +23,8 @@ use core_courseformat\local\overview\overviewfactory;
* @category test
* @copyright 2025 Ferran Recio <[email protected]>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
* @covers \core_courseformat\activityoverviewbase
*/
#[\PHPUnit\Framework\Attributes\CoversClass(activityoverviewbase::class)]
final class activityoverviewbase_test extends \advanced_testcase {
#[\Override()]
public static function setUpBeforeClass(): void {
@@ -39,8 +37,6 @@ final class activityoverviewbase_test extends \advanced_testcase {
/**
* Test get_name_overview method.
*
* @covers ::get_name_overview
*/
public function test_get_name_overview(): void {
$this->resetAfterTest();
@@ -63,10 +59,9 @@ final class activityoverviewbase_test extends \advanced_testcase {
/**
* Test get_completion_overview method.
*
* @covers ::get_completion_overview
* @dataProvider provider_get_completion_overview
* @param int $setcompletion the completion status
*/
#[\PHPUnit\Framework\Attributes\DataProvider('provider_get_completion_overview')]
public function test_get_completion_overview(
int $setcompletion,
): void {
@@ -136,8 +131,6 @@ final class activityoverviewbase_test extends \advanced_testcase {
/**
* Test get_completion_overview method on an activity with no completion.
*
* @covers ::get_completion_overview
*/
public function test_get_completion_overview_no_completion(): void {
$this->resetAfterTest();
@@ -172,8 +165,6 @@ final class activityoverviewbase_test extends \advanced_testcase {
/**
* Test get_grades_overviews method.
*
* @covers ::get_grades_overviews
*/
public function test_get_grades_overviews(): void {
$this->resetAfterTest();
@@ -263,7 +254,7 @@ final class activityoverviewbase_test extends \advanced_testcase {
$cm = $modinfo->get_cm($assign->cmid);
$overview = new \core_courseformat\fake_activityoverview($cm);
$result = $overview->get_grades_overviews();
$this->assertEmpty($result);;
$this->assertEmpty($result);
// Validate workshop gradeitems (having two grade, they should return an empty array).
$cm = $modinfo->get_cm($workshop->cmid);
@@ -280,8 +271,6 @@ final class activityoverviewbase_test extends \advanced_testcase {
/**
* Test get_grades_overviews method.
*
* @covers ::get_grades_overviews
*/
public function test_get_grades_overviews_hidden(): void {
$this->resetAfterTest();
@@ -332,14 +321,13 @@ final class activityoverviewbase_test extends \advanced_testcase {
/**
* Test needs_filtering_by_groups method.
*
* @covers ::needs_filtering_by_groups
* @dataProvider provider_needs_filtering_by_groups
*
* @param string $role of the user to test
* @param int $groupmode of the activity to test
* @param bool $expected result.
* @return void
*/
#[\PHPUnit\Framework\Attributes\DataProvider('provider_needs_filtering_by_groups')]
public function test_needs_filtering_by_groups(string $role, int $groupmode, bool $expected): void {
$this->resetAfterTest();
@@ -414,14 +402,12 @@ final class activityoverviewbase_test extends \advanced_testcase {
/**
* Test needs_filtering_by_groups method.
*
* @covers ::get_groups_for_filtering
* @dataProvider provider_get_groups_for_filtering
*
* @param string $role of the user to test
* @param int $groupmode of the activity to test
* @param array $expected result
* @return void
*/
#[\PHPUnit\Framework\Attributes\DataProvider('provider_get_groups_for_filtering')]
public function test_get_groups_for_filtering(string $role, int $groupmode, array $expected): void {
$this->resetAfterTest();
@@ -512,14 +498,13 @@ final class activityoverviewbase_test extends \advanced_testcase {
/**
* Test has_error method.
*
* @covers ::has_error
* @dataProvider provider_has_error
*
* @param string $role of the user to test
* @param int $groupmode of the activity to test
* @param bool $expected result
* @return void
*/
#[\PHPUnit\Framework\Attributes\DataProvider('provider_has_error')]
public function test_has_error(string $role, int $groupmode, bool $expected): void {
$this->resetAfterTest();
@@ -23,8 +23,8 @@ namespace core_courseformat\external;
* @category test
* @copyright 2025 Ferran Recio <[email protected]>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
* @covers \core_courseformat\external\activityname_exporter
*/
#[\PHPUnit\Framework\Attributes\CoversClass(activityname_exporter::class)]
final class activityname_exporter_test extends \advanced_testcase {
/**
* Test export method.
@@ -26,8 +26,8 @@ use stdClass;
* @category test
* @copyright 2025 Ferran Recio <[email protected]>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
* @covers \core_courseformat\external\get_overview_information
*/
#[\PHPUnit\Framework\Attributes\CoversClass(get_overview_information::class)]
final class get_overview_information_test extends \core_external\tests\externallib_testcase {
public function test_get_overview_information(): void {
$this->resetAfterTest();
@@ -25,8 +25,8 @@ use core_courseformat\output\local\overview\overviewdialog;
* @category test
* @copyright 2025 Ferran Recio <[email protected]>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
* @covers \core_courseformat\external\overviewdialog_exporter
*/
#[\PHPUnit\Framework\Attributes\CoversClass(overviewdialog_exporter::class)]
final class overviewdialog_exporter_test extends \advanced_testcase {
/**
* Test export method.
@@ -26,8 +26,8 @@ use core_courseformat\local\overview\overviewitem;
* @category test
* @copyright 2025 Ferran Recio <[email protected]>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
* @covers \core_courseformat\external\overviewitem_exporter
*/
#[\PHPUnit\Framework\Attributes\CoversClass(overviewitem_exporter::class)]
final class overviewitem_exporter_test extends \advanced_testcase {
/**
* Test export with basic content.
@@ -25,8 +25,8 @@ use core_courseformat\output\local\overview\overviewtable;
* @category test
* @copyright 2025 Ferran Recio <[email protected]>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
* @covers \core_courseformat\external\overviewtable_exporter
*/
#[\PHPUnit\Framework\Attributes\CoversClass(overviewtable_exporter::class)]
final class overviewtable_exporter_test extends \advanced_testcase {
/**
* Test export method.
@@ -23,10 +23,10 @@ namespace core_courseformat\local\overview;
* @category test
* @copyright 2025 Ferran Recio <[email protected]>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
* @covers \core_courseformat\local\overview\overviewfactory
*/
#[\PHPUnit\Framework\Attributes\CoversClass(overviewfactory::class)]
final class overviewfactory_test extends \advanced_testcase {
#[\Override()]
#[\Override]
public static function setUpBeforeClass(): void {
global $CFG;
require_once($CFG->dirroot . '/course/format/tests/fixtures/wrongcm_activityoverview.php');
@@ -36,9 +36,9 @@ final class overviewfactory_test extends \advanced_testcase {
/**
* Test create method on resource activities.
*
* @dataProvider create_resource_provider
* @param string $resourcetype
*/
#[\PHPUnit\Framework\Attributes\DataProvider('create_resource_provider')]
public function test_create_resource(
string $resourcetype,
?string $expected,
@@ -60,97 +60,94 @@ final class overviewfactory_test extends \advanced_testcase {
/**
* Data provider for test_create_resource.
*
* @return array
* @return \Generator
*/
public static function create_resource_provider(): array {
return [
// Resource activities.
'book' => [
'resourcetype' => 'book',
'expected' => resourceoverview::class,
],
'folder' => [
'resourcetype' => 'folder',
'expected' => resourceoverview::class,
],
'page' => [
'resourcetype' => 'page',
'expected' => resourceoverview::class,
],
'resource' => [
'resourcetype' => 'resource',
'expected' => resourceoverview::class,
],
'url' => [
'resourcetype' => 'url',
'expected' => resourceoverview::class,
],
// Fallbacks and integrations.
'assign' => [
'resourcetype' => 'assign',
'expected' => \mod_assign\courseformat\overview::class,
],
'bigbluebuttonbn' => [
'resourcetype' => 'bigbluebuttonbn',
'expected' => \mod_bigbluebuttonbn\courseformat\overview::class,
],
'choice' => [
'resourcetype' => 'choice',
'expected' => \mod_choice\courseformat\overview::class,
],
'data' => [
'resourcetype' => 'data',
'expected' => \mod_data\courseformat\overview::class,
],
'feedback' => [
'resourcetype' => 'feedback',
'expected' => \mod_feedback\courseformat\overview::class,
],
'forum' => [
'resourcetype' => 'forum',
'expected' => \mod_forum\courseformat\overview::class,
],
'glossary' => [
'resourcetype' => 'glossary',
'expected' => \mod_glossary\courseformat\overview::class,
],
'h5pactivity' => [
'resourcetype' => 'h5pactivity',
'expected' => \mod_h5pactivity\courseformat\overview::class,
],
'lesson' => [
'resourcetype' => 'lesson',
'expected' => \mod_lesson\courseformat\overview::class,
],
'lti' => [
'resourcetype' => 'lti',
'expected' => resourceoverview::class,
],
'qbank' => [
'resourcetype' => 'qbank',
'expected' => resourceoverview::class,
],
'quiz' => [
'resourcetype' => 'quiz',
'expected' => \mod_quiz\courseformat\overview::class,
],
'scorm' => [
'resourcetype' => 'scorm',
'expected' => \mod_scorm\courseformat\overview::class,
],
'wiki' => [
'resourcetype' => 'wiki',
'expected' => \mod_wiki\courseformat\overview::class,
],
'workshop' => [
'resourcetype' => 'workshop',
'expected' => \mod_workshop\courseformat\overview::class,
],
public static function create_resource_provider(): \Generator {
// Resource activities.
yield 'book' => [
'resourcetype' => 'book',
'expected' => resourceoverview::class,
];
yield 'folder' => [
'resourcetype' => 'folder',
'expected' => resourceoverview::class,
];
yield 'page' => [
'resourcetype' => 'page',
'expected' => resourceoverview::class,
];
yield 'resource' => [
'resourcetype' => 'resource',
'expected' => resourceoverview::class,
];
yield 'url' => [
'resourcetype' => 'url',
'expected' => resourceoverview::class,
];
yield // Fallbacks and integrations.
'assign' => [
'resourcetype' => 'assign',
'expected' => \mod_assign\courseformat\overview::class,
];
yield 'bigbluebuttonbn' => [
'resourcetype' => 'bigbluebuttonbn',
'expected' => \mod_bigbluebuttonbn\courseformat\overview::class,
];
yield 'choice' => [
'resourcetype' => 'choice',
'expected' => \mod_choice\courseformat\overview::class,
];
yield 'data' => [
'resourcetype' => 'data',
'expected' => \mod_data\courseformat\overview::class,
];
yield 'feedback' => [
'resourcetype' => 'feedback',
'expected' => \mod_feedback\courseformat\overview::class,
];
yield 'forum' => [
'resourcetype' => 'forum',
'expected' => \mod_forum\courseformat\overview::class,
];
yield 'glossary' => [
'resourcetype' => 'glossary',
'expected' => \mod_glossary\courseformat\overview::class,
];
yield 'h5pactivity' => [
'resourcetype' => 'h5pactivity',
'expected' => \mod_h5pactivity\courseformat\overview::class,
];
yield 'lesson' => [
'resourcetype' => 'lesson',
'expected' => \mod_lesson\courseformat\overview::class,
];
yield 'lti' => [
'resourcetype' => 'lti',
'expected' => resourceoverview::class,
];
yield 'qbank' => [
'resourcetype' => 'qbank',
'expected' => resourceoverview::class,
];
yield 'quiz' => [
'resourcetype' => 'quiz',
'expected' => \mod_quiz\courseformat\overview::class,
];
yield 'scorm' => [
'resourcetype' => 'scorm',
'expected' => \mod_scorm\courseformat\overview::class,
];
yield 'wiki' => [
'resourcetype' => 'wiki',
'expected' => \mod_wiki\courseformat\overview::class,
];
yield 'workshop' => [
'resourcetype' => 'workshop',
'expected' => \mod_workshop\courseformat\overview::class,
];
}
public function test_create_exception(
): void {
public function test_create_exception(): void {
$this->resetAfterTest();
$this->setAdminUser();
@@ -178,10 +175,10 @@ final class overviewfactory_test extends \advanced_testcase {
/**
* Test activity_has_overview_integration for existing modules.
*
* @dataProvider activity_has_overview_integration_provider
* @param string $modname
* @param bool $hasintegration
*/
#[\PHPUnit\Framework\Attributes\DataProvider('activity_has_overview_integration_provider')]
public function test_activity_has_overview_integration(
string $modname,
bool $hasintegration,
@@ -193,32 +190,96 @@ final class overviewfactory_test extends \advanced_testcase {
/**
* Data provider for test_overview_integrations.
*
* @return array
* @return \Generator
*/
public static function activity_has_overview_integration_provider(): array {
return [
'assign' => ['modname' => 'assign', 'hasintegration' => true],
'bigbluebuttonbn' => ['modname' => 'bigbluebuttonbn', 'hasintegration' => true],
'book' => ['modname' => 'book', 'hasintegration' => false],
'choice' => ['modname' => 'choice', 'hasintegration' => true],
'data' => ['modname' => 'data', 'hasintegration' => true],
'feedback' => ['modname' => 'feedback', 'hasintegration' => true],
'folder' => ['modname' => 'folder', 'hasintegration' => false],
'forum' => ['modname' => 'forum', 'hasintegration' => true],
'glossary' => ['modname' => 'glossary', 'hasintegration' => true],
'h5pactivity' => ['modname' => 'h5pactivity', 'hasintegration' => true],
'imscp' => ['modname' => 'imscp', 'hasintegration' => false],
'label' => ['modname' => 'label', 'hasintegration' => false],
'lesson' => ['modname' => 'lesson', 'hasintegration' => true],
'lti' => ['modname' => 'lti', 'hasintegration' => false],
'page' => ['modname' => 'page', 'hasintegration' => false],
'qbank' => ['modname' => 'qbank', 'hasintegration' => false],
'quiz' => ['modname' => 'quiz', 'hasintegration' => true],
'resource' => ['modname' => 'resource', 'hasintegration' => true],
'scorm' => ['modname' => 'scorm', 'hasintegration' => true],
'url' => ['modname' => 'url', 'hasintegration' => false],
'wiki' => ['modname' => 'wiki', 'hasintegration' => true],
'workshop' => ['modname' => 'workshop', 'hasintegration' => true],
public static function activity_has_overview_integration_provider(): \Generator {
yield 'assign' => [
'modname' => 'assign',
'hasintegration' => true,
];
yield 'bigbluebuttonbn' => [
'modname' => 'bigbluebuttonbn',
'hasintegration' => true,
];
yield 'book' => [
'modname' => 'book',
'hasintegration' => false,
];
yield 'choice' => [
'modname' => 'choice',
'hasintegration' => true,
];
yield 'data' => [
'modname' => 'data',
'hasintegration' => true,
];
yield 'feedback' => [
'modname' => 'feedback',
'hasintegration' => true,
];
yield 'folder' => [
'modname' => 'folder',
'hasintegration' => false,
];
yield 'forum' => [
'modname' => 'forum',
'hasintegration' => true,
];
yield 'glossary' => [
'modname' => 'glossary',
'hasintegration' => true,
];
yield 'h5pactivity' => [
'modname' => 'h5pactivity',
'hasintegration' => true,
];
yield 'imscp' => [
'modname' => 'imscp',
'hasintegration' => false,
];
yield 'label' => [
'modname' => 'label',
'hasintegration' => false,
];
yield 'lesson' => [
'modname' => 'lesson',
'hasintegration' => true,
];
yield 'lti' => [
'modname' => 'lti',
'hasintegration' => false,
];
yield 'page' => [
'modname' => 'page',
'hasintegration' => false,
];
yield 'qbank' => [
'modname' => 'qbank',
'hasintegration' => false,
];
yield 'quiz' => [
'modname' => 'quiz',
'hasintegration' => true,
];
yield 'resource' => [
'modname' => 'resource',
'hasintegration' => true,
];
yield 'scorm' => [
'modname' => 'scorm',
'hasintegration' => true,
];
yield 'url' => [
'modname' => 'url',
'hasintegration' => false,
];
yield 'wiki' => [
'modname' => 'wiki',
'hasintegration' => true,
];
yield 'workshop' => [
'modname' => 'workshop',
'hasintegration' => true,
];
}
@@ -25,19 +25,11 @@ use core\output\local\properties\text_align;
* @category test
* @copyright 2025 Ferran Recio <[email protected]>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
* @covers \core_courseformat\local\overview\overviewitem
*/
#[\PHPUnit\Framework\Attributes\CoversClass(overviewitem::class)]
final class overviewitem_test extends \advanced_testcase {
/**
* Tests the constructor.
*
* @covers ::__construct
* @covers ::get_name
* @covers ::get_value
* @covers ::get_content
* @covers ::get_text_align
* @covers ::get_alert_count
* @covers ::get_alert_label
*/
public function test_constructor(): void {
$name = 'Activity name';
@@ -65,19 +57,6 @@ final class overviewitem_test extends \advanced_testcase {
/**
* Test chained setters.
*
* @covers ::set_name
* @covers ::set_value
* @covers ::set_content
* @covers ::set_text_align
* @covers ::set_alert_count
* @covers ::set_alert_label
* @covers ::get_name
* @covers ::get_value
* @covers ::get_content
* @covers ::get_text_align
* @covers ::get_alert_count
* @covers ::get_alert_label
*/
public function test_setters(): void {
$item = new overviewitem('Sample', 1, 'Content', text_align::CENTER, 1, 'Alert label');
@@ -23,20 +23,17 @@ namespace core_courseformat\local\overview;
* @category test
* @copyright 2025 Ferran Recio <[email protected]>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
* @covers \core_courseformat\local\overview\resourceoverview
*/
#[\PHPUnit\Framework\Attributes\CoversClass(resourceoverview::class)]
final class resourceoverview_test extends \advanced_testcase {
/**
* Test get_actions_overview.
*
* @covers ::get_actions_overview
* @dataProvider provider_test_get_actions_overview
*
* @param string $role The role of the user to test.
* @param string $resourcetype The type of resource to create.
* @param array|null $expected Expected overview item data.
*/
#[\PHPUnit\Framework\Attributes\DataProvider('provider_test_get_actions_overview')]
public function test_get_actions_overview(
string $role,
string $resourcetype,
@@ -69,72 +66,68 @@ final class resourceoverview_test extends \advanced_testcase {
/**
* Data provider for test_get_actions_overview.
*
* @return array
* @return \Generator
*/
public static function provider_test_get_actions_overview(): array {
return [
'Student' => [
'role' => 'student',
'resourcetype' => 'url',
'expected' => null,
public static function provider_test_get_actions_overview(): \Generator {
yield 'Student' => [
'role' => 'student',
'resourcetype' => 'url',
'expected' => null,
];
yield 'Teacher - Book' => [
'role' => 'editingteacher',
'resourcetype' => 'book',
'expected' => [
'name' => get_string('actions'),
'value' => '',
'content' => get_string('view'),
],
'Teacher - Book' => [
'role' => 'editingteacher',
'resourcetype' => 'book',
'expected' => [
'name' => get_string('actions'),
'value' => '',
'content' => get_string('view'),
],
];
yield 'Teacher - Folder' => [
'role' => 'editingteacher',
'resourcetype' => 'folder',
'expected' => [
'name' => get_string('actions'),
'value' => '',
'content' => get_string('view'),
],
'Teacher - Folder' => [
'role' => 'editingteacher',
'resourcetype' => 'folder',
'expected' => [
'name' => get_string('actions'),
'value' => '',
'content' => get_string('view'),
],
];
yield 'Teacher - Page' => [
'role' => 'editingteacher',
'resourcetype' => 'page',
'expected' => [
'name' => get_string('actions'),
'value' => '',
'content' => get_string('view'),
],
'Teacher - Page' => [
'role' => 'editingteacher',
'resourcetype' => 'page',
'expected' => [
'name' => get_string('actions'),
'value' => '',
'content' => get_string('view'),
],
];
yield 'Teacher - Resource' => [
'role' => 'editingteacher',
'resourcetype' => 'resource',
'expected' => [
'name' => get_string('actions'),
'value' => '',
'content' => get_string('view'),
],
'Teacher - Resource' => [
'role' => 'editingteacher',
'resourcetype' => 'resource',
'expected' => [
'name' => get_string('actions'),
'value' => '',
'content' => get_string('view'),
],
],
'Teacher - URL' => [
'role' => 'editingteacher',
'resourcetype' => 'url',
'expected' => [
'name' => get_string('actions'),
'value' => '',
'content' => get_string('view'),
],
],
'Teacher - Non resource' => [
'role' => 'editingteacher',
'resourcetype' => 'lti',
'expected' => null,
];
yield 'Teacher - URL' => [
'role' => 'editingteacher',
'resourcetype' => 'url',
'expected' => [
'name' => get_string('actions'),
'value' => '',
'content' => get_string('view'),
],
];
yield 'Teacher - Non resource' => [
'role' => 'editingteacher',
'resourcetype' => 'lti',
'expected' => null,
];
}
/**
* Test get_extra_overview_items method.
*
* @covers ::get_extra_overview_items
*/
public function test_get_extra_overview_items(): void {
$this->resetAfterTest();
@@ -168,12 +161,10 @@ final class resourceoverview_test extends \advanced_testcase {
/**
* Test get_extra_type_overview method.
*
* @covers ::get_extra_overview_items
* @covers ::get_extra_type_overview
* @dataProvider get_extra_type_overview_provider
* @param string $resourcetype
* @param string|null $expected
*/
#[\PHPUnit\Framework\Attributes\DataProvider('get_extra_type_overview_provider')]
public function test_get_extra_type_overview(
string $resourcetype,
?string $expected,
@@ -205,79 +196,77 @@ final class resourceoverview_test extends \advanced_testcase {
/**
* Data provider for test_get_extra_type_overview.
*
* @return array
* @return \Generator
*/
public static function get_extra_type_overview_provider(): array {
return [
'book' => [
'resourcetype' => 'book',
'expected' => 'Book',
],
'folder' => [
'resourcetype' => 'folder',
'expected' => 'Folder',
],
'page' => [
'resourcetype' => 'page',
'expected' => 'Page',
],
'resource' => [
'resourcetype' => 'resource',
'expected' => 'File',
],
'url' => [
'resourcetype' => 'url',
'expected' => 'URL',
],
// Non-resource activities.
'bigbluebuttonbn' => [
'resourcetype' => 'bigbluebuttonbn',
'expected' => null,
],
'choice' => [
'resourcetype' => 'choice',
'expected' => null,
],
'data' => [
'resourcetype' => 'data',
'expected' => null,
],
'forum' => [
'resourcetype' => 'forum',
'expected' => null,
],
'glossary' => [
'resourcetype' => 'glossary',
'expected' => null,
],
'h5pactivity' => [
'resourcetype' => 'h5pactivity',
'expected' => null,
],
'lesson' => [
'resourcetype' => 'lesson',
'expected' => null,
],
'lti' => [
'resourcetype' => 'lti',
'expected' => null,
],
'qbank' => [
'resourcetype' => 'qbank',
'expected' => null,
],
'quiz' => [
'resourcetype' => 'quiz',
'expected' => null,
],
'scorm' => [
'resourcetype' => 'scorm',
'expected' => null,
],
'wiki' => [
'resourcetype' => 'wiki',
'expected' => null,
],
public static function get_extra_type_overview_provider(): \Generator {
yield 'book' => [
'resourcetype' => 'book',
'expected' => 'Book',
];
yield 'folder' => [
'resourcetype' => 'folder',
'expected' => 'Folder',
];
yield 'page' => [
'resourcetype' => 'page',
'expected' => 'Page',
];
yield 'resource' => [
'resourcetype' => 'resource',
'expected' => 'File',
];
yield 'url' => [
'resourcetype' => 'url',
'expected' => 'URL',
];
// Non-resource activities.
yield 'bigbluebuttonbn' => [
'resourcetype' => 'bigbluebuttonbn',
'expected' => null,
];
yield 'choice' => [
'resourcetype' => 'choice',
'expected' => null,
];
yield 'data' => [
'resourcetype' => 'data',
'expected' => null,
];
yield 'forum' => [
'resourcetype' => 'forum',
'expected' => null,
];
yield 'glossary' => [
'resourcetype' => 'glossary',
'expected' => null,
];
yield 'h5pactivity' => [
'resourcetype' => 'h5pactivity',
'expected' => null,
];
yield 'lesson' => [
'resourcetype' => 'lesson',
'expected' => null,
];
yield 'lti' => [
'resourcetype' => 'lti',
'expected' => null,
];
yield 'qbank' => [
'resourcetype' => 'qbank',
'expected' => null,
];
yield 'quiz' => [
'resourcetype' => 'quiz',
'expected' => null,
];
yield 'scorm' => [
'resourcetype' => 'scorm',
'expected' => null,
];
yield 'wiki' => [
'resourcetype' => 'wiki',
'expected' => null,
];
}
}
@@ -23,8 +23,8 @@ namespace core_courseformat\output\local\overview;
* @category test
* @copyright 2025 Ferran Recio <[email protected]>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
* @covers \core_courseformat\output\local\overview\activityname
*/
#[\PHPUnit\Framework\Attributes\CoversClass(activityname::class)]
final class activityname_test extends \advanced_testcase {
/**
* Test the exportable interface implementation.
@@ -23,17 +23,16 @@ namespace core_courseformat\output\local\overview;
* @category test
* @copyright 2025 Ferran Recio <[email protected]>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
* @covers \core_courseformat\output\local\overview\missingoverviewnotice
*/
#[\PHPUnit\Framework\Attributes\CoversClass(missingoverviewnotice::class)]
final class missingoverviewnotice_test extends \advanced_testcase {
/**
* Test overview integrations.
*
* @covers ::export_for_template
* @dataProvider overview_integrations_provider
* @param string $modname
* @param bool $expectempty
*/
#[\PHPUnit\Framework\Attributes\DataProvider('overview_integrations_provider')]
public function test_overview_integrations(
string $modname,
bool $expectempty,
@@ -58,32 +57,96 @@ final class missingoverviewnotice_test extends \advanced_testcase {
/**
* Data provider for test_overview_integrations.
*
* @return array
* @return \Generator
*/
public static function overview_integrations_provider(): array {
return [
'assign' => ['modname' => 'assign', 'expectempty' => true],
'bigbluebuttonbn' => ['modname' => 'bigbluebuttonbn', 'expectempty' => true],
'book' => ['modname' => 'book', 'expectempty' => false],
'choice' => ['modname' => 'choice', 'expectempty' => true],
'data' => ['modname' => 'data', 'expectempty' => true],
'feedback' => ['modname' => 'feedback', 'expectempty' => true],
'folder' => ['modname' => 'folder', 'expectempty' => false],
'forum' => ['modname' => 'forum', 'expectempty' => true],
'glossary' => ['modname' => 'glossary', 'expectempty' => true],
'h5pactivity' => ['modname' => 'h5pactivity', 'expectempty' => true],
'imscp' => ['modname' => 'imscp', 'expectempty' => false],
'label' => ['modname' => 'label', 'expectempty' => false],
'lesson' => ['modname' => 'lesson', 'expectempty' => true],
'lti' => ['modname' => 'lti', 'expectempty' => false],
'page' => ['modname' => 'page', 'expectempty' => false],
'qbank' => ['modname' => 'qbank', 'expectempty' => false],
'quiz' => ['modname' => 'quiz', 'expectempty' => true],
'resource' => ['modname' => 'resource', 'expectempty' => true],
'scorm' => ['modname' => 'scorm', 'expectempty' => true],
'url' => ['modname' => 'url', 'expectempty' => false],
'wiki' => ['modname' => 'wiki', 'expectempty' => true],
'workshop' => ['modname' => 'workshop', 'expectempty' => true],
public static function overview_integrations_provider(): \Generator {
yield 'assign' => [
'modname' => 'assign',
'expectempty' => true,
];
yield 'bigbluebuttonbn' => [
'modname' => 'bigbluebuttonbn',
'expectempty' => true,
];
yield 'book' => [
'modname' => 'book',
'expectempty' => false,
];
yield 'choice' => [
'modname' => 'choice',
'expectempty' => true,
];
yield 'data' => [
'modname' => 'data',
'expectempty' => true,
];
yield 'feedback' => [
'modname' => 'feedback',
'expectempty' => true,
];
yield 'folder' => [
'modname' => 'folder',
'expectempty' => false,
];
yield 'forum' => [
'modname' => 'forum',
'expectempty' => true,
];
yield 'glossary' => [
'modname' => 'glossary',
'expectempty' => true,
];
yield 'h5pactivity' => [
'modname' => 'h5pactivity',
'expectempty' => true,
];
yield 'imscp' => [
'modname' => 'imscp',
'expectempty' => false,
];
yield 'label' => [
'modname' => 'label',
'expectempty' => false,
];
yield 'lesson' => [
'modname' => 'lesson',
'expectempty' => true,
];
yield 'lti' => [
'modname' => 'lti',
'expectempty' => false,
];
yield 'page' => [
'modname' => 'page',
'expectempty' => false,
];
yield 'qbank' => [
'modname' => 'qbank',
'expectempty' => false,
];
yield 'quiz' => [
'modname' => 'quiz',
'expectempty' => true,
];
yield 'resource' => [
'modname' => 'resource',
'expectempty' => true,
];
yield 'scorm' => [
'modname' => 'scorm',
'expectempty' => true,
];
yield 'url' => [
'modname' => 'url',
'expectempty' => false,
];
yield 'wiki' => [
'modname' => 'wiki',
'expectempty' => true,
];
yield 'workshop' => [
'modname' => 'workshop',
'expectempty' => true,
];
}
}
@@ -23,8 +23,8 @@ namespace core_courseformat\output\local\overview;
* @category test
* @copyright 2025 Ferran Recio <[email protected]>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
* @covers \core_courseformat\output\local\overview\overviewdialog
*/
#[\PHPUnit\Framework\Attributes\CoversClass(overviewdialog::class)]
final class overviewdialog_test extends \advanced_testcase {
/**
* Test the exportable interface implementation.
@@ -23,8 +23,8 @@ namespace core_courseformat\output\local\overview;
* @category test
* @copyright 2025 Ferran Recio <[email protected]>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
* @covers \core_courseformat\output\local\overview\overviewtable
*/
#[\PHPUnit\Framework\Attributes\CoversClass(overviewtable::class)]
final class overviewtable_test extends \advanced_testcase {
/**
* Test export_for_external method.
@@ -21,12 +21,12 @@ use core_courseformat\local\overview\overviewfactory;
/**
* Tests for Assignment overview integration.
*
* @covers \mod_assign\course\overview
* @package mod_assign
* @category test
* @copyright 2025 Ferran Recio <[email protected]>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
#[\PHPUnit\Framework\Attributes\CoversClass(overview::class)]
final class overview_test extends \advanced_testcase {
#[\Override]
public static function setUpBeforeClass(): void {
@@ -41,9 +41,8 @@ final class overview_test extends \advanced_testcase {
*
* @param int $groupmode The group mode of the course.
* @param bool $teamsubmission Whether the assignment is a team submission.
*
* @dataProvider provider_get_actions_overview
*/
#[\PHPUnit\Framework\Attributes\DataProvider('provider_get_actions_overview')]
public function test_get_actions_overview(int $groupmode, bool $teamsubmission): void {
$this->resetAfterTest();
@@ -162,44 +161,41 @@ final class overview_test extends \advanced_testcase {
/**
* Data provider for test_get_actions_overview.
*
* @return array The data provider array.
* @return \Generator The data provider array.
*/
public static function provider_get_actions_overview(): array {
return [
'No groups - No team submission' => [
'groupmode' => NOGROUPS,
'teamsubmission' => false,
],
'No groups - Team submission' => [
'groupmode' => NOGROUPS,
'teamsubmission' => true,
],
'Visible groups - No team submission' => [
'groupmode' => VISIBLEGROUPS,
'teamsubmission' => false,
],
'Visible groups - Team submission' => [
'groupmode' => VISIBLEGROUPS,
'teamsubmission' => true,
],
'Separate groups - No team submission' => [
'groupmode' => SEPARATEGROUPS,
'teamsubmission' => false,
],
'Separate groups - Team submission' => [
'groupmode' => SEPARATEGROUPS,
'teamsubmission' => true,
],
public static function provider_get_actions_overview(): \Generator {
yield 'No groups - No team submission' => [
'groupmode' => NOGROUPS,
'teamsubmission' => false,
];
yield 'No groups - Team submission' => [
'groupmode' => NOGROUPS,
'teamsubmission' => true,
];
yield 'Visible groups - No team submission' => [
'groupmode' => VISIBLEGROUPS,
'teamsubmission' => false,
];
yield 'Visible groups - Team submission' => [
'groupmode' => VISIBLEGROUPS,
'teamsubmission' => true,
];
yield 'Separate groups - No team submission' => [
'groupmode' => SEPARATEGROUPS,
'teamsubmission' => false,
];
yield 'Separate groups - Team submission' => [
'groupmode' => SEPARATEGROUPS,
'teamsubmission' => true,
];
}
/**
* Test get_due_date_overview method.
*
* @covers ::get_due_date_overview
* @dataProvider get_due_date_overview_provider
* @param int|null $timeincrement null if no due date, or due date increment.
*/
#[\PHPUnit\Framework\Attributes\DataProvider('get_due_date_overview_provider')]
public function test_get_due_date_overview(
int|null $timeincrement,
): void {
@@ -233,19 +229,17 @@ final class overview_test extends \advanced_testcase {
/**
* Provider for get_due_date_overview.
*
* @return array
* @return \Generator
*/
public static function get_due_date_overview_provider(): array {
return [
'no_due' => [
'timeincrement' => null,
],
'past_due' => [
'timeincrement' => -1 * (4 * DAYSECS),
],
'future_due' => [
'timeincrement' => (4 * DAYSECS),
],
public static function get_due_date_overview_provider(): \Generator {
yield 'no_due' => [
'timeincrement' => null,
];
yield 'past_due' => [
'timeincrement' => -1 * (4 * DAYSECS),
];
yield 'future_due' => [
'timeincrement' => (4 * DAYSECS),
];
}
@@ -432,8 +426,6 @@ final class overview_test extends \advanced_testcase {
/**
* Test get_extra_submission_status_overview method.
*
* @covers ::get_extra_submission_status_overview
*/
public function test_get_extra_submission_status_overview(): void {
$this->resetAfterTest();
@@ -511,8 +503,6 @@ final class overview_test extends \advanced_testcase {
/**
* Test get_extra_submission_status_overview method in group submissions.
*
* @covers ::get_extra_submission_status_overview
*/
public function test_get_extra_submission_status_overview_groups(): void {
$this->resetAfterTest();
@@ -24,12 +24,12 @@ use mod_bigbluebuttonbn\test\testcase_helper_trait;
/**
* Tests for bigbluebuttonbn activity overview
*
* @covers \mod_bigbluebuttonbn\courseformat\overview
* @package mod_bigbluebuttonbn
* @category test
* @copyright 2025 Laurent David <[email protected]>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
#[\PHPUnit\Framework\Attributes\CoversClass(overview::class)]
final class overview_test extends \advanced_testcase {
use testcase_helper_trait;
/**
@@ -90,9 +90,8 @@ final class overview_test extends \advanced_testcase {
* Test get_extra_date_open method.
*
* @param int|null $timeincrement
*
* @dataProvider get_extra_date_data
*/
#[\PHPUnit\Framework\Attributes\DataProvider('get_extra_date_data')]
public function test_get_extra_date_open(?int $timeincrement): void {
$this->resetAfterTest();
$this->setAdminUser();
@@ -118,9 +117,8 @@ final class overview_test extends \advanced_testcase {
* Test get_extra_date_close method.
*
* @param int|null $timeincrement
*
* @dataProvider get_extra_date_data
*/
#[\PHPUnit\Framework\Attributes\DataProvider('get_extra_date_data')]
public function test_get_extra_date_close(?int $timeincrement): void {
$this->resetAfterTest();
$this->setAdminUser();
@@ -145,22 +143,20 @@ final class overview_test extends \advanced_testcase {
/**
* Data provider for test_get_due_date_overview.
*
* @return array
* @return \Generator
*/
public static function get_extra_date_data(): array {
return [
'tomorrow' => [
'timeincrement' => DAYSECS,
],
'yesterday' => [
'timeincrement' => -1 * DAYSECS,
],
'today' => [
'timeincrement' => 0,
],
'No date' => [
'timeincrement' => null,
],
public static function get_extra_date_data(): \Generator {
yield 'tomorrow' => [
'timeincrement' => DAYSECS,
];
yield 'yesterday' => [
'timeincrement' => -1 * DAYSECS,
];
yield 'today' => [
'timeincrement' => 0,
];
yield 'No date' => [
'timeincrement' => null,
];
}
@@ -169,9 +165,8 @@ final class overview_test extends \advanced_testcase {
*
* @param int $roomtype
* @param string $expectedtype
*
* @dataProvider get_extra_room_type_overview_data
*/
#[\PHPUnit\Framework\Attributes\DataProvider('get_extra_room_type_overview_data')]
public function test_get_extra_room_type_overview(int $roomtype, string $expectedtype): void {
$this->resetAfterTest();
$this->setAdminUser();
@@ -195,22 +190,20 @@ final class overview_test extends \advanced_testcase {
/**
* Data provider for test_get_due_date_overview.
*
* @return array
* @return \Generator
*/
public static function get_extra_room_type_overview_data(): array {
return [
'All' => [
'roomtype' => instance::TYPE_ALL,
'expectedtype' => get_string('instance_type_default', 'bigbluebuttonbn'),
],
'Room Only' => [
'roomtype' => instance::TYPE_ROOM_ONLY,
'expectedtype' => get_string('instance_type_room_only', 'bigbluebuttonbn'),
],
'Recording Only' => [
'roomtype' => instance::TYPE_RECORDING_ONLY,
'expectedtype' => get_string('instance_type_recording_only', 'bigbluebuttonbn'),
],
public static function get_extra_room_type_overview_data(): \Generator {
yield 'All' => [
'roomtype' => instance::TYPE_ALL,
'expectedtype' => get_string('instance_type_default', 'bigbluebuttonbn'),
];
yield 'Room Only' => [
'roomtype' => instance::TYPE_ROOM_ONLY,
'expectedtype' => get_string('instance_type_room_only', 'bigbluebuttonbn'),
];
yield 'Recording Only' => [
'roomtype' => instance::TYPE_RECORDING_ONLY,
'expectedtype' => get_string('instance_type_recording_only', 'bigbluebuttonbn'),
];
}
@@ -219,9 +212,8 @@ final class overview_test extends \advanced_testcase {
*
* @param string $activityname
* @param int $recordingcount
*
* @dataProvider get_extra_recordings_overview_data
*/
#[\PHPUnit\Framework\Attributes\DataProvider('get_extra_recordings_overview_data')]
public function test_get_extra_recordings_overview(string $activityname, int $recordingcount): void {
$this->resetAfterTest();
$this->setAdminUser();
@@ -253,19 +245,16 @@ final class overview_test extends \advanced_testcase {
/**
* Data provider for test_get_extra_studentsattempted_overview and test_get_extra_totalattempts_overview
*
* @return array
* @return \Generator
*/
public static function get_extra_recordings_overview_data(): array {
return [
'with recordings' => [
'activityname' => 'withrecordings',
'recordingcount' => 2,
],
'without recordings' => [
'activityname' => 'withoutrecordings',
'recordingcount' => 0,
],
public static function get_extra_recordings_overview_data(): \Generator {
yield 'with recordings' => [
'activityname' => 'withrecordings',
'recordingcount' => 2,
];
yield 'without recordings' => [
'activityname' => 'withoutrecordings',
'recordingcount' => 0,
];
}
@@ -275,8 +264,8 @@ final class overview_test extends \advanced_testcase {
* @param string $activityname
* @param int $groupmode
* @param array $recordingcounts Array of recording counts per user in the form of ['group' => string|null, status=> int].
* @dataProvider get_extra_recordings_overview_with_groups_data
*/
#[\PHPUnit\Framework\Attributes\DataProvider('get_extra_recordings_overview_with_groups_data')]
public function test_get_extra_recordings_overview_with_groups(
string $activityname,
int $groupmode,
@@ -324,9 +313,9 @@ final class overview_test extends \advanced_testcase {
/**
* Data provider for test_get_extra_studentsattempted_overview and test_get_extra_totalattempts_overview
*
* @return array
* @return \Generator
*/
public static function get_extra_recordings_overview_with_groups_data(): array {
public static function get_extra_recordings_overview_with_groups_data(): \Generator {
// The setup is as follows:
// - T1 is in group but is editing teacher so can see recordings from group g1 and g2.
// - T2 is not in any group but is editing teacher so can see recordings from group g1 and g2.
@@ -337,39 +326,37 @@ final class overview_test extends \advanced_testcase {
// We have 3 recordings in total (all processed:
// - 2 recordings in group g1.
// - 1 recording in group g2.
return [
'With separate groups' => [
'activityname' => 'withrecordings',
'groupmode' => SEPARATEGROUPS,
'recordingcounts' => [
't1' => 4, // T1 is in group g1 and can see recordings from group g2 (as has all access as editing teacher).
't2' => 4, // T2 is not in any group but can see recordings from group g1 and g2 as editing teacher.
't3' => 2, // T3 is in group g1 so can see recordings from group g1.
't4' => null, // T4 is not in any group so should not see any recording.
't5' => 1, // T5 is in group g2 and can see recordings from group g2.
],
yield 'With separate groups' => [
'activityname' => 'withrecordings',
'groupmode' => SEPARATEGROUPS,
'recordingcounts' => [
't1' => 4, // T1 is in group g1 and can see recordings from group g2 (as has all access as editing teacher).
't2' => 4, // T2 is not in any group but can see recordings from group g1 and g2 as editing teacher.
't3' => 2, // T3 is in group g1 so can see recordings from group g1.
't4' => null, // T4 is not in any group so should not see any recording.
't5' => 1, // T5 is in group g2 and can see recordings from group g2.
],
'With no groups' => [
'activityname' => 'withrecordings',
'groupmode' => NOGROUPS,
'recordingcounts' => [
't1' => 4,
't2' => 4,
't3' => 4,
't4' => 4,
't5' => 4,
],
];
yield 'With no groups' => [
'activityname' => 'withrecordings',
'groupmode' => NOGROUPS,
'recordingcounts' => [
't1' => 4,
't2' => 4,
't3' => 4,
't4' => 4,
't5' => 4,
],
'With visible groups' => [
'activityname' => 'withrecordings',
'groupmode' => VISIBLEGROUPS,
'recordingcounts' => [
't1' => 4,
't2' => 4,
't3' => 4,
't4' => 4,
't5' => 4,
],
];
yield 'With visible groups' => [
'activityname' => 'withrecordings',
'groupmode' => VISIBLEGROUPS,
'recordingcounts' => [
't1' => 4,
't2' => 4,
't3' => 4,
't4' => 4,
't5' => 4,
],
];
}
@@ -21,22 +21,20 @@ use core_courseformat\local\overview\overviewfactory;
/**
* Tests for Choice integration.
*
* @covers \mod_choice\courseformat\overview
* @package mod_choice
* @category test
* @copyright 2025 Laurent David <[email protected]>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
#[\PHPUnit\Framework\Attributes\CoversClass(overview::class)]
final class overview_test extends \advanced_testcase {
/**
* Test get_extra_status_for_user method.
*
* @covers ::get_extra_status_for_user
* @dataProvider data_provider_get_extra_status_for_user
* @param string $user
* @param bool|null $answered
*/
#[\PHPUnit\Framework\Attributes\DataProvider('data_provider_get_extra_status_for_user')]
public function test_get_extra_status_for_user(string $user, ?bool $answered): void {
$this->resetAfterTest();
['users' => $users, 'course' => $course, 'instance' => $instance] =
@@ -58,22 +56,20 @@ final class overview_test extends \advanced_testcase {
/**
* Data provider for test_get_extra_status_for_user.
*
* @return array
* @return \Generator
*/
public static function data_provider_get_extra_status_for_user(): array {
return [
'teacher view answered' => [
'user' => 't1',
'answered' => null, // Teacher can not see the status column.
],
'student view answered' => [
'user' => 's1',
'answered' => true,
],
'student view not answered' => [
'user' => 's2',
'answered' => false,
],
public static function data_provider_get_extra_status_for_user(): \Generator {
yield 'teacher view answered' => [
'user' => 't1',
'answered' => null, // Teacher can not see the status column.
];
yield 'student view answered' => [
'user' => 's1',
'answered' => true,
];
yield 'student view not answered' => [
'user' => 's2',
'answered' => false,
];
}
@@ -81,10 +77,8 @@ final class overview_test extends \advanced_testcase {
* Test get_extra_status_for_user method.
*
* @param int|null $timeincrement
*
* @covers ::get_due_date_overview
* @dataProvider data_provider_get_due_date_overview
*/
#[\PHPUnit\Framework\Attributes\DataProvider('data_provider_get_due_date_overview')]
public function test_get_due_date_overview(?int $timeincrement = null): void {
$this->resetAfterTest();
$this->setAdminUser();
@@ -114,22 +108,20 @@ final class overview_test extends \advanced_testcase {
/**
* Data provider for test_get_due_date_overview.
*
* @return array
* @return \Generator
*/
public static function data_provider_get_due_date_overview(): array {
return [
'tomorrow' => [
'timeincrement' => 1 * DAYSECS,
],
'yesterday' => [
'timeincrement' => -1 * DAYSECS,
],
'today' => [
'timeincrement' => 0,
],
'No date' => [
'timeincrement' => null,
],
public static function data_provider_get_due_date_overview(): \Generator {
yield 'tomorrow' => [
'timeincrement' => 1 * DAYSECS,
];
yield 'yesterday' => [
'timeincrement' => -1 * DAYSECS,
];
yield 'today' => [
'timeincrement' => 0,
];
yield 'No date' => [
'timeincrement' => null,
];
}
@@ -138,10 +130,8 @@ final class overview_test extends \advanced_testcase {
*
* @param string $username The username of the user to test.
* @param int|null $expectedcount the expected count of users who responded
*
* @covers ::get_actions_overview
* @dataProvider provider_test_get_actions_overview
*/
#[\PHPUnit\Framework\Attributes\DataProvider('provider_test_get_actions_overview')]
public function test_get_actions_overview(string $username, ?int $expectedcount = null): void {
$this->resetAfterTest();
['users' => $users, 'course' => $course, 'instance' => $instance] = $this->setup_users_and_activity();
@@ -163,18 +153,16 @@ final class overview_test extends \advanced_testcase {
/**
* Data provider for test_get_actions_overview.
*
* @return array the data provider array
* @return \Generator the data provider array
*/
public static function provider_test_get_actions_overview(): array {
return [
'Student' => [
'username' => 's1',
'expectedcount' => null,
],
'Teacher' => [
'username' => 't1',
'expectedcount' => 3,
],
public static function provider_test_get_actions_overview(): \Generator {
yield 'Student' => [
'username' => 's1',
'expectedcount' => null,
];
yield 'Teacher' => [
'username' => 't1',
'expectedcount' => 3,
];
}
@@ -186,10 +174,8 @@ final class overview_test extends \advanced_testcase {
* @param bool $withanswers whether the choice will be created with answers
* @param int $groupmode The group mode for the choice activity.
* @param int|null $expectedcount the expected count of users who responded
*
* @covers ::get_actions_overview
* @dataProvider provider_get_extra_students_who_responded
*/
#[\PHPUnit\Framework\Attributes\DataProvider('provider_get_extra_students_who_responded')]
public function test_get_extra_students_who_responded(
string $currentuser,
bool $allowmultiple = false,
@@ -244,125 +230,123 @@ final class overview_test extends \advanced_testcase {
/**
* Data provider for test_get_extra_students_who_responded.
*
* @return array the data provider array
* @return \Generator the data provider array
*/
public static function provider_get_extra_students_who_responded(): array {
return [
'Student' => [
'currentuser' => 's1',
'expectedcount' => null,
],
// No groups.
'No groups - Teacher - With answers - No multiple' => [
'currentuser' => 't2',
'allowmultiple' => false,
'withanswers' => true,
'groupmode' => NOGROUPS,
'expectedcount' => 3,
],
'No groups - Teacher - Without answers - No multiple' => [
'currentuser' => 't2',
'withanswers' => false,
'groupmode' => NOGROUPS,
'expectedcount' => 0,
],
'No groups - Teacher - With answers - Multiple' => [
'currentuser' => 't2',
'allowmultiple' => true,
'withanswers' => true,
'groupmode' => NOGROUPS,
'expectedcount' => 3,
],
'No groups - Teacher - Without answers - Multiple' => [
'currentuser' => 't2',
'allowmultiple' => true,
'withanswers' => false,
'groupmode' => NOGROUPS,
'expectedcount' => 0,
],
// Visible groups.
'Visible groups - Teacher - With answers - No multiple' => [
'currentuser' => 't2',
'allowmultiple' => false,
'withanswers' => true,
'groupmode' => VISIBLEGROUPS,
'expectedcount' => 3,
],
'Visible groups - Teacher - Without answers - No multiple' => [
'currentuser' => 't2',
'withanswers' => false,
'groupmode' => VISIBLEGROUPS,
'expectedcount' => 0,
],
'Visible groups - Teacher - With answers - Multiple' => [
'currentuser' => 't2',
'allowmultiple' => true,
'withanswers' => true,
'groupmode' => VISIBLEGROUPS,
'expectedcount' => 3,
],
'Visible groups - Teacher - Without answers - Multiple' => [
'currentuser' => 't2',
'allowmultiple' => true,
'withanswers' => false,
'groupmode' => VISIBLEGROUPS,
'expectedcount' => 0,
],
// Separate groups.
'Separate groups - Editing teacher - With answers - No multiple' => [
'currentuser' => 't1',
'allowmultiple' => false,
'withanswers' => true,
'groupmode' => SEPARATEGROUPS,
'expectedcount' => 3,
],
'Separate groups - Editing teacher - Without answers - No multiple' => [
'currentuser' => 't1',
'withanswers' => false,
'groupmode' => SEPARATEGROUPS,
'expectedcount' => 0,
],
'Separate groups - Editing teacher - With answers - Multiple' => [
'currentuser' => 't1',
'allowmultiple' => true,
'withanswers' => true,
'groupmode' => SEPARATEGROUPS,
'expectedcount' => 3,
],
'Separate groups - Editing teacher - Without answers - Multiple' => [
'currentuser' => 't1',
'allowmultiple' => true,
'withanswers' => false,
'groupmode' => SEPARATEGROUPS,
'expectedcount' => 0,
],
'Separate groups - Non-editing teacher - With answers - No multiple' => [
'currentuser' => 't2',
'allowmultiple' => false,
'withanswers' => true,
'groupmode' => SEPARATEGROUPS,
'expectedcount' => 1,
],
'Separate groups - Non-editing teacher - Without answers - No multiple' => [
'currentuser' => 't2',
'withanswers' => false,
'groupmode' => SEPARATEGROUPS,
'expectedcount' => 0,
],
'Separate groups - Non-editing teacher - With answers - Multiple' => [
'currentuser' => 't2',
'allowmultiple' => true,
'withanswers' => true,
'groupmode' => SEPARATEGROUPS,
'expectedcount' => 1,
],
'Separate groups - Non-editing teacher - Without answers - Multiple' => [
'currentuser' => 't2',
'allowmultiple' => true,
'withanswers' => false,
'groupmode' => SEPARATEGROUPS,
'expectedcount' => 0,
],
public static function provider_get_extra_students_who_responded(): \Generator {
yield 'Student' => [
'currentuser' => 's1',
'expectedcount' => null,
];
// No groups.
yield 'No groups - Teacher - With answers - No multiple' => [
'currentuser' => 't2',
'allowmultiple' => false,
'withanswers' => true,
'groupmode' => NOGROUPS,
'expectedcount' => 3,
];
yield 'No groups - Teacher - Without answers - No multiple' => [
'currentuser' => 't2',
'withanswers' => false,
'groupmode' => NOGROUPS,
'expectedcount' => 0,
];
yield 'No groups - Teacher - With answers - Multiple' => [
'currentuser' => 't2',
'allowmultiple' => true,
'withanswers' => true,
'groupmode' => NOGROUPS,
'expectedcount' => 3,
];
yield 'No groups - Teacher - Without answers - Multiple' => [
'currentuser' => 't2',
'allowmultiple' => true,
'withanswers' => false,
'groupmode' => NOGROUPS,
'expectedcount' => 0,
];
// Visible groups.
yield 'Visible groups - Teacher - With answers - No multiple' => [
'currentuser' => 't2',
'allowmultiple' => false,
'withanswers' => true,
'groupmode' => VISIBLEGROUPS,
'expectedcount' => 3,
];
yield 'Visible groups - Teacher - Without answers - No multiple' => [
'currentuser' => 't2',
'withanswers' => false,
'groupmode' => VISIBLEGROUPS,
'expectedcount' => 0,
];
yield 'Visible groups - Teacher - With answers - Multiple' => [
'currentuser' => 't2',
'allowmultiple' => true,
'withanswers' => true,
'groupmode' => VISIBLEGROUPS,
'expectedcount' => 3,
];
yield 'Visible groups - Teacher - Without answers - Multiple' => [
'currentuser' => 't2',
'allowmultiple' => true,
'withanswers' => false,
'groupmode' => VISIBLEGROUPS,
'expectedcount' => 0,
];
// Separate groups.
yield 'Separate groups - Editing teacher - With answers - No multiple' => [
'currentuser' => 't1',
'allowmultiple' => false,
'withanswers' => true,
'groupmode' => SEPARATEGROUPS,
'expectedcount' => 3,
];
yield 'Separate groups - Editing teacher - Without answers - No multiple' => [
'currentuser' => 't1',
'withanswers' => false,
'groupmode' => SEPARATEGROUPS,
'expectedcount' => 0,
];
yield 'Separate groups - Editing teacher - With answers - Multiple' => [
'currentuser' => 't1',
'allowmultiple' => true,
'withanswers' => true,
'groupmode' => SEPARATEGROUPS,
'expectedcount' => 3,
];
yield 'Separate groups - Editing teacher - Without answers - Multiple' => [
'currentuser' => 't1',
'allowmultiple' => true,
'withanswers' => false,
'groupmode' => SEPARATEGROUPS,
'expectedcount' => 0,
];
yield 'Separate groups - Non-editing teacher - With answers - No multiple' => [
'currentuser' => 't2',
'allowmultiple' => false,
'withanswers' => true,
'groupmode' => SEPARATEGROUPS,
'expectedcount' => 1,
];
yield 'Separate groups - Non-editing teacher - Without answers - No multiple' => [
'currentuser' => 't2',
'withanswers' => false,
'groupmode' => SEPARATEGROUPS,
'expectedcount' => 0,
];
yield 'Separate groups - Non-editing teacher - With answers - Multiple' => [
'currentuser' => 't2',
'allowmultiple' => true,
'withanswers' => true,
'groupmode' => SEPARATEGROUPS,
'expectedcount' => 1,
];
yield 'Separate groups - Non-editing teacher - Without answers - Multiple' => [
'currentuser' => 't2',
'allowmultiple' => true,
'withanswers' => false,
'groupmode' => SEPARATEGROUPS,
'expectedcount' => 0,
];
}
@@ -22,25 +22,23 @@ use mod_data\manager;
/**
* Tests for Database activity overview
*
* @covers \mod_data\courseformat\overview
* @package mod_data
* @category test
* @copyright 2025 Amaia Anabitarte <[email protected]>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
#[\PHPUnit\Framework\Attributes\CoversClass(overview::class)]
final class overview_test extends \advanced_testcase {
/**
* Test get_actions_overview.
*
* @covers ::get_actions_overview
* @dataProvider provider_test_get_actions_overview
*
* @param string $role
* @param bool $needsapproval
* @param array $entries
* @param array|null $expected
* @return void
*/
#[\PHPUnit\Framework\Attributes\DataProvider('provider_test_get_actions_overview')]
public function test_get_actions_overview(
string $role,
bool $needsapproval,
@@ -94,51 +92,49 @@ final class overview_test extends \advanced_testcase {
/**
* Data provider for test_get_actions_overview.
*
* @return array
* @return \Generator
*/
public static function provider_test_get_actions_overview(): array {
return [
'Student' => [
'role' => 'student',
'needsapproval' => false,
'entries' => [1, 0],
'expected' => null,
public static function provider_test_get_actions_overview(): \Generator {
yield 'Student' => [
'role' => 'student',
'needsapproval' => false,
'entries' => [1, 0],
'expected' => null,
];
yield 'Teacher with entries (non-require approval)' => [
'role' => 'editingteacher',
'needsapproval' => false,
'entries' => [1, 0],
'expected' => [
'link' => get_string('view', 'moodle'),
'value' => 0,
],
'Teacher with entries (non-require approval)' => [
'role' => 'editingteacher',
'needsapproval' => false,
'entries' => [1, 0],
'expected' => [
'link' => get_string('view', 'moodle'),
'value' => 0,
],
];
yield 'Teacher without entries (require approval)' => [
'role' => 'editingteacher',
'needsapproval' => true,
'entries' => [],
'expected' => [
'link' => get_string('view', 'moodle'),
'value' => 0,
],
'Teacher without entries (require approval)' => [
'role' => 'editingteacher',
'needsapproval' => true,
'entries' => [],
'expected' => [
'link' => get_string('view', 'moodle'),
'value' => 0,
],
];
yield 'Teacher with entries (require approval)' => [
'role' => 'editingteacher',
'needsapproval' => true,
'entries' => [1, 0],
'expected' => [
'link' => get_string('approve', 'data'),
'value' => 1,
],
'Teacher with entries (require approval)' => [
'role' => 'editingteacher',
'needsapproval' => true,
'entries' => [1, 0],
'expected' => [
'link' => get_string('approve', 'data'),
'value' => 1,
],
],
'Teacher with approved entries (require approval)' => [
'role' => 'editingteacher',
'needsapproval' => true,
'entries' => [1, 1],
'expected' => [
'link' => get_string('view', 'moodle'),
'value' => 0,
],
];
yield 'Teacher with approved entries (require approval)' => [
'role' => 'editingteacher',
'needsapproval' => true,
'entries' => [1, 1],
'expected' => [
'link' => get_string('view', 'moodle'),
'value' => 0,
],
];
}
@@ -146,9 +142,6 @@ final class overview_test extends \advanced_testcase {
/**
* Test get_extra_overview_items.
*
* @covers ::get_extra_overview_items
* @dataProvider provider_test_get_entries_overview
*
* @param string $role
* @param bool $needsapproval
* @param array $entries
@@ -156,6 +149,7 @@ final class overview_test extends \advanced_testcase {
* @param array $expected
* @return void
*/
#[\PHPUnit\Framework\Attributes\DataProvider('provider_test_get_entries_overview')]
public function test_get_extra_entries_overview(
string $role,
bool $needsapproval,
@@ -222,77 +216,73 @@ final class overview_test extends \advanced_testcase {
/**
* Data provider for test entry related extras.
*
* @return array
* @return \Generator
*/
public static function provider_test_get_entries_overview(): array {
return [
'Student not needing approval' => [
'role' => 'student',
'needsapproval' => false,
'entries' => [1, 0],
'myentries' => [1, 0],
'expected' => [
'myentries' => 2,
'totalentries' => 4,
],
public static function provider_test_get_entries_overview(): \Generator {
yield 'Student not needing approval' => [
'role' => 'student',
'needsapproval' => false,
'entries' => [1, 0],
'myentries' => [1, 0],
'expected' => [
'myentries' => 2,
'totalentries' => 4,
],
'Student needing approval' => [
'role' => 'student',
'needsapproval' => true,
'entries' => [1, 0],
'myentries' => [1, 0],
'expected' => [
'myentries' => 2,
'totalentries' => 2,
],
];
yield 'Student needing approval' => [
'role' => 'student',
'needsapproval' => true,
'entries' => [1, 0],
'myentries' => [1, 0],
'expected' => [
'myentries' => 2,
'totalentries' => 2,
],
'Teacher with entries (non-require approval)' => [
'role' => 'editingteacher',
'needsapproval' => false,
'entries' => [1, 0],
'myentries' => [1, 0],
'expected' => [
'myentries' => null,
'totalentries' => 4,
],
];
yield 'Teacher with entries (non-require approval)' => [
'role' => 'editingteacher',
'needsapproval' => false,
'entries' => [1, 0],
'myentries' => [1, 0],
'expected' => [
'myentries' => null,
'totalentries' => 4,
],
'Teacher without entries (require approval)' => [
'role' => 'editingteacher',
'needsapproval' => true,
'entries' => [],
'myentries' => [],
'expected' => [
'myentries' => null,
'totalentries' => 0,
],
];
yield 'Teacher without entries (require approval)' => [
'role' => 'editingteacher',
'needsapproval' => true,
'entries' => [],
'myentries' => [],
'expected' => [
'myentries' => null,
'totalentries' => 0,
],
'Teacher with entries (require approval)' => [
'role' => 'editingteacher',
'needsapproval' => true,
'entries' => [1, 0],
'myentries' => [1, 0],
'expected' => [
'myentries' => null,
'totalentries' => 4,
],
];
yield 'Teacher with entries (require approval)' => [
'role' => 'editingteacher',
'needsapproval' => true,
'entries' => [1, 0],
'myentries' => [1, 0],
'expected' => [
'myentries' => null,
'totalentries' => 4,
],
'Teacher with approved entries (require approval)' => [
'role' => 'editingteacher',
'needsapproval' => true,
'entries' => [1, 1],
'myentries' => [1, 1],
'expected' => [
'myentries' => null,
'totalentries' => 4,
],
];
yield 'Teacher with approved entries (require approval)' => [
'role' => 'editingteacher',
'needsapproval' => true,
'entries' => [1, 1],
'myentries' => [1, 1],
'expected' => [
'myentries' => null,
'totalentries' => 4,
],
];
}
/**
* Test get_extra_overview_items with groups.
*
* @covers ::get_extra_overview_items
*/
public function test_get_extra_entries_overview_with_groups(): void {
$this->resetAfterTest();
@@ -346,7 +336,7 @@ final class overview_test extends \advanced_testcase {
$g1->id,
[],
null,
$student->id
$student->id,
);
$generator->create_entry(
$activity,
@@ -354,7 +344,7 @@ final class overview_test extends \advanced_testcase {
$g2->id,
[],
null,
$otherstudent->id
$otherstudent->id,
);
// Editing teachers can see everything.
@@ -382,15 +372,13 @@ final class overview_test extends \advanced_testcase {
/**
* Test get_extra_comments_overview.
*
* @covers ::get_extra_comments_overview
* @dataProvider provider_test_get_comments_overview
*
* @param string $role
* @param bool $needsapproval
* @param array $entries
* @param int $expected
* @return void
*/
#[\PHPUnit\Framework\Attributes\DataProvider('provider_test_get_comments_overview')]
public function test_get_extra_comments_overview(
string $role,
bool $needsapproval,
@@ -454,82 +442,80 @@ final class overview_test extends \advanced_testcase {
/**
* Data provider for test comments extras.
*
* @return array
* @return \Generator
*/
public static function provider_test_get_comments_overview(): array {
return [
'Student not needing approval with no comments' => [
'role' => 'student',
'needsapproval' => false,
'entries' => [
public static function provider_test_get_comments_overview(): \Generator {
yield 'Student not needing approval with no comments' => [
'role' => 'student',
'needsapproval' => false,
'entries' => [
['approved' => 1, 'comments' => false],
['approved' => 0, 'comments' => false],
],
'expected' => 0,
];
yield 'Student not needing approval with comments' => [
'role' => 'student',
'needsapproval' => false,
'entries' => [
['approved' => 1, 'comments' => true],
['approved' => 0, 'comments' => true],
],
'Student not needing approval with comments' => [
'role' => 'student',
'needsapproval' => false,
'entries' => [
['approved' => 1, 'comments' => true],
['approved' => 0, 'comments' => true],
],
'expected' => 1,
'expected' => 1,
];
yield 'Student needing approval with no comments' => [
'role' => 'student',
'needsapproval' => true,
'entries' => [
['approved' => 1, 'comments' => false],
['approved' => 0, 'comments' => false],
],
'Student needing approval with no comments' => [
'role' => 'student',
'needsapproval' => true,
'entries' => [
['approved' => 1, 'comments' => false],
['approved' => 0, 'comments' => false],
],
'expected' => 0,
'expected' => 0,
];
yield 'Student needing approval with comments' => [
'role' => 'student',
'needsapproval' => true,
'entries' => [
['approved' => 1, 'comments' => true],
['approved' => 0, 'comments' => true],
],
'Student needing approval with comments' => [
'role' => 'student',
'needsapproval' => true,
'entries' => [
['approved' => 1, 'comments' => true],
['approved' => 0, 'comments' => true],
],
'expected' => 1,
'expected' => 1,
];
yield 'Teacher not needing approval with no comments' => [
'role' => 'editingteacher',
'needsapproval' => false,
'entries' => [
['approved' => 1, 'comments' => false],
['approved' => 0, 'comments' => false],
],
'Teacher not needing approval with no comments' => [
'role' => 'editingteacher',
'needsapproval' => false,
'entries' => [
['approved' => 1, 'comments' => false],
['approved' => 0, 'comments' => false],
],
'expected' => 0,
'expected' => 0,
];
yield 'Teacher not needing approval with comments' => [
'role' => 'editingteacher',
'needsapproval' => false,
'entries' => [
['approved' => 1, 'comments' => true],
['approved' => 0, 'comments' => true],
],
'Teacher not needing approval with comments' => [
'role' => 'editingteacher',
'needsapproval' => false,
'entries' => [
['approved' => 1, 'comments' => true],
['approved' => 0, 'comments' => true],
],
'expected' => 2,
'expected' => 2,
];
yield 'Teacher needing approval with no comments' => [
'role' => 'editingteacher',
'needsapproval' => true,
'entries' => [
['approved' => 1, 'comments' => false],
['approved' => 0, 'comments' => false],
],
'Teacher needing approval with no comments' => [
'role' => 'editingteacher',
'needsapproval' => true,
'entries' => [
['approved' => 1, 'comments' => false],
['approved' => 0, 'comments' => false],
],
'expected' => 0,
],
'Teacher needing approval with comments' => [
'role' => 'editingteacher',
'needsapproval' => true,
'entries' => [
['approved' => 1, 'comments' => true],
['approved' => 0, 'comments' => true],
],
'expected' => 2,
'expected' => 0,
];
yield 'Teacher needing approval with comments' => [
'role' => 'editingteacher',
'needsapproval' => true,
'entries' => [
['approved' => 1, 'comments' => true],
['approved' => 0, 'comments' => true],
],
'expected' => 2,
];
}
}
@@ -21,14 +21,13 @@ use core_courseformat\local\overview\overviewfactory;
/**
* Tests for Feedback
*
* @covers \mod_feedback\courseformat\overview
* @package mod_feedback
* @category test
* @copyright 2025 Ferran Recio <[email protected]>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
#[\PHPUnit\Framework\Attributes\CoversClass(overview::class)]
final class overview_test extends \advanced_testcase {
#[\Override]
public static function setUpBeforeClass(): void {
global $CFG;
@@ -40,12 +39,10 @@ final class overview_test extends \advanced_testcase {
/**
* Test get_actions_overview.
*
* @covers ::get_actions_overview
* @dataProvider provider_test_get_actions_overview
*
* @param string $role
* @param array|null $expected
*/
#[\PHPUnit\Framework\Attributes\DataProvider('provider_test_get_actions_overview')]
public function test_get_actions_overview(
string $role,
?array $expected
@@ -55,7 +52,7 @@ final class overview_test extends \advanced_testcase {
$course = $this->getDataGenerator()->create_course();
$currentuser = $this->getDataGenerator()->create_and_enrol($course, $role);
$activity = $this->getDataGenerator()->create_module( 'feedback', ['course' => $course->id]);
$activity = $this->getDataGenerator()->create_module('feedback', ['course' => $course->id]);
$this->setUser($currentuser);
@@ -76,31 +73,29 @@ final class overview_test extends \advanced_testcase {
/**
* Data provider for test_get_actions_overview.
*
* @return array
* @return \Generator
*/
public static function provider_test_get_actions_overview(): array {
return [
'Student' => [
'role' => 'student',
'expected' => null,
],
'Teacher' => [
'role' => 'editingteacher',
'expected' => [
'name' => get_string('actions'),
'value' => get_string('view'),
],
public static function provider_test_get_actions_overview(): \Generator {
yield 'Student' => [
'role' => 'student',
'expected' => null,
];
yield 'Teacher' => [
'role' => 'editingteacher',
'expected' => [
'name' => get_string('actions'),
'value' => get_string('view'),
],
];
}
/**
* Test get_due_date_overview.
* @covers ::get_due_date_overview
* @dataProvider provider_test_get_due_date_overview
*
* @param string $user
* @param bool $hasduedate
*/
#[\PHPUnit\Framework\Attributes\DataProvider('provider_test_get_due_date_overview')]
public function test_get_due_date_overview(string $user, bool $hasduedate): void {
$this->resetAfterTest();
$course = $this->getDataGenerator()->create_course();
@@ -129,39 +124,35 @@ final class overview_test extends \advanced_testcase {
/**
* Data provider for test_get_due_date_overview.
*
* @return array
* @return \Generator
*/
public static function provider_test_get_due_date_overview(): array {
return [
'Teacher with due date' => [
'user' => 'teacher',
'hasduedate' => true,
],
'Student with due date' => [
'user' => 'student',
'hasduedate' => true,
],
'Teacher without due date' => [
'user' => 'teacher',
'hasduedate' => false,
],
'Student without due date' => [
'user' => 'student',
'hasduedate' => false,
],
public static function provider_test_get_due_date_overview(): \Generator {
yield 'Teacher with due date' => [
'user' => 'teacher',
'hasduedate' => true,
];
yield 'Student with due date' => [
'user' => 'student',
'hasduedate' => true,
];
yield 'Teacher without due date' => [
'user' => 'teacher',
'hasduedate' => false,
];
yield 'Student without due date' => [
'user' => 'student',
'hasduedate' => false,
];
}
/**
* Test get_extra_responses_overview.
*
* @covers ::get_extra_responses_overview
* @dataProvider provider_get_extra_responses_overview
*
* @param string $user
* @param bool $expectnull
* @param bool $hasresponses
*/
#[\PHPUnit\Framework\Attributes\DataProvider('provider_get_extra_responses_overview')]
public function test_get_extra_responses_overview(string $user, bool $expectnull, bool $hasresponses): void {
$this->resetAfterTest();
@@ -213,43 +204,39 @@ final class overview_test extends \advanced_testcase {
/**
* Data provider for get_extra_responses_overview.
*
* @return array
* @return \Generator
*/
public static function provider_get_extra_responses_overview(): array {
return [
'Teacher with responses' => [
'user' => 'teacher',
'expectnull' => false,
'hasresponses' => true,
],
'Student with responses' => [
'user' => 'student',
'expectnull' => true,
'hasresponses' => true,
],
'Teacher without responses' => [
'user' => 'teacher',
'expectnull' => false,
'hasresponses' => false,
],
'Student without responses' => [
'user' => 'student',
'expectnull' => true,
'hasresponses' => false,
],
public static function provider_get_extra_responses_overview(): \Generator {
yield 'Teacher with responses' => [
'user' => 'teacher',
'expectnull' => false,
'hasresponses' => true,
];
yield 'Student with responses' => [
'user' => 'student',
'expectnull' => true,
'hasresponses' => true,
];
yield 'Teacher without responses' => [
'user' => 'teacher',
'expectnull' => false,
'hasresponses' => false,
];
yield 'Student without responses' => [
'user' => 'student',
'expectnull' => true,
'hasresponses' => false,
];
}
/**
* Test get_extra_responses_overview_with_groups().
*
* @dataProvider provider_feedback_get_extra_responses_overview_with_groups
* @param int $groupmode The group mode of the course.
* @param string $currentuser The user to set for the test.
* @param int $expectedcount The expected number of completeds.
*
* @covers ::get_extra_responses_overview
*/
#[\PHPUnit\Framework\Attributes\DataProvider('provider_feedback_get_extra_responses_overview_with_groups')]
public function test_get_extra_responses_overview_with_groups(
int $groupmode,
string $currentuser,
@@ -356,113 +343,109 @@ final class overview_test extends \advanced_testcase {
/**
* Data provider for feedback_get_extra_responses_overview_with_groups.
*
* @return array
* @return \Generator
*/
public static function provider_feedback_get_extra_responses_overview_with_groups(): array {
return [
'Separate groups - Editing teacher' => [
'groupmode' => SEPARATEGROUPS,
'currentuser' => 'teacher1',
'expectedcount' => 3,
],
'Separate groups - Non-editing teacher (groupa)' => [
'groupmode' => SEPARATEGROUPS,
'currentuser' => 'teacher2',
'expectedcount' => 2,
],
'Separate groups - Non-editing teacher (groupb)' => [
'groupmode' => SEPARATEGROUPS,
'currentuser' => 'teacher3',
'expectedcount' => 1,
],
'Separate groups - Non-editing teacher (groupc)' => [
'groupmode' => SEPARATEGROUPS,
'currentuser' => 'teacher4',
'expectedcount' => 0,
],
'Separate groups - Non-editing teacher (no group)' => [
'groupmode' => SEPARATEGROUPS,
'currentuser' => 'teacher5',
'expectedcount' => 3, // Although the expected count should be 0, this information will never be shown to the user.
],
'Separate groups - Editing teacher (no group)' => [
'groupmode' => SEPARATEGROUPS,
'currentuser' => 'teacher6',
'expectedcount' => 3,
],
'Visible groups - Editing teacher' => [
'groupmode' => VISIBLEGROUPS,
'currentuser' => 'teacher1',
'expectedcount' => 3,
],
'Visible groups - Non-editing teacher (groupa)' => [
'groupmode' => VISIBLEGROUPS,
'currentuser' => 'teacher2',
'expectedcount' => 3,
],
'Visible groups - Non-editing teacher (groupb)' => [
'groupmode' => VISIBLEGROUPS,
'currentuser' => 'teacher3',
'expectedcount' => 3,
],
'Visible groups - Non-editing teacher (groupc)' => [
'groupmode' => VISIBLEGROUPS,
'currentuser' => 'teacher4',
'expectedcount' => 3,
],
'Visible groups - Non-editing teacher (no group)' => [
'groupmode' => VISIBLEGROUPS,
'currentuser' => 'teacher5',
'expectedcount' => 3,
],
'Visible groups - Editing teacher (no group)' => [
'groupmode' => VISIBLEGROUPS,
'currentuser' => 'teacher6',
'expectedcount' => 3,
],
'No groups - Editing teacher' => [
'groupmode' => NOGROUPS,
'currentuser' => 'teacher1',
'expectedcount' => 3,
],
'No groups - Non-editing teacher (groupa)' => [
'groupmode' => NOGROUPS,
'currentuser' => 'teacher2',
'expectedcount' => 3,
],
'No groups - Non-editing teacher (groupb)' => [
'groupmode' => NOGROUPS,
'currentuser' => 'teacher3',
'expectedcount' => 3,
],
'No groups - Non-editing teacher (groupc)' => [
'groupmode' => NOGROUPS,
'currentuser' => 'teacher4',
'expectedcount' => 3,
],
'No groups - Non-editing teacher (no group)' => [
'groupmode' => NOGROUPS,
'currentuser' => 'teacher5',
'expectedcount' => 3,
],
'No groups - Editing teacher (no group)' => [
'groupmode' => NOGROUPS,
'currentuser' => 'teacher6',
'expectedcount' => 3,
],
public static function provider_feedback_get_extra_responses_overview_with_groups(): \Generator {
yield 'Separate groups - Editing teacher' => [
'groupmode' => SEPARATEGROUPS,
'currentuser' => 'teacher1',
'expectedcount' => 3,
];
yield 'Separate groups - Non-editing teacher (groupa)' => [
'groupmode' => SEPARATEGROUPS,
'currentuser' => 'teacher2',
'expectedcount' => 2,
];
yield 'Separate groups - Non-editing teacher (groupb)' => [
'groupmode' => SEPARATEGROUPS,
'currentuser' => 'teacher3',
'expectedcount' => 1,
];
yield 'Separate groups - Non-editing teacher (groupc)' => [
'groupmode' => SEPARATEGROUPS,
'currentuser' => 'teacher4',
'expectedcount' => 0,
];
yield 'Separate groups - Non-editing teacher (no group)' => [
'groupmode' => SEPARATEGROUPS,
'currentuser' => 'teacher5',
'expectedcount' => 3, // Although the expected count should be 0, this information will never be shown to the user.
];
yield 'Separate groups - Editing teacher (no group)' => [
'groupmode' => SEPARATEGROUPS,
'currentuser' => 'teacher6',
'expectedcount' => 3,
];
yield 'Visible groups - Editing teacher' => [
'groupmode' => VISIBLEGROUPS,
'currentuser' => 'teacher1',
'expectedcount' => 3,
];
yield 'Visible groups - Non-editing teacher (groupa)' => [
'groupmode' => VISIBLEGROUPS,
'currentuser' => 'teacher2',
'expectedcount' => 3,
];
yield 'Visible groups - Non-editing teacher (groupb)' => [
'groupmode' => VISIBLEGROUPS,
'currentuser' => 'teacher3',
'expectedcount' => 3,
];
yield 'Visible groups - Non-editing teacher (groupc)' => [
'groupmode' => VISIBLEGROUPS,
'currentuser' => 'teacher4',
'expectedcount' => 3,
];
yield 'Visible groups - Non-editing teacher (no group)' => [
'groupmode' => VISIBLEGROUPS,
'currentuser' => 'teacher5',
'expectedcount' => 3,
];
yield 'Visible groups - Editing teacher (no group)' => [
'groupmode' => VISIBLEGROUPS,
'currentuser' => 'teacher6',
'expectedcount' => 3,
];
yield 'No groups - Editing teacher' => [
'groupmode' => NOGROUPS,
'currentuser' => 'teacher1',
'expectedcount' => 3,
];
yield 'No groups - Non-editing teacher (groupa)' => [
'groupmode' => NOGROUPS,
'currentuser' => 'teacher2',
'expectedcount' => 3,
];
yield 'No groups - Non-editing teacher (groupb)' => [
'groupmode' => NOGROUPS,
'currentuser' => 'teacher3',
'expectedcount' => 3,
];
yield 'No groups - Non-editing teacher (groupc)' => [
'groupmode' => NOGROUPS,
'currentuser' => 'teacher4',
'expectedcount' => 3,
];
yield 'No groups - Non-editing teacher (no group)' => [
'groupmode' => NOGROUPS,
'currentuser' => 'teacher5',
'expectedcount' => 3,
];
yield 'No groups - Editing teacher (no group)' => [
'groupmode' => NOGROUPS,
'currentuser' => 'teacher6',
'expectedcount' => 3,
];
}
/**
* Test get_extra_submitted_overview.
*
* @covers ::get_extra_submitted_overview
* @dataProvider provider_test_get_extra_submitted_overview
*
* @param string $user
* @param bool $expectnull
* @param bool $hasresponses
*/
#[\PHPUnit\Framework\Attributes\DataProvider('provider_test_get_extra_submitted_overview')]
public function test_get_extra_submitted_overview(string $user, bool $expectnull, bool $hasresponses): void {
$this->resetAfterTest();
$course = $this->getDataGenerator()->create_course();
@@ -511,30 +494,28 @@ final class overview_test extends \advanced_testcase {
/**
* Data provider for test_get_extra_submitted_overview.
*
* @return array
* @return \Generator
*/
public static function provider_test_get_extra_submitted_overview(): array {
return [
'Teacher with responses' => [
'user' => 'teacher',
'expectnull' => true,
'hasresponses' => true,
],
'Student with responses' => [
'user' => 'student',
'expectnull' => false,
'hasresponses' => true,
],
'Teacher without responses' => [
'user' => 'teacher',
'expectnull' => true,
'hasresponses' => false,
],
'Student without responses' => [
'user' => 'student',
'expectnull' => false,
'hasresponses' => false,
],
public static function provider_test_get_extra_submitted_overview(): \Generator {
yield 'Teacher with responses' => [
'user' => 'teacher',
'expectnull' => true,
'hasresponses' => true,
];
yield 'Student with responses' => [
'user' => 'student',
'expectnull' => false,
'hasresponses' => true,
];
yield 'Teacher without responses' => [
'user' => 'teacher',
'expectnull' => true,
'hasresponses' => false,
];
yield 'Student without responses' => [
'user' => 'student',
'expectnull' => false,
'hasresponses' => false,
];
}
}
@@ -16,11 +16,6 @@
namespace mod_forum\courseformat;
defined('MOODLE_INTERNAL') || die();
global $CFG;
require_once($CFG->dirroot . '/mod/forum/lib.php');
use core_courseformat\local\overview\overviewfactory;
use mod_forum\subscriptions;
@@ -31,9 +26,16 @@ use mod_forum\subscriptions;
* @category test
* @copyright 2025 Sara Arjona <[email protected]>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
* @covers \mod_forum\course\overview
*/
#[\PHPUnit\Framework\Attributes\CoversClass(overview::class)]
final class overview_test extends \advanced_testcase {
#[\Override]
public static function setUpBeforeClass(): void {
global $CFG;
parent::setUpBeforeClass();
require_once($CFG->dirroot . '/mod/forum/lib.php');
}
#[\Override]
protected function setUp(): void {
@@ -53,8 +55,6 @@ final class overview_test extends \advanced_testcase {
/**
* Test get_actions_overview method.
*
* @covers ::get_actions_overview
*/
public function test_get_actions_overview(): void {
$this->resetAfterTest();
@@ -106,10 +106,9 @@ final class overview_test extends \advanced_testcase {
/**
* Test get_due_date_overview method.
*
* @covers ::get_due_date_overview
* @dataProvider get_due_date_overview_provider
* @param int|null $timeincrement null if no due date, or due date increment.
*/
#[\PHPUnit\Framework\Attributes\DataProvider('get_due_date_overview_provider')]
public function test_get_due_date_overview(
int|null $timeincrement,
): void {
@@ -148,31 +147,27 @@ final class overview_test extends \advanced_testcase {
/**
* Provider for get_due_date_overview.
*
* @return array
* @return \Generator
*/
public static function get_due_date_overview_provider(): array {
return [
'no_due' => [
'timeincrement' => null,
],
'past_due' => [
'timeincrement' => -1 * (4 * DAYSECS),
],
'future_due' => [
'timeincrement' => (4 * DAYSECS),
],
public static function get_due_date_overview_provider(): \Generator {
yield 'no_due' => [
'timeincrement' => null,
];
yield 'past_due' => [
'timeincrement' => -1 * (4 * DAYSECS),
];
yield 'future_due' => [
'timeincrement' => (4 * DAYSECS),
];
}
/**
* Test get_extra_forumtype_overview method.
*
* @dataProvider get_extra_forumtype_overview_provider
* @covers ::get_extra_forumtype_overview
*
* @param string $forumtype Forum type to test.
* @param string $expected Expected string for the forum type.
*/
#[\PHPUnit\Framework\Attributes\DataProvider('get_extra_forumtype_overview_provider')]
public function test_get_extra_forumtype_overview(
string $forumtype,
string $expected,
@@ -217,43 +212,38 @@ final class overview_test extends \advanced_testcase {
/**
* Provider for get_extra_forumtype_overview.
*
* @return array
* @return \Generator
*/
public static function get_extra_forumtype_overview_provider(): array {
return [
'General' => [
'forumtype' => 'general',
'expected' => get_string('generalforum', 'forum'),
],
'Single discussion' => [
'forumtype' => 'single',
'expected' => get_string('singleforum', 'forum'),
],
'Each user' => [
'forumtype' => 'eachuser',
'expected' => get_string('eachuserforum', 'forum'),
],
'Question&Answer' => [
'forumtype' => 'qanda',
'expected' => get_string('qandaforum', 'forum'),
],
'Blog' => [
'forumtype' => 'blog',
'expected' => get_string('blogforum', 'forum'),
],
'News' => [
'forumtype' => 'news',
'expected' => get_string('namenews', 'forum'),
],
public static function get_extra_forumtype_overview_provider(): \Generator {
yield 'General' => [
'forumtype' => 'general',
'expected' => get_string('generalforum', 'forum'),
];
yield 'Single discussion' => [
'forumtype' => 'single',
'expected' => get_string('singleforum', 'forum'),
];
yield 'Each user' => [
'forumtype' => 'eachuser',
'expected' => get_string('eachuserforum', 'forum'),
];
yield 'Question&Answer' => [
'forumtype' => 'qanda',
'expected' => get_string('qandaforum', 'forum'),
];
yield 'Blog' => [
'forumtype' => 'blog',
'expected' => get_string('blogforum', 'forum'),
];
yield 'News' => [
'forumtype' => 'news',
'expected' => get_string('namenews', 'forum'),
];
}
/**
* Test get_extra_track_overview method.
*
* @dataProvider get_extra_track_overview_provider
* @covers ::get_extra_track_overview
*
* @param string $role User role to test, 'student' or 'teacher'.
* @param int $forumtype Forum tracking type to test.
* @param int $tracked Expected tracked state of the forum.
@@ -261,6 +251,7 @@ final class overview_test extends \advanced_testcase {
* @param bool $allowforced Whether the $CFG->forum_allowforcedreadtracking setting is enabled.
* @param int $trackforums Whether the user has the trackforums setting enabled.
*/
#[\PHPUnit\Framework\Attributes\DataProvider('get_extra_track_overview_provider')]
public function test_get_extra_track_overview(
string $role = 'student',
int $forumtype = FORUM_TRACKING_OPTIONAL,
@@ -299,8 +290,8 @@ final class overview_test extends \advanced_testcase {
$this->assertEquals(get_string('tracking', 'forum'), $item->get_name());
$this->assertStringContainsString('data-type="forum-track-toggle"', $item->get_content());
$this->assertStringContainsString('data-action="toggle"', $item->get_content());
$this->assertStringContainsString('data-forumid="'.$activity->id.'"', $item->get_content());
$this->assertStringContainsString('data-targetstate="'.((int)!$tracked).'"', $item->get_content());
$this->assertStringContainsString('data-forumid="' . $activity->id . '"', $item->get_content());
$this->assertStringContainsString('data-targetstate="' . ((int)!$tracked) . '"', $item->get_content());
if ($disabled) {
$this->assertStringContainsString('disabled', $item->get_content());
} else {
@@ -311,126 +302,122 @@ final class overview_test extends \advanced_testcase {
/**
* Data provider for test_get_extra_track_overview.
*
* @return array
* @return \Generator
*/
public static function get_extra_track_overview_provider(): array {
return [
// Student role tests.
'Student. Tracking optional' => [
'forumtype' => FORUM_TRACKING_OPTIONAL,
'tracked' => 1,
'disabled' => false,
],
'Student. Tracking forced off' => [
'forumtype' => FORUM_TRACKING_OFF,
'tracked' => 0,
'disabled' => true,
],
'Student. Tracking forced on' => [
'forumtype' => FORUM_TRACKING_FORCED,
'tracked' => 1,
'disabled' => true,
],
'Student. Tracking forced on, with $CFG->forum_allowforcedreadtracking disabled' => [
'forumtype' => FORUM_TRACKING_FORCED,
'tracked' => 1,
'disabled' => false,
'allowforced' => false,
],
'Student. $USER->trackforums disabled. Tracking optional. ' => [
'forumtype' => FORUM_TRACKING_OPTIONAL,
'tracked' => 0,
'disabled' => true,
'trackforums' => 0,
],
'Student. $USER->trackforums disabled. Tracking forced off' => [
'forumtype' => FORUM_TRACKING_OFF,
'tracked' => 0,
'disabled' => true,
'trackforums' => 0,
],
'Student. $USER->trackforums disabled. Tracking forced on' => [
'forumtype' => FORUM_TRACKING_FORCED,
'tracked' => 1,
'disabled' => true,
'trackforums' => 0,
],
'Student. $USER->trackforums disabled. Tracking forced on, with $CFG->forum_allowforcedreadtracking disabled' => [
'forumtype' => FORUM_TRACKING_FORCED,
'tracked' => 0,
'disabled' => true,
'allowforced' => false,
'trackforums' => 0,
],
// Teacher role tests.
'Teacher. Tracking optional' => [
'role' => 'teacher',
'forumtype' => FORUM_TRACKING_OPTIONAL,
'tracked' => 1,
'disabled' => false,
],
'Teacher. Tracking forced off' => [
'role' => 'teacher',
'forumtype' => FORUM_TRACKING_OFF,
'tracked' => 0,
'disabled' => true,
],
'Teacher. Tracking forced on' => [
'role' => 'teacher',
'forumtype' => FORUM_TRACKING_FORCED,
'tracked' => 1,
'disabled' => true,
],
'Teacher. Tracking forced on, with $CFG->forum_allowforcedreadtracking disabled' => [
'role' => 'teacher',
'forumtype' => FORUM_TRACKING_FORCED,
'tracked' => 1,
'disabled' => false,
'allowforced' => false,
],
'Teacher. $USER->trackforums disabled. Tracking optional' => [
'role' => 'teacher',
'forumtype' => FORUM_TRACKING_OPTIONAL,
'tracked' => 0,
'disabled' => true,
'trackforums' => 0,
],
'Teacher. $USER->trackforums disabled. Tracking forced off' => [
'role' => 'teacher',
'forumtype' => FORUM_TRACKING_OFF,
'tracked' => 0,
'disabled' => true,
'trackforums' => 0,
],
'Teacher. $USER->trackforums disabled. Tracking forced on' => [
'role' => 'teacher',
'forumtype' => FORUM_TRACKING_FORCED,
'tracked' => 1,
'disabled' => true,
'trackforums' => 0,
],
'Teacher. $USER->trackforums disabled. Tracking forced on, with $CFG->forum_allowforcedreadtracking disabled' => [
'role' => 'teacher',
'forumtype' => FORUM_TRACKING_FORCED,
'tracked' => 0,
'disabled' => true,
'allowforced' => false,
'trackforums' => 0,
],
public static function get_extra_track_overview_provider(): \Generator {
// Student role tests.
yield 'Student. Tracking optional' => [
'forumtype' => FORUM_TRACKING_OPTIONAL,
'tracked' => 1,
'disabled' => false,
];
yield 'Student. Tracking forced off' => [
'forumtype' => FORUM_TRACKING_OFF,
'tracked' => 0,
'disabled' => true,
];
yield 'Student. Tracking forced on' => [
'forumtype' => FORUM_TRACKING_FORCED,
'tracked' => 1,
'disabled' => true,
];
yield 'Student. Tracking forced on, with $CFG->forum_allowforcedreadtracking disabled' => [
'forumtype' => FORUM_TRACKING_FORCED,
'tracked' => 1,
'disabled' => false,
'allowforced' => false,
];
yield 'Student. $USER->trackforums disabled. Tracking optional. ' => [
'forumtype' => FORUM_TRACKING_OPTIONAL,
'tracked' => 0,
'disabled' => true,
'trackforums' => 0,
];
yield 'Student. $USER->trackforums disabled. Tracking forced off' => [
'forumtype' => FORUM_TRACKING_OFF,
'tracked' => 0,
'disabled' => true,
'trackforums' => 0,
];
yield 'Student. $USER->trackforums disabled. Tracking forced on' => [
'forumtype' => FORUM_TRACKING_FORCED,
'tracked' => 1,
'disabled' => true,
'trackforums' => 0,
];
yield 'Student. $USER->trackforums disabled. Tracking forced on, with $CFG->forum_allowforcedreadtracking disabled' => [
'forumtype' => FORUM_TRACKING_FORCED,
'tracked' => 0,
'disabled' => true,
'allowforced' => false,
'trackforums' => 0,
];
// Teacher role tests.
yield 'Teacher. Tracking optional' => [
'role' => 'teacher',
'forumtype' => FORUM_TRACKING_OPTIONAL,
'tracked' => 1,
'disabled' => false,
];
yield 'Teacher. Tracking forced off' => [
'role' => 'teacher',
'forumtype' => FORUM_TRACKING_OFF,
'tracked' => 0,
'disabled' => true,
];
yield 'Teacher. Tracking forced on' => [
'role' => 'teacher',
'forumtype' => FORUM_TRACKING_FORCED,
'tracked' => 1,
'disabled' => true,
];
yield 'Teacher. Tracking forced on, with $CFG->forum_allowforcedreadtracking disabled' => [
'role' => 'teacher',
'forumtype' => FORUM_TRACKING_FORCED,
'tracked' => 1,
'disabled' => false,
'allowforced' => false,
];
yield 'Teacher. $USER->trackforums disabled. Tracking optional' => [
'role' => 'teacher',
'forumtype' => FORUM_TRACKING_OPTIONAL,
'tracked' => 0,
'disabled' => true,
'trackforums' => 0,
];
yield 'Teacher. $USER->trackforums disabled. Tracking forced off' => [
'role' => 'teacher',
'forumtype' => FORUM_TRACKING_OFF,
'tracked' => 0,
'disabled' => true,
'trackforums' => 0,
];
yield 'Teacher. $USER->trackforums disabled. Tracking forced on' => [
'role' => 'teacher',
'forumtype' => FORUM_TRACKING_FORCED,
'tracked' => 1,
'disabled' => true,
'trackforums' => 0,
];
yield 'Teacher. $USER->trackforums disabled. Tracking forced on, with $CFG->forum_allowforcedreadtracking disabled' => [
'role' => 'teacher',
'forumtype' => FORUM_TRACKING_FORCED,
'tracked' => 0,
'disabled' => true,
'allowforced' => false,
'trackforums' => 0,
];
}
/**
* Test get_extra_subscribed_overview method.
*
* @dataProvider get_extra_subscribed_overview_provider
* @covers ::get_extra_subscribed_overview
*
* @param string $role User role to test, 'student' or 'teacher'.
* @param int $forumtype Forum subscribe type to test.
* @param int $subscribed Expected subscribed state of the forum.
* @param bool $disabled Whether the toggle should be disabled.
*/
#[\PHPUnit\Framework\Attributes\DataProvider('get_extra_subscribed_overview_provider')]
public function test_get_extra_subscribed_overview(
string $role = 'student',
int $forumtype = FORUM_CHOOSESUBSCRIBE,
@@ -463,8 +450,8 @@ final class overview_test extends \advanced_testcase {
$this->assertEquals(get_string('subscribed', 'forum'), $item->get_name());
$this->assertStringContainsString('data-type="forum-subscription-toggle"', $item->get_content());
$this->assertStringContainsString('data-action="toggle"', $item->get_content());
$this->assertStringContainsString('data-forumid="'.$activity->id.'"', $item->get_content());
$this->assertStringContainsString('data-targetstate="'.((int)!$subscribed).'"', $item->get_content());
$this->assertStringContainsString('data-forumid="' . $activity->id . '"', $item->get_content());
$this->assertStringContainsString('data-targetstate="' . ((int)!$subscribed) . '"', $item->get_content());
if ($disabled) {
$this->assertStringContainsString('disabled', $item->get_content());
} else {
@@ -475,70 +462,66 @@ final class overview_test extends \advanced_testcase {
/**
* Data provider for get_extra_subscribed_overview.
*
* @return array
* @return \Generator
*/
public static function get_extra_subscribed_overview_provider(): array {
return [
// Student role tests.
'Student. Tracking forced on' => [
'forumtype' => FORUM_FORCESUBSCRIBE,
'subscribed' => 1,
'disabled' => true,
],
'Student. Tracking forced off' => [
'forumtype' => FORUM_DISALLOWSUBSCRIBE,
'subscribed' => 0,
'disabled' => true,
],
'Student. Tracking choose' => [
'forumtype' => FORUM_CHOOSESUBSCRIBE,
'subscribed' => 0,
'disabled' => false,
],
'Student. Tracking initial on' => [
'forumtype' => FORUM_INITIALSUBSCRIBE,
'subscribed' => 1,
'disabled' => false,
],
// Teacher role tests.
'Teacher. Tracking forced on' => [
'role' => 'teacher',
'forumtype' => FORUM_FORCESUBSCRIBE,
'subscribed' => 1,
'disabled' => true,
],
'Teacher. Tracking forced off' => [
'role' => 'teacher',
'forumtype' => FORUM_DISALLOWSUBSCRIBE,
'subscribed' => 0,
'disabled' => false,
],
'Teacher. Tracking choose' => [
'role' => 'teacher',
'forumtype' => FORUM_CHOOSESUBSCRIBE,
'subscribed' => 0,
'disabled' => false,
],
'Teacher. Tracking initial on' => [
'role' => 'teacher',
'forumtype' => FORUM_INITIALSUBSCRIBE,
'subscribed' => 1,
'disabled' => false,
],
public static function get_extra_subscribed_overview_provider(): \Generator {
// Student role tests.
yield 'Student. Tracking forced on' => [
'forumtype' => FORUM_FORCESUBSCRIBE,
'subscribed' => 1,
'disabled' => true,
];
yield 'Student. Tracking forced off' => [
'forumtype' => FORUM_DISALLOWSUBSCRIBE,
'subscribed' => 0,
'disabled' => true,
];
yield 'Student. Tracking choose' => [
'forumtype' => FORUM_CHOOSESUBSCRIBE,
'subscribed' => 0,
'disabled' => false,
];
yield 'Student. Tracking initial on' => [
'forumtype' => FORUM_INITIALSUBSCRIBE,
'subscribed' => 1,
'disabled' => false,
];
yield // Teacher role tests.
'Teacher. Tracking forced on' => [
'role' => 'teacher',
'forumtype' => FORUM_FORCESUBSCRIBE,
'subscribed' => 1,
'disabled' => true,
];
yield 'Teacher. Tracking forced off' => [
'role' => 'teacher',
'forumtype' => FORUM_DISALLOWSUBSCRIBE,
'subscribed' => 0,
'disabled' => false,
];
yield 'Teacher. Tracking choose' => [
'role' => 'teacher',
'forumtype' => FORUM_CHOOSESUBSCRIBE,
'subscribed' => 0,
'disabled' => false,
];
yield 'Teacher. Tracking initial on' => [
'role' => 'teacher',
'forumtype' => FORUM_INITIALSUBSCRIBE,
'subscribed' => 1,
'disabled' => false,
];
}
/**
* Test get_extra_emaildigest_overview method.
*
* @dataProvider get_extra_emaildigest_overview_provider
* @covers ::get_extra_emaildigest_overview
*
* @param string $role User role to test, 'student' or 'teacher'.
* @param int $forumtype Forum subscribe type to test.
* @param string $emaildigestvalue Expected email digest value for the forum.
* @param int $usermaildigest User's email digest setting.
*/
#[\PHPUnit\Framework\Attributes\DataProvider('get_extra_emaildigest_overview_provider')]
public function test_get_extra_emaildigest_overview(
string $role = 'student',
int $forumtype = FORUM_CHOOSESUBSCRIBE,
@@ -600,77 +583,73 @@ final class overview_test extends \advanced_testcase {
/**
* Data provider for get_extra_emaildigest_overview.
*
* @return array
* @return \Generator
*/
public static function get_extra_emaildigest_overview_provider(): array {
return [
// Student role tests.
'Student. Tracking forced on. No digest' => [
'forumtype' => FORUM_FORCESUBSCRIBE,
'emaildigestvalue' => 'default',
],
'Student. Tracking forced off' => [
'forumtype' => FORUM_DISALLOWSUBSCRIBE,
'emaildigestvalue' => '-',
],
'Student. Tracking choose' => [
'forumtype' => FORUM_CHOOSESUBSCRIBE,
'emaildigestvalue' => 'default',
],
'Student. Tracking initial on' => [
'forumtype' => FORUM_INITIALSUBSCRIBE,
'emaildigestvalue' => 'default',
],
'Student. Complete' => [
'forumtype' => FORUM_FORCESUBSCRIBE,
'emaildigestvalue' => 'default',
'usermaildigest' => 1,
],
'Student. Subjects' => [
'forumtype' => FORUM_FORCESUBSCRIBE,
'emaildigestvalue' => 'default',
'usermaildigest' => 2,
],
// Teacher role tests.
'Teacher. Tracking forced on. No digest' => [
'role' => 'teacher',
'forumtype' => FORUM_FORCESUBSCRIBE,
'emaildigestvalue' => 'default',
],
'Teacher. Tracking forced off' => [
'role' => 'teacher',
'forumtype' => FORUM_DISALLOWSUBSCRIBE,
'emaildigestvalue' => 'default',
],
'Teacher. Tracking choose' => [
'role' => 'teacher',
'forumtype' => FORUM_CHOOSESUBSCRIBE,
'emaildigestvalue' => 'default',
],
'Teacher. Tracking initial on' => [
'role' => 'teacher',
'forumtype' => FORUM_INITIALSUBSCRIBE,
'emaildigestvalue' => 'default',
],
'Teacher. Complete' => [
'role' => 'teacher',
'forumtype' => FORUM_FORCESUBSCRIBE,
'emaildigestvalue' => 'default',
'usermaildigest' => 1,
],
'Teacher. Subjects' => [
'role' => 'teacher',
'forumtype' => FORUM_FORCESUBSCRIBE,
'emaildigestvalue' => 'default',
'usermaildigest' => 2,
],
public static function get_extra_emaildigest_overview_provider(): \Generator {
// Student role tests.
yield 'Student. Tracking forced on. No digest' => [
'forumtype' => FORUM_FORCESUBSCRIBE,
'emaildigestvalue' => 'default',
];
yield 'Student. Tracking forced off' => [
'forumtype' => FORUM_DISALLOWSUBSCRIBE,
'emaildigestvalue' => '-',
];
yield 'Student. Tracking choose' => [
'forumtype' => FORUM_CHOOSESUBSCRIBE,
'emaildigestvalue' => 'default',
];
yield 'Student. Tracking initial on' => [
'forumtype' => FORUM_INITIALSUBSCRIBE,
'emaildigestvalue' => 'default',
];
yield 'Student. Complete' => [
'forumtype' => FORUM_FORCESUBSCRIBE,
'emaildigestvalue' => 'default',
'usermaildigest' => 1,
];
yield 'Student. Subjects' => [
'forumtype' => FORUM_FORCESUBSCRIBE,
'emaildigestvalue' => 'default',
'usermaildigest' => 2,
];
// Teacher role tests.
yield 'Teacher. Tracking forced on. No digest' => [
'role' => 'teacher',
'forumtype' => FORUM_FORCESUBSCRIBE,
'emaildigestvalue' => 'default',
];
yield 'Teacher. Tracking forced off' => [
'role' => 'teacher',
'forumtype' => FORUM_DISALLOWSUBSCRIBE,
'emaildigestvalue' => 'default',
];
yield 'Teacher. Tracking choose' => [
'role' => 'teacher',
'forumtype' => FORUM_CHOOSESUBSCRIBE,
'emaildigestvalue' => 'default',
];
yield 'Teacher. Tracking initial on' => [
'role' => 'teacher',
'forumtype' => FORUM_INITIALSUBSCRIBE,
'emaildigestvalue' => 'default',
];
yield 'Teacher. Complete' => [
'role' => 'teacher',
'forumtype' => FORUM_FORCESUBSCRIBE,
'emaildigestvalue' => 'default',
'usermaildigest' => 1,
];
yield 'Teacher. Subjects' => [
'role' => 'teacher',
'forumtype' => FORUM_FORCESUBSCRIBE,
'emaildigestvalue' => 'default',
'usermaildigest' => 2,
];
}
/**
* Test get_extra_discussions_overview method.
*
* @covers ::get_extra_discussions_overview
*/
public function test_get_extra_discussions_overview(): void {
$this->resetAfterTest();
@@ -21,25 +21,23 @@ use core_courseformat\local\overview\overviewfactory;
/**
* Tests for Glossary
*
* @covers \mod_glossary\courseformat\overview
* @package mod_glossary
* @category test
* @copyright 2025 Mikel Martín <[email protected]>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
#[\PHPUnit\Framework\Attributes\CoversClass(overview::class)]
final class overview_test extends \advanced_testcase {
/**
* Test get_actions_overview.
*
* @covers ::get_actions_overview
* @dataProvider provider_test_get_actions_overview
*
* @param string $role
* @param bool $requireapproval
* @param bool $hasentries
* @param array|null $expected
* @return void
*/
#[\PHPUnit\Framework\Attributes\DataProvider('provider_test_get_actions_overview')]
public function test_get_actions_overview(
string $role,
bool $requireapproval,
@@ -102,45 +100,43 @@ final class overview_test extends \advanced_testcase {
/**
* Data provider for test_get_actions_overview.
*
* @return array
* @return \Generator
*/
public static function provider_test_get_actions_overview(): array {
return [
'Student' => [
'role' => 'student',
'requireapproval' => false,
'hasentries' => true,
'expected' => null,
public static function provider_test_get_actions_overview(): \Generator {
yield 'Student' => [
'role' => 'student',
'requireapproval' => false,
'hasentries' => true,
'expected' => null,
];
yield 'Teacher with entries (non-require approval)' => [
'role' => 'editingteacher',
'requireapproval' => false,
'hasentries' => true,
'expected' => [
'name' => get_string('actions'),
'value' => 0,
'content' => get_string('view'),
],
'Teacher with entries (non-require approval)' => [
'role' => 'editingteacher',
'requireapproval' => false,
'hasentries' => true,
'expected' => [
'name' => get_string('actions'),
'value' => 0,
'content' => get_string('view'),
],
];
yield 'Teacher without entries (require approval)' => [
'role' => 'editingteacher',
'requireapproval' => true,
'hasentries' => false,
'expected' => [
'name' => get_string('actions'),
'value' => 0,
'content' => get_string('view'),
],
'Teacher without entries (require approval)' => [
'role' => 'editingteacher',
'requireapproval' => true,
'hasentries' => false,
'expected' => [
'name' => get_string('actions'),
'value' => 0,
'content' => get_string('view'),
],
],
'Teacher with entries (require approval)' => [
'role' => 'editingteacher',
'requireapproval' => true,
'hasentries' => true,
'expected' => [
'name' => get_string('actions'),
'value' => 2,
'content' => get_string('approve', 'mod_glossary'),
],
];
yield 'Teacher with entries (require approval)' => [
'role' => 'editingteacher',
'requireapproval' => true,
'hasentries' => true,
'expected' => [
'name' => get_string('actions'),
'value' => 2,
'content' => get_string('approve', 'mod_glossary'),
],
];
}
@@ -148,14 +144,12 @@ final class overview_test extends \advanced_testcase {
/**
* Test get_extra_comments_overview.
*
* @covers ::get_extra_comments_overview
* @dataProvider provider_test_get_extra_comments_overview
*
* @param string $role The role of the current user.
* @param bool $requireapproval Whether approval is required for entries.
* @param bool $hasentries Whether there are entries in the glossary.
* @param string|null $expected Expected value for the overview item.
*/
#[\PHPUnit\Framework\Attributes\DataProvider('provider_test_get_extra_comments_overview')]
public function test_get_extra_comments_overview(
string $role,
bool $requireapproval,
@@ -256,59 +250,55 @@ final class overview_test extends \advanced_testcase {
/**
* Data provider for test_get_extra_comments_overview.
*
* @return array
* @return \Generator
*/
public static function provider_test_get_extra_comments_overview(): array {
return [
'Teacher without responses' => [
'role' => 'editingteacher',
'requireapproval' => false,
'hasentries' => false,
'expected' => '0',
],
'Teacher with responses (non-require approval)' => [
'role' => 'editingteacher',
'requireapproval' => false,
'hasentries' => true,
'expected' => '5',
],
'Teacher with responses (require approval)' => [
'role' => 'editingteacher',
'requireapproval' => true,
'hasentries' => true,
'expected' => '5',
],
'Student without responses' => [
'role' => 'student',
'requireapproval' => false,
'hasentries' => false,
'expected' => '0',
],
'Student with responses (non-require approval)' => [
'role' => 'student',
'requireapproval' => false,
'hasentries' => true,
'expected' => '5',
],
'Student with responses (require approval)' => [
'role' => 'student',
'requireapproval' => true,
'hasentries' => true,
'expected' => '4', // One comment is from an unapproved entry created by a different user.
],
public static function provider_test_get_extra_comments_overview(): \Generator {
yield 'Teacher without responses' => [
'role' => 'editingteacher',
'requireapproval' => false,
'hasentries' => false,
'expected' => '0',
];
yield 'Teacher with responses (non-require approval)' => [
'role' => 'editingteacher',
'requireapproval' => false,
'hasentries' => true,
'expected' => '5',
];
yield 'Teacher with responses (require approval)' => [
'role' => 'editingteacher',
'requireapproval' => true,
'hasentries' => true,
'expected' => '5',
];
yield 'Student without responses' => [
'role' => 'student',
'requireapproval' => false,
'hasentries' => false,
'expected' => '0',
];
yield 'Student with responses (non-require approval)' => [
'role' => 'student',
'requireapproval' => false,
'hasentries' => true,
'expected' => '5',
];
yield 'Student with responses (require approval)' => [
'role' => 'student',
'requireapproval' => true,
'hasentries' => true,
'expected' => '4', // One comment is from an unapproved entry created by a different user.
];
}
/**
* Test get_extra_comments_overview when comments are not allowed.
*
* @covers ::get_extra_comments_overview
* @dataProvider provider_test_get_extra_comments_overview_with_comments_disabled
*
* @param bool $usecomments Whether comments are allowed globally.
* @param bool $allowcomments Whether comments are allowed in the glossary.
* @param string $expected Expected value for the overview item.
*/
#[\PHPUnit\Framework\Attributes\DataProvider('provider_test_get_extra_comments_overview_with_comments_disabled')]
public function test_get_extra_comments_overview_with_comments_disabled(
bool $usecomments,
bool $allowcomments,
@@ -340,45 +330,41 @@ final class overview_test extends \advanced_testcase {
/**
* Data provider for test_get_extra_comments_overview_with_comments_disabled.
*
* @return array
* @return \Generator
*/
public static function provider_test_get_extra_comments_overview_with_comments_disabled(): array {
return [
'Use comments disabled, allow comments disabled' => [
'usecomments' => false,
'allowcomments' => false,
'expected' => '-',
],
'Use comments enabled, allow comments disabled' => [
'usecomments' => true,
'allowcomments' => false,
'expected' => '-',
],
'Use comments disabled, allow comments enabled' => [
'usecomments' => false,
'allowcomments' => true,
'expected' => '-',
],
'Use comments enabled, allow comments enabled' => [
'usecomments' => true,
'allowcomments' => true,
'expected' => '0',
],
public static function provider_test_get_extra_comments_overview_with_comments_disabled(): \Generator {
yield 'Use comments disabled, allow comments disabled' => [
'usecomments' => false,
'allowcomments' => false,
'expected' => '-',
];
yield 'Use comments enabled, allow comments disabled' => [
'usecomments' => true,
'allowcomments' => false,
'expected' => '-',
];
yield 'Use comments disabled, allow comments enabled' => [
'usecomments' => false,
'allowcomments' => true,
'expected' => '-',
];
yield 'Use comments enabled, allow comments enabled' => [
'usecomments' => true,
'allowcomments' => true,
'expected' => '0',
];
}
/**
* Test get_extra_totalentries_overview.
*
* @covers ::get_extra_totalentries_overview
* @dataProvider provider_test_get_extra_totalentries_overview
*
* @param string $role
* @param bool $requireapproval
* @param bool $hasentries
* @param array $expected
* @return void
*/
#[\PHPUnit\Framework\Attributes\DataProvider('provider_test_get_extra_totalentries_overview')]
public function test_get_extra_totalentries_overview(
string $role,
bool $requireapproval,
@@ -441,45 +427,43 @@ final class overview_test extends \advanced_testcase {
/**
* Data provider for test_get_extra_submitted_overview.
*
* @return array
* @return \Generator
*/
public static function provider_test_get_extra_totalentries_overview(): array {
return [
'Teacher with entries (non-require approval)' => [
'role' => 'editingteacher',
'requireapproval' => false,
'hasentries' => true,
'expected' => [
'name' => get_string('entries', 'mod_glossary'),
'value' => 4,
],
public static function provider_test_get_extra_totalentries_overview(): \Generator {
yield 'Teacher with entries (non-require approval)' => [
'role' => 'editingteacher',
'requireapproval' => false,
'hasentries' => true,
'expected' => [
'name' => get_string('entries', 'mod_glossary'),
'value' => 4,
],
'Student without entries' => [
'role' => 'student',
'requireapproval' => false,
'hasentries' => false,
'expected' => [
'name' => get_string('totalentries', 'mod_glossary'),
'value' => 0,
],
];
yield 'Student without entries' => [
'role' => 'student',
'requireapproval' => false,
'hasentries' => false,
'expected' => [
'name' => get_string('totalentries', 'mod_glossary'),
'value' => 0,
],
'Student with entries (non-require approval)' => [
'role' => 'student',
'requireapproval' => false,
'hasentries' => true,
'expected' => [
'name' => get_string('totalentries', 'mod_glossary'),
'value' => 4,
],
];
yield 'Student with entries (non-require approval)' => [
'role' => 'student',
'requireapproval' => false,
'hasentries' => true,
'expected' => [
'name' => get_string('totalentries', 'mod_glossary'),
'value' => 4,
],
'Student with entries (require approval)' => [
'role' => 'student',
'requireapproval' => true,
'hasentries' => true,
'expected' => [
'name' => get_string('totalentries', 'mod_glossary'),
'value' => 3,
],
];
yield 'Student with entries (require approval)' => [
'role' => 'student',
'requireapproval' => true,
'hasentries' => true,
'expected' => [
'name' => get_string('totalentries', 'mod_glossary'),
'value' => 3,
],
];
}
@@ -487,15 +471,13 @@ final class overview_test extends \advanced_testcase {
/**
* Test get_extra_myentries_overview.
*
* @covers ::get_extra_myentries_overview
* @dataProvider provider_test_get_extra_myentries_overview
*
* @param string $role
* @param bool $requireapproval
* @param bool $hasentries
* @param array|null $expected
* @return void
*/
#[\PHPUnit\Framework\Attributes\DataProvider('provider_test_get_extra_myentries_overview')]
public function test_get_extra_myentries_overview(
string $role,
bool $requireapproval,
@@ -563,42 +545,40 @@ final class overview_test extends \advanced_testcase {
/**
* Data provider for test_get_extra_submitted_overview.
*
* @return array
* @return \Generator
*/
public static function provider_test_get_extra_myentries_overview(): array {
return [
'Teacher' => [
'role' => 'editingteacher',
'requireapproval' => false,
'hasentries' => true,
'expected' => null,
public static function provider_test_get_extra_myentries_overview(): \Generator {
yield 'Teacher' => [
'role' => 'editingteacher',
'requireapproval' => false,
'hasentries' => true,
'expected' => null,
];
yield 'Student without responses' => [
'role' => 'student',
'requireapproval' => false,
'hasentries' => false,
'expected' => [
'name' => get_string('myentries', 'mod_glossary'),
'value' => 0,
],
'Student without responses' => [
'role' => 'student',
'requireapproval' => false,
'hasentries' => false,
'expected' => [
'name' => get_string('myentries', 'mod_glossary'),
'value' => 0,
],
];
yield 'Student with responses (non-require approval)' => [
'role' => 'student',
'requireapproval' => false,
'hasentries' => true,
'expected' => [
'name' => get_string('myentries', 'mod_glossary'),
'value' => 1,
],
'Student with responses (non-require approval)' => [
'role' => 'student',
'requireapproval' => false,
'hasentries' => true,
'expected' => [
'name' => get_string('myentries', 'mod_glossary'),
'value' => 1,
],
],
'Student with responses (require approval)' => [
'role' => 'student',
'requireapproval' => true,
'hasentries' => true,
'expected' => [
'name' => get_string('myentries', 'mod_glossary'),
'value' => 1,
],
];
yield 'Student with responses (require approval)' => [
'role' => 'student',
'requireapproval' => true,
'hasentries' => true,
'expected' => [
'name' => get_string('myentries', 'mod_glossary'),
'value' => 1,
],
];
}
@@ -21,18 +21,15 @@ use core_courseformat\local\overview\overviewfactory;
/**
* Tests for H5P activity overview
*
* @covers \mod_h5pactivity\courseformat\overview
* @package mod_h5pactivity
* @category test
* @copyright 2025 Amaia Anabitarte <[email protected]>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
#[\PHPUnit\Framework\Attributes\CoversClass(overview::class)]
final class overview_test extends \advanced_testcase {
/**
* Test get_actions_overview.
*
* @covers ::get_actions_overview
*/
public function test_get_actions_overview(): void {
$this->resetAfterTest();
@@ -40,8 +37,8 @@ final class overview_test extends \advanced_testcase {
$course = $this->getDataGenerator()->create_course();
$activity = $this->getDataGenerator()->create_module(
'h5pactivity',
['course' => $course, 'enabletracking' => 1],
'h5pactivity',
['course' => $course, 'enabletracking' => 1],
);
$cm = get_fast_modinfo($course)->get_cm($activity->cmid);
@@ -49,8 +46,6 @@ final class overview_test extends \advanced_testcase {
$teacher = $this->getDataGenerator()->create_and_enrol($course, 'editingteacher');
$student = $this->getDataGenerator()->create_and_enrol($course, 'student');
$generator = $this->getDataGenerator()->get_plugin_generator('mod_h5pactivity');
// Students have no action column.
$this->setUser($student);
$this->assertNull(overviewfactory::create($cm)->get_actions_overview());
@@ -65,18 +60,16 @@ final class overview_test extends \advanced_testcase {
/**
* Test get_extra_h5ptype_overview.
*
* @covers ::get_extra_h5ptype_overview
* @dataProvider provider_test_get_extra_h5type_overview
*
* @param string $h5pfile
* @param bool $iscorrect
* @param string $expected
* @return void
*/
#[\PHPUnit\Framework\Attributes\DataProvider('provider_test_get_extra_h5type_overview')]
public function test_get_extra_h5ptype_overview(
string $h5pfile,
bool $iscorrect,
string $expected
string $h5pfile,
bool $iscorrect,
string $expected
): void {
global $CFG;
@@ -85,9 +78,9 @@ final class overview_test extends \advanced_testcase {
$course = $this->getDataGenerator()->create_course();
$params = [
'course' => $course->id,
'packagefilepath' => $CFG->dirroot.'/h5p/tests/fixtures/'.$h5pfile,
'introformat' => 1,
'course' => $course->id,
'packagefilepath' => "{$CFG->dirroot}/h5p/tests/fixtures/{$h5pfile}",
'introformat' => 1,
];
$activity = $this->getDataGenerator()->create_module('h5pactivity', $params);
// Add filename and contextid to make easier the asserts.
@@ -125,32 +118,28 @@ final class overview_test extends \advanced_testcase {
/**
* Data provider for test h5p type overview extra.
*
* @return array
* @return \Generator
*/
public static function provider_test_get_extra_h5type_overview(): array {
return [
'Basic package' => [
'h5pfile' => 'basic_essay.h5p',
'iscorrect' => true,
'expected' => 'Essay',
],
'No json file' => [
'h5pfile' => 'no-json-file.h5p',
'iscorrect' => false,
'expected' => get_string('unknowntype', 'mod_h5pactivity'),
],
'Unzippable package' => [
'h5pfile' => 'unzippable.h5p',
'iscorrect' => false,
'expected' => get_string('unknowntype', 'mod_h5pactivity'),
],
public static function provider_test_get_extra_h5type_overview(): \Generator {
yield 'Basic package' => [
'h5pfile' => 'basic_essay.h5p',
'iscorrect' => true,
'expected' => 'Essay',
];
yield 'No json file' => [
'h5pfile' => 'no-json-file.h5p',
'iscorrect' => false,
'expected' => get_string('unknowntype', 'mod_h5pactivity'),
];
yield 'Unzippable package' => [
'h5pfile' => 'unzippable.h5p',
'iscorrect' => false,
'expected' => get_string('unknowntype', 'mod_h5pactivity'),
];
}
/**
* Test get_extra_overview_items.
*
* @covers ::get_extra_overview_items
*/
public function test_get_extra_attempts_overview(): void {
$this->resetAfterTest();
@@ -158,8 +147,8 @@ final class overview_test extends \advanced_testcase {
$course = $this->getDataGenerator()->create_course();
$activity = $this->getDataGenerator()->create_module(
'h5pactivity',
['course' => $course, 'enabletracking' => 1],
'h5pactivity',
['course' => $course, 'enabletracking' => 1],
);
$cm = get_fast_modinfo($course)->get_cm($activity->cmid);
@@ -214,8 +203,6 @@ final class overview_test extends \advanced_testcase {
/**
* Test get_extra_studentsattempted_overview.
*
* @covers ::get_extra_studentsattempted_overview
*/
public function test_get_extra_studentsattempted_overview(): void {
$this->resetAfterTest();
@@ -223,15 +210,15 @@ final class overview_test extends \advanced_testcase {
$course = $this->getDataGenerator()->create_course();
$activity = $this->getDataGenerator()->create_module(
'h5pactivity',
['course' => $course, 'enabletracking' => 1],
'h5pactivity',
['course' => $course, 'enabletracking' => 1],
);
$cm = get_fast_modinfo($course)->get_cm($activity->cmid);
// Prepare users: 1 teacher, 2 students, 1 unenroled user.
$teacher = $this->getDataGenerator()->create_and_enrol($course, 'editingteacher');
$student = $this->getDataGenerator()->create_and_enrol($course, 'student');
$other = $this->getDataGenerator()->create_and_enrol($course, 'student');
$this->getDataGenerator()->create_and_enrol($course, 'student');
$generator = $this->getDataGenerator()->get_plugin_generator('mod_h5pactivity');
@@ -258,8 +245,6 @@ final class overview_test extends \advanced_testcase {
/**
* Test get_extra_studentsattempted_overview filtering by groups.
*
* @covers ::get_extra_studentsattempted_overview
*/
public function test_get_extra_studentsattempted_overview_by_groups(): void {
$this->resetAfterTest();
@@ -322,8 +307,6 @@ final class overview_test extends \advanced_testcase {
/**
* Test get_extra_totalattempts_overview filtering by groups.
*
* @covers ::get_extra_totalattempts_overview
*/
public function test_get_extra_totalattempts_overview_by_groups(): void {
$this->resetAfterTest();
@@ -27,6 +27,7 @@ use lesson;
* @copyright 2025 Mikel Martín <[email protected]>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
#[\PHPUnit\Framework\Attributes\CoversClass(overview::class)]
final class overview_test extends \advanced_testcase {
/**
* Helper function to create lesson pages with multichoice questions.
@@ -54,12 +55,10 @@ final class overview_test extends \advanced_testcase {
/**
* Test get_due_date_overview.
*
* @covers ::get_due_date_overview
* @dataProvider provider_test_get_due_date_overview
*
* @param int|null $timeincrement the time increment in seconds to add to the current time for the deadline.
* @return void
*/
#[\PHPUnit\Framework\Attributes\DataProvider('provider_test_get_due_date_overview')]
public function test_get_due_date_overview(?int $timeincrement): void {
$this->resetAfterTest();
$this->setAdminUser();
@@ -88,32 +87,28 @@ final class overview_test extends \advanced_testcase {
/**
* Provider for test_get_due_date_overview.
*
* @return array
* @return \Generator
*/
public static function provider_test_get_due_date_overview(): array {
return [
'no_due' => [
'timeincrement' => null,
],
'past_due' => [
'timeincrement' => -1 * (4 * DAYSECS),
],
'future_due' => [
'timeincrement' => (4 * DAYSECS),
],
public static function provider_test_get_due_date_overview(): \Generator {
yield 'no_due' => [
'timeincrement' => null,
];
yield 'past_due' => [
'timeincrement' => -1 * (4 * DAYSECS),
];
yield 'future_due' => [
'timeincrement' => (4 * DAYSECS),
];
}
/**
* Test get_actions_overview.
*
* @covers ::get_actions_overview
* @dataProvider provider_test_get_actions_overview
*
* @param string $role
* @param array|null $expected
* @return void
*/
#[\PHPUnit\Framework\Attributes\DataProvider('provider_test_get_actions_overview')]
public function test_get_actions_overview(
string $role,
?array $expected
@@ -123,7 +118,7 @@ final class overview_test extends \advanced_testcase {
$course = $this->getDataGenerator()->create_course();
$currentuser = $this->getDataGenerator()->create_and_enrol($course, $role);
$lesson = $this->getDataGenerator()->create_module( 'lesson', ['course' => $course->id]);
$lesson = $this->getDataGenerator()->create_module('lesson', ['course' => $course->id]);
$this->setUser($currentuser);
@@ -144,20 +139,18 @@ final class overview_test extends \advanced_testcase {
/**
* Data provider for test_get_actions_overview.
*
* @return array
* @return \Generator
*/
public static function provider_test_get_actions_overview(): array {
return [
'Student' => [
'role' => 'student',
'expected' => null,
],
'Teacher' => [
'role' => 'editingteacher',
'expected' => [
'name' => get_string('actions'),
'value' => '',
],
public static function provider_test_get_actions_overview(): \Generator {
yield 'Student' => [
'role' => 'student',
'expected' => null,
];
yield 'Teacher' => [
'role' => 'editingteacher',
'expected' => [
'name' => get_string('actions'),
'value' => '',
],
];
}
@@ -165,9 +158,6 @@ final class overview_test extends \advanced_testcase {
/**
* Test get_extra_totalattempts_overview.
*
* @covers ::get_extra_totalattempts_overview
* @dataProvider provider_test_get_extra_totalattempts_overview
*
* @param string $role
* @param int $groupmode
* @param bool $hasentries
@@ -175,6 +165,7 @@ final class overview_test extends \advanced_testcase {
* @param array|null $expected
* @return void
*/
#[\PHPUnit\Framework\Attributes\DataProvider('provider_test_get_extra_totalattempts_overview')]
public function test_get_extra_totalattempts_overview(
string $role,
int $groupmode,
@@ -342,15 +333,13 @@ final class overview_test extends \advanced_testcase {
/**
* Test get_extra_attemptedstudents_overview.
*
* @covers ::get_extra_attemptedstudents_overview
* @dataProvider provider_test_get_extra_attemptedstudents_overview
*
* @param string $role
* @param bool $groupmode
* @param bool $hasentries
* @param array|null $expected
* @return void
*/
#[\PHPUnit\Framework\Attributes\DataProvider('provider_test_get_extra_attemptedstudents_overview')]
public function test_get_extra_attemptedstudents_overview(
string $role,
int $groupmode,
@@ -27,16 +27,16 @@ use mod_quiz\quiz_settings;
* @category test
* @copyright 2025 Laurent David <[email protected]>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
* @covers \mod_quiz\courseformat\overview
*/
#[\PHPUnit\Framework\Attributes\CoversClass(overview::class)]
final class overview_test extends \advanced_testcase {
/**
* Test get_due_date_overview.
*
* @param int|null $timeincrement the time increment in seconds to add to the current time for the deadline.
* @return void
* @dataProvider provider_test_get_due_date_overview
**/
*/
#[\PHPUnit\Framework\Attributes\DataProvider('provider_test_get_due_date_overview')]
public function test_get_due_date_overview(?int $timeincrement): void {
$this->resetAfterTest();
$this->setAdminUser();
@@ -65,19 +65,17 @@ final class overview_test extends \advanced_testcase {
/**
* Provider for test_get_due_date_overview.
*
* @return array
* @return \Generator
*/
public static function provider_test_get_due_date_overview(): array {
return [
'no_due' => [
'timeincrement' => null,
],
'past_due' => [
'timeincrement' => -1 * (4 * DAYSECS),
],
'future_due' => [
'timeincrement' => (4 * DAYSECS),
],
public static function provider_test_get_due_date_overview(): \Generator {
yield 'no_due' => [
'timeincrement' => null,
];
yield 'past_due' => [
'timeincrement' => -1 * (4 * DAYSECS),
];
yield 'future_due' => [
'timeincrement' => (4 * DAYSECS),
];
}
@@ -87,8 +85,8 @@ final class overview_test extends \advanced_testcase {
* @param string $currentuser
* @param array|null $expected
* @return void
* @dataProvider provider_test_get_actions_overview
*/
#[\PHPUnit\Framework\Attributes\DataProvider('provider_test_get_actions_overview')]
public function test_get_actions_overview(
string $currentuser,
?array $expected
@@ -115,27 +113,25 @@ final class overview_test extends \advanced_testcase {
/**
* Data provider for test_get_actions_overview.
*
* @return array
* @return \Generator
*/
public static function provider_test_get_actions_overview(): array {
return [
'Student' => [
'currentuser' => 's1',
'expected' => null,
public static function provider_test_get_actions_overview(): \Generator {
yield 'Student' => [
'currentuser' => 's1',
'expected' => null,
];
yield 'Editing Teacher' => [
'currentuser' => 't1',
'expected' => [
'name' => get_string('actions'),
'value' => '',
],
'Editing Teacher' => [
'currentuser' => 't1',
'expected' => [
'name' => get_string('actions'),
'value' => '',
],
],
'Non editing Teacher' => [
'currentuser' => 't2',
'expected' => [
'name' => get_string('actions'),
'value' => '',
],
];
yield 'Non editing Teacher' => [
'currentuser' => 't2',
'expected' => [
'name' => get_string('actions'),
'value' => '',
],
];
}
@@ -146,8 +142,8 @@ final class overview_test extends \advanced_testcase {
* @param int $groupmode
* @param array $expected
* @return void
* @dataProvider provider_test_get_total_attempts_overview
*/
#[\PHPUnit\Framework\Attributes\DataProvider('provider_test_get_total_attempts_overview')]
public function test_get_extra_totalattempts_overview(
int $groupmode,
array $expected,
@@ -182,33 +178,31 @@ final class overview_test extends \advanced_testcase {
/**
* Data provider for provider_test_get_total_attempts_overview.
*
* @return array
* @return \Generator
*/
public static function provider_test_get_total_attempts_overview(): array {
return [
'Without groups' => [
'groupmode' => NOGROUPS,
'expected' => [
't1' => 5, // Count all attempts (even teacher's attempts).
't2' => 5,
's1' => null,
],
public static function provider_test_get_total_attempts_overview(): \Generator {
yield 'Without groups' => [
'groupmode' => NOGROUPS,
'expected' => [
't1' => 5, // Count all attempts (even teacher's attempts).
't2' => 5,
's1' => null,
],
'With separate groups' => [
'groupmode' => SEPARATEGROUPS,
'expected' => [
't1' => 5,
't2' => 3, // User 1 two attempts, teacher 2 one attempt (counted).
's1' => null,
],
];
yield 'With separate groups' => [
'groupmode' => SEPARATEGROUPS,
'expected' => [
't1' => 5,
't2' => 3, // User 1 two attempts, teacher 2 one attempt (counted).
's1' => null,
],
'With visible groups' => [
'groupmode' => VISIBLEGROUPS,
'expected' => [
't1' => 5,
't2' => 5,
's1' => null,
],
];
yield 'With visible groups' => [
'groupmode' => VISIBLEGROUPS,
'expected' => [
't1' => 5,
't2' => 5,
's1' => null,
],
];
}
@@ -219,8 +213,8 @@ final class overview_test extends \advanced_testcase {
* @param int $groupmode
* @param array $expected
* @return void
* @dataProvider provider_test_get_students_who_attempted_overview
**/
#[\PHPUnit\Framework\Attributes\DataProvider('provider_test_get_students_who_attempted_overview')]
public function test_get_extra_studentswhoattempted_overview(
int $groupmode,
array $expected,
@@ -253,33 +247,31 @@ final class overview_test extends \advanced_testcase {
/**
* Data provider for test_get_students_who_attempted_overview.
*
* @return array
* @return \Generator
*/
public static function provider_test_get_students_who_attempted_overview(): array {
return [
'With no groups' => [
'groupmode' => NOGROUPS,
'expected' => [
't1' => "3 of 4", // 3 students and one teacher out (not counted) of 4 made at least one attempt.
't2' => "3 of 4",
's1' => null,
],
public static function provider_test_get_students_who_attempted_overview(): \Generator {
yield 'With no groups' => [
'groupmode' => NOGROUPS,
'expected' => [
't1' => "3 of 4", // 3 students and one teacher out (not counted) of 4 made at least one attempt.
't2' => "3 of 4",
's1' => null,
],
'With separate groups' => [
'groupmode' => SEPARATEGROUPS,
'expected' => [
't1' => "3 of 4", // Teacher 1 can see all groups.
't2' => "1 of 1", // Only student 1 in group 1 made at least one attempt.
's1' => null,
],
];
yield 'With separate groups' => [
'groupmode' => SEPARATEGROUPS,
'expected' => [
't1' => "3 of 4", // Teacher 1 can see all groups.
't2' => "1 of 1", // Only student 1 in group 1 made at least one attempt.
's1' => null,
],
'With visible groups' => [
'groupmode' => VISIBLEGROUPS,
'expected' => [
't1' => "3 of 4", // 3 students and one teacher out (not counted) of 4 made at least one attempt.
't2' => "3 of 4",
's1' => null,
],
];
yield 'With visible groups' => [
'groupmode' => VISIBLEGROUPS,
'expected' => [
't1' => "3 of 4", // 3 students and one teacher out (not counted) of 4 made at least one attempt.
't2' => "3 of 4",
's1' => null,
],
];
}
@@ -21,12 +21,12 @@ use core_courseformat\local\overview\overviewfactory;
/**
* Tests for SCORM activity overview
*
* @covers \mod_scorm\courseformat\overview
* @package mod_scorm
* @category test
* @copyright 2025 Laurent David <[email protected]>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
#[\PHPUnit\Framework\Attributes\CoversClass(overview::class)]
final class overview_test extends \advanced_testcase {
/**
* Test get_actions_overview.
@@ -51,9 +51,8 @@ final class overview_test extends \advanced_testcase {
* Test get_due_date_overview method.
*
* @param int|null $timeincrement
*
* @dataProvider get_due_date_overview_data
*/
#[\PHPUnit\Framework\Attributes\DataProvider('get_due_date_overview_data')]
public function test_get_due_date_overview(?int $timeincrement = null): void {
$this->resetAfterTest();
$this->setAdminUser();
@@ -78,22 +77,20 @@ final class overview_test extends \advanced_testcase {
/**
* Data provider for test_get_due_date_overview.
*
* @return array
* @return \Generator
*/
public static function get_due_date_overview_data(): array {
return [
'tomorrow' => [
'timeincrement' => DAYSECS,
],
'yesterday' => [
'timeincrement' => -1 * DAYSECS,
],
'today' => [
'timeincrement' => 0,
],
'No date' => [
'timeincrement' => null,
],
public static function get_due_date_overview_data(): \Generator {
yield 'tomorrow' => [
'timeincrement' => DAYSECS,
];
yield 'yesterday' => [
'timeincrement' => -1 * DAYSECS,
];
yield 'today' => [
'timeincrement' => 0,
];
yield 'No date' => [
'timeincrement' => null,
];
}
@@ -105,9 +102,8 @@ final class overview_test extends \advanced_testcase {
* @param string $activity the activity name to run this test with (there is one created with attemts ('withattempts') and one
* created without attempts ('withoutattempts')).
* @param array $expected
*
* @dataProvider get_extra_overview_items_data
*/
#[\PHPUnit\Framework\Attributes\DataProvider('get_extra_overview_items_data')]
public function test_get_extra_totalattempts_overview(
string $username,
string $activity,
@@ -159,9 +155,8 @@ final class overview_test extends \advanced_testcase {
* @param string $activity the activity name to run this test with (there is one created with attemts ('withattempts') and one
* created without attempts ('withoutattempts')).
* @param array $expected
*
* @dataProvider get_extra_overview_items_data
*/
#[\PHPUnit\Framework\Attributes\DataProvider('get_extra_overview_items_data')]
public function test_get_extra_studentsattempted_overview(
string $username,
string $activity,
@@ -251,181 +246,179 @@ final class overview_test extends \advanced_testcase {
/**
* Data provider for test_get_extra_studentsattempted_overview and test_get_extra_totalattempts_overview
*
* @return array
* @return \Generator
*/
public static function get_extra_overview_items_data(): array {
public static function get_extra_overview_items_data(): \Generator {
// Here we intentionally just test the case where course mode is set to NOGROUPS as groups are is not
// yet supported by the overview page for SCORM module. This will be followed up in a future issue (MDL-85852).
return [
'teacher 1 - no groups with attempts' => [
'username' => 't1',
'activity' => 'withattempts',
'groupmode' => NOGROUPS,
'expected' => [
'attempted' => [
'value' => 2,
'content' => '<strong>2</strong> of 4',
],
'totalattempts' => [
'value' => 2,
'items' => [
[
'label' => 'Grading method',
'value' => 'Highest attempt',
],
[
'label' => 'Allowed attempts per student',
'value' => 'Unlimited',
],
[
'label' => 'Average attempts per student',
'value' => '1',
],
],
],
yield 'teacher 1 - no groups with attempts' => [
'username' => 't1',
'activity' => 'withattempts',
'groupmode' => NOGROUPS,
'expected' => [
'attempted' => [
'value' => 2,
'content' => '<strong>2</strong> of 4',
],
],
'teacher 1 - no groups without attempts' => [
'username' => 't1',
'activity' => 'withoutattempts',
'groupmode' => NOGROUPS,
'expected' => [
'attempted' => [
'value' => 0,
'content' => '<strong>0</strong> of 4',
],
'totalattempts' => [
'value' => 0,
'items' => [
[
'label' => 'Grading method',
'value' => 'Highest attempt',
],
[
'label' => 'Allowed attempts per student',
'value' => 'Unlimited',
],
[
'label' => 'Average attempts per student',
'value' => '0',
],
'totalattempts' => [
'value' => 2,
'items' => [
[
'label' => 'Grading method',
'value' => 'Highest attempt',
],
[
'label' => 'Allowed attempts per student',
'value' => 'Unlimited',
],
[
'label' => 'Average attempts per student',
'value' => '1',
],
],
],
],
'teacher 2 - no groups' => [
'username' => 't2',
'activity' => 'withattempts',
'groupmode' => NOGROUPS,
'expected' => [
'attempted' => [
'value' => 2,
'content' => '<strong>2</strong> of 4',
];
yield 'teacher 1 - no groups without attempts' => [
'username' => 't1',
'activity' => 'withoutattempts',
'groupmode' => NOGROUPS,
'expected' => [
'attempted' => [
'value' => 0,
'content' => '<strong>0</strong> of 4',
],
'totalattempts' => [
'value' => 0,
'items' => [
[
'label' => 'Grading method',
'value' => 'Highest attempt',
],
[
'label' => 'Allowed attempts per student',
'value' => 'Unlimited',
],
[
'label' => 'Average attempts per student',
'value' => '0',
],
],
'totalattempts' => [
'value' => 2,
'items' => [
[
'label' => 'Grading method',
'value' => 'Highest attempt',
],
[
'label' => 'Allowed attempts per student',
'value' => 'Unlimited',
],
[
'label' => 'Average attempts per student',
'value' => '1',
],
],
],
];
yield 'teacher 2 - no groups' => [
'username' => 't2',
'activity' => 'withattempts',
'groupmode' => NOGROUPS,
'expected' => [
'attempted' => [
'value' => 2,
'content' => '<strong>2</strong> of 4',
],
'totalattempts' => [
'value' => 2,
'items' => [
[
'label' => 'Grading method',
'value' => 'Highest attempt',
],
[
'label' => 'Allowed attempts per student',
'value' => 'Unlimited',
],
[
'label' => 'Average attempts per student',
'value' => '1',
],
],
],
],
'teacher 1 - separate group' => [
'username' => 't1',
'activity' => 'withattempts',
'groupmode' => SEPARATEGROUPS,
'expected' => [
'attempted' => [
'value' => 1,
'content' => '<strong>1</strong> of 2', // Teacher can also attempt, so s1 and t1 are counted.
],
'totalattempts' => [
'value' => 1, // Attempt from s1 only.
'items' => [
[
'label' => 'Grading method',
'value' => 'Highest attempt',
],
[
'label' => 'Allowed attempts per student',
'value' => 'Unlimited',
],
[
'label' => 'Average attempts per student',
'value' => '1',
],
];
yield 'teacher 1 - separate group' => [
'username' => 't1',
'activity' => 'withattempts',
'groupmode' => SEPARATEGROUPS,
'expected' => [
'attempted' => [
'value' => 1,
'content' => '<strong>1</strong> of 2', // Teacher can also attempt, so s1 and t1 are counted.
],
'totalattempts' => [
'value' => 1, // Attempt from s1 only.
'items' => [
[
'label' => 'Grading method',
'value' => 'Highest attempt',
],
[
'label' => 'Allowed attempts per student',
'value' => 'Unlimited',
],
[
'label' => 'Average attempts per student',
'value' => '1',
],
],
],
],
// Teacher 2 is not in any group, so no attempt can be counted and the overview will return an error.
// But still the attempts can be counted if we call directly the manager methods, so we just skip the test here.
'teacher 1 - visible group' => [
'username' => 't1',
'activity' => 'withattempts',
'groupmode' => VISIBLEGROUPS,
'expected' => [
'attempted' => [
'value' => 2,
'content' => '<strong>2</strong> of 4',
],
'totalattempts' => [
'value' => 2,
'items' => [
[
'label' => 'Grading method',
'value' => 'Highest attempt',
],
[
'label' => 'Allowed attempts per student',
'value' => 'Unlimited',
],
[
'label' => 'Average attempts per student',
'value' => '1',
],
];
// Teacher 2 is not in any group, so no attempt can be counted and the overview will return an error.
// But still the attempts can be counted if we call directly the manager methods, so we just skip the test here.
yield 'teacher 1 - visible group' => [
'username' => 't1',
'activity' => 'withattempts',
'groupmode' => VISIBLEGROUPS,
'expected' => [
'attempted' => [
'value' => 2,
'content' => '<strong>2</strong> of 4',
],
'totalattempts' => [
'value' => 2,
'items' => [
[
'label' => 'Grading method',
'value' => 'Highest attempt',
],
[
'label' => 'Allowed attempts per student',
'value' => 'Unlimited',
],
[
'label' => 'Average attempts per student',
'value' => '1',
],
],
],
],
'teacher 2 - visible group' => [
'username' => 't2',
'activity' => 'withattempts',
'groupmode' => VISIBLEGROUPS,
'expected' => [
'attempted' => [
'value' => 2,
'content' => '<strong>2</strong> of 4',
],
'totalattempts' => [
'value' => 2,
'items' => [
[
'label' => 'Grading method',
'value' => 'Highest attempt',
],
[
'label' => 'Allowed attempts per student',
'value' => 'Unlimited',
],
[
'label' => 'Average attempts per student',
'value' => '1',
],
];
yield 'teacher 2 - visible group' => [
'username' => 't2',
'activity' => 'withattempts',
'groupmode' => VISIBLEGROUPS,
'expected' => [
'attempted' => [
'value' => 2,
'content' => '<strong>2</strong> of 4',
],
'totalattempts' => [
'value' => 2,
'items' => [
[
'label' => 'Grading method',
'value' => 'Highest attempt',
],
[
'label' => 'Allowed attempts per student',
'value' => 'Unlimited',
],
[
'label' => 'Average attempts per student',
'value' => '1',
],
],
],
@@ -22,15 +22,12 @@ namespace mod_subsection\courseformat;
* @package mod_subsection
* @copyright 2024 Sara Arjona <[email protected]>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
* @covers \mod_subsection\courseformat\sectiondelegate
* @coversDefaultClass \mod_subsection\courseformat\sectiondelegate
*/
#[\PHPUnit\Framework\Attributes\CoversClass(sectiondelegate::class)]
final class sectiondelegate_test extends \advanced_testcase {
/**
* Test has_delegate_class().
*
* @covers ::has_delegate_class
*/
public function test_has_delegate_class(): void {
$this->assertTrue(sectiondelegate::has_delegate_class('mod_subsection'));
@@ -39,7 +36,6 @@ final class sectiondelegate_test extends \advanced_testcase {
/**
* Test get_section_action_menu().
*
* @covers ::get_section_action_menu
*/
public function test_get_section_action_menu(): void {
global $PAGE;
@@ -64,8 +60,9 @@ final class sectiondelegate_test extends \advanced_testcase {
// Highlight is only present in section menu (not module), so they shouldn't be found in the result.
// Duplicate is not implemented yet, so they shouldn't be found in the result.
// The possible options are: View, Edit, Show, Hide, Delete and Permalink.
if (get_string_manager()->string_exists('editsection', 'format_'.$format->get_format())) {
$streditsection = get_string('editsection', 'format_'.$format->get_format());
$formatprovider = 'format_' . $format->get_format();
if (get_string_manager()->string_exists('editsection', $formatprovider)) {
$streditsection = get_string('editsection', $formatprovider);
} else {
$streditsection = get_string('editsection');
}
@@ -27,15 +27,11 @@ use stdClass;
* @package mod_subsection
* @copyright 2024 Mikel Martín <[email protected]>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
* @covers \core_courseformat\sectiondelegatemodule
* @coversDefaultClass \core_courseformat\sectiondelegatemodule
*/
#[\PHPUnit\Framework\Attributes\CoversClass(sectiondelegatemodule::class)]
final class sectiondelegatemodule_test extends \advanced_testcase {
/**
* Test get_parent_section.
*
* @covers ::get_parent_section
*/
public function test_get_parent_section(): void {
$this->resetAfterTest();
@@ -57,8 +53,6 @@ final class sectiondelegatemodule_test extends \advanced_testcase {
/**
* Test get_cm.
*
* @covers ::get_cm
*/
public function test_get_cm(): void {
$this->resetAfterTest();
@@ -80,8 +74,6 @@ final class sectiondelegatemodule_test extends \advanced_testcase {
/**
* Test get_course.
*
* @covers ::get_course
*/
public function test_get_course(): void {
$this->resetAfterTest();
@@ -22,24 +22,21 @@ use core_courseformat\local\overview\overviewfactory;
/**
* Tests for Wiki integration.
*
* @covers \mod_wiki\courseformat\overview
* @package mod_wiki
* @category test
* @copyright 2025 Laurent David <[email protected]>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
#[\PHPUnit\Framework\Attributes\CoversClass(overview::class)]
final class overview_test extends \advanced_testcase {
/**
* Data provider for wiki modes.
*
* @return array
* @return \Generator
*/
public static function get_wiki_mode_provider(): array {
return [
'collaborative' => ['mode' => wiki_mode::COLLABORATIVE],
'individual' => ['mode' => wiki_mode::INDIVIDUAL],
];
public static function get_wiki_mode_provider(): \Generator {
yield 'collaborative' => ['mode' => wiki_mode::COLLABORATIVE];
yield 'individual' => ['mode' => wiki_mode::INDIVIDUAL];
}
/**
@@ -48,10 +45,8 @@ final class overview_test extends \advanced_testcase {
* @param string $username
* @param int|null $expectedcount
* @return void
*
* @covers ::get_extra_my_entries
* @dataProvider get_extra_my_entries_provider
*/
#[\PHPUnit\Framework\Attributes\DataProvider('get_extra_my_entries_provider')]
public function test_get_extra_my_entries(string $username, ?int $expectedcount = null): void {
$this->resetAfterTest();
['users' => $users, 'instance' => $instance, 'course' => $course] = $this->setup_users_and_activity();
@@ -70,24 +65,20 @@ final class overview_test extends \advanced_testcase {
/**
* Data provider for get_extra_my_entries.
*
* @return array
* @return \Generator
*/
public static function get_extra_my_entries_provider(): array {
return [
'student 1' => ['s1', 1],
'student 2' => ['s2', 1],
'teacher 1' => ['t1', null], // Teacher 1 does not have any entries.
];
public static function get_extra_my_entries_provider(): \Generator {
yield 'student 1' => ['s1', 1];
yield 'student 2' => ['s2', 1];
yield 'teacher 1' => ['t1', null]; // Teacher 1 does not have any entries.
}
/**
* Test the wiki mode of the wiki instance.
*
* @param wiki_mode $mode the expected wiki mode.
*
* @covers ::get_extra_wiki_type
* @dataProvider get_wiki_mode_provider
*/
#[\PHPUnit\Framework\Attributes\DataProvider('get_wiki_mode_provider')]
public function test_wiki_mode(wiki_mode $mode): void {
$this->resetAfterTest();
['users' => $users, 'instance' => $instance, 'course' => $course] =
@@ -195,10 +186,8 @@ final class overview_test extends \advanced_testcase {
* @param string $username
* @param int $coursegroupmode
* @param int $expectedcount
*
* @covers ::get_extra_entries
* @dataProvider data_provider_get_extra_entries
*/
#[\PHPUnit\Framework\Attributes\DataProvider('data_provider_get_extra_entries')]
public function test_get_extra_entries(
string $username,
int $coursegroupmode,
@@ -239,8 +228,6 @@ final class overview_test extends \advanced_testcase {
/**
* Test get_extra_entries method.
*
* @covers ::get_actions_overview
*/
public function test_get_actions_overview(): void {
$this->resetAfterTest();
@@ -16,11 +16,6 @@
namespace mod_workshop\courseformat;
defined('MOODLE_INTERNAL') || die();
global $CFG;
require_once($CFG->dirroot . '/mod/workshop/locallib.php');
use core_courseformat\local\overview\overviewfactory;
/**
@@ -33,6 +28,14 @@ use core_courseformat\local\overview\overviewfactory;
*/
#[\PHPUnit\Framework\Attributes\CoversClass(overview::class)]
final class overview_test extends \advanced_testcase {
#[\Override]
public static function setUpBeforeClass(): void {
global $CFG;
parent::setUpBeforeClass();
require_once($CFG->dirroot . '/mod/workshop/locallib.php');
}
/**
* Test get_grade_item_names method.
@@ -140,28 +143,26 @@ final class overview_test extends \advanced_testcase {
/**
* Data provider for test_get_grade_item_names.
*
* @return array
* @return \Generator
*/
public static function data_provider_get_grade_item_names(): array {
return [
'student with submissions' => [
'user' => 'student',
'expectempty' => false,
'hassubmission' => true,
'hasassesment' => false,
],
'student with assessments' => [
'user' => 'student',
'expectempty' => false,
'hassubmission' => true,
'hasassesment' => true,
],
'teacher' => [
'user' => 'teacher',
'expectempty' => true,
'hassubmission' => false,
'hasassesment' => false,
],
public static function data_provider_get_grade_item_names(): \Generator {
yield 'student with submissions' => [
'user' => 'student',
'expectempty' => false,
'hassubmission' => true,
'hasassesment' => false,
];
yield 'student with assessments' => [
'user' => 'student',
'expectempty' => false,
'hassubmission' => true,
'hasassesment' => true,
];
yield 'teacher' => [
'user' => 'teacher',
'expectempty' => true,
'hassubmission' => false,
'hasassesment' => false,
];
}
@@ -205,50 +206,48 @@ final class overview_test extends \advanced_testcase {
/**
* Data provider for test_get_extra_phase_overview.
*
* @return array
* @return \Generator
*/
public static function data_provider_get_extra_phase_overview(): array {
return [
'teacher setup phase' => [
'user' => 'teacher',
'currentphase' => \workshop::PHASE_SETUP,
],
'student setup phase' => [
'user' => 'student',
'currentphase' => \workshop::PHASE_SETUP,
],
'teacher submission phase' => [
'user' => 'teacher',
'currentphase' => \workshop::PHASE_SUBMISSION,
],
'student submission phase' => [
'user' => 'student',
'currentphase' => \workshop::PHASE_SUBMISSION,
],
'teacher assessment phase' => [
'user' => 'teacher',
'currentphase' => \workshop::PHASE_ASSESSMENT,
],
'student assessment phase' => [
'user' => 'student',
'currentphase' => \workshop::PHASE_ASSESSMENT,
],
'teacher evaluation phase' => [
'user' => 'teacher',
'currentphase' => \workshop::PHASE_EVALUATION,
],
'student evaluation phase' => [
'user' => 'student',
'currentphase' => \workshop::PHASE_EVALUATION,
],
'teacher closed phase' => [
'user' => 'teacher',
'currentphase' => \workshop::PHASE_CLOSED,
],
'student closed phase' => [
'user' => 'student',
'currentphase' => \workshop::PHASE_CLOSED,
],
public static function data_provider_get_extra_phase_overview(): \Generator {
yield 'teacher setup phase' => [
'user' => 'teacher',
'currentphase' => \workshop::PHASE_SETUP,
];
yield 'student setup phase' => [
'user' => 'student',
'currentphase' => \workshop::PHASE_SETUP,
];
yield 'teacher submission phase' => [
'user' => 'teacher',
'currentphase' => \workshop::PHASE_SUBMISSION,
];
yield 'student submission phase' => [
'user' => 'student',
'currentphase' => \workshop::PHASE_SUBMISSION,
];
yield 'teacher assessment phase' => [
'user' => 'teacher',
'currentphase' => \workshop::PHASE_ASSESSMENT,
];
yield 'student assessment phase' => [
'user' => 'student',
'currentphase' => \workshop::PHASE_ASSESSMENT,
];
yield 'teacher evaluation phase' => [
'user' => 'teacher',
'currentphase' => \workshop::PHASE_EVALUATION,
];
yield 'student evaluation phase' => [
'user' => 'student',
'currentphase' => \workshop::PHASE_EVALUATION,
];
yield 'teacher closed phase' => [
'user' => 'teacher',
'currentphase' => \workshop::PHASE_CLOSED,
];
yield 'student closed phase' => [
'user' => 'student',
'currentphase' => \workshop::PHASE_CLOSED,
];
}
@@ -313,82 +312,80 @@ final class overview_test extends \advanced_testcase {
/**
* Data provider for test_get_extra_phase_overview.
*
* @return array
* @return \Generator
*/
public static function data_provider_get_extra_deadline_overview(): array {
public static function data_provider_get_extra_deadline_overview(): \Generator {
$submissionend = 3600;
$assessmentend = 7200;
return [
'teacher setup phase' => [
'user' => 'teacher',
'currentphase' => \workshop::PHASE_SETUP,
'submissionend' => $submissionend,
'assessmentend' => $assessmentend,
'expectedincrement' => null,
],
'student setup phase' => [
'user' => 'student',
'currentphase' => \workshop::PHASE_SETUP,
'submissionend' => $submissionend,
'assessmentend' => $assessmentend,
'expectedincrement' => null,
],
'teacher submission phase' => [
'user' => 'teacher',
'currentphase' => \workshop::PHASE_SUBMISSION,
'submissionend' => $submissionend,
'assessmentend' => $assessmentend,
'expectedincrement' => $submissionend,
],
'student submission phase' => [
'user' => 'student',
'currentphase' => \workshop::PHASE_SUBMISSION,
'submissionend' => $submissionend,
'assessmentend' => $assessmentend,
'expectedincrement' => $submissionend,
],
'teacher assessment phase' => [
'user' => 'teacher',
'currentphase' => \workshop::PHASE_ASSESSMENT,
'submissionend' => $submissionend,
'assessmentend' => $assessmentend,
'expectedincrement' => $assessmentend,
],
'student assessment phase' => [
'user' => 'student',
'currentphase' => \workshop::PHASE_ASSESSMENT,
'submissionend' => $submissionend,
'assessmentend' => $assessmentend,
'expectedincrement' => $assessmentend,
],
'teacher evaluation phase' => [
'user' => 'teacher',
'currentphase' => \workshop::PHASE_EVALUATION,
'submissionend' => $submissionend,
'assessmentend' => $assessmentend,
'expectedincrement' => null,
],
'student evaluation phase' => [
'user' => 'student',
'currentphase' => \workshop::PHASE_EVALUATION,
'submissionend' => $submissionend,
'assessmentend' => $assessmentend,
'expectedincrement' => null,
],
'teacher closed phase' => [
'user' => 'teacher',
'currentphase' => \workshop::PHASE_CLOSED,
'submissionend' => $submissionend,
'assessmentend' => $assessmentend,
'expectedincrement' => null,
],
'student closed phase' => [
'user' => 'student',
'currentphase' => \workshop::PHASE_CLOSED,
'submissionend' => $submissionend,
'assessmentend' => $assessmentend,
'expectedincrement' => null,
],
yield 'teacher setup phase' => [
'user' => 'teacher',
'currentphase' => \workshop::PHASE_SETUP,
'submissionend' => $submissionend,
'assessmentend' => $assessmentend,
'expectedincrement' => null,
];
yield 'student setup phase' => [
'user' => 'student',
'currentphase' => \workshop::PHASE_SETUP,
'submissionend' => $submissionend,
'assessmentend' => $assessmentend,
'expectedincrement' => null,
];
yield 'teacher submission phase' => [
'user' => 'teacher',
'currentphase' => \workshop::PHASE_SUBMISSION,
'submissionend' => $submissionend,
'assessmentend' => $assessmentend,
'expectedincrement' => $submissionend,
];
yield 'student submission phase' => [
'user' => 'student',
'currentphase' => \workshop::PHASE_SUBMISSION,
'submissionend' => $submissionend,
'assessmentend' => $assessmentend,
'expectedincrement' => $submissionend,
];
yield 'teacher assessment phase' => [
'user' => 'teacher',
'currentphase' => \workshop::PHASE_ASSESSMENT,
'submissionend' => $submissionend,
'assessmentend' => $assessmentend,
'expectedincrement' => $assessmentend,
];
yield 'student assessment phase' => [
'user' => 'student',
'currentphase' => \workshop::PHASE_ASSESSMENT,
'submissionend' => $submissionend,
'assessmentend' => $assessmentend,
'expectedincrement' => $assessmentend,
];
yield 'teacher evaluation phase' => [
'user' => 'teacher',
'currentphase' => \workshop::PHASE_EVALUATION,
'submissionend' => $submissionend,
'assessmentend' => $assessmentend,
'expectedincrement' => null,
];
yield 'student evaluation phase' => [
'user' => 'student',
'currentphase' => \workshop::PHASE_EVALUATION,
'submissionend' => $submissionend,
'assessmentend' => $assessmentend,
'expectedincrement' => null,
];
yield 'teacher closed phase' => [
'user' => 'teacher',
'currentphase' => \workshop::PHASE_CLOSED,
'submissionend' => $submissionend,
'assessmentend' => $assessmentend,
'expectedincrement' => null,
];
yield 'student closed phase' => [
'user' => 'student',
'currentphase' => \workshop::PHASE_CLOSED,
'submissionend' => $submissionend,
'assessmentend' => $assessmentend,
'expectedincrement' => null,
];
}
@@ -517,208 +514,206 @@ final class overview_test extends \advanced_testcase {
/**
* Data provider for test_get_extra_submissions_overview.
*
* @return array
* @return \Generator
*/
public static function data_provider_get_extra_submissions_overview(): array {
return [
'teacher setup phase without activity' => [
'role' => 'editingteacher',
'currentphase' => \workshop::PHASE_SETUP,
'groupmode' => NOGROUPS,
'hasstudentactivity' => false,
'expectnull' => false,
'expected' => ['submissions' => 0, 'assessments' => 0],
],
'student setup phase without activity' => [
'role' => 'student',
'currentphase' => \workshop::PHASE_SETUP,
'groupmode' => NOGROUPS,
'hasstudentactivity' => false,
'expectnull' => true,
],
'teacher submission phase without activity' => [
'role' => 'editingteacher',
'currentphase' => \workshop::PHASE_SUBMISSION,
'groupmode' => NOGROUPS,
'hasstudentactivity' => false,
'expectnull' => false,
'expected' => ['submissions' => 0, 'assessments' => 0],
],
'student submission phase without activity' => [
'role' => 'student',
'currentphase' => \workshop::PHASE_SUBMISSION,
'groupmode' => NOGROUPS,
'hasstudentactivity' => false,
'expectnull' => true,
],
'teacher assessment phase without activity' => [
'role' => 'editingteacher',
'currentphase' => \workshop::PHASE_ASSESSMENT,
'groupmode' => NOGROUPS,
'hasstudentactivity' => false,
'expectnull' => false,
'expected' => ['submissions' => 0, 'assessments' => 0],
],
'student assessment phase without activity' => [
'role' => 'student',
'currentphase' => \workshop::PHASE_ASSESSMENT,
'groupmode' => NOGROUPS,
'hasstudentactivity' => false,
'expectnull' => true,
],
'teacher evaluation phase without activity' => [
'role' => 'editingteacher',
'currentphase' => \workshop::PHASE_EVALUATION,
'groupmode' => NOGROUPS,
'hasstudentactivity' => false,
'expectnull' => false,
'expected' => ['submissions' => 0, 'assessments' => 0],
],
'student evaluation phase without activity' => [
'role' => 'student',
'currentphase' => \workshop::PHASE_EVALUATION,
'groupmode' => NOGROUPS,
'hasstudentactivity' => false,
'expectnull' => true,
],
'teacher closed phase without activity' => [
'role' => 'editingteacher',
'currentphase' => \workshop::PHASE_CLOSED,
'groupmode' => NOGROUPS,
'hasstudentactivity' => false,
'expectnull' => false,
'expected' => ['submissions' => 0, 'assessments' => 0],
],
'student closed phase without activity' => [
'role' => 'student',
'currentphase' => \workshop::PHASE_CLOSED,
'groupmode' => NOGROUPS,
'hasstudentactivity' => false,
'expectnull' => true,
],
// Tests with assessments.
'teacher setup phase with activity' => [
'role' => 'editingteacher',
'currentphase' => \workshop::PHASE_SETUP,
'groupmode' => NOGROUPS,
'hasstudentactivity' => true,
'expectnull' => false,
'expected' => ['submissions' => 2, 'assessments' => 3],
],
'student setup phase with activity' => [
'role' => 'student',
'currentphase' => \workshop::PHASE_SETUP,
'groupmode' => NOGROUPS,
'hasstudentactivity' => true,
'expectnull' => true,
],
'teacher submission phase with activity' => [
'role' => 'editingteacher',
'currentphase' => \workshop::PHASE_SUBMISSION,
'groupmode' => NOGROUPS,
'hasstudentactivity' => true,
'expectnull' => false,
'expected' => ['submissions' => 2, 'assessments' => 3],
],
'student submission phase with activity' => [
'role' => 'student',
'currentphase' => \workshop::PHASE_SUBMISSION,
'groupmode' => NOGROUPS,
'hasstudentactivity' => true,
'expectnull' => true,
],
'teacher assessment phase with activity' => [
'role' => 'editingteacher',
'currentphase' => \workshop::PHASE_ASSESSMENT,
'groupmode' => NOGROUPS,
'hasstudentactivity' => true,
'expectnull' => false,
'expected' => ['submissions' => 2, 'assessments' => 3],
],
'student assessment phase with activity' => [
'role' => 'student',
'currentphase' => \workshop::PHASE_ASSESSMENT,
'groupmode' => NOGROUPS,
'hasstudentactivity' => true,
'expectnull' => true,
],
'teacher evaluation phase with activity' => [
'role' => 'editingteacher',
'currentphase' => \workshop::PHASE_EVALUATION,
'groupmode' => NOGROUPS,
'hasstudentactivity' => true,
'expectnull' => false,
'expected' => ['submissions' => 2, 'assessments' => 3],
],
'student evaluation phase with activity' => [
'role' => 'student',
'currentphase' => \workshop::PHASE_EVALUATION,
'groupmode' => NOGROUPS,
'hasstudentactivity' => true,
'expectnull' => true,
],
'teacher closed phase with activity' => [
'role' => 'editingteacher',
'currentphase' => \workshop::PHASE_CLOSED,
'groupmode' => NOGROUPS,
'hasstudentactivity' => true,
'expectnull' => false,
'expected' => ['submissions' => 2, 'assessments' => 3],
],
'student closed phase with activity' => [
'role' => 'student',
'currentphase' => \workshop::PHASE_CLOSED,
'groupmode' => NOGROUPS,
'hasstudentactivity' => true,
'expectnull' => true,
],
// Group mode tests.
'teacher closed phase with group activity (separate groups)' => [
'role' => 'editingteacher',
'currentphase' => \workshop::PHASE_CLOSED,
'groupmode' => SEPARATEGROUPS,
'hasstudentactivity' => true,
'expectnull' => false,
'expected' => ['submissions' => 2, 'assessments' => 3],
],
'non-editing teacher closed phase with group activity (separate groups)' => [
'role' => 'teacher',
'currentphase' => \workshop::PHASE_CLOSED,
'groupmode' => SEPARATEGROUPS,
'hasstudentactivity' => true,
'expectnull' => false,
'expected' => ['submissions' => 1, 'assessments' => 1],
],
'student closed phase with group activity (separate groups)' => [
'role' => 'student',
'currentphase' => \workshop::PHASE_CLOSED,
'groupmode' => SEPARATEGROUPS,
'hasstudentactivity' => true,
'expectnull' => true,
],
'teacher closed phase with group activity (visible groups)' => [
'role' => 'editingteacher',
'currentphase' => \workshop::PHASE_CLOSED,
'groupmode' => VISIBLEGROUPS,
'hasstudentactivity' => true,
'expectnull' => false,
'expected' => ['submissions' => 2, 'assessments' => 3],
],
'non-editing teacher closed phase with group activity (visible groups)' => [
'role' => 'teacher',
'currentphase' => \workshop::PHASE_CLOSED,
'groupmode' => VISIBLEGROUPS,
'hasstudentactivity' => true,
'expectnull' => false,
'expected' => ['submissions' => 2, 'assessments' => 3],
],
'student closed phase with group activity (visible groups)' => [
'role' => 'student',
'currentphase' => \workshop::PHASE_CLOSED,
'groupmode' => VISIBLEGROUPS,
'hasstudentactivity' => true,
'expectnull' => true,
],
public static function data_provider_get_extra_submissions_overview(): \Generator {
yield 'teacher setup phase without activity' => [
'role' => 'editingteacher',
'currentphase' => \workshop::PHASE_SETUP,
'groupmode' => NOGROUPS,
'hasstudentactivity' => false,
'expectnull' => false,
'expected' => ['submissions' => 0, 'assessments' => 0],
];
yield 'student setup phase without activity' => [
'role' => 'student',
'currentphase' => \workshop::PHASE_SETUP,
'groupmode' => NOGROUPS,
'hasstudentactivity' => false,
'expectnull' => true,
];
yield 'teacher submission phase without activity' => [
'role' => 'editingteacher',
'currentphase' => \workshop::PHASE_SUBMISSION,
'groupmode' => NOGROUPS,
'hasstudentactivity' => false,
'expectnull' => false,
'expected' => ['submissions' => 0, 'assessments' => 0],
];
yield 'student submission phase without activity' => [
'role' => 'student',
'currentphase' => \workshop::PHASE_SUBMISSION,
'groupmode' => NOGROUPS,
'hasstudentactivity' => false,
'expectnull' => true,
];
yield 'teacher assessment phase without activity' => [
'role' => 'editingteacher',
'currentphase' => \workshop::PHASE_ASSESSMENT,
'groupmode' => NOGROUPS,
'hasstudentactivity' => false,
'expectnull' => false,
'expected' => ['submissions' => 0, 'assessments' => 0],
];
yield 'student assessment phase without activity' => [
'role' => 'student',
'currentphase' => \workshop::PHASE_ASSESSMENT,
'groupmode' => NOGROUPS,
'hasstudentactivity' => false,
'expectnull' => true,
];
yield 'teacher evaluation phase without activity' => [
'role' => 'editingteacher',
'currentphase' => \workshop::PHASE_EVALUATION,
'groupmode' => NOGROUPS,
'hasstudentactivity' => false,
'expectnull' => false,
'expected' => ['submissions' => 0, 'assessments' => 0],
];
yield 'student evaluation phase without activity' => [
'role' => 'student',
'currentphase' => \workshop::PHASE_EVALUATION,
'groupmode' => NOGROUPS,
'hasstudentactivity' => false,
'expectnull' => true,
];
yield 'teacher closed phase without activity' => [
'role' => 'editingteacher',
'currentphase' => \workshop::PHASE_CLOSED,
'groupmode' => NOGROUPS,
'hasstudentactivity' => false,
'expectnull' => false,
'expected' => ['submissions' => 0, 'assessments' => 0],
];
yield 'student closed phase without activity' => [
'role' => 'student',
'currentphase' => \workshop::PHASE_CLOSED,
'groupmode' => NOGROUPS,
'hasstudentactivity' => false,
'expectnull' => true,
];
// Tests with assessments.
yield 'teacher setup phase with activity' => [
'role' => 'editingteacher',
'currentphase' => \workshop::PHASE_SETUP,
'groupmode' => NOGROUPS,
'hasstudentactivity' => true,
'expectnull' => false,
'expected' => ['submissions' => 2, 'assessments' => 3],
];
yield 'student setup phase with activity' => [
'role' => 'student',
'currentphase' => \workshop::PHASE_SETUP,
'groupmode' => NOGROUPS,
'hasstudentactivity' => true,
'expectnull' => true,
];
yield 'teacher submission phase with activity' => [
'role' => 'editingteacher',
'currentphase' => \workshop::PHASE_SUBMISSION,
'groupmode' => NOGROUPS,
'hasstudentactivity' => true,
'expectnull' => false,
'expected' => ['submissions' => 2, 'assessments' => 3],
];
yield 'student submission phase with activity' => [
'role' => 'student',
'currentphase' => \workshop::PHASE_SUBMISSION,
'groupmode' => NOGROUPS,
'hasstudentactivity' => true,
'expectnull' => true,
];
yield 'teacher assessment phase with activity' => [
'role' => 'editingteacher',
'currentphase' => \workshop::PHASE_ASSESSMENT,
'groupmode' => NOGROUPS,
'hasstudentactivity' => true,
'expectnull' => false,
'expected' => ['submissions' => 2, 'assessments' => 3],
];
yield 'student assessment phase with activity' => [
'role' => 'student',
'currentphase' => \workshop::PHASE_ASSESSMENT,
'groupmode' => NOGROUPS,
'hasstudentactivity' => true,
'expectnull' => true,
];
yield 'teacher evaluation phase with activity' => [
'role' => 'editingteacher',
'currentphase' => \workshop::PHASE_EVALUATION,
'groupmode' => NOGROUPS,
'hasstudentactivity' => true,
'expectnull' => false,
'expected' => ['submissions' => 2, 'assessments' => 3],
];
yield 'student evaluation phase with activity' => [
'role' => 'student',
'currentphase' => \workshop::PHASE_EVALUATION,
'groupmode' => NOGROUPS,
'hasstudentactivity' => true,
'expectnull' => true,
];
yield 'teacher closed phase with activity' => [
'role' => 'editingteacher',
'currentphase' => \workshop::PHASE_CLOSED,
'groupmode' => NOGROUPS,
'hasstudentactivity' => true,
'expectnull' => false,
'expected' => ['submissions' => 2, 'assessments' => 3],
];
yield 'student closed phase with activity' => [
'role' => 'student',
'currentphase' => \workshop::PHASE_CLOSED,
'groupmode' => NOGROUPS,
'hasstudentactivity' => true,
'expectnull' => true,
];
// Group mode tests.
yield 'teacher closed phase with group activity (separate groups)' => [
'role' => 'editingteacher',
'currentphase' => \workshop::PHASE_CLOSED,
'groupmode' => SEPARATEGROUPS,
'hasstudentactivity' => true,
'expectnull' => false,
'expected' => ['submissions' => 2, 'assessments' => 3],
];
yield 'non-editing teacher closed phase with group activity (separate groups)' => [
'role' => 'teacher',
'currentphase' => \workshop::PHASE_CLOSED,
'groupmode' => SEPARATEGROUPS,
'hasstudentactivity' => true,
'expectnull' => false,
'expected' => ['submissions' => 1, 'assessments' => 1],
];
yield 'student closed phase with group activity (separate groups)' => [
'role' => 'student',
'currentphase' => \workshop::PHASE_CLOSED,
'groupmode' => SEPARATEGROUPS,
'hasstudentactivity' => true,
'expectnull' => true,
];
yield 'teacher closed phase with group activity (visible groups)' => [
'role' => 'editingteacher',
'currentphase' => \workshop::PHASE_CLOSED,
'groupmode' => VISIBLEGROUPS,
'hasstudentactivity' => true,
'expectnull' => false,
'expected' => ['submissions' => 2, 'assessments' => 3],
];
yield 'non-editing teacher closed phase with group activity (visible groups)' => [
'role' => 'teacher',
'currentphase' => \workshop::PHASE_CLOSED,
'groupmode' => VISIBLEGROUPS,
'hasstudentactivity' => true,
'expectnull' => false,
'expected' => ['submissions' => 2, 'assessments' => 3],
];
yield 'student closed phase with group activity (visible groups)' => [
'role' => 'student',
'currentphase' => \workshop::PHASE_CLOSED,
'groupmode' => VISIBLEGROUPS,
'hasstudentactivity' => true,
'expectnull' => true,
];
}
@@ -759,27 +754,25 @@ final class overview_test extends \advanced_testcase {
/**
* Data provider for test_get_actions_overview.
*
* @return array
* @return \Generator
*/
public static function provider_test_get_actions_overview(): array {
return [
'Student' => [
'role' => 'student',
'expected' => null,
public static function provider_test_get_actions_overview(): \Generator {
yield 'Student' => [
'role' => 'student',
'expected' => null,
];
yield 'Editing teacher' => [
'role' => 'editingteacher',
'expected' => [
'name' => get_string('actions'),
'value' => get_string('view'),
],
'Editing teacher' => [
'role' => 'editingteacher',
'expected' => [
'name' => get_string('actions'),
'value' => get_string('view'),
],
],
'Teacher' => [
'role' => 'teacher',
'expected' => [
'name' => get_string('actions'),
'value' => get_string('view'),
],
];
yield 'Teacher' => [
'role' => 'teacher',
'expected' => [
'name' => get_string('actions'),
'value' => get_string('view'),
],
];
}