Skip to content

Commit 5be34c4

Browse files
committed
Adding Behat tests to pdfannotator.
1 parent bea2d65 commit 5be34c4

File tree

6 files changed

+266
-9
lines changed

6 files changed

+266
-9
lines changed

.github/workflows/moodle-plugin-ci.yml

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ jobs:
88

99
services:
1010
postgres:
11-
image: postgres:13
11+
image: postgres:14
1212
env:
1313
POSTGRES_USER: 'postgres'
1414
POSTGRES_HOST_AUTH_METHOD: 'trust'
@@ -17,7 +17,7 @@ jobs:
1717
options: --health-cmd pg_isready --health-interval 10s --health-timeout 5s --health-retries 3
1818

1919
mariadb:
20-
image: mariadb:10
20+
image: mariadb:10.6
2121
env:
2222
MYSQL_USER: 'root'
2323
MYSQL_ALLOW_EMPTY_PASSWORD: "true"
@@ -31,6 +31,13 @@ jobs:
3131
fail-fast: false
3232
matrix:
3333
include:
34+
- php: 8.3
35+
moodle-branch: MOODLE_405_STABLE
36+
database: pgsql
37+
- php: 8.3
38+
moodle-branch: MOODLE_405_STABLE
39+
database: mariadb
40+
3441
- php: 8.3
3542
moodle-branch: MOODLE_404_STABLE
3643
database: pgsql
@@ -80,13 +87,6 @@ jobs:
8087
moodle-branch: MOODLE_400_STABLE
8188
database: mariadb
8289

83-
- php: 7.4
84-
moodle-branch: MOODLE_311_STABLE
85-
database: pgsql
86-
- php: 7.4
87-
moodle-branch: MOODLE_311_STABLE
88-
database: mariadb
89-
9090
steps:
9191
- name: Check out repository code
9292
uses: actions/checkout@v4
@@ -175,3 +175,4 @@ jobs:
175175
- name: Mark cancelled jobs as failed.
176176
if: ${{ cancelled() }}
177177
run: exit 1
178+
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
@mod @mod_pdfannotator @_file_upload
2+
Feature: Add a pdfannotator activity
3+
In order to let the users use the pdfannotator in a course
4+
As a teacher
5+
I need to add a pdfannotator to a moodle course
6+
7+
@javascript
8+
Scenario: Add a pdfannotator to a course
9+
Given the following "users" exist:
10+
| username | firstname | lastname | email |
11+
| teacher1 | Teacher | 1 | teacher1@example.com |
12+
| student1 | Student | 1 | student1@example.com |
13+
And the following "courses" exist:
14+
| fullname | shortname | category |
15+
| Course 1 | C1 | 0 |
16+
And the following "course enrolments" exist:
17+
| user | course | role |
18+
| teacher1 | C1 | editingteacher |
19+
| student1 | C1 | student |
20+
And the following "user preferences" exist:
21+
| user | preference | value |
22+
| teacher1 | htmleditor | atto |
23+
| student1 | htmleditor | atto |
24+
And I log in as "teacher1"
25+
And I am on "Course 1" course homepage with editing mode on
26+
And I add a pdfannotator activity to course "Course 1" section "1" and I fill the form with:
27+
| Name | Test pdf annotation |
28+
| Description | Test pdf annotation description |
29+
| Select a pdf-file | mod/pdfannotator/tests/fixtures/submission.pdf |
30+
And I am on "Course 1" course homepage with editing mode on
31+
And I log out
32+
And I log in as "student1"
33+
And I am on "Course 1" course homepage
34+
And I follow "Test pdf annotation"
35+
Then I should see "Test pdf annotation"
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
@mod @mod_pdfannotator @_file_upload @javascript
2+
Feature: Annotate in a pdfannotator activity
3+
In order to annotate in the pdfannotator in a course
4+
As a student
5+
I need to note questions and subscribe or unsubscribe to notificatoins
6+
7+
Background:
8+
Given the following "users" exist:
9+
| username | firstname | lastname | email |
10+
| teacher1 | Teacher | 1 | teacher1@example.com |
11+
| student1 | Student | 1 | student1@example.com |
12+
And the following "courses" exist:
13+
| fullname | shortname | category |
14+
| Course 1 | C1 | 0 |
15+
And the following "course enrolments" exist:
16+
| user | course | role |
17+
| teacher1 | C1 | editingteacher |
18+
| student1 | C1 | student |
19+
And the following "user preferences" exist:
20+
| user | preference | value |
21+
| teacher1 | htmleditor | atto |
22+
| student1 | htmleditor | atto |
23+
And I log in as "teacher1"
24+
And I am on "Course 1" course homepage with editing mode on
25+
And I add a pdfannotator activity to course "Course 1" section "1" and I fill the form with:
26+
| Name | Test PDF annotation |
27+
| Description | Test pdf annotation description |
28+
| Select a pdf-file | mod/pdfannotator/tests/fixtures/submission.pdf |
29+
And I am on "Course 1" course homepage with editing mode on
30+
And I log out
31+
32+
Scenario: Add a question to a pdfannotator
33+
Given I am on the "Test PDF annotation" "mod_pdfannotator > View" page logged in as "student1"
34+
And I click on "comment" "button"
35+
And I wait "1" seconds
36+
And I point at the pdfannotator canvas
37+
And I wait "1" seconds
38+
And I set the field with xpath "//div[@id='id_pdfannotator_contenteditable']" to "This is a smurfing smurf"
39+
And I click on "Create Annotation" "button"
40+
And I wait until the page is ready
41+
Then I should see "This is a smurfing smurf"
42+
And I log out
Lines changed: 120 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,120 @@
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+
* Steps definitions related to mod_pdfannotator.
19+
*
20+
* @package mod_pdfannotator
21+
* @category test
22+
* @copyright 2019 HSR (http://www.hsr.ch)
23+
* @author 2019 Huong Nguyen <[email protected]>
24+
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
25+
*/
26+
27+
require_once(__DIR__ . '/../../../../lib/behat/behat_base.php');
28+
29+
use mod_pdfannotator\utils;
30+
use Behat\Mink\Exception\ExpectationException as ExpectationException;
31+
use Behat\Mink\Exception\ElementNotFoundException as ElementNotFoundException;
32+
use Behat\Gherkin\Node\TableNode as TableNode;
33+
34+
/**
35+
* Steps definitions related to mod_pdfannotator.
36+
*
37+
* @package pdfannotator
38+
* @category test
39+
* @copyright 2024 Luca Bösch <[email protected]>
40+
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
41+
*/
42+
class behat_mod_pdfannotator extends behat_base {
43+
44+
/**
45+
* Convert page names to URLs for steps like 'When I am on the "[page name]" page'.
46+
*
47+
* Recognised page names are:
48+
* | None so far! | |
49+
*
50+
* @param string $page name of the page, with the component name removed e.g. 'Admin notification'.
51+
* @return moodle_url the corresponding URL.
52+
* @throws Exception with a meaningful error message if the specified page cannot be found.
53+
*/
54+
protected function resolve_page_url(string $page): moodle_url {
55+
switch ($page) {
56+
default:
57+
throw new Exception('Unrecognised pdfannotator page type "' . $page . '."');
58+
}
59+
}
60+
61+
/**
62+
* Convert page names to URLs for steps like 'When I am on the "[identifier]" "[page type]" page'.
63+
*
64+
* Recognised page names are:
65+
* | pagetype | name meaning | description |
66+
* | View | Student Quiz name | The student quiz info page (view.php) |
67+
* | Edit | Student Quiz name | The edit quiz page (edit.php) |
68+
* | Statistics | Student Quiz name | The Statistics report page |
69+
* | Ranking | Student Quiz name | The Ranking page |
70+
*
71+
* @param string $type identifies which type of page this is, e.g. 'View'.
72+
* @param string $identifier identifies the particular page, e.g. 'Test student quiz'.
73+
* @return moodle_url the corresponding URL.
74+
* @throws Exception with a meaningful error message if the specified page cannot be found.
75+
*/
76+
protected function resolve_page_instance_url(string $type, string $identifier): moodle_url {
77+
switch ($type) {
78+
case 'View':
79+
return new moodle_url('/mod/pdfannotator/view.php',
80+
['id' => $this->get_cm_by_pdfannotator_name($identifier)->id]);
81+
82+
case 'Edit':
83+
return new moodle_url('/course/modedit.php',
84+
['update' => $this->get_cm_by_pdfannotator_name($identifier)->id]);
85+
86+
case 'Statistics':
87+
return new moodle_url('/mod/pdfannotator/reportstat.php',
88+
['id' => $this->get_cm_by_pdfannotator_name($identifier)->id]);
89+
90+
case 'Ranking':
91+
return new moodle_url('/mod/pdfannotator/reportrank.php',
92+
['id' => $this->get_cm_by_pdfannotator_name($identifier)->id]);
93+
94+
default:
95+
throw new Exception('Unrecognised pdfannotator page type "' . $type . '."');
96+
}
97+
}
98+
99+
/**
100+
* Get a pdfannotator by name.
101+
*
102+
* @param string $name pdfannotator name.
103+
* @return stdClass the corresponding DB row.
104+
*/
105+
protected function get_pdfannotator_by_name(string $name): stdClass {
106+
global $DB;
107+
return $DB->get_record('pdfannotator', array('name' => $name), '*', MUST_EXIST);
108+
}
109+
110+
/**
111+
* Get cmid from the pdfannotator name.
112+
*
113+
* @param string $name pdfannotator name.
114+
* @return stdClass cm from get_coursemodule_from_instance.
115+
*/
116+
protected function get_cm_by_pdfannotator_name(string $name): stdClass {
117+
$pdfannotator = $this->get_pdfannotator_by_name($name);
118+
return get_coursemodule_from_instance('pdfannotator', $pdfannotator->id, $pdfannotator->course);
119+
}
120+
}
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
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+
* Behat pdfannotator-related steps definitions.
19+
*
20+
* @package pdfannotator
21+
* @category test
22+
* @copyright 2021 Luca Bösch <[email protected]>
23+
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
24+
*/
25+
26+
// NOTE: no MOODLE_INTERNAL test here, this file may be required by behat before including /config.php.
27+
28+
require_once(__DIR__ . '/../../../../lib/behat/behat_base.php');
29+
30+
/**
31+
* Steps definitions related with the pdfannotator.
32+
*
33+
* @package pdfannotator
34+
* @category test
35+
* @copyright 2021 Luca Bösch <[email protected]>
36+
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
37+
*/
38+
class behat_pdfannotator_editpdf extends behat_base {
39+
40+
/**
41+
* Point at the pdfannotator pdf.
42+
*
43+
* @When /^I point at the pdfannotator canvas$/
44+
*/
45+
public function i_point_at_the_pdfannotator_canvas() {
46+
$node = $this->find('xpath', '//div[@id=\'pageContainer1\']');
47+
$this->execute('behat_general::i_click_on', [$node, 'NodeElement']);
48+
}
49+
50+
/**
51+
* Point at the pdfannotator pdf.
52+
*
53+
* @When /^I click the pdfannotator public comment dropdown menu button$/
54+
*/
55+
public function i_click_the_pdfannotator_public_comment_dropdown_menu_button() {
56+
$node = $this->find('xpath', '//a[@id=\'dropdownMenuButton\']');
57+
$this->execute('behat_general::i_click_on', [$node, 'NodeElement']);
58+
}
59+
}

tests/fixtures/submission.pdf

24.2 KB
Binary file not shown.

0 commit comments

Comments
 (0)