2023-04-25 13:13:40 +02:00

66 lines
2.0 KiB
PHP
Executable File

<?php
class HTMLPurifier_Injector_LinkifyTest extends HTMLPurifier_InjectorHarness
{
public function setup()
{
parent::setup();
$this->config->set('AutoFormat.Linkify', true);
}
public function testLinkifyURLInRootNode()
{
$this->assertResult(
'https://example.com',
'<a href="https://example.com">https://example.com</a>'
);
}
public function testLinkifyURLInInlineNode()
{
$this->assertResult(
'<b>https://example.com</b>',
'<b><a href="https://example.com">https://example.com</a></b>'
);
}
public function testBasicUsageCase()
{
$this->assertResult(
'This URL https://example.com is what you need',
'This URL <a href="https://example.com">https://example.com</a> is what you need'
);
}
public function testIgnoreURLInATag()
{
$this->assertResult(
'<a>https://example.com/</a>'
);
}
public function testNeeded()
{
$this->config->set('HTML.Allowed', 'b');
$this->expectError('Cannot enable Linkify injector because a is not allowed');
$this->assertResult('https://example.com/');
}
public function testExcludes()
{
$this->assertResult('<a><span>https://example.com</span></a>');
}
public function testRegexIsSmart()
{
$this->assertResult('https://example.com/foo.', '<a href="https://example.com/foo">https://example.com/foo</a>.');
$this->assertResult('“https://example.com/foo”', '“<a href="https://example.com/foo">https://example.com/foo</a>”');
$this->assertResult('“https://example.com”', '“<a href="https://example.com">https://example.com</a>”');
$this->assertResult('(https://example.com/f(o)o)', '(<a href="https://example.com/f(o)o">https://example.com/f(o)o</a>)');
}
}
// vim: et sw=4 sts=4