Skip to content

Commit

Permalink
MDL-52263 libraries: Add test cases to external_format_text options
Browse files Browse the repository at this point in the history
  • Loading branch information
crazyserver committed Apr 12, 2016
1 parent 19a131e commit b1a9804
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/externallib.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
34 changes: 34 additions & 0 deletions lib/tests/externallib_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,40 @@ public function test_external_format_text() {
</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);
}
Expand Down

0 comments on commit b1a9804

Please sign in to comment.