diff --git a/h5p/tests/editor_test.php b/h5p/tests/editor_test.php index d8d69b657f27..fb007bfc1c5c 100644 --- a/h5p/tests/editor_test.php +++ b/h5p/tests/editor_test.php @@ -27,15 +27,11 @@ defined('MOODLE_INTERNAL') || die(); -global $CFG; - use advanced_testcase; use core_h5p\local\library\autoloader; use MoodleQuickForm; use page_requirements_manager; -require_once($CFG->libdir . '/formslib.php'); - /** * * Test class covering the editor class. @@ -48,6 +44,34 @@ */ class editor_testcase extends advanced_testcase { + /** + * Form object to be used in test case. + */ + protected function get_test_form() { + global $CFG; + + require_once($CFG->libdir . '/formslib.php'); + + return new class extends \moodleform { + /** + * Form definition. + */ + public function definition(): void { + // No definition required. + } + + /** + * Returns form reference. + * + * @return MoodleQuickForm + */ + public function getform() { + $mform = $this->_form; + return $mform; + } + }; + } + /** * Test that existing content is properly set. */ @@ -159,7 +183,7 @@ public function test_add_editor_to_form() { global $PAGE, $CFG; // Get form data. - $form = new temp_form(); + $form = $this->get_test_form(); $mform = $form->getform(); // Call method. @@ -255,27 +279,3 @@ public function test_save_content() { $this->assertNotEmpty($out); } } - -/** - * Form object to be used in test case. - */ -class temp_form extends \moodleform { - /** - * Form definition. - */ - public function definition(): void { - // No definition required. - } - - /** - * Returns form reference. - * - * @return MoodleQuickForm - */ - public function getform() { - $mform = $this->_form; - // Set submitted flag, to simulate submission. - $mform->_flagSubmitted = true; - return $mform; - } -}