#129 Added Behat test coverage
This commit is contained in:
parent
852408ee17
commit
dc56808e32
13 changed files with 741 additions and 4 deletions
|
@ -237,6 +237,7 @@ class edit_form extends \moodleform {
|
|||
$numelements = count($elements);
|
||||
// Create a table to display these elements.
|
||||
$table = new \html_table();
|
||||
$table->attributes = array('class' => 'generaltable elementstable');
|
||||
$table->head = array(get_string('name', 'customcert'), get_string('type', 'customcert'), '');
|
||||
$table->align = array('left', 'left', 'left');
|
||||
// Loop through and add the elements to the table.
|
||||
|
@ -250,11 +251,13 @@ class edit_form extends \moodleform {
|
|||
// Link to edit this element.
|
||||
$link = new \moodle_url($editelementlink, $editelementlinkparams + array('id' => $element->id,
|
||||
'action' => 'edit'));
|
||||
$icons = $OUTPUT->action_icon($link, new \pix_icon('t/edit', get_string('edit')));
|
||||
$icons = $OUTPUT->action_icon($link, new \pix_icon('t/edit', get_string('edit')), null,
|
||||
array('class' => 'action-icon edit-icon'));
|
||||
// Link to delete the element.
|
||||
$link = new \moodle_url($editlink, $editlinkparams + array('action' => 'deleteelement',
|
||||
'aid' => $element->id));
|
||||
$icons .= $OUTPUT->action_icon($link, new \pix_icon('t/delete', get_string('delete')));
|
||||
$icons .= $OUTPUT->action_icon($link, new \pix_icon('t/delete', get_string('delete')), null,
|
||||
array('class' => 'action-icon delete-icon'));
|
||||
// Now display any moving arrows if they are needed.
|
||||
if ($numelements > 1) {
|
||||
// Only display the move up arrow if it is not the first.
|
||||
|
|
3
edit.php
3
edit.php
|
@ -224,7 +224,8 @@ echo $OUTPUT->heading(get_string('editcustomcert', 'customcert'));
|
|||
$mform->display();
|
||||
if ($tid) {
|
||||
$loadtemplateurl = new moodle_url('/mod/customcert/load_template.php', array('tid' => $tid));
|
||||
$loadtemplateform = new \mod_customcert\load_template_form($loadtemplateurl, array('context' => $context));
|
||||
$loadtemplateform = new \mod_customcert\load_template_form($loadtemplateurl, array('context' => $context), 'post',
|
||||
'', array('id' => 'loadtemplateform'));
|
||||
$loadtemplateform->display();
|
||||
}
|
||||
echo $OUTPUT->footer();
|
||||
|
|
|
@ -95,7 +95,8 @@ if ($templates = $DB->get_records('customcert_templates', array('contextid' => $
|
|||
// Link to delete the element.
|
||||
$deletelink = new \moodle_url('/mod/customcert/manage_templates.php', array('tid' => $template->id,
|
||||
'action' => 'delete'));
|
||||
$deleteicon = $OUTPUT->action_icon($deletelink, new \pix_icon('t/delete', get_string('delete')));
|
||||
$deleteicon = $OUTPUT->action_icon($deletelink, new \pix_icon('t/delete', get_string('delete')), null,
|
||||
array('class' => 'action-icon delete-icon'));
|
||||
|
||||
$row = new html_table_row();
|
||||
$row->cells[] = $template->name;
|
||||
|
|
118
tests/behat/behat_mod_customcert.php
Normal file
118
tests/behat/behat_mod_customcert.php
Normal file
|
@ -0,0 +1,118 @@
|
|||
<?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/>.
|
||||
|
||||
/**
|
||||
* Contains the class responsible for step definitions related to mod_customcert.
|
||||
*
|
||||
* @package mod_customcert
|
||||
* @category test
|
||||
* @copyright 2017 Mark Nelson <markn@moodle.com>
|
||||
* @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');
|
||||
|
||||
/**
|
||||
* The class responsible for step definitions related to mod_customcert.
|
||||
*
|
||||
* @package mod_customcert
|
||||
* @category test
|
||||
* @copyright 2017 Mark Nelson <markn@moodle.com>
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
class behat_mod_customcert extends behat_base {
|
||||
|
||||
/**
|
||||
* Adds an element to the specified page of a template.
|
||||
*
|
||||
* @codingStandardsIgnoreLine
|
||||
* @Given /^I add the element "(?P<element_name>(?:[^"]|\\")*)" to page "(?P<page_number>\d+)" of the "(?P<template_name>(?:[^"]|\\")*)" certificate template$/
|
||||
* @param string $elementname
|
||||
* @param int $pagenum
|
||||
* @param string $templatename
|
||||
*/
|
||||
public function i_add_the_element_to_the_certificate_template_page($elementname, $pagenum, $templatename) {
|
||||
global $DB;
|
||||
|
||||
$template = $DB->get_record('customcert_templates', array('name' => $templatename), '*', MUST_EXIST);
|
||||
$page = $DB->get_record('customcert_pages', array('templateid' => $template->id, 'sequence' => $pagenum),
|
||||
'*', MUST_EXIST);
|
||||
|
||||
$this->execute('behat_forms::i_set_the_field_to', array($this->escape('element_' . $page->id),
|
||||
$this->escape($elementname)));
|
||||
$this->execute('behat_forms::press_button', get_string('addelement', 'customcert'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Deletes an element from a specified page of a template.
|
||||
*
|
||||
* @Given /^I delete page "(?P<page_number>\d+)" of the "(?P<template_name>(?:[^"]|\\")*)" certificate template$/
|
||||
* @param int $pagenum
|
||||
* @param string $templatename
|
||||
*/
|
||||
public function i_delete_the_certificate_page($pagenum, $templatename) {
|
||||
global $DB;
|
||||
|
||||
$template = $DB->get_record('customcert_templates', array('name' => $templatename), '*', MUST_EXIST);
|
||||
$page = $DB->get_record('customcert_pages', array('templateid' => $template->id, 'sequence' => $pagenum),
|
||||
'*', MUST_EXIST);
|
||||
|
||||
$this->execute('behat_general::i_click_on_in_the', array('Delete page', 'link',
|
||||
$this->escape('#id_page_' . $page->id), 'css_element'));
|
||||
$this->execute('behat_forms::press_button', get_string('continue'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Verifies the certificate code for a user.
|
||||
*
|
||||
* @Given /^I verify the "(?P<certificate_name>(?:[^"]|\\")*)" certificate for the user "(?P<user_name>(?:[^"]|\\")*)"$/
|
||||
* @param string $certificatename
|
||||
* @param string $username
|
||||
*/
|
||||
public function i_verify_the_custom_certificate_for_user($certificatename, $username) {
|
||||
global $DB;
|
||||
|
||||
$certificate = $DB->get_record('customcert', array('name' => $certificatename), '*', MUST_EXIST);
|
||||
$user = $DB->get_record('user', array('username' => $username), '*', MUST_EXIST);
|
||||
$issue = $DB->get_record('customcert_issues', array('userid' => $user->id, 'customcertid' => $certificate->id),
|
||||
'*', MUST_EXIST);
|
||||
|
||||
$this->execute('behat_forms::i_set_the_field_to', array(get_string('code', 'customcert'), $issue->code));
|
||||
$this->execute('behat_forms::press_button', get_string('verify', 'customcert'));
|
||||
$this->execute('behat_general::assert_page_contains_text', get_string('verified', 'customcert'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Directs the user to the URL for verifying a certificate.
|
||||
*
|
||||
* This has been created as we allow non-users to verify certificates and they can not navigate to
|
||||
* the page like a conventional user.
|
||||
*
|
||||
* @Given /^I visit the verification url for the "(?P<certificate_name>(?:[^"]|\\")*)" certificate$/
|
||||
* @param string $certificatename
|
||||
*/
|
||||
public function i_visit_the_verification_url_for_custom_certificate($certificatename) {
|
||||
global $DB;
|
||||
|
||||
$certificate = $DB->get_record('customcert', array('name' => $certificatename), '*', MUST_EXIST);
|
||||
$template = $DB->get_record('customcert_templates', array('id' => $certificate->templateid), '*', MUST_EXIST);
|
||||
|
||||
$url = new moodle_url('/mod/customcert/verify_certificate.php', array('contextid' => $template->contextid));
|
||||
$this->getSession()->visit($this->locate_path($url->out_as_local_url()));
|
||||
}
|
||||
}
|
277
tests/behat/managing_elements.feature
Normal file
277
tests/behat/managing_elements.feature
Normal file
|
@ -0,0 +1,277 @@
|
|||
@mod @mod_customcert
|
||||
Feature: Being able to manage elements in a certificate template
|
||||
In order to ensure managing elements in a certificate template works as expected
|
||||
As a teacher
|
||||
I need to manage elements in a certificate template
|
||||
|
||||
Background:
|
||||
Given the following "courses" exist:
|
||||
| fullname | shortname | category |
|
||||
| Course 1 | C1 | 0 |
|
||||
And the following "users" exist:
|
||||
| username | firstname | lastname | email |
|
||||
| teacher1 | Teacher | 1 | teacher1@example.com |
|
||||
| teacher2 | Teacher | 2 | teacher2@example.com |
|
||||
And the following "course enrolments" exist:
|
||||
| user | course | role |
|
||||
| teacher1 | C1 | editingteacher |
|
||||
| teacher2 | C1 | editingteacher |
|
||||
And the following "activities" exist:
|
||||
| activity | name | intro | course | idnumber |
|
||||
| assign | Assignment 1 | Assignment 1 intro | C1 | assign1 |
|
||||
| assign | Assignment 2 | Assignment 2 intro | C1 | assign2 |
|
||||
| customcert | Custom certificate 1 | Custom certificate 1 intro | C1 | customcert1 |
|
||||
And I log in as "teacher1"
|
||||
And I am on "Course 1" course homepage
|
||||
And I follow "Custom certificate 1"
|
||||
And I navigate to "Edit certificate" in current page administration
|
||||
|
||||
Scenario: Add and edit elements in a certificate template
|
||||
# Background image.
|
||||
And I add the element "Background image" to page "1" of the "Custom certificate 1" certificate template
|
||||
And I press "Save changes"
|
||||
And I should see "Background image" in the "elementstable" "table"
|
||||
# Border.
|
||||
And I add the element "Border" to page "1" of the "Custom certificate 1" certificate template
|
||||
And I set the following fields to these values:
|
||||
| Width | 2 |
|
||||
| Colour | #045ECD |
|
||||
And I press "Save changes"
|
||||
And I should see "Border" in the "elementstable" "table"
|
||||
And I click on ".edit-icon" "css_element" in the "Border" "table_row"
|
||||
And the following fields match these values:
|
||||
| Width | 2 |
|
||||
| Colour | #045ECD |
|
||||
And I press "Save changes"
|
||||
# Category name.
|
||||
And I add the element "Category name" to page "1" of the "Custom certificate 1" certificate template
|
||||
And I set the following fields to these values:
|
||||
| Font | Helvetica |
|
||||
| Size | 20 |
|
||||
| Colour | #045ECD |
|
||||
| Width | 20 |
|
||||
| Reference point location | Top left |
|
||||
And I press "Save changes"
|
||||
And I should see "Category name" in the "elementstable" "table"
|
||||
And I click on ".edit-icon" "css_element" in the "Category name" "table_row"
|
||||
And the following fields match these values:
|
||||
| Font | Helvetica |
|
||||
| Size | 20 |
|
||||
| Colour | #045ECD |
|
||||
| Width | 20 |
|
||||
| Reference point location | Top left |
|
||||
And I press "Save changes"
|
||||
# Code.
|
||||
And I add the element "Code" to page "1" of the "Custom certificate 1" certificate template
|
||||
And I set the following fields to these values:
|
||||
| Font | Helvetica |
|
||||
| Size | 20 |
|
||||
| Colour | #045ECD |
|
||||
| Width | 20 |
|
||||
| Reference point location | Top left |
|
||||
And I press "Save changes"
|
||||
And I should see "Code" in the "elementstable" "table"
|
||||
And I click on ".edit-icon" "css_element" in the "Code" "table_row"
|
||||
And the following fields match these values:
|
||||
| Font | Helvetica |
|
||||
| Size | 20 |
|
||||
| Colour | #045ECD |
|
||||
| Width | 20 |
|
||||
| Reference point location | Top left |
|
||||
And I press "Save changes"
|
||||
# Course name.
|
||||
And I add the element "Course name" to page "1" of the "Custom certificate 1" certificate template
|
||||
And I set the following fields to these values:
|
||||
| Font | Helvetica |
|
||||
| Size | 20 |
|
||||
| Colour | #045ECD |
|
||||
| Width | 20 |
|
||||
| Reference point location | Top left |
|
||||
And I press "Save changes"
|
||||
And I should see "Course name" in the "elementstable" "table"
|
||||
And I click on ".edit-icon" "css_element" in the "Course name" "table_row"
|
||||
And the following fields match these values:
|
||||
| Font | Helvetica |
|
||||
| Size | 20 |
|
||||
| Colour | #045ECD |
|
||||
| Width | 20 |
|
||||
| Reference point location | Top left |
|
||||
And I press "Save changes"
|
||||
# Date.
|
||||
And I add the element "Date" to page "1" of the "Custom certificate 1" certificate template
|
||||
And I set the following fields to these values:
|
||||
| Date item | Course start date |
|
||||
| Date format | 2 |
|
||||
| Font | Helvetica |
|
||||
| Size | 20 |
|
||||
| Colour | #045ECD |
|
||||
| Width | 20 |
|
||||
| Reference point location | Top left |
|
||||
And I press "Save changes"
|
||||
And I should see "Date" in the "elementstable" "table"
|
||||
And I click on ".edit-icon" "css_element" in the "Date" "table_row"
|
||||
And the following fields match these values:
|
||||
| Date item | Course start date |
|
||||
| Date format | 2 |
|
||||
| Font | Helvetica |
|
||||
| Size | 20 |
|
||||
| Colour | #045ECD |
|
||||
| Width | 20 |
|
||||
| Reference point location | Top left |
|
||||
And I press "Save changes"
|
||||
# Grade.
|
||||
And I add the element "Grade" to page "1" of the "Custom certificate 1" certificate template
|
||||
And I set the following fields to these values:
|
||||
| Grade item | Topic 0 : Assignment 1 |
|
||||
| Grade format | Percentage |
|
||||
| Font | Helvetica |
|
||||
| Size | 20 |
|
||||
| Colour | #045ECD |
|
||||
| Width | 20 |
|
||||
| Reference point location | Top left |
|
||||
And I press "Save changes"
|
||||
And I should see "Grade" in the "elementstable" "table"
|
||||
And I click on ".edit-icon" "css_element" in the "Grade" "table_row"
|
||||
And the following fields match these values:
|
||||
| Grade item | Topic 0 : Assignment 1 |
|
||||
| Grade format | Percentage |
|
||||
| Font | Helvetica |
|
||||
| Size | 20 |
|
||||
| Colour | #045ECD |
|
||||
| Width | 20 |
|
||||
| Reference point location | Top left |
|
||||
And I press "Save changes"
|
||||
# Grade item name.
|
||||
And I add the element "Grade item name" to page "1" of the "Custom certificate 1" certificate template
|
||||
And I set the following fields to these values:
|
||||
| Grade item | Topic 0 : Assignment 2 |
|
||||
| Font | Helvetica |
|
||||
| Size | 20 |
|
||||
| Colour | #045ECD |
|
||||
| Width | 20 |
|
||||
| Reference point location | Top left |
|
||||
And I press "Save changes"
|
||||
And I should see "Grade item name" in the "elementstable" "table"
|
||||
And I click on ".edit-icon" "css_element" in the "Grade item name" "table_row"
|
||||
And the following fields match these values:
|
||||
| Grade item | Topic 0 : Assignment 2 |
|
||||
| Font | Helvetica |
|
||||
| Size | 20 |
|
||||
| Colour | #045ECD |
|
||||
| Width | 20 |
|
||||
| Reference point location | Top left |
|
||||
And I press "Save changes"
|
||||
# Image.
|
||||
And I add the element "Image" to page "1" of the "Custom certificate 1" certificate template
|
||||
And I press "Save changes"
|
||||
And I should see "Image" in the "elementstable" "table"
|
||||
# Student name.
|
||||
And I add the element "Student name" to page "1" of the "Custom certificate 1" certificate template
|
||||
And I set the following fields to these values:
|
||||
| Font | Helvetica |
|
||||
| Size | 20 |
|
||||
| Colour | #045ECD |
|
||||
| Width | 20 |
|
||||
| Reference point location | Top left |
|
||||
And I press "Save changes"
|
||||
And I should see "Student name" in the "elementstable" "table"
|
||||
And I click on ".edit-icon" "css_element" in the "Student name" "table_row"
|
||||
And the following fields match these values:
|
||||
| Font | Helvetica |
|
||||
| Size | 20 |
|
||||
| Colour | #045ECD |
|
||||
| Width | 20 |
|
||||
| Reference point location | Top left |
|
||||
And I press "Save changes"
|
||||
# Teacher name.
|
||||
And I add the element "Teacher name" to page "1" of the "Custom certificate 1" certificate template
|
||||
And I set the following fields to these values:
|
||||
| Teacher | Teacher 2 |
|
||||
| Font | Helvetica |
|
||||
| Size | 20 |
|
||||
| Colour | #045ECD |
|
||||
| Width | 20 |
|
||||
| Reference point location | Top left |
|
||||
And I press "Save changes"
|
||||
And I should see "Teacher name" in the "elementstable" "table"
|
||||
And I click on ".edit-icon" "css_element" in the "Teacher name" "table_row"
|
||||
And the following fields match these values:
|
||||
| Teacher | Teacher 2 |
|
||||
| Font | Helvetica |
|
||||
| Size | 20 |
|
||||
| Colour | #045ECD |
|
||||
| Width | 20 |
|
||||
| Reference point location | Top left |
|
||||
And I press "Save changes"
|
||||
# Text.
|
||||
And I add the element "Text" to page "1" of the "Custom certificate 1" certificate template
|
||||
And I set the following fields to these values:
|
||||
| Text | Test this |
|
||||
| Font | Helvetica |
|
||||
| Size | 20 |
|
||||
| Colour | #045ECD |
|
||||
| Width | 20 |
|
||||
| Reference point location | Top left |
|
||||
And I press "Save changes"
|
||||
And I should see "Text" in the "elementstable" "table"
|
||||
And I click on ".edit-icon" "css_element" in the "Text" "table_row"
|
||||
And the following fields match these values:
|
||||
| Text | Test this |
|
||||
| Font | Helvetica |
|
||||
| Size | 20 |
|
||||
| Colour | #045ECD |
|
||||
| Width | 20 |
|
||||
| Reference point location | Top left |
|
||||
And I press "Save changes"
|
||||
# User field.
|
||||
And I add the element "User field" to page "1" of the "Custom certificate 1" certificate template
|
||||
And I set the following fields to these values:
|
||||
| User field | Country |
|
||||
| Font | Helvetica |
|
||||
| Size | 20 |
|
||||
| Colour | #045ECD |
|
||||
| Width | 20 |
|
||||
| Reference point location | Top left |
|
||||
And I press "Save changes"
|
||||
And I should see "User field" in the "elementstable" "table"
|
||||
And I click on ".edit-icon" "css_element" in the "User field" "table_row"
|
||||
And the following fields match these values:
|
||||
| User field | Country |
|
||||
| Font | Helvetica |
|
||||
| Size | 20 |
|
||||
| Colour | #045ECD |
|
||||
| Width | 20 |
|
||||
| Reference point location | Top left |
|
||||
And I press "Save changes"
|
||||
# User picture.
|
||||
And I add the element "User picture" to page "1" of the "Custom certificate 1" certificate template
|
||||
And I set the following fields to these values:
|
||||
| Width | 10 |
|
||||
| Height | 10 |
|
||||
And I press "Save changes"
|
||||
And I should see "User picture" in the "elementstable" "table"
|
||||
And I click on ".edit-icon" "css_element" in the "User picture" "table_row"
|
||||
And the following fields match these values:
|
||||
| Width | 10 |
|
||||
| Height | 10 |
|
||||
And I press "Save changes"
|
||||
# Just to test there are no exceptions being thrown.
|
||||
And I follow "Reposition elements"
|
||||
And I press "Save and close"
|
||||
And I press "Save changes and preview"
|
||||
|
||||
Scenario: Delete an element from a certificate template
|
||||
And I add the element "Background image" to page "1" of the "Custom certificate 1" certificate template
|
||||
And I press "Save changes"
|
||||
And I should see "Background image" in the "elementstable" "table"
|
||||
And I add the element "Student name" to page "1" of the "Custom certificate 1" certificate template
|
||||
And I press "Save changes"
|
||||
And I should see "Student name" in the "elementstable" "table"
|
||||
And I click on ".delete-icon" "css_element" in the "Student name" "table_row"
|
||||
And I press "Cancel"
|
||||
And I should see "Background image" in the "elementstable" "table"
|
||||
And I should see "Student name" in the "elementstable" "table"
|
||||
And I click on ".delete-icon" "css_element" in the "Student name" "table_row"
|
||||
And I press "Continue"
|
||||
And I should see "Background image" in the "elementstable" "table"
|
||||
And I should not see "Student name" in the "elementstable" "table"
|
42
tests/behat/managing_pages.feature
Normal file
42
tests/behat/managing_pages.feature
Normal file
|
@ -0,0 +1,42 @@
|
|||
@mod @mod_customcert
|
||||
Feature: Being able to manage pages in a certificate template
|
||||
In order to ensure managing pages in a certificate template works as expected
|
||||
As a teacher
|
||||
I need to manage pages in a certificate template
|
||||
|
||||
Background:
|
||||
Given the following "courses" exist:
|
||||
| fullname | shortname | category |
|
||||
| Course 1 | C1 | 0 |
|
||||
And the following "users" exist:
|
||||
| username | firstname | lastname | email |
|
||||
| teacher1 | Teacher | 1 | teacher1@example.com |
|
||||
And the following "course enrolments" exist:
|
||||
| user | course | role |
|
||||
| teacher1 | C1 | editingteacher |
|
||||
And the following "activities" exist:
|
||||
| activity | name | intro | course | idnumber |
|
||||
| customcert | Custom certificate 1 | Custom certificate 1 intro | C1 | customcert1 |
|
||||
And I log in as "teacher1"
|
||||
And I am on "Course 1" course homepage
|
||||
And I follow "Custom certificate 1"
|
||||
And I navigate to "Edit certificate" in current page administration
|
||||
|
||||
Scenario: Adding a page to a certificate template
|
||||
And I follow "Add page"
|
||||
And I should see "Page 1"
|
||||
And I should see "Page 2"
|
||||
|
||||
Scenario: Deleting a page from a certificate template
|
||||
And I add the element "Background image" to page "1" of the "Custom certificate 1" certificate template
|
||||
And I press "Save changes"
|
||||
And I add the element "Student name" to page "1" of the "Custom certificate 1" certificate template
|
||||
And I press "Save changes"
|
||||
And I follow "Add page"
|
||||
And I should see "Page 1"
|
||||
And I should see "Page 2"
|
||||
And I delete page "2" of the "Custom certificate 1" certificate template
|
||||
And I should see "Background image" in the "elementstable" "table"
|
||||
And I should see "Student name" in the "elementstable" "table"
|
||||
And I should not see "Page 1"
|
||||
And I should not see "Page 2"
|
65
tests/behat/managing_templates.feature
Normal file
65
tests/behat/managing_templates.feature
Normal file
|
@ -0,0 +1,65 @@
|
|||
@mod @mod_customcert
|
||||
Feature: Being able to manage site templates
|
||||
In order to ensure managing site templates works as expected
|
||||
As an admin
|
||||
I need to manage and load site templates
|
||||
|
||||
Background:
|
||||
Given the following "courses" exist:
|
||||
| fullname | shortname | category |
|
||||
| Course 1 | C1 | 0 |
|
||||
And the following "users" exist:
|
||||
| username | firstname | lastname | email |
|
||||
| teacher1 | Teacher | 1 | teacher1@example.com |
|
||||
And the following "course enrolments" exist:
|
||||
| user | course | role |
|
||||
| teacher1 | C1 | editingteacher |
|
||||
And the following "activities" exist:
|
||||
| activity | name | intro | course | idnumber |
|
||||
| customcert | Custom certificate 1 | Custom certificate 1 intro | C1 | customcert1 |
|
||||
And I log in as "admin"
|
||||
|
||||
Scenario: Adding a site template and loading it into a course certificate
|
||||
And I navigate to "Plugins" in site administration
|
||||
And I follow "Manage activities"
|
||||
And I click on "Settings" "link" in the "Custom certificate" "table_row"
|
||||
And I follow "Manage templates"
|
||||
And I press "Create template"
|
||||
And I set the field "Name" to "Site template"
|
||||
And I press "Save changes"
|
||||
And I add the element "Border" to page "1" of the "Site template" certificate template
|
||||
And I set the following fields to these values:
|
||||
| Width | 5 |
|
||||
And I press "Save changes"
|
||||
And I add the element "User picture" to page "1" of the "Site template" certificate template
|
||||
And I press "Save changes"
|
||||
And I am on "Course 1" course homepage
|
||||
And I follow "Custom certificate 1"
|
||||
And I navigate to "Edit certificate" in current page administration
|
||||
And I set the field "ltid" to "Site template"
|
||||
And I click on "Load" "button" in the "#loadtemplateform" "css_element"
|
||||
And I should see "Are you sure you wish to load this template"
|
||||
And I press "Cancel"
|
||||
And "elementstable" "table" should not exist
|
||||
And I set the field "ltid" to "Site template"
|
||||
And I click on "Load" "button" in the "#loadtemplateform" "css_element"
|
||||
And I should see "Are you sure you wish to load this template"
|
||||
And I press "Continue"
|
||||
And I should see "Border" in the "elementstable" "table"
|
||||
And I should see "User picture" in the "elementstable" "table"
|
||||
|
||||
Scenario: Deleting a site template
|
||||
And I navigate to "Plugins" in site administration
|
||||
And I follow "Manage activities"
|
||||
And I click on "Settings" "link" in the "Custom certificate" "table_row"
|
||||
And I follow "Manage templates"
|
||||
And I press "Create template"
|
||||
And I set the field "Name" to "Site template"
|
||||
And I press "Save changes"
|
||||
And I follow "Manage templates"
|
||||
And I click on ".delete-icon" "css_element" in the "Site template" "table_row"
|
||||
And I press "Cancel"
|
||||
And I should see "Site template"
|
||||
And I click on ".delete-icon" "css_element" in the "Site template" "table_row"
|
||||
And I press "Continue"
|
||||
And I should not see "Site template"
|
39
tests/behat/my_certificates.feature
Normal file
39
tests/behat/my_certificates.feature
Normal file
|
@ -0,0 +1,39 @@
|
|||
@mod @mod_customcert
|
||||
Feature: Being able to view the certificates you have been issued
|
||||
In order to ensure that a user can view the certificates they have been issued
|
||||
As a student
|
||||
I need to view the certificates I have been issued
|
||||
|
||||
Background:
|
||||
Given the following "courses" exist:
|
||||
| fullname | shortname | category |
|
||||
| Course 1 | C1 | 0 |
|
||||
| Course 2 | C2 | 0 |
|
||||
And the following "users" exist:
|
||||
| username | firstname | lastname | email |
|
||||
| student1 | Student | 1 | student1@example.com |
|
||||
And the following "course enrolments" exist:
|
||||
| user | course | role |
|
||||
| student1 | C1 | student |
|
||||
| student1 | C2 | student |
|
||||
And the following "activities" exist:
|
||||
| activity | name | intro | course | idnumber |
|
||||
| customcert | Custom certificate 1 | Custom certificate 1 intro | C1 | customcert1 |
|
||||
| customcert | Custom certificate 2 | Custom certificate 2 intro | C2 | customcert2 |
|
||||
|
||||
Scenario: View your issued certificates on the my certificates page
|
||||
And I log in as "student1"
|
||||
And I am on "Course 1" course homepage
|
||||
And I follow "Custom certificate 1"
|
||||
And I press "Download certificate"
|
||||
And I follow "Profile" in the user menu
|
||||
And I follow "My certificates"
|
||||
And I should see "Custom certificate 1"
|
||||
And I should not see "Custom certificate 2"
|
||||
And I am on "Course 2" course homepage
|
||||
And I follow "Custom certificate 2"
|
||||
And I press "Download certificate"
|
||||
And I follow "Profile" in the user menu
|
||||
And I follow "My certificates"
|
||||
And I should see "Custom certificate 1"
|
||||
And I should see "Custom certificate 2"
|
39
tests/behat/required_minutes.feature
Normal file
39
tests/behat/required_minutes.feature
Normal file
|
@ -0,0 +1,39 @@
|
|||
@mod @mod_customcert
|
||||
Feature: Being able to set the required minutes in a course before viewing the certificate
|
||||
In order to ensure the required minutes in a course setting works as expected
|
||||
As a teacher
|
||||
I need to ensure students can not view a certificate until the required minutes have passed
|
||||
|
||||
Background:
|
||||
Given the following "courses" exist:
|
||||
| fullname | shortname | category |
|
||||
| Course 1 | C1 | 0 |
|
||||
And the following "users" exist:
|
||||
| username | firstname | lastname | email |
|
||||
| teacher1 | Teacher | 1 | teacher1@example.com |
|
||||
| student1 | Student | 1 | student1@example.com |
|
||||
And the following "course enrolments" exist:
|
||||
| user | course | role |
|
||||
| teacher1 | C1 | editingteacher |
|
||||
| student1 | C1 | student |
|
||||
And the following "activities" exist:
|
||||
| activity | name | intro | course | idnumber | requiredtime |
|
||||
| customcert | Custom certificate 1 | Custom certificate 1 intro | C1 | customcert1 | 1 |
|
||||
|
||||
Scenario: Check the user can not access the certificate before the required time
|
||||
And I log in as "student1"
|
||||
And I am on "Course 1" course homepage
|
||||
And I follow "Custom certificate 1"
|
||||
And I should see "You must spend at least a minimum of"
|
||||
And I should not see "Download certificate"
|
||||
And I press "Continue"
|
||||
And I should see "Custom certificate 1"
|
||||
|
||||
Scenario: Check the user can access the certificate after the required time
|
||||
And I log in as "student1"
|
||||
And I am on "Course 1" course homepage
|
||||
And I wait "60" seconds
|
||||
And I am on "Course 1" course homepage
|
||||
And I follow "Custom certificate 1"
|
||||
And I should not see "You must spend at least a minimum of"
|
||||
And I should see "Download certificate"
|
52
tests/behat/show_position_x_y.feature
Normal file
52
tests/behat/show_position_x_y.feature
Normal file
|
@ -0,0 +1,52 @@
|
|||
@mod @mod_customcert
|
||||
Feature: Being able to set a site setting to determine whether or not to display the position X and Y fields
|
||||
In order to ensure the show position X and Y fields setting works as expected
|
||||
As an admin
|
||||
I need to ensure teachers can see the position X and Y fields depending on the site setting
|
||||
|
||||
Background:
|
||||
Given the following "courses" exist:
|
||||
| fullname | shortname | category |
|
||||
| Course 1 | C1 | 0 |
|
||||
And the following "users" exist:
|
||||
| username | firstname | lastname | email |
|
||||
| teacher1 | Teacher | 1 | teacher1@example.com |
|
||||
And the following "course enrolments" exist:
|
||||
| user | course | role |
|
||||
| teacher1 | C1 | editingteacher |
|
||||
And the following "activities" exist:
|
||||
| activity | name | intro | course | idnumber |
|
||||
| customcert | Custom certificate 1 | Custom certificate 1 intro | C1 | customcert1 |
|
||||
|
||||
Scenario: Adding an element with the show position X and Y setting disabled
|
||||
And I log in as "teacher1"
|
||||
And I am on "Course 1" course homepage
|
||||
And I follow "Custom certificate 1"
|
||||
And I navigate to "Edit certificate" in current page administration
|
||||
And I add the element "Code" to page "1" of the "Custom certificate 1" certificate template
|
||||
And I should not see "Position X"
|
||||
And I should not see "Position Y"
|
||||
|
||||
Scenario: Adding an element with the show position X and Y setting enabled
|
||||
And I log in as "admin"
|
||||
And I navigate to "Plugins" in site administration
|
||||
And I follow "Manage activities"
|
||||
And I click on "Settings" "link" in the "Custom certificate" "table_row"
|
||||
And I set the field "Show position X and Y" to "1"
|
||||
And I press "Save changes"
|
||||
And I log out
|
||||
And I log in as "teacher1"
|
||||
And I am on "Course 1" course homepage
|
||||
And I follow "Custom certificate 1"
|
||||
And I navigate to "Edit certificate" in current page administration
|
||||
And I add the element "Code" to page "1" of the "Custom certificate 1" certificate template
|
||||
And I should see "Position X"
|
||||
And I should see "Position Y"
|
||||
And I set the following fields to these values:
|
||||
| Position X | 5 |
|
||||
| Position Y | 10 |
|
||||
And I press "Save changes"
|
||||
And I click on ".edit-icon" "css_element" in the "Code" "table_row"
|
||||
And the following fields match these values:
|
||||
| Position X | 5 |
|
||||
| Position Y | 10 |
|
54
tests/behat/verify_certificates.feature
Normal file
54
tests/behat/verify_certificates.feature
Normal file
|
@ -0,0 +1,54 @@
|
|||
@mod @mod_customcert
|
||||
Feature: Being able to verify that a certificate is valid or not
|
||||
In order to ensure that a user can verify a certificate is valid
|
||||
As a teacher and non-user
|
||||
I need to be able to verify a certificate
|
||||
|
||||
Background:
|
||||
Given the following "courses" exist:
|
||||
| fullname | shortname | category |
|
||||
| Course 1 | C1 | 0 |
|
||||
And the following "users" exist:
|
||||
| username | firstname | lastname | email |
|
||||
| teacher1 | Teacher | 1 | teacher1@example.com |
|
||||
| student1 | Student | 1 | student1@example.com |
|
||||
And the following "course enrolments" exist:
|
||||
| user | course | role |
|
||||
| teacher1 | C1 | editingteacher |
|
||||
| student1 | C1 | student |
|
||||
And the following "activities" exist:
|
||||
| activity | name | intro | course | idnumber | verifyany |
|
||||
| customcert | Custom certificate 1 | Custom certificate 1 intro | C1 | customcert1 | 0 |
|
||||
| customcert | Custom certificate 2 | Custom certificate 2 intro | C1 | customcert2 | 1 |
|
||||
|
||||
Scenario: Verify a certificate as a teacher
|
||||
And I log in as "student1"
|
||||
And I am on "Course 1" course homepage
|
||||
And I follow "Custom certificate 1"
|
||||
And I press "Download certificate"
|
||||
And I log out
|
||||
And I log in as "teacher1"
|
||||
And I am on "Course 1" course homepage
|
||||
And I follow "Custom certificate 1"
|
||||
And I navigate to "Verify certificate" in current page administration
|
||||
And I set the field "Code" to "NOTAVALIDCODE"
|
||||
And I press "Verify"
|
||||
And I should see "Not verified"
|
||||
And I verify the "Custom certificate 1" certificate for the user "student1"
|
||||
|
||||
Scenario: Attempt to verify a certificate as a non-user
|
||||
And I visit the verification url for the "Custom certificate 1" certificate
|
||||
# User should get redirected to log in as we do not allow non-users to verify.
|
||||
And I should see "Remember username"
|
||||
|
||||
Scenario: Verify a certificate as a non-user
|
||||
And I log in as "student1"
|
||||
And I am on "Course 1" course homepage
|
||||
And I follow "Custom certificate 2"
|
||||
And I press "Download certificate"
|
||||
And I log out
|
||||
And I visit the verification url for the "Custom certificate 2" certificate
|
||||
And I set the field "Code" to "NOTAVALIDCODE"
|
||||
And I press "Verify"
|
||||
And I should see "Not verified"
|
||||
And I verify the "Custom certificate 2" certificate for the user "student1"
|
41
tests/behat/view_issued_certificates.feature
Normal file
41
tests/behat/view_issued_certificates.feature
Normal file
|
@ -0,0 +1,41 @@
|
|||
@mod @mod_customcert
|
||||
Feature: Being able to view the certificates that have been issued
|
||||
In order to ensure that a user can view the certificates that have been issued
|
||||
As a teacher
|
||||
I need to view the certificates that have been issued
|
||||
|
||||
Background:
|
||||
Given the following "courses" exist:
|
||||
| fullname | shortname | category |
|
||||
| Course 1 | C1 | 0 |
|
||||
And the following "users" exist:
|
||||
| username | firstname | lastname | email |
|
||||
| teacher1 | Teacher | 1 | teacher1@example.com |
|
||||
| student1 | Student | 1 | student1@example.com |
|
||||
| student2 | Student | 2 | student2@example.com |
|
||||
And the following "course enrolments" exist:
|
||||
| user | course | role |
|
||||
| teacher1 | C1 | editingteacher |
|
||||
| student1 | C1 | student |
|
||||
| student2 | C1 | student |
|
||||
And the following "activities" exist:
|
||||
| activity | name | intro | course | idnumber |
|
||||
| customcert | Custom certificate 1 | Custom certificate 1 intro | C1 | customcert1 |
|
||||
|
||||
Scenario: View the issued certificates
|
||||
And I log in as "student1"
|
||||
And I am on "Course 1" course homepage
|
||||
And I follow "Custom certificate 1"
|
||||
And I press "Download certificate"
|
||||
And I log out
|
||||
And I log in as "student2"
|
||||
And I am on "Course 1" course homepage
|
||||
And I follow "Custom certificate 1"
|
||||
And I press "Download certificate"
|
||||
And I log out
|
||||
And I log in as "teacher1"
|
||||
And I am on "Course 1" course homepage
|
||||
And I follow "Custom certificate 1"
|
||||
And I follow "View 2 issued certificates"
|
||||
And I should see "Student 1"
|
||||
And I should see "Student 2"
|
5
view.php
5
view.php
|
@ -134,6 +134,11 @@ if (empty($action)) {
|
|||
$completion = new completion_info($course);
|
||||
$completion->set_module_viewed($cm);
|
||||
|
||||
// Hack alert - don't initiate the download when running Behat.
|
||||
if (defined('BEHAT_SITE_RUNNING')) {
|
||||
redirect(new moodle_url('/mod/customcert/view.php', array('id' => $cm->id)));
|
||||
}
|
||||
|
||||
// Now we want to generate the PDF.
|
||||
$template = new \mod_customcert\template($template);
|
||||
$template->generate_pdf();
|
||||
|
|
Loading…
Reference in a new issue