__ __ __ __ _____ _ _ _____ _ _ _ | \/ | \ \ / / | __ \ (_) | | / ____| | | | | | \ / |_ __\ V / | |__) | __ ___ ____ _| |_ ___ | (___ | |__ ___| | | | |\/| | '__|> < | ___/ '__| \ \ / / _` | __/ _ \ \___ \| '_ \ / _ \ | | | | | | |_ / . \ | | | | | |\ V / (_| | || __/ ____) | | | | __/ | | |_| |_|_(_)_/ \_\ |_| |_| |_| \_/ \__,_|\__\___| |_____/|_| |_|\___V 2.1 if you need WebShell for Seo everyday contact me on Telegram Telegram Address : @jackleetFor_More_Tools:
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
namespace core_completion;
/**
* PHPUnit data generator testcase
*
* @package core_completion
* @category test
* @copyright 2023 Amaia Anabitarte <amaia@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
* @coversDefaultClass \core_completion_generator
*/
final class generator_test extends \advanced_testcase {
/**
* Test create_default_completion.
*
* @dataProvider create_default_completion_provider
*
* @param int|null|string $course The course to add the default activities conditions to.
* @param int|null|string $module The module to add the default activities conditions to.
* @param bool $exception Whether an exception is expected or not.
* @param int $count The number of default activity completions to be created.
* @param int $completion The value for completion setting.
*
* @covers ::create_default_completion
*/
public function test_create_default_completion($course, $module, bool $exception, int $count, int $completion = 0): void {
global $DB;
$this->resetAfterTest(true);
$generator = $this->getDataGenerator()->get_plugin_generator('core_completion');
$record = [
'course' => $course,
'module' => $module,
'completion' => $completion,
];
$result = (object) array_merge([
'completion' => 0,
'completionview' => 0,
'completionusegrade' => 0,
'completionpassgrade' => 0,
'completionexpected' => 0,
'customrules' => '',
], $record);
if ($exception) {
$this->expectException('moodle_exception');
}
$defaultcompletion = $generator->create_default_completion($record);
if (!$exception) {
foreach ($result as $key => $value) {
$this->assertEquals($defaultcompletion->{$key}, $value);
}
}
$this->assertEquals(
$count,
$DB->count_records('course_completion_defaults', ['course' => $course, 'module' => $module])
);
}
/**
* Data provider for test_create_default_completion().
* @return array[]
*/
public static function create_default_completion_provider(): array {
global $SITE;
return [
'Null course' => [
'course' => null,
'module' => null,
'exception' => true,
'count' => 0,
],
'Empty course' => [
'course' => '',
'module' => null,
'exception' => true,
'count' => 0,
],
'Invalid course' => [
'course' => 0,
'module' => null,
'exception' => true,
'count' => 0,
],
'Null module' => [
'course' => $SITE->id,
'module' => null,
'exception' => true,
'count' => 0,
],
'Empty module' => [
'course' => $SITE->id,
'module' => null,
'exception' => true,
'count' => 0,
],
'Invalid module' => [
'course' => $SITE->id,
'module' => 0,
'exception' => true,
'count' => 0,
],
'Default activity completion: NONE' => [
'course' => $SITE->id,
'module' => 1,
'exception' => false,
'count' => 1,
],
'Default activity completion: AUTOMATIC' => [
'course' => $SITE->id,
'module' => 1,
'exception' => false,
'count' => 1,
'completion' => 2,
],
];
}
}
| Name | Type | Size | Permission | Actions |
|---|---|---|---|---|
| behat | Folder | 0777 |
|
|
| fixtures | Folder | 0777 |
|
|
| generator | Folder | 0777 |
|
|
| privacy | Folder | 0777 |
|
|
| activity_custom_completion_test.php | File | 6.84 KB | 0777 |
|
| api_test.php | File | 15.96 KB | 0777 |
|
| bulk_update_test.php | File | 13.74 KB | 0777 |
|
| capabilities_test.php | File | 2.09 KB | 0777 |
|
| cm_completion_details_test.php | File | 25.23 KB | 0777 |
|
| completion_criteria_test.php | File | 12.46 KB | 0777 |
|
| coverage.php | File | 1.62 KB | 0777 |
|
| externallib_test.php | File | 30.64 KB | 0777 |
|
| generator_test.php | File | 4.52 KB | 0777 |
|
| progress_test.php | File | 12.17 KB | 0777 |
|