MDL-52263 libraries: Add test cases to external_format_text options

This commit is contained in:
Pau Ferrer Ocaña 2016-04-12 14:36:07 +02:00
parent 19a131edff
commit b1a9804a9b
2 changed files with 35 additions and 1 deletions

View File

@ -836,7 +836,7 @@ function external_format_text($text, $textformat, $contextid, $component, $filea
// If context is passed in options, check that is the same to show a debug message.
if (isset($options['context'])) {
if ((is_object($options['context']) && $options['context']->id != $contextid)
|| $options['context'] != $contextid) {
|| (!is_object($options['context']) && $options['context'] != $contextid)) {
debugging('Different contexts found in external_format_text parameters. $options[\'context\'] not allowed.
Using $contextid parameter...', DEBUG_DEVELOPER);
}

View File

@ -96,6 +96,40 @@ class core_externallib_testcase extends advanced_testcase {
</span></span>', FORMAT_HTML);
$this->assertSame(external_format_text($test, $testformat, $context->id, 'core', '', 0), $correct);
$test = '<p><a id="test"></a><a href="#test">Text</a></p>';
$testformat = FORMAT_HTML;
$correct = array($test, FORMAT_HTML);
$options = array('allowid' => true);
$this->assertSame(external_format_text($test, $testformat, $context->id, 'core', '', 0, $options), $correct);
$test = '<p><a id="test"></a><a href="#test">Text</a></p>';
$testformat = FORMAT_HTML;
$correct = array('<p><a></a><a href="#test">Text</a></p>', FORMAT_HTML);
$options = new StdClass();
$options->allowid = false;
$this->assertSame(external_format_text($test, $testformat, $context->id, 'core', '', 0, $options), $correct);
$test = '<p><a id="test"></a><a href="#test">Text</a></p>'."\n".'Newline';
$testformat = FORMAT_MOODLE;
$correct = array('<p><a id="test"></a><a href="#test">Text</a></p> Newline', FORMAT_HTML);
$options = new StdClass();
$options->newlines = false;
$this->assertSame(external_format_text($test, $testformat, $context->id, 'core', '', 0, $options), $correct);
$test = '<p><a id="test"></a><a href="#test">Text</a></p>';
$testformat = FORMAT_MOODLE;
$correct = array('<div class="text_to_html">'.$test.'</div>', FORMAT_HTML);
$options = new StdClass();
$options->para = true;
$this->assertSame(external_format_text($test, $testformat, $context->id, 'core', '', 0, $options), $correct);
$test = '<p><a id="test"></a><a href="#test">Text</a></p>';
$testformat = FORMAT_MOODLE;
$correct = array($test, FORMAT_HTML);
$options = new StdClass();
$options->context = $context;
$this->assertSame(external_format_text($test, $testformat, $context->id, 'core', '', 0, $options), $correct);
$settings->set_raw($currentraw);
$settings->set_filter($currentfilter);
}