Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WR422914 Subplugin refactor #161

Draft
wants to merge 6 commits into
base: MOODLE_403_STABLE
Choose a base branch
from
Draft
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Readded and updated unit and behat tests
SimonThornett committed Dec 5, 2024
commit 0de6d99931253a9df99f5ab65c7969e2c6cf5d92
2 changes: 1 addition & 1 deletion history.php
Original file line number Diff line number Diff line change
@@ -49,7 +49,7 @@
$cancelurl = new moodle_url('/local/assessfreq/history.php');
echo $OUTPUT->confirm(
get_string('history:confirmreprocess', 'local_assessfreq'),
new single_button($actionurl, get_string('continue'), 'post', true),
new single_button($actionurl, get_string('continue'), 'post', single_button::BUTTON_PRIMARY),
new single_button($cancelurl, get_string('cancel'), 'get')
);
} else if ($action == 'confirmed') {
52 changes: 52 additions & 0 deletions phpunit.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="../../lib/phpunit/phpunit.xsd"
bootstrap="../../lib/phpunit/bootstrap.php"
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
processIsolation="false"
backupGlobals="false"
backupStaticAttributes="false"
cacheResult="false"
stopOnError="false"
stopOnFailure="false"
stopOnIncomplete="false"
stopOnSkipped="false"
beStrictAboutTestsThatDoNotTestAnything="false"
beStrictAboutOutputDuringTests="true"
>

<php>
<!--<const name="PHPUNIT_LONGTEST" value="1"/> uncomment to execute also slow or otherwise expensive tests-->
<const name="PHPUNIT_SEQUENCE_START" value="107000"/>

<!--Following constants instruct tests to fetch external test files from alternative location
or skip tests if empty, clone https://github.com/moodlehq/moodle-exttests to local web server-->
<!--<const name="TEST_EXTERNAL_FILES_HTTP_URL" value="http://download.moodle.org/unittest"/>
uncomment and alter to fetch external test files from alternative location-->
<!--<const name="TEST_EXTERNAL_FILES_HTTPS_URL" value="https://download.moodle.org/unittest"/>
uncomment and alter to fetch external test files from alternative location-->
</php>

<testsuites>
<testsuite name="local_assessfreq_testsuite">
<directory suffix="_test.php">.</directory>
<exclude>./classes</exclude>
</testsuite>
</testsuites>

<coverage>
<include>
<directory suffix=".php">classes</directory>
<directory suffix=".php">tests/generator</directory>
<file>externallib.php</file>
<file>lib.php</file>
<file>locallib.php</file>
<file>renderer.php</file>
<file>rsslib.php</file>
</include>
</coverage>

</phpunit>
10 changes: 10 additions & 0 deletions report/activities_in_progress/classes/output/renderer.php
Original file line number Diff line number Diff line change
@@ -33,6 +33,7 @@
use local_assessfreq\source_base;
use local_assessfreq\utils;
use paging_bar;
use PHPUnit\TextUI\XmlConfiguration\PHPUnit;
use plugin_renderer_base;

defined('MOODLE_INTERNAL') || die();
@@ -44,6 +45,9 @@ class renderer extends plugin_renderer_base {

public function render_report($data) {
daledavies marked this conversation as resolved.
Show resolved Hide resolved

// Charts array for unit testing.
$charts = [];

// In progress counts.
$contents = '';
foreach ($data['inprogress'] as $count) {
@@ -114,6 +118,7 @@ public function render_report($data) {
} else {
$contents = '';
}
$charts['upcoming'] = $chart;
$upcomingcontainer = $this->render_from_template(
'local_assessfreq/card',
[
@@ -167,6 +172,7 @@ public function render_report($data) {
} else {
$contents = '';
}
$charts['participants'] = $chart;

$summarycontainer = $this->render_from_template(
'local_assessfreq/card',
@@ -209,6 +215,10 @@ public function render_report($data) {
// Only get modules with the "get_inprogress_count" method as only these display on the report.
$modules = get_modules($preferencemodule, 'get_inprogress_count');

if (PHPUNIT_TEST) {
return $charts;
}

return $this->render_from_template(
'assessfreqreport_activities_in_progress/activities-in-progress',
[
8 changes: 6 additions & 2 deletions report/student_search/classes/output/user_table.php
Original file line number Diff line number Diff line change
@@ -79,19 +79,23 @@ public function __construct(
string $baseurl,
int $contextid,
string $search,
int $page = 0
int $page = 0,
int $now = 0
) {
parent::__construct('local_assessfreq_student_search_table');

$this->hoursahead = (int)get_user_preferences('assessfreqreport_student_search_hoursahead_preference', 8);
$this->hoursbehind = (int)get_user_preferences('assessfreqreport_student_search_hoursbehind_preference', 1);

$this->hoursahead = 8;
$this->hoursbehind = 8;

$this->search = $search;
$this->set_attribute('id', 'local_assessfreq_ackreport_table');
$this->set_attribute('class', 'generaltable generalbox');
$this->downloadable = false;
$this->define_baseurl($baseurl);
$this->now = time();
$this->now = empty($now) ? time() : $now;

$context = \context::instance_by_id($contextid);

4 changes: 4 additions & 0 deletions report/summary_graphs/classes/output/assess_by_activity.php
Original file line number Diff line number Diff line change
@@ -84,6 +84,10 @@ public function get_assess_by_activity_chart(int $year, int $month) : array {
}
$chart->add_series($events);
$chart->set_labels($labels);
if (PHPUNIT_TEST) {
$result['chart'] = $chart;
return $result;
}
$result['chart'] = $OUTPUT->render($chart);
}

Original file line number Diff line number Diff line change
@@ -61,6 +61,10 @@ protected function generate_chart($charttype, array $yeardata, string $charttitl
$chart->set_labels($labels);

$result['hasdata'] = true;
if (PHPUNIT_TEST) {
$result['chart'] = $chart;
return $result;
}
$result['chart'] = $OUTPUT->render($chart);

return $result;
5 changes: 5 additions & 0 deletions source/quiz/classes/output/participant_summary.php
Original file line number Diff line number Diff line change
@@ -83,6 +83,11 @@ public function get_participant_summary_chart(array $allparticipantdata) : array
$chart->add_series($participants);
$chart->set_labels($labels);

if (PHPUNIT_TEST) {
$result['chart'] = $chart;
return $result;
}

$result['chart'] = $OUTPUT->render($chart);
}

6 changes: 6 additions & 0 deletions source/quiz/classes/output/participant_trend.php
Original file line number Diff line number Diff line change
@@ -26,6 +26,7 @@

use core\chart_line;
use core\chart_series;
use PHPUnit\TextUI\XmlConfiguration\PHPUnit;

/**
* Renderable for participant trend card.
@@ -91,6 +92,11 @@ public function get_participant_trend_chart(array $allparticipantdata): array {
$chart->add_series($finishedseries);
$chart->set_labels($labels);

if (PHPUNIT_TEST) {
$result['chart'] = $chart;
return $result;
}

$result['chart'] = $OUTPUT->render($chart);
}

17 changes: 13 additions & 4 deletions source/quiz/classes/source.php
Original file line number Diff line number Diff line change
@@ -214,7 +214,7 @@ private function get_quiz_questions(quiz_settings $quizobject) : stdClass {
* @param int $hoursahead
* @param int $hoursbehind
*/
public function get_inprogress_count(int $now, int $hoursahead, int $hoursbehind) {
public function get_inprogress_count(int $now, int $hoursahead, int $hoursbehind, bool $returnstring = true) {
// Get tracked quizzes.
$trackedquizzes = $this->get_tracked_quizzes_with_overrides($now, $hoursahead * HOURSECS, $hoursbehind * HOURSECS);

@@ -233,7 +233,10 @@ public function get_inprogress_count(int $now, int $hoursahead, int $hoursbehind
}
}

return get_string('inprogress:assessments', 'assessfreqsource_quiz', $counts);
if ($returnstring) {
return get_string('inprogress:assessments', 'assessfreqsource_quiz', $counts);
}
return $counts;
}

/**
@@ -547,6 +550,7 @@ public function get_quiz_data($quiz) : stdClass {
// Dashboard link.
$dashboardlink = new moodle_url('/local/assessfreq/', ['activityid' => $context->instanceid], 'activity_dashboard');

$quizdata->id = $quiz->id;
$quizdata->name = format_string($quizrecord->name, true, ["context" => $context, "escape" => true]);
$quizdata->timeopen = $timesopen;
$quizdata->timeclose = $timeclose;
@@ -555,7 +559,12 @@ public function get_quiz_data($quiz) : stdClass {
$quizdata->earlyopenstamp = $earlyopenstamp;
$quizdata->lateclose = $lateclose;
$quizdata->lateclosestamp = $lateclosestamp;
$quizdata->participants = count($frequency->get_event_users($context->id, 'quiz', false));
// For unit tests get the raw data as scheduled tasks won't have run.
if (PHPUNIT_TEST) {
$quizdata->participants = count($frequency->get_event_users_raw($context->id, 'quiz', false));
} else {
$quizdata->participants = count($frequency->get_event_users($context->id, 'quiz', false));
}
$quizdata->overrideparticipants = $overrideinfo->users;
$quizdata->url = $context->get_url()->out(false);
$quizdata->types = $questions->types;
@@ -573,7 +582,7 @@ public function get_quiz_data($quiz) : stdClass {
$quizdata->timestampopen = $quizobject->get_quiz()->timeopen;
$quizdata->timestampclose = $quizobject->get_quiz()->timeclose;
$quizdata->timestamplimit = $quizobject->get_quiz()->timelimit;
$quizdata->isoverride = $quiz->isoverride;
$quizdata->isoverride = $quiz->isoverride ?? 0;

if (isset($quiz->overrides)) {
$quizdata->overrides = $quiz->overrides;
15 changes: 11 additions & 4 deletions source/quiz/classes/task/quiz_tracking.php
Original file line number Diff line number Diff line change
@@ -56,10 +56,16 @@ public function get_name() : string {
*/
public function execute() : void {
global $DB;
mtrace('assessfreqsource_quiz: Processing quiz tracking');

if (!PHPUNIT_TEST) {
mtrace('assessfreqsource_quiz: Processing quiz tracking');
}
$actionstart = time();

// If a unit test is running, use the epoche from local/assessfreq/tests/quiz_test.php:147.
if (PHPUNIT_TEST) {
$actionstart = 1594788000;
}

$source = new source();
$frequency = new frequency();

@@ -109,7 +115,8 @@ public function execute() : void {
}

$actionduration = time() - $actionstart;

mtrace("assessfreqsource_quiz: Processing quiz tracking of $count records finished in: $actionduration seconds");
if (!PHPUNIT_TEST) {
mtrace("assessfreqsource_quiz: Processing quiz tracking of $count records finished in: $actionduration seconds");
}
}
}
106 changes: 106 additions & 0 deletions tests/behat/assessmentfreq.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
@catalyst @javascript @local @local_assessfreq
Feature: Assessment frequency

Background:
Given the following "courses" exist:
| shortname | fullname |
| C1 | Course 1 |
And the following "activities" exist:
| activity | course | name | duedate |
| assign | C1 | Test assignment 1 | ## January 1st, 2022 ## |
| assign | C1 | Test assignment 2 | ## February 1st, 2022 ## |
| assign | C1 | Test assignment 3 | ## March 1st, 2022 ## |
| assign | C1 | Test assignment 4 | ## April 1st, 2022 ## |
| assign | C1 | Test assignment 5 | ## May 1st, 2022 ## |
| assign | C1 | Test assignment 6 | ## June 1st, 2022 ## |
| assign | C1 | Test assignment 7 | ## July 1st, 2022 ## |
| assign | C1 | Test assignment 8 | ## August 1st, 2022 ## |
| assign | C1 | Test assignment 9 | ## September 1st, 2022 ## |
| assign | C1 | Test assignment 10 | ## October 1st, 2022 ## |
And the following "activities" exist:
| activity | course | name | timeclose |
| choice | C1 | Test choice 1 | ## January 1st, 2022 ## |
| choice | C1 | Test choice 2 | ## February 1st, 2022 ## |
| choice | C1 | Test choice 3 | ## March 1st, 2022 ## |
| choice | C1 | Test choice 4 | ## April 1st, 2022 ## |
| choice | C1 | Test choice 5 | ## May 1st, 2022 ## |
| choice | C1 | Test choice 6 | ## June 1st, 2022 ## |
| choice | C1 | Test choice 7 | ## July 1st, 2022 ## |
| choice | C1 | Test choice 8 | ## August 1st, 2022 ## |
| choice | C1 | Test choice 9 | ## September 1st, 2022 ## |
And the following "activities" exist:
| activity | course | name | timeavailableto |
| data | C1 | Test database 1 | ## January 1st, 2022 ## |
| data | C1 | Test database 2 | ## February 1st, 2022 ## |
| data | C1 | Test database 3 | ## March 1st, 2022 ## |
| data | C1 | Test database 4 | ## April 1st, 2022 ## |
| data | C1 | Test database 5 | ## May 1st, 2022 ## |
| data | C1 | Test database 6 | ## June 1st, 2022 ## |
| data | C1 | Test database 7 | ## July 1st, 2022 ## |
| data | C1 | Test database 8 | ## August 1st, 2022 ## |
And the following "activities" exist:
| activity | course | name | timeclose |
| feedback | C1 | Test feedback 1 | ## January 1st, 2022 ## |
| feedback | C1 | Test feedback 2 | ## February 1st, 2022 ## |
| feedback | C1 | Test feedback 3 | ## March 1st, 2022 ## |
| feedback | C1 | Test feedback 4 | ## April 1st, 2022 ## |
| feedback | C1 | Test feedback 5 | ## May 1st, 2022 ## |
| feedback | C1 | Test feedback 6 | ## June 1st, 2022 ## |
| feedback | C1 | Test feedback 7 | ## July 1st, 2022 ## |
And the following "activities" exist:
| activity | course | name | duedate |
| forum | C1 | Test forum 1 | ## January 1st, 2022 ## |
| forum | C1 | Test forum 2 | ## February 1st, 2022 ## |
| forum | C1 | Test forum 3 | ## March 1st, 2022 ## |
| forum | C1 | Test forum 4 | ## April 1st, 2022 ## |
| forum | C1 | Test forum 5 | ## May 1st, 2022 ## |
| forum | C1 | Test forum 6 | ## June 1st, 2022 ## |
And the following "activities" exist:
| activity | course | name | deadline |
| lesson | C1 | Test lesson 1 | ## January 1st, 2022 ## |
| lesson | C1 | Test lesson 2 | ## February 1st, 2022 ## |
| lesson | C1 | Test lesson 3 | ## March 1st, 2022 ## |
| lesson | C1 | Test lesson 4 | ## April 1st, 2022 ## |
| lesson | C1 | Test lesson 5 | ## May 1st, 2022 ## |
And the following "activities" exist:
| activity | course | name | timeclose |
| quiz | C1 | Test quiz 1 | ## January 1st, 2022 ## |
| quiz | C1 | Test quiz 2 | ## February 1st, 2022 ## |
| quiz | C1 | Test quiz 3 | ## March 1st, 2022 ## |
| quiz | C1 | Test quiz 4 | ## April 1st, 2022 ## |
And the following "activities" exist:
| activity | course | name | timeclose |
| scorm | C1 | Test scorm 1 | ## January 1st, 2022 ## |
| scorm | C1 | Test scorm 2 | ## February 1st, 2022 ## |
| scorm | C1 | Test scorm 3 | ## March 1st, 2022 ## |
And the following "activities" exist:
| activity | course | name | submissionend |
| workshop | C1 | Test workshop 1 | ## January 1st, 2022 ## |
| workshop | C1 | Test workshop 2 | ## February 1st, 2022 ## |
And the following config values are set as admin:
| config | value | plugin |
| modules | assign,choice,data,feedback,forum,lesson,quiz,scorm,workshop | local_assessfreq |

Scenario: Basic test of dashboard display
Given I log in as "admin"
When I navigate to "Plugins > Local plugins > Assessment Frequency Clear History" in site administration
And I press "Reprocess all events"
And I press "Continue"
And I run all adhoc tasks
And I navigate to "Reports > Assessment Frequency Report" in site administration
And I wait "3" seconds
And I click on "Select year" "button"
And I click on "2022" "link"
And I wait "3" seconds
And I click on "td[data-target='2022-1-1']" "css_element"
Then the following should exist in the "report-dayview-table" table:
| Daily schedule |
| Assignment: Test assignment 1 |
| Choice: Test choice 1 |
| Database: Test database 1 |
| Feedback: Test feedback 1 |
| Forum: Test forum 1 |
| Lesson: Test lesson 1 |
| Quiz: Test quiz 1 |
| SCORM package: Test scorm 1 |
| Workshop: Test workshop 1 |
Loading
Loading