Skip to content

Commit 63d735e

Browse files
committed
Add behat tests
1 parent 5813463 commit 63d735e

2 files changed

Lines changed: 176 additions & 0 deletions

File tree

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
@tool @tool_corruptpdfdetector
2+
Feature: View the corrupt PDF submissions report
3+
In order to monitor corrupt PDF assignment submissions
4+
As a site administrator
5+
I need to be able to view the corrupt PDF detector report page
6+
7+
Background:
8+
Given I log in as "admin"
9+
10+
Scenario: Admin can navigate to the corrupt PDF report via site administration
11+
When I navigate to "Server > Corrupt pdf assignment finder" in site administration
12+
Then I should see "Detected corrupt pdf submissions"
13+
And I should see "Faulty pdf file percentage:"
14+
15+
Scenario: The report page shows the correct table columns when empty
16+
When I navigate to "Server > Corrupt pdf assignment finder" in site administration
17+
Then I should see "Detected corrupt pdf submissions"
18+
And I should see "Course"
19+
And I should see "Assignment"
20+
And I should see "Student name"
21+
And I should see "Email"
22+
And I should see "Reason"
23+
And I should see "Last modified"
24+
And I should see "Detected"
25+
And I should see "Fixed"
26+
27+
Scenario: The error percentage shows 0 when there are no detections
28+
When I navigate to "Server > Corrupt pdf assignment finder" in site administration
29+
Then I should see "Faulty pdf file percentage: 0"
30+
31+
Scenario: Non-admin users cannot access the corrupt PDF report
32+
Given I log out
33+
And the following "users" exist:
34+
| username | firstname | lastname | email |
35+
| teacher1 | Teacher | One | t1@example.com |
36+
And the following "courses" exist:
37+
| fullname | shortname |
38+
| Course 1 | C1 |
39+
And the following "course enrolments" exist:
40+
| user | course | role |
41+
| teacher1 | C1 | editingteacher |
42+
When I log in as "teacher1"
43+
And I visit "/admin/tool/corruptpdfdetector/index.php"
44+
Then I should not see "Detected corrupt pdf submissions"
45+
46+
Scenario: Report page shows an unfixed detection record
47+
Given the following "tool_corruptpdfdetector > detections" exist:
48+
| coursename | assignname | userfullname | email | filename | message | fixed |
49+
| Course 1 | Assignment 1 | Alice Smith | alice@example.com | fakehash01 | Invalid header | 0 |
50+
When I navigate to "Server > Corrupt pdf assignment finder" in site administration
51+
Then I should see "Course 1"
52+
And I should see "Assignment 1"
53+
And I should see "Alice Smith"
54+
And I should see "alice@example.com"
55+
And I should see "Invalid header"
56+
And I should see "No" in the "Alice Smith" "table_row"
57+
58+
Scenario: A fixed detection record is shown with Fixed = Yes
59+
Given the following "tool_corruptpdfdetector > detections" exist:
60+
| coursename | assignname | userfullname | email | filename | message | fixed |
61+
| Course 1 | Assignment 1 | Alice Smith | alice@example.com | fakehash02 | Invalid header | 1 |
62+
When I navigate to "Server > Corrupt pdf assignment finder" in site administration
63+
Then I should see "Yes" in the "Alice Smith" "table_row"
64+
65+
Scenario: Multiple detection records are all shown in the report
66+
Given the following "tool_corruptpdfdetector > detections" exist:
67+
| coursename | assignname | userfullname | email | filename | message | fixed |
68+
| Course 1 | Assignment 1 | Alice Smith | alice@test.com | fakehash03 | Invalid header | 0 |
69+
| Course 2 | Assignment 2 | Bob Jones | bob@test.com | fakehash04 | Missing xref | 0 |
70+
When I navigate to "Server > Corrupt pdf assignment finder" in site administration
71+
Then I should see "Alice Smith"
72+
And I should see "Bob Jones"
73+
And I should see "Course 1"
74+
And I should see "Course 2"
75+

tests/generator/lib.php

Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
<?php
2+
// This file is part of Moodle - http://moodle.org/
3+
//
4+
// Moodle is free software: you can redistribute it and/or modify
5+
// it under the terms of the GNU General Public License as published by
6+
// the Free Software Foundation, either version 3 of the License, or
7+
// (at your option) any later version.
8+
//
9+
// Moodle is distributed in the hope that it will be useful,
10+
// but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+
// GNU General Public License for more details.
13+
//
14+
// You should have received a copy of the GNU General Public License
15+
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
16+
17+
/**
18+
* Test data generator for tool_corruptpdfdetector.
19+
*
20+
* @package tool_corruptpdfdetector
21+
* @category test
22+
* @copyright Catalyst IT
23+
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
24+
*/
25+
26+
defined('MOODLE_INTERNAL') || die();
27+
28+
/**
29+
* Data generator for tool_corruptpdfdetector.
30+
*
31+
* @package tool_corruptpdfdetector
32+
* @category test
33+
* @copyright Catalyst IT
34+
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
35+
*/
36+
class tool_corruptpdfdetector_generator extends testing_module_generator {
37+
/**
38+
* Create a detection record in tool_corruptpdfdetector_assigns.
39+
*
40+
* Accepted keys in $record:
41+
* - assignid (int, default 0)
42+
* - submissionid (int, default auto-incremented unique value)
43+
* - coursename (string, default '')
44+
* - assignname (string, default '')
45+
* - userfullname (string, default '')
46+
* - email (string, default '')
47+
* - filename (string, default sha1 of submissionid)
48+
* - message (string, default '')
49+
* - submitted (int, default current time)
50+
* - detected (int, default current time)
51+
* - fixed (int, default 0)
52+
*
53+
* @param array|stdClass|null $record Detection record data.
54+
* @return stdClass Inserted record with id populated.
55+
*/
56+
public function create_detection($record = null): stdClass {
57+
global $DB;
58+
59+
$record = (object)(array) $record;
60+
61+
if (!isset($record->assignid)) {
62+
$record->assignid = 0;
63+
}
64+
if (!isset($record->submissionid)) {
65+
$record->submissionid = $DB->get_field_sql(
66+
'SELECT COALESCE(MAX(submissionid), 0) + 1 FROM {tool_corruptpdfdetector_assigns}'
67+
);
68+
}
69+
if (!isset($record->coursename)) {
70+
$record->coursename = '';
71+
}
72+
if (!isset($record->assignname)) {
73+
$record->assignname = '';
74+
}
75+
if (!isset($record->userfullname)) {
76+
$record->userfullname = '';
77+
}
78+
if (!isset($record->email)) {
79+
$record->email = '';
80+
}
81+
if (!isset($record->filename)) {
82+
$record->filename = sha1((string) $record->submissionid);
83+
}
84+
if (!isset($record->message)) {
85+
$record->message = '';
86+
}
87+
if (!isset($record->submitted)) {
88+
$record->submitted = time();
89+
}
90+
if (!isset($record->detected)) {
91+
$record->detected = time();
92+
}
93+
if (!isset($record->fixed)) {
94+
$record->fixed = 0;
95+
}
96+
97+
$record->id = $DB->insert_record('tool_corruptpdfdetector_assigns', $record);
98+
99+
return $record;
100+
}
101+
}

0 commit comments

Comments
 (0)