Skip to content

Commit

Permalink
Add namespace to editform_test
Browse files Browse the repository at this point in the history
  • Loading branch information
ScottVerbeek committed Jan 15, 2024
1 parent ef45d4f commit d415cce
Showing 1 changed file with 20 additions and 18 deletions.
38 changes: 20 additions & 18 deletions tests/editform_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.

namespace qtype_stack;

defined('MOODLE_INTERNAL') || die();

global $CFG;
Expand All @@ -29,32 +31,32 @@
* @group qtype_stack
* @covers \qtype_stack_edit_form
*/
class editform_test extends qtype_stack_edit_form {
class editform_test extends \qtype_stack_edit_form {

public function __construct($questiontext, $specificfeedback) {
global $USER;
$syscontext = context_system::instance();
$syscontext = \context_system::instance();
$category = question_make_default_categories(array($syscontext));
$fakequestion = new stdClass();
$fakequestion = new \stdClass();
$fakequestion->qtype = 'stack';
$fakequestion->category = $category->id;
$fakequestion->contextid = $syscontext->id;
$fakequestion->createdby = $USER->id;
$fakequestion->modifiedby = $USER->id;
$fakequestion->questiontext = $questiontext;
$fakequestion->options = new stdClass();
$fakequestion->options = new \stdClass();
$fakequestion->options->specificfeedback = $specificfeedback;
$fakequestion->formoptions = new stdClass();
$fakequestion->formoptions = new \stdClass();
$fakequestion->formoptions->movecontext = null;
$fakequestion->formoptions->repeatelements = true;
$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($syscontext);
} else {
$contexts = new question_edit_contexts($syscontext);
$contexts = new \question_edit_contexts($syscontext);
}
parent::__construct(new moodle_url('/'), $fakequestion, $category, $contexts);
parent::__construct(new \moodle_url('/'), $fakequestion, $category, $contexts);
}

}
Expand All @@ -67,31 +69,31 @@ public function __construct($questiontext, $specificfeedback) {
* @group qtype_stack
* @covers \qtype_stack_edit_form
*/
class qtype_stack_edit_form_test extends advanced_testcase {
class qtype_stack_edit_form_test extends \advanced_testcase {

protected function get_form($questiontext, $specificfeedback) {
$this->setAdminUser();
$this->resetAfterTest();

return new qtype_stack_edit_form_testable($questiontext, $specificfeedback);
return new \qtype_stack_edit_form_testable($questiontext, $specificfeedback);
}

public function test_get_input_names_from_question_text_default() {
$form = $this->get_form(qtype_stack_edit_form::DEFAULT_QUESTION_TEXT,
qtype_stack_edit_form::DEFAULT_SPECIFIC_FEEDBACK);
$qtype = new qtype_stack();
$form = $this->get_form(\qtype_stack_edit_form::DEFAULT_QUESTION_TEXT,
\qtype_stack_edit_form::DEFAULT_SPECIFIC_FEEDBACK);
$qtype = new \qtype_stack();

$this->assertEquals(array('ans1' => array(1, 1)),
$qtype->get_input_names_from_question_text(qtype_stack_edit_form::DEFAULT_QUESTION_TEXT));
$qtype->get_input_names_from_question_text(\qtype_stack_edit_form::DEFAULT_QUESTION_TEXT));
}

public function test_get_prt_names_from_question_default() {
$form = $this->get_form(qtype_stack_edit_form::DEFAULT_QUESTION_TEXT,
qtype_stack_edit_form::DEFAULT_SPECIFIC_FEEDBACK);
$qtype = new qtype_stack();
$form = $this->get_form(\qtype_stack_edit_form::DEFAULT_QUESTION_TEXT,
\qtype_stack_edit_form::DEFAULT_SPECIFIC_FEEDBACK);
$qtype = new \qtype_stack();

$this->assertEquals(array('prt1' => 1),
$qtype->get_prt_names_from_question(qtype_stack_edit_form::DEFAULT_QUESTION_TEXT,
qtype_stack_edit_form::DEFAULT_SPECIFIC_FEEDBACK));
$qtype->get_prt_names_from_question(\qtype_stack_edit_form::DEFAULT_QUESTION_TEXT,
\qtype_stack_edit_form::DEFAULT_SPECIFIC_FEEDBACK));
}
}

0 comments on commit d415cce

Please sign in to comment.