Commit b1a9804a authored by Pau Ferrer's avatar Pau Ferrer
Browse files

MDL-52263 libraries: Add test cases to external_format_text options

parent 19a131ed
...@@ -836,7 +836,7 @@ function external_format_text($text, $textformat, $contextid, $component, $filea ...@@ -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 context is passed in options, check that is the same to show a debug message.
if (isset($options['context'])) { if (isset($options['context'])) {
if ((is_object($options['context']) && $options['context']->id != $contextid) 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. debugging('Different contexts found in external_format_text parameters. $options[\'context\'] not allowed.
Using $contextid parameter...', DEBUG_DEVELOPER); Using $contextid parameter...', DEBUG_DEVELOPER);
} }
......
...@@ -96,6 +96,40 @@ class core_externallib_testcase extends advanced_testcase { ...@@ -96,6 +96,40 @@ class core_externallib_testcase extends advanced_testcase {
</span></span>', FORMAT_HTML); </span></span>', FORMAT_HTML);
$this->assertSame(external_format_text($test, $testformat, $context->id, 'core', '', 0), $correct); $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_raw($currentraw);
$settings->set_filter($currentfilter); $settings->set_filter($currentfilter);
} }
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment