Skip to content

Commit

Permalink
code review
Browse files Browse the repository at this point in the history
  • Loading branch information
rdebleu committed Apr 5, 2024
1 parent fe85ee0 commit 7b3a6af
Show file tree
Hide file tree
Showing 9 changed files with 26 additions and 24 deletions.
26 changes: 13 additions & 13 deletions classes/condition.php
Expand Up @@ -40,7 +40,6 @@
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class condition extends \core_availability\condition {

/** @var string coursecompleted 0 => No, 1 => Yes */
protected $coursecompleted;

Expand All @@ -56,7 +55,7 @@ public function __construct($structure) {
} else if (is_string($structure->id)) {
$this->coursecompleted = $structure->id;
} else {
throw new coding_exception('Invalid value for course completed condition');
new coding_exception('Invalid value for course completed condition');
}
}

Expand Down Expand Up @@ -134,7 +133,7 @@ public function get_description($full, $not, info $info) {
* @return string Text representation of parameters
*/
protected function get_debug_string() {
return $this->coursecompleted ? '#' . 'True' : 'False';
return get_string($this->coursecompleted ? 'true' : 'false', 'mod_quiz');
}

/**
Expand Down Expand Up @@ -162,7 +161,8 @@ public function filter_user_list(
array $users,
$not,
\core_availability\info $info,
\core_availability\capability_checker $checker) {
\core_availability\capability_checker $checker
) {

global $DB;

Expand All @@ -186,15 +186,15 @@ public function filter_user_list(
// Always include users with access to completion report.
if (array_key_exists($id, $adusers)) {
$result[$id] = $user;
continue;
}
// Other users are included or not based on course completion.
$allow = array_key_exists($id, $compusers);
if ($not) {
$allow = !$allow;
}
if ($allow) {
$result[$id] = $user;
} else {
// Other users are included or not based on course completion.
$allow = array_key_exists($id, $compusers);
if ($not) {
$allow = !$allow;
}
if ($allow) {
$result[$id] = $user;
}
}
}
return $result;
Expand Down
2 changes: 0 additions & 2 deletions classes/frontend.php
Expand Up @@ -39,8 +39,6 @@
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class frontend extends \core_availability\frontend {


/**
* Decides whether this plugin should be available in a given course. The
* plugin can do this depending on course or system settings.
Expand Down
1 change: 0 additions & 1 deletion classes/privacy/provider.php
Expand Up @@ -34,7 +34,6 @@
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class provider implements \core_privacy\local\metadata\null_provider {

/**
* Get the language string identifier with the component's language
* file to explain why this plugin stores no data.
Expand Down
7 changes: 4 additions & 3 deletions tests/advanced_test.php
Expand Up @@ -41,7 +41,6 @@
* @coversDefaultClass \availability_coursecompleted
*/
final class advanced_test extends \advanced_testcase {

/** @var stdClass course. */
private $course;

Expand Down Expand Up @@ -208,7 +207,9 @@ public function test_page(): void {
$this->assertFalse($cond->is_available_for_all());
$this->assertFalse($cond->update_dependency_id(null, 1, 2));
$this->assertEquals($cond->__toString(), '{coursecompleted:False}');
$this->assertEquals($cond->get_standalone_description(true, true, $info),
'Not available unless: You completed this course.');
$this->assertEquals(
$cond->get_standalone_description(true, true, $info),
'Not available unless: You completed this course.'
);
}
}
1 change: 0 additions & 1 deletion tests/basic_test.php
Expand Up @@ -41,7 +41,6 @@
* @coversDefaultClass \availability_coursecompleted
*/
final class basic_test extends \basic_testcase {

/**
* Tests the constructor including error conditions.
* @covers \availability_coursecompleted\condition
Expand Down
3 changes: 1 addition & 2 deletions tests/behat/behat_availability_coursecompleted.php
Expand Up @@ -30,7 +30,7 @@
require_once(__DIR__ . '/../../../../../lib/behat/behat_base.php');
// @codeCoverageIgnoreEnd

use Behat\Mink\Exception\ElementNotFoundException as ElementNotFoundException;
use Behat\Mink\Exception\ElementNotFoundException;

/**
* Step definitions related to mark user complete.
Expand All @@ -41,7 +41,6 @@
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class behat_availability_coursecompleted extends behat_base {

/**
* Complete user in a course
* @Then /^I mark course "(?P<course>[^"]*)" completed for user "(?P<user>[^"]*)"$/
Expand Down
1 change: 0 additions & 1 deletion tests/behat_test.php
Expand Up @@ -35,7 +35,6 @@
* @coversDefaultClass \availability_coursecompleted
*/
final class behat_test extends \advanced_testcase {

/**
* Test behat funcs
* @covers \behat_availability_coursecompleted
Expand Down
8 changes: 8 additions & 0 deletions tests/coverage.php
Expand Up @@ -25,6 +25,14 @@

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

/**
* Unit tests for the coursecompleted condition.
*
* @package availability_coursecompleted
* @copyright 2022 iplusacademy (www.iplusacademy.org)
* @author Renaat Debleu <info@eWallah.net>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
return new class extends phpunit_coverage_info {
/** @var array The list of folders relative to the plugin root to include in coverage generation. */
protected $includelistfolders = ['classes'];
Expand Down
1 change: 0 additions & 1 deletion tests/privacy/privacy_test.php
Expand Up @@ -38,7 +38,6 @@
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
final class privacy_test extends provider_testcase {

/**
* Test returning metadata.
* @covers \availability_coursecompleted\privacy\provider
Expand Down

0 comments on commit 7b3a6af

Please sign in to comment.