MDL-45837 Grades: Add unit & behat tests for events
This commit is contained in:
committed by
Mark Nelson
parent
31647f0cc9
commit
b302d434ae
@@ -0,0 +1,37 @@
|
||||
@core @core_grades
|
||||
Feature: We can view the logs for any changes to grade letters.
|
||||
In order to view changes the letter boundary of a course
|
||||
As an administrator
|
||||
I need to add make changes and then view the logs.
|
||||
|
||||
Scenario: I override the letter boundaries and check the logs.
|
||||
Given the following "courses" exist:
|
||||
| fullname | shortname | category |
|
||||
| Course 1 | C1 | 0 |
|
||||
And I log in as "admin"
|
||||
And I am on "Course 1" course homepage
|
||||
And I navigate to "Setup > Course grade settings" in the course gradebook
|
||||
And I set the following fields to these values:
|
||||
| Grade display type | Letter |
|
||||
And I press "Save changes"
|
||||
And I navigate to "Letters" in the course gradebook
|
||||
And I follow "Edit grade letters"
|
||||
And I set the following fields to these values:
|
||||
| id_override | 1 |
|
||||
| id_gradeboundary10 | 57 |
|
||||
And I press "Save changes"
|
||||
And I follow "Edit grade letters"
|
||||
And I set the following fields to these values:
|
||||
| id_override | 1 |
|
||||
| id_gradeboundary10 | 50 |
|
||||
And I press "Save changes"
|
||||
And I follow "Edit grade letters"
|
||||
And I set the following fields to these values:
|
||||
| id_override | 1 |
|
||||
| id_gradeletter11 | |
|
||||
| id_gradeboundary11 | |
|
||||
And I press "Save changes"
|
||||
When I navigate to "Live logs" node in "Site administration > Reports"
|
||||
Then I should see "Grade letter created"
|
||||
And I should see "Grade letter updated"
|
||||
And I should see "Grade letter deleted"
|
||||
@@ -0,0 +1,27 @@
|
||||
@core @core_grades
|
||||
Feature: We can view the logs for any changes to grade scales.
|
||||
In order to view changes grade scales
|
||||
As an administrator
|
||||
I need to add make changes and then view the logs.
|
||||
|
||||
Scenario: I edit scales and then view the logs.
|
||||
Given I log in as "admin"
|
||||
And I navigate to "Scales" node in "Site administration > Grades"
|
||||
# Add a scale
|
||||
And I press "Add a new scale"
|
||||
And I set the following fields to these values:
|
||||
| Name | Letterscale |
|
||||
| Scale | F,D,C,B,A |
|
||||
And I press "Save changes"
|
||||
# Delete first scale
|
||||
And I follow "Delete"
|
||||
And I press "Continue"
|
||||
# Edit first scale
|
||||
And I follow "Edit"
|
||||
And I set the following fields to these values:
|
||||
| id_scale | ONE,TWO,THREE |
|
||||
And I press "Save changes"
|
||||
When I navigate to "Live logs" node in "Site administration > Reports"
|
||||
Then I should see "Scale created"
|
||||
And I should see "Scale updated"
|
||||
And I should see "Scale deleted"
|
||||
@@ -0,0 +1,222 @@
|
||||
<?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/>.
|
||||
|
||||
/**
|
||||
* Unit tests for events found in /grade/letter and /grade/scale.
|
||||
*
|
||||
* @package core_grades
|
||||
* @category test
|
||||
* @copyright 2017 Stephen Bourget
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU Public License
|
||||
*/
|
||||
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
|
||||
global $CFG;
|
||||
require_once($CFG->dirroot . '/grade/lib.php');
|
||||
|
||||
/**
|
||||
* Unit tests for grade/lib.php.
|
||||
*
|
||||
* @package core_grades
|
||||
* @category test
|
||||
* @copyright 2017 Stephen Bourget
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
class core_grade_events_test extends advanced_testcase {
|
||||
|
||||
/** @var stdClass the course used for testing */
|
||||
private $course;
|
||||
|
||||
/**
|
||||
* Test set up.
|
||||
*
|
||||
* This is executed before running any test in this file.
|
||||
*/
|
||||
public function setUp() {
|
||||
$this->resetAfterTest();
|
||||
|
||||
$this->setAdminUser();
|
||||
$this->course = $this->getDataGenerator()->create_course();
|
||||
}
|
||||
|
||||
/**
|
||||
* Test the grade_letter added event.
|
||||
*
|
||||
* There is no external API for triggering this event, so the unit test will simply
|
||||
* create and trigger the event and ensure the data is returned as expected.
|
||||
*/
|
||||
public function test_grade_letter_created() {
|
||||
|
||||
// Create a scale aded event.
|
||||
$event = \core\event\grade_letter_created::create(array(
|
||||
'objectid' => 10,
|
||||
'context' => context_course::instance($this->course->id)
|
||||
));
|
||||
|
||||
// Trigger and capture the event.
|
||||
$sink = $this->redirectEvents();
|
||||
$event->trigger();
|
||||
$events = $sink->get_events();
|
||||
$event = reset($events);
|
||||
|
||||
// Check that the event data is valid.
|
||||
$this->assertInstanceOf('\core\event\grade_letter_created', $event);
|
||||
$this->assertEquals(context_course::instance($this->course->id), $event->get_context());
|
||||
}
|
||||
|
||||
/**
|
||||
* Test the grade_letter deleted event.
|
||||
*
|
||||
* There is no external API for triggering this event, so the unit test will simply
|
||||
* create and trigger the event and ensure the data is returned as expected.
|
||||
*/
|
||||
public function test_grade_letter_deleted() {
|
||||
|
||||
// Create a grade_letter deleted event.
|
||||
$event = \core\event\grade_letter_deleted::create(array(
|
||||
'objectid' => 10,
|
||||
'context' => context_course::instance($this->course->id)
|
||||
));
|
||||
|
||||
// Trigger and capture the event.
|
||||
$sink = $this->redirectEvents();
|
||||
$event->trigger();
|
||||
$events = $sink->get_events();
|
||||
$event = reset($events);
|
||||
|
||||
// Check that the event data is valid.
|
||||
$this->assertInstanceOf('\core\event\grade_letter_deleted', $event);
|
||||
$this->assertEquals(context_course::instance($this->course->id), $event->get_context());
|
||||
}
|
||||
|
||||
/**
|
||||
* Test the grade_letter updated event.
|
||||
*
|
||||
* There is no external API for triggering this event, so the unit test will simply
|
||||
* create and trigger the event and ensure the data is returned as expected.
|
||||
*/
|
||||
public function test_grade_letter_updated() {
|
||||
|
||||
// Create a scale updated event.
|
||||
$event = \core\event\grade_letter_updated::create(array(
|
||||
'objectid' => 10,
|
||||
'context' => context_course::instance($this->course->id)
|
||||
));
|
||||
|
||||
// Trigger and capture the event.
|
||||
$sink = $this->redirectEvents();
|
||||
$event->trigger();
|
||||
$events = $sink->get_events();
|
||||
$event = reset($events);
|
||||
|
||||
// Check that the event data is valid.
|
||||
$this->assertInstanceOf('\core\event\grade_letter_updated', $event);
|
||||
$this->assertEquals(context_course::instance($this->course->id), $event->get_context());
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Test the scale added event.
|
||||
*
|
||||
* There is no external API for triggering this event, so the unit test will simply
|
||||
* create and trigger the event and ensure the data is returned as expected.
|
||||
*/
|
||||
public function test_scale_created() {
|
||||
|
||||
$gradescale = new grade_scale();
|
||||
|
||||
$gradescale->name = 'unittestscale3';
|
||||
$gradescale->courseid = $this->course->id;
|
||||
$gradescale->userid = 317;
|
||||
$gradescale->scale = 'Distinction, Very Good, Good, Pass, Fail';
|
||||
$gradescale->description = 'This scale is used to mark standard assignments.';
|
||||
|
||||
$url = new \moodle_url('/grade/edit/scale/index.php', array('id' => $this->course->id));
|
||||
|
||||
// Trigger and capture the event.
|
||||
$sink = $this->redirectEvents();
|
||||
$id = $gradescale->insert();
|
||||
$events = $sink->get_events();
|
||||
$event = reset($events);
|
||||
|
||||
// Check that the event data is valid.
|
||||
$this->assertInstanceOf('\core\event\scale_created', $event);
|
||||
$this->assertEquals($id, $event->objectid);
|
||||
$this->assertEquals($url, $event->get_url());
|
||||
$this->assertEquals(context_course::instance($this->course->id), $event->get_context());
|
||||
}
|
||||
|
||||
/**
|
||||
* Test the scale deleted event.
|
||||
*
|
||||
* There is no external API for triggering this event, so the unit test will simply
|
||||
* create and trigger the event and ensure the data is returned as expected.
|
||||
*/
|
||||
public function test_scale_deleted() {
|
||||
|
||||
$gradescale = new grade_scale();
|
||||
|
||||
$gradescale->name = 'unittestscale3';
|
||||
$gradescale->courseid = $this->course->id;
|
||||
$gradescale->userid = 317;
|
||||
$gradescale->scale = 'Distinction, Very Good, Good, Pass, Fail';
|
||||
$gradescale->description = 'This scale is used to mark standard assignments.';
|
||||
$gradescale->insert();
|
||||
|
||||
// Trigger and capture the event.
|
||||
$sink = $this->redirectEvents();
|
||||
$gradescale->delete();
|
||||
$events = $sink->get_events();
|
||||
$event = reset($events);
|
||||
|
||||
// Check that the event data is valid.
|
||||
$this->assertInstanceOf('\core\event\scale_deleted', $event);
|
||||
$this->assertEquals(context_course::instance($this->course->id), $event->get_context());
|
||||
}
|
||||
|
||||
/**
|
||||
* Test the scale updated event.
|
||||
*
|
||||
* There is no external API for triggering this event, so the unit test will simply
|
||||
* create and trigger the event and ensure the data is returned as expected.
|
||||
*/
|
||||
public function test_scale_updated() {
|
||||
|
||||
$gradescale = new grade_scale();
|
||||
$gradescale->name = 'unittestscale3';
|
||||
$gradescale->courseid = $this->course->id;
|
||||
$gradescale->userid = 317;
|
||||
$gradescale->scale = 'Distinction, Very Good, Good, Pass, Fail';
|
||||
$gradescale->description = 'This scale is used to mark standard assignments.';
|
||||
$id = $gradescale->insert();
|
||||
|
||||
$gradescale->name = 'Updated info for this unittest grade_scale';
|
||||
$url = new \moodle_url('/grade/edit/scale/index.php', array('id' => $this->course->id));
|
||||
|
||||
// Trigger and capture the event.
|
||||
$sink = $this->redirectEvents();
|
||||
$gradescale->update();
|
||||
$events = $sink->get_events();
|
||||
$event = reset($events);
|
||||
|
||||
// Check that the event data is valid.
|
||||
$this->assertInstanceOf('\core\event\scale_updated', $event);
|
||||
$this->assertEquals($id, $event->objectid);
|
||||
$this->assertEquals($url, $event->get_url());
|
||||
$this->assertEquals(context_course::instance($this->course->id), $event->get_context());
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user