Merge branch 'MDL-68473-master' of git://github.com/vmdef/moodle
authorAndrew Nicols <andrew@nicols.co.uk>
Sun, 3 May 2020 11:59:46 +0000 (19:59 +0800)
committerAndrew Nicols <andrew@nicols.co.uk>
Sun, 3 May 2020 11:59:46 +0000 (19:59 +0800)
h5p/tests/editor_test.php

index 05f5877..fb007bf 100644 (file)
  * @copyright  2020 Victor Deniz <victor@moodle.com>
  * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  */
+
 namespace core_h5p;
 
+defined('MOODLE_INTERNAL') || die();
+
 use advanced_testcase;
 use core_h5p\local\library\autoloader;
-use moodleform;
 use MoodleQuickForm;
 use page_requirements_manager;
 
@@ -42,6 +44,34 @@ use page_requirements_manager;
  */
 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.
      */
@@ -153,7 +183,7 @@ class editor_testcase extends advanced_testcase {
         global $PAGE, $CFG;
 
         // Get form data.
-        $form = new temp_form();
+        $form = $this->get_test_form();
         $mform = $form->getform();
 
         // Call method.
@@ -249,27 +279,3 @@ class editor_testcase extends advanced_testcase {
         $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;
-    }
-}