Skip to content

Commit

Permalink
coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
rdebleu committed Oct 19, 2024
1 parent da171ca commit ba25da0
Showing 1 changed file with 24 additions and 1 deletion.
25 changes: 24 additions & 1 deletion tests/condition_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
*/
namespace availability_language;

use core_availability\{mock_info, tree};
use core_availability\{tree, mock_info, info_module, info_section};
use availability_language\condition;
use moodle_exception;

Expand Down Expand Up @@ -210,6 +210,29 @@ public function test_get_description(): void {
$this->assertEquals('en', $result);
}

/**
* Tests is available.
* @covers \availability_language\condition
*/
public function test_is_available(): void {
global $DB, $USER;
$this->resetAfterTest();
$dg = $this->getDataGenerator();
$course = $dg->create_course(['enablecompletion' => 1]);
$user = $dg->create_user();
$roleid = $DB->get_field('role', 'id', ['shortname' => 'student']);
$dg->enrol_user($user->id, $course->id, $roleid);
$pg = $this->getDataGenerator()->get_plugin_generator('mod_page');
$page = $pg->create_instance(['course' => $course, 'completion' => COMPLETION_TRACKING_MANUAL]);
$pg->create_instance(['course' => $course]);
$modinfo = get_fast_modinfo($course);
$cm = $modinfo->get_cm($page->cmid);
$info = new info_module($cm);
$cond = new condition((object)['type' => 'language', 'id' => 'en']);
$this->assertTrue($cond->is_available(false, $info, false, $user->id));
$this->assertFalse($cond->is_available(true, $info, false, $user->id));
}

/**
* Tests using language condition in front end.
* @covers \availability_language\frontend
Expand Down

0 comments on commit ba25da0

Please sign in to comment.