Skip to content

Commit

Permalink
MDL-42025 assignfeedback_editpdf: add behat tests
Browse files Browse the repository at this point in the history
  • Loading branch information
mouneyrac authored and marinaglancy committed Mar 18, 2014
1 parent 3aa7190 commit 9e103d6
Show file tree
Hide file tree
Showing 3 changed files with 140 additions and 9 deletions.
27 changes: 18 additions & 9 deletions lib/behat/behat_files.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,15 +63,24 @@ protected function get_filepicker_node($filepickerelement) {
// More info about the problem (in case there is a problem).
$exception = new ExpectationException('"' . $filepickerelement . '" filepicker can not be found', $this->getSession());

// Gets the ffilemanager node specified by the locator which contains the filepicker container.
$filepickerelement = $this->getSession()->getSelectorsHandler()->xpathLiteral($filepickerelement);
$filepickercontainer = $this->find(
'xpath',
"//input[./@id = //label[normalize-space(.)=$filepickerelement]/@for]" .
"//ancestor::div[contains(concat(' ', normalize-space(@class), ' '), ' ffilemanager ') or " .
"contains(concat(' ', normalize-space(@class), ' '), ' ffilepicker ')]",
$exception
);
// If no file picker label is mentioned take the first file picker from the page.
if (empty($filepickerelement)) {
$filepickercontainer = $this->find(
'xpath',
"//*[@class=\"form-filemanager\"]",
$exception
);
} else {
// Gets the ffilemanager node specified by the locator which contains the filepicker container.
$filepickerelement = $this->getSession()->getSelectorsHandler()->xpathLiteral($filepickerelement);
$filepickercontainer = $this->find(
'xpath',
"//input[./@id = //label[normalize-space(.)=$filepickerelement]/@for]" .
"//ancestor::div[contains(concat(' ', normalize-space(@class), ' '), ' ffilemanager ') or " .
"contains(concat(' ', normalize-space(@class), ' '), ' ffilepicker ')]",
$exception
);
}

return $filepickercontainer;
}
Expand Down
68 changes: 68 additions & 0 deletions mod/assign/feedback/editpdf/tests/behat/annotate_pdf.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
@mod @mod_assign @assignfeedback @assignfeedback_editpdf @_only_local
Feature: In an assignment, teacher can annotate PDF files during grading
In order to provide visual report on a graded PDF
As a teacher
I need to use the PDF editor

@javascript
Scenario: Submit a PDF file as a student and annotate the PDF as a teacher
Given ghostscript is installed
And the following "courses" exists:
| fullname | shortname | category | groupmode |
| Course 1 | C1 | 0 | 1 |
And the following "users" exists:
| username | firstname | lastname | email |
| teacher1 | Teacher | 1 | teacher1@asd.com |
| student1 | Student | 1 | student1@asd.com |
And the following "course enrolments" exists:
| user | course | role |
| teacher1 | C1 | editingteacher |
| student1 | C1 | student |
And I log in as "admin"
And I expand "Site administration" node
And I expand "Plugins" node
And I expand "Activity modules" node
And I expand "Assignment" node
And I expand "Feedback plugins" node
And I follow "Annotate PDF"
And I upload "pix/help.png" file to "" filemanager
And I upload "pix/docs.png" file to "" filemanager
When I press "Save changes"
Then I should see "Changes saved"
And I follow "Test ghostscript path"
And I should see "The ghostscript path appears to be OK"
And I log out
And I log in as "teacher1"
And I follow "Course 1"
And I turn editing mode on
And I add a "Assignment" to section "1" and I fill the form with:
| Assignment name | Test assignment name |
| Description | Submit your PDF file |
| assignsubmission_file_enabled | 1 |
| Maximum number of uploaded files | 2 |
And I log out
And I log in as "student1"
And I follow "Course 1"
And I follow "Test assignment name"
And I press "Add submission"
And I upload "mod/assign/feedback/editpdf/tests/fixtures/submission.pdf" file to "File submissions" filemanager
And I upload "mod/assign/feedback/editpdf/tests/fixtures/testgs.pdf" file to "File submissions" filemanager
And I press "Save changes"
And I should see "Submitted for grading"
And I should see "submission.pdf"
And I should see "Not graded"
And I log out
And I log in as "teacher1"
And I follow "Course 1"
And I follow "Test assignment name"
And I follow "View/grade all submissions"
And I click on "Grade" "link" in the "Submitted for grading" "table_row"
And I follow "Launch PDF editor..."
And I click on ".navigate-next-button" "css_element"
And I click on ".stampbutton" "css_element"
And I click on ".linebutton" "css_element"
And I click on ".commentcolourbutton" "css_element"
And I click on "//img[@alt=\"Blue\"]" "xpath_element"
And I click on "Close" "button"
And I press "Save changes"
And I should see "The grade changes were saved"
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
<?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/>.

/**
* Behat editpdf-related steps definitions.
*
* @package assignfeedback_editpdf
* @category test
* @copyright 2013 Jerome Mouneyrac
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/

// NOTE: no MOODLE_INTERNAL test here, this file may be required by behat before including /config.php.

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

use Behat\Behat\Context\Step\Given as Given;

/**
* Steps definitions related with the editpdf.
*
* @package assignfeedback_editpdf
* @category test
* @copyright 2013 Jerome Mouneyrac
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class behat_assignfeedback_editpdf extends behat_base {

/**
* Checks that Ghostscript is installed.
*
* @Given /^ghostscript is installed$/
*/
public function ghostscript_is_installed() {
$testpath = assignfeedback_editpdf\pdf::test_gs_path();
if (!extension_loaded('zlib') or
$testpath->status !== assignfeedback_editpdf\pdf::GSPATH_OK) {
throw new \Moodle\BehatExtension\Exception\SkippedException;
}
}
}

0 comments on commit 9e103d6

Please sign in to comment.