From e3b48d2ba2bdd22ddcb7b1c25155cd4e42f55d5b Mon Sep 17 00:00:00 2001 From: Joseph Baxter Date: Thu, 19 Jun 2014 17:29:31 +0100 Subject: [PATCH 1/4] behat tests for uon functionality --- tests/behat/attendance_mod.feature | 87 ++++++++++++++++++++++++++++++ 1 file changed, 87 insertions(+) create mode 100644 tests/behat/attendance_mod.feature diff --git a/tests/behat/attendance_mod.feature b/tests/behat/attendance_mod.feature new file mode 100644 index 0000000..24fc6fa --- /dev/null +++ b/tests/behat/attendance_mod.feature @@ -0,0 +1,87 @@ +@mod @uon @mod_attendance +Feature: Teachers and Students can record session attendance + In order to record session attendance + As a student + I need to be able to mark my own attendance to a session + And as a teacher + I need to be able to mark any students attendance to a session + In order to report on session attendance + As a teacher + I need to be able to export session attendance and run reports + In order to contact students with poor attendance + As a teacher + I need the ability to message a group of students with low attendance + + Background: + Given the following "courses" exist: + | fullname | shortname | summary | category | + | Course 1 | C101 | Prove the attendance activity works | 0 | + And the following "users" exist: + | username | firstname | lastname | email | + | student1 | Sam | Student | student1@asd.com | + | teacher1 | Teacher | One | teacher1@asd.com | + And the following "course enrolments" exist: + | user | course | role | + | student1 | C101 | student | + | teacher1 | C101 | editingteacher | + And I log in as "teacher1" + And I follow "Course 1" + And I turn editing mode on + And I add a "Attendance" to section "1" + And I press "Save and display" + And I log out + + Scenario: Students can mark their own attendance + When I log in as "teacher1" + And I follow "Course 1" + And I follow "Attendance" + And I follow "Add" + And I check "Allow students to record own attendance" + And I set the following fields to these values: + | id_sessiondate_hour | 23 | + And I click on "id_submitbutton" "button" + And I follow "Continue" + And I log out + When I log in as "student1" + And I follow "Course 1" + And I follow "Attendance" + And I follow "Submit attendance" + And I check "Present" + And I press "Save changes" + Then I should see "Self-recorded" + And I log out + When I log in as "teacher1" + And I follow "Course 1" + And I expand "Reports" node + And I follow "Logs" + And I click on "Get these logs" "button" + Then "attendance taken by student" "link" should exist + + Scenario: Teachers can view low grade report and send a message + When I log in as "teacher1" + And I follow "Course 1" + And I follow "Attendance" + And I follow "Add" + And I set the following fields to these values: + | id_sessiondate_hour | 01 | + And I click on "id_submitbutton" "button" + And I follow "Continue" + And I follow "Report" + And I follow "Low grade" + And I check "user3" + And I click on "Send a message" "button" + Then I should see "Message body" + And I should see "student1@asd.com" + And I expand "Reports" node + And I follow "Logs" + And I click on "Get these logs" "button" + Then "attendance report viewed" "link" should exist + + Scenario: Export report id number, department and institution are unchecked by default + When I log in as "teacher1" + And I follow "Course 1" + And I follow "Attendance" + And I follow "Export" + Then the "id_ident_idnumber" checkbox should not be checked + And the "id_ident_institution" checkbox should not be checked + And the "id_ident_department" checkbox should not be checked From 846653b85a1c96b0da82a100ed5d9f83b0314eda Mon Sep 17 00:00:00 2001 From: Joseph Baxter Date: Fri, 20 Jun 2014 16:52:38 +0100 Subject: [PATCH 2/4] added test of file export --- tests/behat/attendance_mod.feature | 30 ++++++++++++++++++++++++------ 1 file changed, 24 insertions(+), 6 deletions(-) diff --git a/tests/behat/attendance_mod.feature b/tests/behat/attendance_mod.feature index 24fc6fa..cef3a96 100644 --- a/tests/behat/attendance_mod.feature +++ b/tests/behat/attendance_mod.feature @@ -17,9 +17,9 @@ Feature: Teachers and Students can record session attendance | fullname | shortname | summary | category | | Course 1 | C101 | Prove the attendance activity works | 0 | And the following "users" exist: - | username | firstname | lastname | email | - | student1 | Sam | Student | student1@asd.com | - | teacher1 | Teacher | One | teacher1@asd.com | + | username | firstname | lastname | email | idnumber | department | institution | + | student1 | Sam | Student | student1@asd.com | 1234 | computer science | University of Nottingham | + | teacher1 | Teacher | One | teacher1@asd.com | 5678 | computer science | University of Nottingham | And the following "course enrolments" exist: | user | course | role | | student1 | C101 | student | @@ -38,7 +38,7 @@ Feature: Teachers and Students can record session attendance And I follow "Add" And I check "Allow students to record own attendance" And I set the following fields to these values: - | id_sessiondate_hour | 23 | + | id_sessiondate_hour | 23 | And I click on "id_submitbutton" "button" And I follow "Continue" And I log out @@ -63,7 +63,7 @@ Feature: Teachers and Students can record session attendance And I follow "Attendance" And I follow "Add" And I set the following fields to these values: - | id_sessiondate_hour | 01 | + | id_sessiondate_hour | 01 | And I click on "id_submitbutton" "button" And I follow "Continue" And I follow "Report" @@ -77,11 +77,29 @@ Feature: Teachers and Students can record session attendance And I click on "Get these logs" "button" Then "attendance report viewed" "link" should exist - Scenario: Export report id number, department and institution are unchecked by default + # Dependency - selenium running with firefox profile with auto saving of txt files to $CFG->behat_download. + @javascript @ignore + Scenario: Export report includes id number, department and institution When I log in as "teacher1" And I follow "Course 1" And I follow "Attendance" + And I follow "Add" + And I set the following fields to these values: + | id_sessiondate_hour | 01 | + And I click on "id_submitbutton" "button" + And I follow "Continue" And I follow "Export" Then the "id_ident_idnumber" checkbox should not be checked And the "id_ident_institution" checkbox should not be checked And the "id_ident_department" checkbox should not be checked + And I check "id_ident_idnumber" + And I check "id_ident_institution" + And I check "id_ident_department" + And I set the following fields to these values: + | format | Download in text format | + And I click on "OK" "button" + Then attendance export file is ok + And I should see "ID number" as "1234" in the file + And I should see "Department" as "computer science" in the file + And I should see "Institution" as "University of Nottingham" in the file + From cc95000198b9662f9eac7615c0b97d07a27b64a2 Mon Sep 17 00:00:00 2001 From: Joseph Baxter Date: Fri, 20 Jun 2014 16:54:19 +0100 Subject: [PATCH 3/4] new steps definitions --- tests/behat/behat_mod_attendance.php | 116 +++++++++++++++++++++++++++ 1 file changed, 116 insertions(+) create mode 100644 tests/behat/behat_mod_attendance.php diff --git a/tests/behat/behat_mod_attendance.php b/tests/behat/behat_mod_attendance.php new file mode 100644 index 0000000..cbcd3b0 --- /dev/null +++ b/tests/behat/behat_mod_attendance.php @@ -0,0 +1,116 @@ +. + + +// 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\Mink\Exception\ExpectationException as ExpectationException, + Behat\Behat\Exception\PendingException as PendingException; + +/** + * Attendance steps definitions. + * + * @package mod + * @subpackage attendance + * @category test + * @copyright 2014 University of Nottingham + * @author Joseph Baxter (joseph.baxter@nottingham.ac.uk) + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ +class behat_mod_attendance extends behat_base { + + protected $file_contents; + + /** + * @Then /^attendance export file is ok$/ + */ + public function attendance_export_file_is_ok() { + + global $CFG; + + $check = true; + + // Location selenium will download to. + $dir = $CFG->behat_download; + $files = scandir($dir, 1); + $filename = $files[0]; + $file = fopen($dir . $filename, "r"); + + $count = 0; + $header = null; + + // The file is tab seperated but not exactly a tsv. + while (($row = fgetcsv($file, 0, "\t")) !== FALSE) { + + // Ignore unwanted information at the start of the file. + if ($count < 3) { + $count++; + continue; + } + + if (!$header) { + $header = $row; + } else { + $this->file_contents = array_combine($header, $row); + } + + $count++; + } + + fclose($file); + unlink($dir . $filename); + + // Check if data rows exist. + if ($count < 2) { + $check = false; + } + + if ($check) { + + return true; + + } else { + + throw new ExpectationException('Attendance export file not ok', $this->getSession()); + } + + } + + /** + * @Given /^I should see "([^"]*)" as "([^"]*)" in the file$/ + */ + public function i_should_see_as_in_the_file($field, $value) { + + foreach ($this->file_contents as $array_field => $array_value) { + + if ($field == $array_field) { + + if ($value == $array_value) { + + return true; + + } else { + + throw new PendingException(); + + } + } + } + } + +} From c6cb46c4f35a7734369d119c1568399854521cdf Mon Sep 17 00:00:00 2001 From: Joseph Baxter Date: Mon, 23 Jun 2014 09:23:38 +0100 Subject: [PATCH 4/4] changed tag --- tests/behat/attendance_mod.feature | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/behat/attendance_mod.feature b/tests/behat/attendance_mod.feature index cef3a96..34c04c9 100644 --- a/tests/behat/attendance_mod.feature +++ b/tests/behat/attendance_mod.feature @@ -78,7 +78,7 @@ Feature: Teachers and Students can record session attendance Then "attendance report viewed" "link" should exist # Dependency - selenium running with firefox profile with auto saving of txt files to $CFG->behat_download. - @javascript @ignore + @javascript @_file_download Scenario: Export report includes id number, department and institution When I log in as "teacher1" And I follow "Course 1"