Skip to content

Commit eacb460

Browse files
authored
Merge pull request #276 from vuvanhieu143/wip938666
Make upgrade prototype only run when upgrade. Add prototype creation into unit test.
2 parents 6fd2502 + edb5629 commit eacb460

12 files changed

+99
-13
lines changed

db/upgradelib.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,9 @@ function update_question_types() {
8686
function update_question_types_internal() {
8787
mtrace("Setting up CodeRunner question prototypes...");
8888
$result = false;
89+
if (PHPUNIT_TEST) {
90+
return $result;
91+
}
8992
try {
9093
if (qtype_coderunner_util::using_mod_qbank()) {
9194
$result = update_question_types_with_qbank();

tests/graphui_save_test.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ class graphui_save_test extends \qtype_coderunner_testcase {
4040
protected $qtype;
4141

4242
protected function setUp(): void {
43+
parent::setUp();
4344
$this->resetAfterTest(true);
4445
$this->qtype = new \qtype_coderunner();
4546
}

tests/penaltyregime_test.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
require_once($CFG->dirroot . '/question/engine/tests/helpers.php');
3333
require_once($CFG->dirroot . '/question/type/coderunner/tests/test.php');
3434
require_once($CFG->dirroot . '/question/type/coderunner/tests/helper.php');
35-
35+
require_once($CFG->dirroot . '/question/type/coderunner/tests/walkthrough_testbase.php');
3636
/**
3737
* More extensive testing of penalty regime.
3838
*
@@ -41,7 +41,7 @@
4141
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
4242
*/
4343

44-
class penaltyregime_test extends \qbehaviour_walkthrough_test_base {
44+
class penaltyregime_test extends walkthrough_testbase {
4545
protected function setUp(): void {
4646
parent::setUp();
4747
\qtype_coderunner_testcase::setup_test_sandbox_configuration();

tests/precheckwalkthrough_test.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,13 +32,14 @@
3232
require_once($CFG->dirroot . '/question/engine/tests/helpers.php');
3333
require_once($CFG->dirroot . '/question/type/coderunner/tests/test.php');
3434
require_once($CFG->dirroot . '/question/type/coderunner/question.php');
35+
require_once($CFG->dirroot . '/question/type/coderunner/tests/walkthrough_testbase.php');
3536

3637
use qtype_coderunner\constants;
3738

3839
/**
3940
* @coversNothing
4041
*/
41-
class precheckwalkthrough_test extends \qbehaviour_walkthrough_test_base {
42+
class precheckwalkthrough_test extends walkthrough_testbase {
4243
protected function setUp(): void {
4344
parent::setUp();
4445
\qtype_coderunner_testcase::setup_test_sandbox_configuration();

tests/test.php

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
global $CFG;
3030
require_once($CFG->dirroot . '/question/engine/tests/helpers.php');
3131
require_once($CFG->dirroot . '/question/type/coderunner/question.php');
32-
32+
require_once($CFG->dirroot . '/question/type/coderunner/db/upgradelib.php');
3333
/**
3434
* @coversNothing
3535
*/
@@ -39,11 +39,22 @@ class qtype_coderunner_testcase extends advanced_testcase {
3939
/** @var stdClass Holds question category.*/
4040
protected $category;
4141

42+
protected static bool $prototypesinstalled = false;
43+
4244
protected function setUp(): void {
4345
parent::setUp();
4446
self::setup_test_sandbox_configuration();
45-
$this->resetAfterTest(false);
47+
$this->resetAfterTest(true);
4648
$this->setAdminUser();
49+
ob_start();
50+
if (!self::$prototypesinstalled) {
51+
if (\qtype_coderunner_util::using_mod_qbank()) {
52+
update_question_types_with_qbank();
53+
} else {
54+
update_question_types_legacy();
55+
}
56+
}
57+
ob_end_clean();
4758
$generator = $this->getDataGenerator()->get_plugin_generator('core_question');
4859
$this->category = $generator->create_question_category([]);
4960
}

tests/walkthrough_combinator_grader_test.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
global $CFG;
3333
require_once($CFG->dirroot . '/question/engine/tests/helpers.php');
3434
require_once($CFG->dirroot . '/question/type/coderunner/tests/test.php');
35+
require_once($CFG->dirroot . '/question/type/coderunner/tests/walkthrough_testbase.php');
3536

3637
/**
3738
* Unit tests for the coderunner question type.
@@ -40,7 +41,7 @@
4041
* @copyright 2011, 2020 The Open University
4142
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
4243
*/
43-
class walkthrough_combinator_grader_test extends \qbehaviour_walkthrough_test_base {
44+
class walkthrough_combinator_grader_test extends walkthrough_testbase {
4445
protected function setUp(): void {
4546
global $CFG;
4647
parent::setUp();

tests/walkthrough_display_feedback_test.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
require_once($CFG->dirroot . '/question/engine/tests/helpers.php');
2323
require_once($CFG->dirroot . '/question/type/coderunner/tests/test.php');
2424
require_once($CFG->dirroot . '/question/type/coderunner/question.php');
25-
25+
require_once($CFG->dirroot . '/question/type/coderunner/tests/walkthrough_testbase.php');
2626

2727
/**
2828
* Use a walkthrough test to validate the new (2019) display-feedback options.
@@ -33,7 +33,7 @@
3333
* @copyright 2019 Richard Lobb, The University of Canterbury
3434
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
3535
*/
36-
class walkthrough_display_feedback_test extends \qbehaviour_walkthrough_test_base {
36+
class walkthrough_display_feedback_test extends walkthrough_testbase {
3737
protected function setUp(): void {
3838
parent::setUp();
3939
\qtype_coderunner_testcase::setup_test_sandbox_configuration();

tests/walkthrough_extras_test.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
require_once($CFG->dirroot . '/question/engine/tests/helpers.php');
2525
require_once($CFG->dirroot . '/question/type/coderunner/tests/test.php');
2626
require_once($CFG->dirroot . '/question/type/coderunner/question.php');
27+
require_once($CFG->dirroot . '/question/type/coderunner/tests/walkthrough_testbase.php');
2728

2829
define('PRELOAD_TEST', "# TEST COMMENT TO CHECK PRELOAD IS WORKING\n");
2930

@@ -38,7 +39,7 @@
3839
* @copyright 2012, 2014 Richard Lobb, The University of Canterbury
3940
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
4041
*/
41-
class walkthrough_extras_test extends \qbehaviour_walkthrough_test_base {
42+
class walkthrough_extras_test extends walkthrough_testbase {
4243
protected function setUp(): void {
4344
parent::setUp();
4445
\qtype_coderunner_testcase::setup_test_sandbox_configuration();

tests/walkthrough_multilang_test.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
require_once($CFG->dirroot . '/question/engine/tests/helpers.php');
2525
require_once($CFG->dirroot . '/question/type/coderunner/tests/test.php');
2626
require_once($CFG->dirroot . '/question/type/coderunner/question.php');
27-
27+
require_once($CFG->dirroot . '/question/type/coderunner/tests/walkthrough_testbase.php');
2828

2929
/**
3030
* A walkthrough of a simple multilanguage question that asks for a program
@@ -37,7 +37,7 @@
3737
* @copyright 2018 Richard Lobb, The University of Canterbury
3838
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
3939
*/
40-
class walkthrough_multilang_test extends \qbehaviour_walkthrough_test_base {
40+
class walkthrough_multilang_test extends walkthrough_testbase {
4141
protected function setUp(): void {
4242
parent::setUp();
4343
\qtype_coderunner_testcase::setup_test_sandbox_configuration();

tests/walkthrough_randomisation_test.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
require_once($CFG->dirroot . '/question/engine/tests/helpers.php');
2323
require_once($CFG->dirroot . '/question/type/coderunner/tests/test.php');
2424
require_once($CFG->dirroot . '/question/type/coderunner/question.php');
25+
require_once($CFG->dirroot . '/question/type/coderunner/tests/walkthrough_testbase.php');
2526

2627
/**
2728
* Further walkthrough tests for the CodeRunner plugin, testing the
@@ -33,7 +34,7 @@
3334
* @copyright 2018 Richard Lobb, The University of Canterbury
3435
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
3536
*/
36-
class walkthrough_randomisation_test extends \qbehaviour_walkthrough_test_base {
37+
class walkthrough_randomisation_test extends walkthrough_testbase {
3738
protected function setUp(): void {
3839
parent::setUp();
3940
\qtype_coderunner_testcase::setup_test_sandbox_configuration();

0 commit comments

Comments
 (0)