Skip to content

Commit

Permalink
MDL-68473 core_h5p: moved fixture to anonymous class
Browse files Browse the repository at this point in the history
  • Loading branch information
vmdef committed May 1, 2020
1 parent e4127c9 commit a8455b7
Showing 1 changed file with 29 additions and 29 deletions.
58 changes: 29 additions & 29 deletions h5p/tests/editor_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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.
*/
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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;
}
}

0 comments on commit a8455b7

Please sign in to comment.