diff --git a/mod/workshop/allocation/random/tests/allocator_test.php b/mod/workshop/allocation/random/tests/allocator_test.php index 8a53e6e25bf..07327f5e20c 100644 --- a/mod/workshop/allocation/random/tests/allocator_test.php +++ b/mod/workshop/allocation/random/tests/allocator_test.php @@ -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() { diff --git a/mod/workshop/eval/best/tests/lib_test.php b/mod/workshop/eval/best/tests/lib_test.php index edcb30820e7..a11f5bb394a 100644 --- a/mod/workshop/eval/best/tests/lib_test.php +++ b/mod/workshop/eval/best/tests/lib_test.php @@ -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); } diff --git a/mod/workshop/form/accumulative/tests/lib_test.php b/mod/workshop/form/accumulative/tests/lib_test.php index 8bd011fbfd2..97a52ff89a6 100644 --- a/mod/workshop/form/accumulative/tests/lib_test.php +++ b/mod/workshop/form/accumulative/tests/lib_test.php @@ -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); } diff --git a/mod/workshop/form/numerrors/tests/lib_test.php b/mod/workshop/form/numerrors/tests/lib_test.php index 4eb1f745a00..d350b55dc8f 100644 --- a/mod/workshop/form/numerrors/tests/lib_test.php +++ b/mod/workshop/form/numerrors/tests/lib_test.php @@ -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); } diff --git a/mod/workshop/form/rubric/tests/lib_test.php b/mod/workshop/form/rubric/tests/lib_test.php index bf1195f3d15..adb8d663b1c 100644 --- a/mod/workshop/form/rubric/tests/lib_test.php +++ b/mod/workshop/form/rubric/tests/lib_test.php @@ -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 diff --git a/mod/workshop/locallib.php b/mod/workshop/locallib.php index bc352957419..c1e5ed6f769 100644 --- a/mod/workshop/locallib.php +++ b/mod/workshop/locallib.php @@ -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; } }