Improved the workshop constructor to support unit testing
Thanks to Tim Hunt for the hint.
This commit is contained in:
@@ -68,10 +68,11 @@ class workshop_allocation_random_test extends UnitTestCase {
|
||||
protected $allocator;
|
||||
|
||||
public function setUp() {
|
||||
$cm = (object)array('id' => 3);
|
||||
$course = (object)array('id' => 11);
|
||||
$cm = new stdClass();
|
||||
$course = new stdClass();
|
||||
$context = new stdClass();
|
||||
$workshop = (object)array('id' => 42);
|
||||
$this->workshop = new workshop($workshop, $cm, $course);
|
||||
$this->workshop = new workshop($workshop, $cm, $course, $context);
|
||||
$this->allocator = new testable_workshop_random_allocator($this->workshop);
|
||||
}
|
||||
|
||||
|
||||
@@ -67,10 +67,11 @@ class workshop_accumulative_strategy_test extends UnitTestCase {
|
||||
$this->realDB = $DB;
|
||||
$DB = new mockDB();
|
||||
|
||||
$cm = (object)array('id' => 3);
|
||||
$course = (object)array('id' => 11);
|
||||
$cm = new stdClass();
|
||||
$course = new stdClass();
|
||||
$context = new stdClass();
|
||||
$workshop = (object)array('id' => 42, 'strategy' => 'accumulative');
|
||||
$this->workshop = new workshop($workshop, $cm, $course);
|
||||
$this->workshop = new workshop($workshop, $cm, $course, $context);
|
||||
$this->strategy = new testable_workshop_accumulative_strategy($this->workshop);
|
||||
}
|
||||
|
||||
|
||||
@@ -70,10 +70,11 @@ class workshop_numerrors_strategy_test extends UnitTestCase {
|
||||
$this->realDB = $DB;
|
||||
$DB = new mockDB();
|
||||
|
||||
$cm = (object)array('id' => 3);
|
||||
$course = (object)array('id' => 11);
|
||||
$cm = new stdClass();
|
||||
$course = new stdClass();
|
||||
$context = new stdClass();
|
||||
$workshop = (object)array('id' => 42, 'strategy' => 'numerrors');
|
||||
$this->workshop = new workshop($workshop, $cm, $course);
|
||||
$this->workshop = new workshop($workshop, $cm, $course, $context);
|
||||
$this->strategy = new testable_workshop_numerrors_strategy($this->workshop);
|
||||
}
|
||||
|
||||
|
||||
@@ -80,18 +80,22 @@ class workshop {
|
||||
* @param stdClass $dbrecord Workshop instance data from {workshop} table
|
||||
* @param stdClass $cm Course module record as returned by {@link get_coursemodule_from_id()}
|
||||
* @param stdClass $course Course record from {course} table
|
||||
* @param stdClass $context The context of the workshop instance
|
||||
*/
|
||||
public function __construct(stdClass $dbrecord, stdClass $cm, stdClass $course) {
|
||||
public function __construct(stdClass $dbrecord, stdClass $cm, stdClass $course, stdClass $context=null) {
|
||||
foreach ($dbrecord as $field => $value) {
|
||||
$this->{$field} = $value;
|
||||
}
|
||||
$this->evaluation = 'best'; // todo make this configurable
|
||||
$this->cm = $cm;
|
||||
$this->course = $course; // beware - this replaces the standard course field in the instance table
|
||||
// this is intentional - IMO there should be no such field as it violates
|
||||
// 3rd normal form with no real performance gain. This way I try to
|
||||
// demonstrate how backwards compatibility could be achieved --mudrd8mz
|
||||
$this->context = get_context_instance(CONTEXT_MODULE, $this->cm->id);
|
||||
// 3rd normal form with no real performance gain
|
||||
if (is_null($context)) {
|
||||
$this->context = get_context_instance(CONTEXT_MODULE, $this->cm->id);
|
||||
} else {
|
||||
$this->context = $context;
|
||||
}
|
||||
$this->evaluation = 'best'; // todo make this configurable although we have no alternatives yet
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
Reference in New Issue
Block a user