Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
M
moodle-qtype_stack
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
elc
moodle-qtype_stack
Commits
08d73d1c
Commit
08d73d1c
authored
6 months ago
by
Chris Sangwin
Browse files
Options
Downloads
Patches
Plain Diff
Copy over editform_test.php to fix CI in latest moodle (main). Part of
7d530484
.
parent
a32dac2e
No related branches found
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
tests/editform_test.php
+42
-17
42 additions, 17 deletions
tests/editform_test.php
with
42 additions
and
17 deletions
tests/editform_test.php
+
42
−
17
View file @
08d73d1c
...
...
@@ -14,6 +14,14 @@
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* Subclass of qtype_stack_edit_form_testable that is easier to use in unit tests.
*
* @package qtype_stack
* @copyright 2012 The Open University.
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later.
*/
namespace
qtype_stack
;
defined
(
'MOODLE_INTERNAL'
)
||
die
();
...
...
@@ -22,25 +30,34 @@ global $CFG;
require_once
(
$CFG
->
dirroot
.
'/question/engine/tests/helpers.php'
);
require_once
(
__DIR__
.
'/../edit_stack_form.php'
);
// Subclass of qtype_stack_edit_form_testable that is easier to use in unit tests.
//
// @copyright 2012 The Open University.
// @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later.
/**
* Subclass of qtype_stack_edit_form_testable that is easier to use in unit tests.
* @group qtype_stack
* @covers \qtype_stack_edit_form
*/
class
editform_test_class
extends
\qtype_stack_edit_form
{
final
class
editform_test_class
extends
\qtype_stack_edit_form
{
public
function
__construct
(
$questiontext
,
$specificfeedback
)
{
// phpcs:ignore moodle.Commenting.MissingDocblock.MissingTestcaseMethodDescription
public
function
__construct
(
$questiontext
,
$specificfeedback
,
$quizmoduleid
)
{
global
$USER
;
$syscontext
=
\context_system
::
instance
();
$category
=
question_make_default_categories
([
$syscontext
]);
// ISS1325 - Use quiz context rather than system context as
// question categories only allowed in modules from Moodle 5.
$quizcontext
=
\context_module
::
instance
(
$quizmoduleid
);
if
(
function_exists
(
'question_get_default_category'
))
{
// This function exists from Moodle 4.5 onwards but the second parameter
// which creates the category if it doesn't exist is 5.0 onwards.
$category
=
question_get_default_category
(
$quizcontext
->
id
,
true
);
if
(
!
$category
)
{
$category
=
$category
=
question_make_default_categories
([
$quizcontext
]);
}
}
else
{
// Deprecated from 5.0.
$category
=
$category
=
question_make_default_categories
([
$quizcontext
]);
}
$fakequestion
=
new
\stdClass
();
$fakequestion
->
qtype
=
'stack'
;
$fakequestion
->
category
=
$category
->
id
;
$fakequestion
->
contextid
=
$
sys
context
->
id
;
$fakequestion
->
contextid
=
$
quiz
context
->
id
;
$fakequestion
->
createdby
=
$USER
->
id
;
$fakequestion
->
modifiedby
=
$USER
->
id
;
$fakequestion
->
questiontext
=
$questiontext
;
...
...
@@ -52,9 +69,9 @@ class editform_test_class extends \qtype_stack_edit_form {
$fakequestion
->
inputs
=
null
;
// Support both Moodle 4.x and 3.x.
if
(
class_exists
(
'\core_question\local\bank\question_edit_contexts'
))
{
$contexts
=
new
\core_question\local\bank\question_edit_contexts
(
$
sys
context
);
$contexts
=
new
\core_question\local\bank\question_edit_contexts
(
$
quiz
context
);
}
else
{
$contexts
=
new
\question_edit_contexts
(
$
sys
context
);
$contexts
=
new
\question_edit_contexts
(
$
quiz
context
);
}
parent
::
__construct
(
new
\moodle_url
(
'/'
),
$fakequestion
,
$category
,
$contexts
);
}
...
...
@@ -64,21 +81,28 @@ class editform_test_class extends \qtype_stack_edit_form {
/**
* Unit tests for Stack question editing form.
*
* @package qtype_stack
* @copyright 2012 The Open University
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
* @group qtype_stack
* @covers \qtype_stack_edit_form
*/
class
editform_test
extends
\advanced_testcase
{
final
class
editform_test
extends
\advanced_testcase
{
// phpcs:ignore moodle.Commenting.MissingDocblock.MissingTestcaseMethodDescription
protected
function
get_form
(
$questiontext
,
$specificfeedback
)
{
$this
->
setAdminUser
();
$this
->
resetAfterTest
();
return
new
editform_test_class
(
$questiontext
,
$specificfeedback
);
$quizgenerator
=
self
::
getDataGenerator
()
->
get_plugin_generator
(
'mod_quiz'
);
$site
=
get_site
();
// Add a quiz to the site course.
$quiz
=
$quizgenerator
->
create_instance
([
'course'
=>
$site
->
id
,
'grade'
=>
100.0
,
'sumgrades'
=>
2
,
'layout'
=>
'1,0'
]);
$quizmoduleid
=
$quiz
->
cmid
;
return
new
editform_test_class
(
$questiontext
,
$specificfeedback
,
$quizmoduleid
);
}
public
function
test_get_input_names_from_question_text_default
()
{
public
function
test_get_input_names_from_question_text_default
():
void
{
$form
=
$this
->
get_form
(
\qtype_stack_edit_form
::
DEFAULT_QUESTION_TEXT
,
\qtype_stack_edit_form
::
DEFAULT_SPECIFIC_FEEDBACK
);
$qtype
=
new
\qtype_stack
();
...
...
@@ -87,7 +111,8 @@ class editform_test extends \advanced_testcase {
$qtype
->
get_input_names_from_question_text
(
\qtype_stack_edit_form
::
DEFAULT_QUESTION_TEXT
));
}
public
function
test_get_prt_names_from_question_default
()
{
public
function
test_get_prt_names_from_question_default
():
void
{
$form
=
$this
->
get_form
(
\qtype_stack_edit_form
::
DEFAULT_QUESTION_TEXT
,
\qtype_stack_edit_form
::
DEFAULT_SPECIFIC_FEEDBACK
);
$qtype
=
new
\qtype_stack
();
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment