no filters
xx"; $this->assertSame('
xx
def
hij
defefghij
abc
abc"; $this->assertTrue(is_purify_html_necessary($text)); } public function test_allowed_schemes() { // First standard schemas. $text = 'link'; $this->assertSame($text, purify_html($text)); $text = 'link'; $this->assertSame($text, purify_html($text)); $text = 'link'; $this->assertSame($text, purify_html($text)); $text = 'link'; $this->assertSame($text, purify_html($text)); $text = 'link'; $this->assertSame($text, purify_html($text)); $text = 'link'; $this->assertSame($text, purify_html($text)); // Extra schemes allowed in moodle. $text = 'link'; $this->assertSame($text, purify_html($text)); $text = 'link'; $this->assertSame($text, purify_html($text)); $text = 'link'; $this->assertSame($text, purify_html($text)); $text = 'link'; $this->assertSame($text, purify_html($text)); $text = 'link'; $this->assertSame($text, purify_html($text)); $text = 'link'; $this->assertSame($text, purify_html($text)); // Now some borked or dangerous schemes. $text = 'link'; $this->assertSame('link', purify_html($text)); $text = 'link'; $this->assertSame('link', purify_html($text)); } /** * Test non-ascii domain names */ public function test_idn() { // Example of domain that gives the same result in IDNA2003 and IDNA2008 . $text = 'правительство.рф'; $expected = 'правительство.рф'; $this->assertSame($expected, purify_html($text)); // Examples of deviations from http://www.unicode.org/reports/tr46/#Table_Deviation_Characters . $text = 'teßt.de'; $expected = 'teßt.de'; $this->assertSame($expected, purify_html($text)); $text = 'http://βόλος.com'; $expected = 'http://βόλος.com'; $this->assertSame($expected, purify_html($text)); $text = 'http://نامهای.com'; $expected = 'http://نامهای.com'; $this->assertSame($expected, purify_html($text)); } /** * Tests media tags. * * @dataProvider media_tags_provider * @param string $mediatag HTML media tag * @param string $expected expected result */ public function test_media_tags($mediatag, $expected) { $actual = format_text($mediatag, FORMAT_MOODLE, ['filter' => false]); $this->assertEquals($expected, $actual); } /** * Test cases for the test_media_tags test. */ public function media_tags_provider() { // Takes an array of attributes, then generates a test for each of them. $generatetestcases = function($prefix, array $attrs, array $templates) { return array_reduce($attrs, function($carry, $attr) use ($prefix, $templates) { $testcase = [$prefix . '/' . $attr => [ sprintf($templates[0], $attr), sprintf($templates[1], $attr) ]]; return empty(array_values($carry)[0]) ? $testcase : $carry + $testcase; }, [[]]); }; $audioattrs = [ 'preload="auto"', 'autoplay=""', 'loop=""', 'muted=""', 'controls=""', 'crossorigin="anonymous"', 'crossorigin="use-credentials"' ]; $videoattrs = [ 'crossorigin="anonymous"', 'crossorigin="use-credentials"', 'poster="https://upload.wikimedia.org/wikipedia/en/1/14/Space_jam.jpg"', 'preload="auto"', 'autoplay=""', 'playsinline=""', 'loop=""', 'muted=""', 'controls=""', 'width="420"', 'height="69"' ]; return $generatetestcases('Plain audio', $audioattrs + ['src="http://example.com/jam.wav"'], [ 'Looks like you can\'t slam the jams.', '