Skip to content

Commit cd21d6a

Browse files
committed
Adding Behat tests to pdfannotator.
1 parent e2314a1 commit cd21d6a

File tree

7 files changed

+319
-34
lines changed

7 files changed

+319
-34
lines changed

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

Lines changed: 62 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,15 @@ jobs:
88

99
services:
1010
postgres:
11-
image: postgres
11+
image: postgres:14
1212
env:
1313
POSTGRES_USER: 'postgres'
1414
POSTGRES_HOST_AUTH_METHOD: 'trust'
1515
ports:
1616
- 5432:5432
1717
options: --health-cmd pg_isready --health-interval 10s --health-timeout 5s --health-retries 3
1818
mariadb:
19-
image: mariadb
19+
image: mariadb:10.6
2020
env:
2121
MYSQL_USER: 'root'
2222
MYSQL_ALLOW_EMPTY_PASSWORD: "true"
@@ -28,51 +28,86 @@ jobs:
2828
fail-fast: false
2929
matrix:
3030
include:
31-
- php: 8.0
32-
moodle-branch: MOODLE_401_STABLE
31+
- php: 8.3
32+
moodle-branch: MOODLE_404_STABLE
3333
database: pgsql
34-
- php: 8.0
35-
moodle-branch: MOODLE_401_STABLE
34+
- php: 8.3
35+
moodle-branch: MOODLE_404_STABLE
3636
database: mariadb
3737

38-
- php: 8.0
39-
moodle-branch: MOODLE_400_STABLE
38+
- php: 8.2
39+
moodle-branch: MOODLE_404_STABLE
4040
database: pgsql
41-
- php: 8.0
42-
moodle-branch: MOODLE_400_STABLE
41+
- php: 8.2
42+
moodle-branch: MOODLE_404_STABLE
43+
database: mariadb
44+
- php: 8.2
45+
moodle-branch: MOODLE_403_STABLE
46+
database: pgsql
47+
- php: 8.2
48+
moodle-branch: MOODLE_403_STABLE
49+
database: mariadb
50+
- php: 8.2
51+
moodle-branch: MOODLE_402_STABLE
52+
database: pgsql
53+
- php: 8.2
54+
moodle-branch: MOODLE_402_STABLE
4355
database: mariadb
4456

45-
- php: 7.4
57+
- php: 8.1
58+
moodle-branch: MOODLE_404_STABLE
59+
database: pgsql
60+
- php: 8.1
61+
moodle-branch: MOODLE_404_STABLE
62+
database: mariadb
63+
- php: 8.1
64+
moodle-branch: MOODLE_403_STABLE
65+
database: pgsql
66+
- php: 8.1
67+
moodle-branch: MOODLE_403_STABLE
68+
database: mariadb
69+
- php: 8.1
70+
moodle-branch: MOODLE_402_STABLE
71+
database: pgsql
72+
- php: 8.1
73+
moodle-branch: MOODLE_402_STABLE
74+
database: mariadb
75+
- php: 8.1
4676
moodle-branch: MOODLE_401_STABLE
4777
database: pgsql
48-
- php: 7.4
78+
- php: 8.1
4979
moodle-branch: MOODLE_401_STABLE
5080
database: mariadb
5181

52-
- php: 7.4
53-
moodle-branch: MOODLE_400_STABLE
82+
- php: 8.0
83+
moodle-branch: MOODLE_403_STABLE
5484
database: pgsql
55-
- php: 7.4
56-
moodle-branch: MOODLE_400_STABLE
85+
- php: 8.0
86+
moodle-branch: MOODLE_403_STABLE
5787
database: mariadb
58-
59-
- php: 7.4
60-
moodle-branch: MOODLE_311_STABLE
88+
- php: 8.0
89+
moodle-branch: MOODLE_402_STABLE
6190
database: pgsql
62-
- php: 7.4
63-
moodle-branch: MOODLE_311_STABLE
91+
- php: 8.0
92+
moodle-branch: MOODLE_402_STABLE
93+
database: mariadb
94+
- php: 8.0
95+
moodle-branch: MOODLE_401_STABLE
96+
database: pgsql
97+
- php: 8.0
98+
moodle-branch: MOODLE_401_STABLE
6499
database: mariadb
65100

66-
- php: 7.3
67-
moodle-branch: MOODLE_311_STABLE
101+
- php: 7.4
102+
moodle-branch: MOODLE_401_STABLE
68103
database: pgsql
69-
- php: 7.3
70-
moodle-branch: MOODLE_311_STABLE
104+
- php: 7.4
105+
moodle-branch: MOODLE_401_STABLE
71106
database: mariadb
72107

73108
steps:
74109
- name: Check out repository code
75-
uses: actions/checkout@v3
110+
uses: actions/checkout@v4
76111
with:
77112
path: plugin
78113

@@ -86,7 +121,7 @@ jobs:
86121

87122
- name: Initialise moodle-plugin-ci
88123
run: |
89-
composer create-project -n --no-dev --prefer-dist moodlehq/moodle-plugin-ci ci ^3
124+
composer create-project -n --no-dev --prefer-dist moodlehq/moodle-plugin-ci ci ^4
90125
echo $(cd ci/bin; pwd) >> $GITHUB_PATH
91126
echo $(cd ci/vendor/bin; pwd) >> $GITHUB_PATH
92127
sudo locale-gen en_AU.UTF-8

lib.php

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -68,14 +68,7 @@ function pdfannotator_supports($feature) {
6868
return null;
6969
}
7070
}
71-
/**
72-
* Function currently unused.
73-
*
74-
* @return string
75-
*/
76-
function mod_pdfannotator_before_standard_html_head() {
7771

78-
}
7972
/**
8073
* Returns all other caps used in module
8174
* @return array
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: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
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+
And I click the pdfannotator public comment dropdown menu button
42+
Then I should see "This is a smurfing smurf"
43+
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 <huongnv13@gmail.com>
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 <luca.boesch@bfh.ch>
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+
}

0 commit comments

Comments
 (0)