MDL-44725 workshop: correct module generation in unittests (15)
This commit is contained in:
committed by
sam marshall
parent
002ccdcf49
commit
ed2ecd3e35
@@ -31,7 +31,7 @@ require_once($CFG->dirroot . '/mod/workshop/locallib.php');
|
||||
require_once($CFG->dirroot . '/mod/workshop/allocation/random/lib.php');
|
||||
|
||||
|
||||
class workshopallocation_random_testcase extends basic_testcase {
|
||||
class workshopallocation_random_testcase extends advanced_testcase {
|
||||
|
||||
/** workshop instance emulation */
|
||||
protected $workshop;
|
||||
@@ -41,10 +41,13 @@ class workshopallocation_random_testcase extends basic_testcase {
|
||||
|
||||
protected function setUp() {
|
||||
parent::setUp();
|
||||
|
||||
$workshop = (object)array('id' => 42);
|
||||
$this->workshop = new workshop($workshop, null, null);
|
||||
$this->allocator = new testable_workshop_random_allocator($this->workshop);
|
||||
$this->resetAfterTest();
|
||||
$this->setAdminUser();
|
||||
$course = $this->getDataGenerator()->create_course();
|
||||
$workshop = $this->getDataGenerator()->create_module('workshop', array('course' => $course));
|
||||
$cm = get_fast_modinfo($course)->instances['workshop'][$workshop->id];
|
||||
$this->workshop = new workshop($workshop, $cm, $course);
|
||||
$this->allocator = new testable_workshop_random_allocator($this->workshop);
|
||||
}
|
||||
|
||||
protected function tearDown() {
|
||||
|
||||
@@ -32,7 +32,7 @@ require_once($CFG->dirroot . '/mod/workshop/eval/best/lib.php');
|
||||
require_once($CFG->libdir . '/gradelib.php');
|
||||
|
||||
|
||||
class workshopeval_best_evaluation_testcase extends basic_testcase {
|
||||
class workshopeval_best_evaluation_testcase extends advanced_testcase {
|
||||
|
||||
/** workshop instance emulation */
|
||||
protected $workshop;
|
||||
@@ -45,9 +45,12 @@ class workshopeval_best_evaluation_testcase extends basic_testcase {
|
||||
*/
|
||||
protected function setUp() {
|
||||
parent::setUp();
|
||||
|
||||
$workshop = (object)array('id' => 42, 'evaluation' => 'best');
|
||||
$this->workshop = new workshop($workshop, null, null);
|
||||
$this->resetAfterTest();
|
||||
$this->setAdminUser();
|
||||
$course = $this->getDataGenerator()->create_course();
|
||||
$workshop = $this->getDataGenerator()->create_module('workshop', array('evaluation' => 'best', 'course' => $course));
|
||||
$cm = get_fast_modinfo($course)->instances['workshop'][$workshop->id];
|
||||
$this->workshop = new workshop($workshop, $cm, $course);
|
||||
$this->evaluator = new testable_workshop_best_evaluation($this->workshop);
|
||||
}
|
||||
|
||||
|
||||
@@ -43,9 +43,12 @@ class workshop_accumulative_strategy_testcase extends advanced_testcase {
|
||||
*/
|
||||
protected function setUp() {
|
||||
parent::setUp();
|
||||
|
||||
$workshop = (object)array('id' => 42, 'strategy' => 'accumulative');
|
||||
$this->workshop = new workshop($workshop, null, null);
|
||||
$this->resetAfterTest();
|
||||
$this->setAdminUser();
|
||||
$course = $this->getDataGenerator()->create_course();
|
||||
$workshop = $this->getDataGenerator()->create_module('workshop', array('strategy' => 'accumulative', 'course' => $course));
|
||||
$cm = get_fast_modinfo($course)->instances['workshop'][$workshop->id];
|
||||
$this->workshop = new workshop($workshop, $cm, $course);
|
||||
$this->strategy = new testable_workshop_accumulative_strategy($this->workshop);
|
||||
}
|
||||
|
||||
|
||||
@@ -45,9 +45,12 @@ class workshopform_numerrors_strategy_testcase extends advanced_testcase {
|
||||
*/
|
||||
protected function setUp() {
|
||||
parent::setUp();
|
||||
|
||||
$workshop = (object)array('id' => 42, 'strategy' => 'numerrors');
|
||||
$this->workshop = new workshop($workshop, null, null);
|
||||
$this->resetAfterTest();
|
||||
$this->setAdminUser();
|
||||
$course = $this->getDataGenerator()->create_course();
|
||||
$workshop = $this->getDataGenerator()->create_module('workshop', array('strategy' => 'numerrors', 'course' => $course));
|
||||
$cm = get_fast_modinfo($course)->instances['workshop'][$workshop->id];
|
||||
$this->workshop = new workshop($workshop, $cm, $course);
|
||||
$this->strategy = new testable_workshop_numerrors_strategy($this->workshop);
|
||||
}
|
||||
|
||||
|
||||
@@ -44,8 +44,12 @@ class workshopform_rubric_strategy_test extends advanced_testcase {
|
||||
*/
|
||||
protected function setUp() {
|
||||
parent::setUp();
|
||||
$workshop = (object)array('id' => 42, 'strategy' => 'rubric');
|
||||
$this->workshop = new workshop($workshop, null, null, null);
|
||||
$this->resetAfterTest();
|
||||
$this->setAdminUser();
|
||||
$course = $this->getDataGenerator()->create_course();
|
||||
$workshop = $this->getDataGenerator()->create_module('workshop', array('strategy' => 'rubric', 'course' => $course));
|
||||
$cm = get_fast_modinfo($course)->instances['workshop'][$workshop->id];
|
||||
$this->workshop = new workshop($workshop, $cm, $course);
|
||||
$this->strategy = new testable_workshop_rubric_strategy($this->workshop);
|
||||
|
||||
// prepare dimensions definition
|
||||
|
||||
+12
-15
@@ -196,22 +196,19 @@ class workshop {
|
||||
}
|
||||
}
|
||||
if (is_null($cm) || is_null($course)) {
|
||||
if (!PHPUNIT_TEST) {
|
||||
throw new coding_exception('Must specify $cm and $course');
|
||||
}
|
||||
throw new coding_exception('Must specify $cm and $course');
|
||||
}
|
||||
$this->course = $course;
|
||||
if ($cm instanceof cm_info) {
|
||||
$this->cm = $cm;
|
||||
} else {
|
||||
$this->course = $course;
|
||||
if ($cm instanceof cm_info) {
|
||||
$this->cm = $cm;
|
||||
} else {
|
||||
$modinfo = get_fast_modinfo($course);
|
||||
$this->cm = $modinfo->get_cm($cm->id);
|
||||
}
|
||||
if (is_null($context)) {
|
||||
$this->context = context_module::instance($this->cm->id);
|
||||
} else {
|
||||
$this->context = $context;
|
||||
}
|
||||
$modinfo = get_fast_modinfo($course);
|
||||
$this->cm = $modinfo->get_cm($cm->id);
|
||||
}
|
||||
if (is_null($context)) {
|
||||
$this->context = context_module::instance($this->cm->id);
|
||||
} else {
|
||||
$this->context = $context;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user