mirror of
https://github.com/moodle/moodle.git
synced 2025-03-14 04:30:15 +01:00
MDL-40921 mod_workshop: fix unit tests
This commit is contained in:
parent
3e692810d7
commit
0d0514cf3b
@ -23,8 +23,12 @@
|
||||
*/
|
||||
|
||||
namespace mod_workshop\event;
|
||||
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
|
||||
global $CFG;
|
||||
require_once("$CFG->dirroot/mod/workshop/locallib.php");
|
||||
|
||||
/**
|
||||
* Event for when a workshop activity is viewed.
|
||||
*
|
||||
|
@ -26,9 +26,10 @@
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
|
||||
global $CFG;
|
||||
require_once($CFG->dirroot . '/mod/workshop/lib.php'); // Include the code to test
|
||||
require_once($CFG->dirroot . '/mod/workshop/locallib.php'); // Include the code to test
|
||||
require_once($CFG->dirroot . '/lib/cronlib.php'); // Include the code to test
|
||||
require_once($CFG->dirroot . '/mod/workshop/lib.php'); // Include the code to test.
|
||||
require_once($CFG->dirroot . '/mod/workshop/locallib.php'); // Include the code to test.
|
||||
require_once($CFG->dirroot . '/lib/cronlib.php'); // Include the code to test.
|
||||
require_once(__DIR__ . '/fixtures/testable.php');
|
||||
|
||||
|
||||
/**
|
||||
@ -36,11 +37,13 @@ require_once($CFG->dirroot . '/lib/cronlib.php'); // Include the code to test
|
||||
*/
|
||||
class mod_workshop_events_testcase extends advanced_testcase {
|
||||
|
||||
/** $workshop Basic workshop data stored in an object. */
|
||||
/** @var stdClass $workshop Basic workshop data stored in an object. */
|
||||
protected $workshop;
|
||||
/** $course Generated Random Course. */
|
||||
/** @var stdClass $course Generated Random Course. */
|
||||
protected $course;
|
||||
/** $context Course module context. */
|
||||
/** @var stdClass mod info */
|
||||
protected $cm;
|
||||
/** @var context $context Course module context. */
|
||||
protected $context;
|
||||
|
||||
/**
|
||||
@ -53,18 +56,22 @@ class mod_workshop_events_testcase extends advanced_testcase {
|
||||
// Create a workshop activity.
|
||||
$this->course = $this->getDataGenerator()->create_course();
|
||||
$this->workshop = $this->getDataGenerator()->create_module('workshop', array('course' => $this->course));
|
||||
$this->context = context_module::instance($this->workshop->id);
|
||||
$this->cm = get_coursemodule_from_instance('workshop', $this->workshop->id);
|
||||
$this->context = context_module::instance($this->cm->id);
|
||||
}
|
||||
|
||||
protected function tearDown() {
|
||||
$this->workshop = null;
|
||||
$this->course = null;
|
||||
$this->cm = null;
|
||||
$this->context = null;
|
||||
parent::tearDown();
|
||||
}
|
||||
|
||||
/**
|
||||
* This event is triggered in view.php and workshop/lib.php through the function workshop_cron().
|
||||
*/
|
||||
function test_phase_switched_event() {
|
||||
public function test_phase_switched_event() {
|
||||
$this->resetAfterTest();
|
||||
$this->setAdminUser();
|
||||
|
||||
@ -88,13 +95,13 @@ class mod_workshop_events_testcase extends advanced_testcase {
|
||||
|
||||
// Check that the legacy log data is valid.
|
||||
$expected = array($this->course->id, 'workshop', 'update switch phase', 'view.php?id=' . $this->workshop->id,
|
||||
$this->workshop->phase, $this->workshop->id);
|
||||
$this->workshop->phase, $this->cm->id);
|
||||
$this->assertEventLegacyLogData($expected, $event);
|
||||
|
||||
$sink->close();
|
||||
}
|
||||
|
||||
function test_assessment_evaluated() {
|
||||
public function test_assessment_evaluated() {
|
||||
$this->resetAfterTest();
|
||||
$this->setAdminUser();
|
||||
|
||||
@ -103,8 +110,8 @@ class mod_workshop_events_testcase extends advanced_testcase {
|
||||
$workshop = new testable_workshop($this->workshop, $cm, $this->course);
|
||||
|
||||
$assessments = array();
|
||||
$assessments[] = (object)array('reviewerid'=>2, 'gradinggrade'=>null, 'gradinggradeover'=>null, 'aggregationid'=>null,
|
||||
'aggregatedgrade'=>12);
|
||||
$assessments[] = (object)array('reviewerid' => 2, 'gradinggrade' => null,
|
||||
'gradinggradeover' => null, 'aggregationid' => null, 'aggregatedgrade' => 12);
|
||||
|
||||
// Trigger and capture the event.
|
||||
$sink = $this->redirectEvents();
|
||||
@ -114,12 +121,12 @@ class mod_workshop_events_testcase extends advanced_testcase {
|
||||
|
||||
$this->assertInstanceOf('\mod_workshop\event\assessment_evaluated', $event);
|
||||
$this->assertEquals('workshop_aggregations', $event->objecttable);
|
||||
$this->assertEquals(context_module::instance($workshop->id), $event->get_context());
|
||||
$this->assertEquals(context_module::instance($cm->id), $event->get_context());
|
||||
|
||||
$sink->close();
|
||||
}
|
||||
|
||||
function test_assessment_reevaluated() {
|
||||
public function test_assessment_reevaluated() {
|
||||
$this->resetAfterTest();
|
||||
$this->setAdminUser();
|
||||
|
||||
@ -128,8 +135,8 @@ class mod_workshop_events_testcase extends advanced_testcase {
|
||||
$workshop = new testable_workshop($this->workshop, $cm, $this->course);
|
||||
|
||||
$assessments = array();
|
||||
$assessments[] = (object)array('reviewerid'=>2, 'gradinggrade'=>null, 'gradinggradeover'=>null, 'aggregationid'=>2,
|
||||
'aggregatedgrade'=>12);
|
||||
$assessments[] = (object)array('reviewerid' => 2, 'gradinggrade' => null, 'gradinggradeover' => null,
|
||||
'aggregationid' => 2, 'aggregatedgrade' => 12);
|
||||
|
||||
// Trigger and capture the event.
|
||||
$sink = $this->redirectEvents();
|
||||
@ -139,9 +146,9 @@ class mod_workshop_events_testcase extends advanced_testcase {
|
||||
|
||||
$this->assertInstanceOf('\mod_workshop\event\assessment_reevaluated', $event);
|
||||
$this->assertEquals('workshop_aggregations', $event->objecttable);
|
||||
$this->assertEquals(context_module::instance($workshop->id), $event->get_context());
|
||||
$expected = array($this->course->id, 'workshop', 'update aggregate grade', 'view.php?id=' . $event->get_context()->instanceid,
|
||||
$event->objectid, $event->get_context()->instanceid);
|
||||
$this->assertEquals(context_module::instance($cm->id), $event->get_context());
|
||||
$expected = array($this->course->id, 'workshop', 'update aggregate grade',
|
||||
'view.php?id=' . $event->get_context()->instanceid, $event->objectid, $event->get_context()->instanceid);
|
||||
$this->assertEventLegacyLogData($expected, $event);
|
||||
|
||||
$sink->close();
|
||||
@ -150,7 +157,7 @@ class mod_workshop_events_testcase extends advanced_testcase {
|
||||
/**
|
||||
* There is no api involved so the best we can do is test legacy data by triggering event manually.
|
||||
*/
|
||||
function test_aggregate_grades_reset_event() {
|
||||
public function test_aggregate_grades_reset_event() {
|
||||
$this->resetAfterTest();
|
||||
$this->setAdminUser();
|
||||
|
||||
@ -168,7 +175,7 @@ class mod_workshop_events_testcase extends advanced_testcase {
|
||||
|
||||
// Check that the legacy log data is valid.
|
||||
$expected = array($this->course->id, 'workshop', 'update clear aggregated grade', 'view.php?id=' . $this->workshop->id,
|
||||
$this->workshop->id, $this->workshop->id);
|
||||
$this->workshop->id, $this->cm->id);
|
||||
$this->assertEventLegacyLogData($expected, $event);
|
||||
|
||||
$sink->close();
|
||||
@ -177,7 +184,7 @@ class mod_workshop_events_testcase extends advanced_testcase {
|
||||
/**
|
||||
* There is no api involved so the best we can do is test legacy data by triggering event manually.
|
||||
*/
|
||||
function test_instances_list_viewed_event() {
|
||||
public function test_instances_list_viewed_event() {
|
||||
$this->resetAfterTest();
|
||||
$this->setAdminUser();
|
||||
|
||||
@ -201,7 +208,7 @@ class mod_workshop_events_testcase extends advanced_testcase {
|
||||
/**
|
||||
* There is no api involved so the best we can do is test legacy data by triggering event manually.
|
||||
*/
|
||||
function test_submission_created_event() {
|
||||
public function test_submission_created_event() {
|
||||
$this->resetAfterTest();
|
||||
$this->setAdminUser();
|
||||
|
||||
@ -209,12 +216,12 @@ class mod_workshop_events_testcase extends advanced_testcase {
|
||||
$submissionid = 48;
|
||||
|
||||
$event = \mod_workshop\event\submission_created::create(array(
|
||||
'objectid' => $submissionid,
|
||||
'context' => $this->context,
|
||||
'courseid' => $this->course->id,
|
||||
'relateduserid' => $user->id,
|
||||
'other' => array(
|
||||
'workshopid' => $this->workshop->id
|
||||
'objectid' => $submissionid,
|
||||
'context' => $this->context,
|
||||
'courseid' => $this->course->id,
|
||||
'relateduserid' => $user->id,
|
||||
'other' => array(
|
||||
'workshopid' => $this->workshop->id
|
||||
)
|
||||
)
|
||||
);
|
||||
@ -227,7 +234,7 @@ class mod_workshop_events_testcase extends advanced_testcase {
|
||||
|
||||
// Check that the legacy log data is valid.
|
||||
$expected = array($this->course->id, 'workshop', 'add submission',
|
||||
'submission.php?cmid=' . $this->workshop->id . '&id=' . $submissionid, $submissionid, $this->workshop->id);
|
||||
'submission.php?cmid=' . $this->workshop->id . '&id=' . $submissionid, $submissionid, $this->cm->id);
|
||||
$this->assertEventLegacyLogData($expected, $event);
|
||||
|
||||
$sink->close();
|
||||
@ -236,7 +243,7 @@ class mod_workshop_events_testcase extends advanced_testcase {
|
||||
/**
|
||||
* There is no api involved so the best we can do is test legacy data by triggering event manually.
|
||||
*/
|
||||
function test_submission_updated_event() {
|
||||
public function test_submission_updated_event() {
|
||||
$this->resetAfterTest();
|
||||
$this->setAdminUser();
|
||||
|
||||
@ -244,12 +251,12 @@ class mod_workshop_events_testcase extends advanced_testcase {
|
||||
$submissionid = 48;
|
||||
|
||||
$event = \mod_workshop\event\submission_updated::create(array(
|
||||
'objectid' => $submissionid,
|
||||
'context' => $this->context,
|
||||
'courseid' => $this->course->id,
|
||||
'relateduserid' => $user->id,
|
||||
'other' => array(
|
||||
'workshopid' => $this->workshop->id
|
||||
'objectid' => $submissionid,
|
||||
'context' => $this->context,
|
||||
'courseid' => $this->course->id,
|
||||
'relateduserid' => $user->id,
|
||||
'other' => array(
|
||||
'workshopid' => $this->workshop->id
|
||||
)
|
||||
)
|
||||
);
|
||||
@ -262,7 +269,7 @@ class mod_workshop_events_testcase extends advanced_testcase {
|
||||
|
||||
// Check that the legacy log data is valid.
|
||||
$expected = array($this->course->id, 'workshop', 'update submission',
|
||||
'submission.php?cmid=' . $this->workshop->id . '&id=' . $submissionid, $submissionid, $this->workshop->id);
|
||||
'submission.php?cmid=' . $this->workshop->id . '&id=' . $submissionid, $submissionid, $this->cm->id);
|
||||
$this->assertEventLegacyLogData($expected, $event);
|
||||
|
||||
$sink->close();
|
||||
@ -271,7 +278,7 @@ class mod_workshop_events_testcase extends advanced_testcase {
|
||||
/**
|
||||
* There is no api involved so the best we can do is test legacy data by triggering event manually.
|
||||
*/
|
||||
function test_submission_viewed_event() {
|
||||
public function test_submission_viewed_event() {
|
||||
$this->resetAfterTest();
|
||||
$this->setAdminUser();
|
||||
|
||||
@ -279,12 +286,12 @@ class mod_workshop_events_testcase extends advanced_testcase {
|
||||
$submissionid = 48;
|
||||
|
||||
$event = \mod_workshop\event\submission_viewed::create(array(
|
||||
'objectid' => $submissionid,
|
||||
'context' => $this->context,
|
||||
'courseid' => $this->course->id,
|
||||
'relateduserid' => $user->id,
|
||||
'other' => array(
|
||||
'workshopid' => $this->workshop->id
|
||||
'objectid' => $submissionid,
|
||||
'context' => $this->context,
|
||||
'courseid' => $this->course->id,
|
||||
'relateduserid' => $user->id,
|
||||
'other' => array(
|
||||
'workshopid' => $this->workshop->id
|
||||
)
|
||||
)
|
||||
);
|
||||
@ -297,21 +304,9 @@ class mod_workshop_events_testcase extends advanced_testcase {
|
||||
|
||||
// Check that the legacy log data is valid.
|
||||
$expected = array($this->course->id, 'workshop', 'view submission',
|
||||
'submission.php?cmid=' . $this->workshop->id . '&id=' . $submissionid, $submissionid, $this->workshop->id);
|
||||
'submission.php?cmid=' . $this->workshop->id . '&id=' . $submissionid, $submissionid, $this->cm->id);
|
||||
$this->assertEventLegacyLogData($expected, $event);
|
||||
|
||||
$sink->close();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Test subclass that makes all the protected methods we want to test public.
|
||||
*/
|
||||
class testable_workshop extends workshop {
|
||||
|
||||
public function aggregate_grading_grades_process(array $assessments, $timegraded = null) {
|
||||
parent::aggregate_grading_grades_process($assessments, $timegraded);
|
||||
}
|
||||
|
||||
}
|
||||
|
41
mod/workshop/tests/fixtures/testable.php
vendored
Normal file
41
mod/workshop/tests/fixtures/testable.php
vendored
Normal file
@ -0,0 +1,41 @@
|
||||
<?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/>.
|
||||
|
||||
/**
|
||||
* mod_workshop fixtures
|
||||
*
|
||||
* @package mod_workshop
|
||||
* @category phpunit
|
||||
* @copyright 2014 Petr Skoda
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
|
||||
/**
|
||||
* Test subclass that makes all the protected methods we want to test public.
|
||||
*/
|
||||
class testable_workshop extends workshop {
|
||||
|
||||
public function aggregate_submission_grades_process(array $assessments) {
|
||||
parent::aggregate_submission_grades_process($assessments);
|
||||
}
|
||||
|
||||
public function aggregate_grading_grades_process(array $assessments, $timegraded = null) {
|
||||
parent::aggregate_grading_grades_process($assessments, $timegraded);
|
||||
}
|
||||
|
||||
}
|
@ -27,6 +27,7 @@ defined('MOODLE_INTERNAL') || die();
|
||||
|
||||
global $CFG;
|
||||
require_once($CFG->dirroot . '/mod/workshop/locallib.php'); // Include the code to test
|
||||
require_once(__DIR__ . '/fixtures/testable.php');
|
||||
|
||||
|
||||
/**
|
||||
@ -416,19 +417,3 @@ class mod_workshop_internal_api_testcase extends advanced_testcase {
|
||||
$a = $this->workshop->prepare_example_reference_assessment($fakerawrecord);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Test subclass that makes all the protected methods we want to test public.
|
||||
*/
|
||||
class testable_workshop extends workshop {
|
||||
|
||||
public function aggregate_submission_grades_process(array $assessments) {
|
||||
parent::aggregate_submission_grades_process($assessments);
|
||||
}
|
||||
|
||||
public function aggregate_grading_grades_process(array $assessments, $timegraded = null) {
|
||||
parent::aggregate_grading_grades_process($assessments, $timegraded);
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user