From dc56808e32ebc78a361a2b2488abc58d162289a6 Mon Sep 17 00:00:00 2001 From: Mark Nelson Date: Wed, 9 Aug 2017 19:05:57 +0800 Subject: [PATCH] #129 Added Behat test coverage --- classes/edit_form.php | 7 +- edit.php | 3 +- manage_templates.php | 3 +- tests/behat/behat_mod_customcert.php | 118 ++++++++ tests/behat/managing_elements.feature | 277 +++++++++++++++++++ tests/behat/managing_pages.feature | 42 +++ tests/behat/managing_templates.feature | 65 +++++ tests/behat/my_certificates.feature | 39 +++ tests/behat/required_minutes.feature | 39 +++ tests/behat/show_position_x_y.feature | 52 ++++ tests/behat/verify_certificates.feature | 54 ++++ tests/behat/view_issued_certificates.feature | 41 +++ view.php | 5 + 13 files changed, 741 insertions(+), 4 deletions(-) create mode 100644 tests/behat/behat_mod_customcert.php create mode 100644 tests/behat/managing_elements.feature create mode 100644 tests/behat/managing_pages.feature create mode 100644 tests/behat/managing_templates.feature create mode 100644 tests/behat/my_certificates.feature create mode 100644 tests/behat/required_minutes.feature create mode 100644 tests/behat/show_position_x_y.feature create mode 100644 tests/behat/verify_certificates.feature create mode 100644 tests/behat/view_issued_certificates.feature diff --git a/classes/edit_form.php b/classes/edit_form.php index 69b7111..1244a3d 100644 --- a/classes/edit_form.php +++ b/classes/edit_form.php @@ -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. diff --git a/edit.php b/edit.php index 3357ebb..036cc2f 100644 --- a/edit.php +++ b/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(); diff --git a/manage_templates.php b/manage_templates.php index 170b3c6..12644e8 100644 --- a/manage_templates.php +++ b/manage_templates.php @@ -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; diff --git a/tests/behat/behat_mod_customcert.php b/tests/behat/behat_mod_customcert.php new file mode 100644 index 0000000..bd7feed --- /dev/null +++ b/tests/behat/behat_mod_customcert.php @@ -0,0 +1,118 @@ +. + +/** + * Contains the class responsible for step definitions related to mod_customcert. + * + * @package mod_customcert + * @category test + * @copyright 2017 Mark Nelson + * @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 + * @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(?:[^"]|\\")*)" to page "(?P\d+)" of the "(?P(?:[^"]|\\")*)" 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\d+)" of the "(?P(?:[^"]|\\")*)" 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 for the user "(?P(?:[^"]|\\")*)"$/ + * @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$/ + * @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())); + } +} diff --git a/tests/behat/managing_elements.feature b/tests/behat/managing_elements.feature new file mode 100644 index 0000000..21d6a16 --- /dev/null +++ b/tests/behat/managing_elements.feature @@ -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" diff --git a/tests/behat/managing_pages.feature b/tests/behat/managing_pages.feature new file mode 100644 index 0000000..43e1a74 --- /dev/null +++ b/tests/behat/managing_pages.feature @@ -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" diff --git a/tests/behat/managing_templates.feature b/tests/behat/managing_templates.feature new file mode 100644 index 0000000..a01f0d4 --- /dev/null +++ b/tests/behat/managing_templates.feature @@ -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" diff --git a/tests/behat/my_certificates.feature b/tests/behat/my_certificates.feature new file mode 100644 index 0000000..1ad4416 --- /dev/null +++ b/tests/behat/my_certificates.feature @@ -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" diff --git a/tests/behat/required_minutes.feature b/tests/behat/required_minutes.feature new file mode 100644 index 0000000..49e85b2 --- /dev/null +++ b/tests/behat/required_minutes.feature @@ -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" diff --git a/tests/behat/show_position_x_y.feature b/tests/behat/show_position_x_y.feature new file mode 100644 index 0000000..e4aad1d --- /dev/null +++ b/tests/behat/show_position_x_y.feature @@ -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 | diff --git a/tests/behat/verify_certificates.feature b/tests/behat/verify_certificates.feature new file mode 100644 index 0000000..814588a --- /dev/null +++ b/tests/behat/verify_certificates.feature @@ -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" diff --git a/tests/behat/view_issued_certificates.feature b/tests/behat/view_issued_certificates.feature new file mode 100644 index 0000000..af253e7 --- /dev/null +++ b/tests/behat/view_issued_certificates.feature @@ -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" diff --git a/view.php b/view.php index 3708f28..5d09752 100644 --- a/view.php +++ b/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();