Skip to content

Commit

Permalink
Adding Behat tests to pdfannotator.
Browse files Browse the repository at this point in the history
  • Loading branch information
lucaboesch committed Jun 12, 2024
1 parent e2314a1 commit f85c37d
Show file tree
Hide file tree
Showing 7 changed files with 313 additions and 34 deletions.
83 changes: 56 additions & 27 deletions .github/workflows/moodle-plugin-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,15 @@ jobs:

services:
postgres:
image: postgres
image: postgres:14
env:
POSTGRES_USER: 'postgres'
POSTGRES_HOST_AUTH_METHOD: 'trust'
ports:
- 5432:5432
options: --health-cmd pg_isready --health-interval 10s --health-timeout 5s --health-retries 3
mariadb:
image: mariadb
image: mariadb:10.6
env:
MYSQL_USER: 'root'
MYSQL_ALLOW_EMPTY_PASSWORD: "true"
Expand All @@ -28,51 +28,80 @@ jobs:
fail-fast: false
matrix:
include:
- php: 8.0
moodle-branch: MOODLE_401_STABLE
- php: 8.3
moodle-branch: MOODLE_404_STABLE
database: pgsql
- php: 8.0
moodle-branch: MOODLE_401_STABLE
- php: 8.3
moodle-branch: MOODLE_404_STABLE
database: mariadb

- php: 8.0
moodle-branch: MOODLE_400_STABLE
- php: 8.2
moodle-branch: MOODLE_404_STABLE
database: pgsql
- php: 8.0
moodle-branch: MOODLE_400_STABLE
- php: 8.2
moodle-branch: MOODLE_404_STABLE
database: mariadb
- php: 8.2
moodle-branch: MOODLE_403_STABLE
database: pgsql
- php: 8.2
moodle-branch: MOODLE_403_STABLE
database: mariadb
- php: 8.2
moodle-branch: MOODLE_402_STABLE
database: pgsql
- php: 8.2
moodle-branch: MOODLE_402_STABLE
database: mariadb

- php: 7.4
- php: 8.1
moodle-branch: MOODLE_404_STABLE
database: pgsql
- php: 8.1
moodle-branch: MOODLE_404_STABLE
database: mariadb
- php: 8.1
moodle-branch: MOODLE_403_STABLE
database: pgsql
- php: 8.1
moodle-branch: MOODLE_403_STABLE
database: mariadb
- php: 8.1
moodle-branch: MOODLE_402_STABLE
database: pgsql
- php: 8.1
moodle-branch: MOODLE_402_STABLE
database: mariadb
- php: 8.1
moodle-branch: MOODLE_401_STABLE
database: pgsql
- php: 7.4
- php: 8.1
moodle-branch: MOODLE_401_STABLE
database: mariadb

- php: 7.4
moodle-branch: MOODLE_400_STABLE
- php: 8.0
moodle-branch: MOODLE_401_STABLE
database: pgsql
- php: 7.4
moodle-branch: MOODLE_400_STABLE
- php: 8.0
moodle-branch: MOODLE_401_STABLE
database: mariadb

- php: 7.4
moodle-branch: MOODLE_311_STABLE
- php: 8.0
moodle-branch: MOODLE_401_STABLE
database: pgsql
- php: 7.4
moodle-branch: MOODLE_311_STABLE
- php: 8.0
moodle-branch: MOODLE_401_STABLE
database: mariadb

- php: 7.3
moodle-branch: MOODLE_311_STABLE
- php: 7.4
moodle-branch: MOODLE_401_STABLE
database: pgsql
- php: 7.3
moodle-branch: MOODLE_311_STABLE
- php: 7.4
moodle-branch: MOODLE_401_STABLE
database: mariadb

steps:
- name: Check out repository code
uses: actions/checkout@v3
uses: actions/checkout@v4
with:
path: plugin

Expand All @@ -86,7 +115,7 @@ jobs:

- name: Initialise moodle-plugin-ci
run: |
composer create-project -n --no-dev --prefer-dist moodlehq/moodle-plugin-ci ci ^3
composer create-project -n --no-dev --prefer-dist moodlehq/moodle-plugin-ci ci ^4
echo $(cd ci/bin; pwd) >> $GITHUB_PATH
echo $(cd ci/vendor/bin; pwd) >> $GITHUB_PATH
sudo locale-gen en_AU.UTF-8
Expand Down
7 changes: 0 additions & 7 deletions lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,14 +68,7 @@ function pdfannotator_supports($feature) {
return null;
}
}
/**
* Function currently unused.
*
* @return string
*/
function mod_pdfannotator_before_standard_html_head() {

}
/**
* Returns all other caps used in module
* @return array
Expand Down
35 changes: 35 additions & 0 deletions tests/behat/add_pdfannotator.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
@mod @mod_pdfannotator @_file_upload
Feature: Add a pdfannotator activity
In order to let the users use the pdfannotator in a course
As a teacher
I need to add a pdfannotator to a moodle course

@javascript
Scenario: Add a pdfannotator to a course
Given the following "users" exist:
| username | firstname | lastname | email |
| teacher1 | Teacher | 1 | teacher1@example.com |
| student1 | Student | 1 | student1@example.com |
And the following "courses" exist:
| fullname | shortname | category |
| Course 1 | C1 | 0 |
And the following "course enrolments" exist:
| user | course | role |
| teacher1 | C1 | editingteacher |
| student1 | C1 | student |
And the following "user preferences" exist:
| user | preference | value |
| teacher1 | htmleditor | atto |
| student1 | htmleditor | atto |
And I log in as "teacher1"
And I am on "Course 1" course homepage with editing mode on
And I add a pdfannotator activity to course "Course 1" section "1" and I fill the form with:
| Name | Test pdf annotation |
| Description | Test pdf annotation description |
| Select a pdf-file | mod/pdfannotator/tests/fixtures/submission.pdf |
And I am on "Course 1" course homepage with editing mode on
And I log out
And I log in as "student1"
And I am on "Course 1" course homepage
And I follow "Test pdf annotation"
Then I should see "Test pdf annotation"
43 changes: 43 additions & 0 deletions tests/behat/annotate_pdfannotator.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
@mod @mod_pdfannotator @_file_upload @javascript
Feature: Annotate in a pdfannotator activity
In order to annotate in the pdfannotator in a course
As a student
I need to note questions and subscribe or unsubscribe to notificatoins

Background:
Given the following "users" exist:
| username | firstname | lastname | email |
| teacher1 | Teacher | 1 | teacher1@example.com |
| student1 | Student | 1 | student1@example.com |
And the following "courses" exist:
| fullname | shortname | category |
| Course 1 | C1 | 0 |
And the following "course enrolments" exist:
| user | course | role |
| teacher1 | C1 | editingteacher |
| student1 | C1 | student |
And the following "user preferences" exist:
| user | preference | value |
| teacher1 | htmleditor | atto |
| student1 | htmleditor | atto |
And I log in as "teacher1"
And I am on "Course 1" course homepage with editing mode on
And I add a pdfannotator activity to course "Course 1" section "1" and I fill the form with:
| Name | Test PDF annotation |
| Description | Test pdf annotation description |
| Select a pdf-file | mod/pdfannotator/tests/fixtures/submission.pdf |
And I am on "Course 1" course homepage with editing mode on
And I log out

Scenario: Add a question to a pdfannotator
Given I am on the "Test PDF annotation" "mod_pdfannotator > View" page logged in as "student1"
And I click on "comment" "button"
And I wait "1" seconds
And I point at the pdfannotator canvas
And I wait "1" seconds
And I set the field with xpath "//div[@id='id_pdfannotator_contenteditable']" to "This is a smurfing smurf"
And I click on "Create Annotation" "button"
And I wait until the page is ready
And I click the pdfannotator public comment dropdown menu button
Then I should see "This is a smurfing smurf"
And I log out
120 changes: 120 additions & 0 deletions tests/behat/behat_mod_pdfannotator.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.

/**
* Steps definitions related to mod_pdfannotator.
*
* @package mod_pdfannotator
* @category test
* @copyright 2019 HSR (http://www.hsr.ch)
* @author 2019 Huong Nguyen <[email protected]>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/

require_once(__DIR__ . '/../../../../lib/behat/behat_base.php');

use mod_pdfannotator\utils;
use Behat\Mink\Exception\ExpectationException as ExpectationException;
use Behat\Mink\Exception\ElementNotFoundException as ElementNotFoundException;
use Behat\Gherkin\Node\TableNode as TableNode;

/**
* Steps definitions related to mod_pdfannotator.
*
* @package pdfannotator
* @category test
* @copyright 2024 Luca Bösch <[email protected]>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class behat_mod_pdfannotator extends behat_base {

/**
* Convert page names to URLs for steps like 'When I am on the "[page name]" page'.
*
* Recognised page names are:
* | None so far! | |
*
* @param string $page name of the page, with the component name removed e.g. 'Admin notification'.
* @return moodle_url the corresponding URL.
* @throws Exception with a meaningful error message if the specified page cannot be found.
*/
protected function resolve_page_url(string $page): moodle_url {
switch ($page) {
default:
throw new Exception('Unrecognised pdfannotator page type "' . $page . '."');
}
}

/**
* Convert page names to URLs for steps like 'When I am on the "[identifier]" "[page type]" page'.
*
* Recognised page names are:
* | pagetype | name meaning | description |
* | View | Student Quiz name | The student quiz info page (view.php) |
* | Edit | Student Quiz name | The edit quiz page (edit.php) |
* | Statistics | Student Quiz name | The Statistics report page |
* | Ranking | Student Quiz name | The Ranking page |
*
* @param string $type identifies which type of page this is, e.g. 'View'.
* @param string $identifier identifies the particular page, e.g. 'Test student quiz'.
* @return moodle_url the corresponding URL.
* @throws Exception with a meaningful error message if the specified page cannot be found.
*/
protected function resolve_page_instance_url(string $type, string $identifier): moodle_url {
switch ($type) {
case 'View':
return new moodle_url('/mod/pdfannotator/view.php',
['id' => $this->get_cm_by_pdfannotator_name($identifier)->id]);

case 'Edit':
return new moodle_url('/course/modedit.php',
['update' => $this->get_cm_by_pdfannotator_name($identifier)->id]);

case 'Statistics':
return new moodle_url('/mod/pdfannotator/reportstat.php',
['id' => $this->get_cm_by_pdfannotator_name($identifier)->id]);

case 'Ranking':
return new moodle_url('/mod/pdfannotator/reportrank.php',
['id' => $this->get_cm_by_pdfannotator_name($identifier)->id]);

default:
throw new Exception('Unrecognised pdfannotator page type "' . $type . '."');
}
}

/**
* Get a pdfannotator by name.
*
* @param string $name pdfannotator name.
* @return stdClass the corresponding DB row.
*/
protected function get_pdfannotator_by_name(string $name): stdClass {
global $DB;
return $DB->get_record('pdfannotator', array('name' => $name), '*', MUST_EXIST);
}

/**
* Get cmid from the pdfannotator name.
*
* @param string $name pdfannotator name.
* @return stdClass cm from get_coursemodule_from_instance.
*/
protected function get_cm_by_pdfannotator_name(string $name): stdClass {
$pdfannotator = $this->get_pdfannotator_by_name($name);
return get_coursemodule_from_instance('pdfannotator', $pdfannotator->id, $pdfannotator->course);
}
}
Loading

0 comments on commit f85c37d

Please sign in to comment.