*/ require_once 'tests/unit/fakeserver.php'; require_once 'lib/classes/htmlpurifier/HTMLPurifier_Injector_ClassifyLinks.php'; /** * Test case for HTMLPurifier_Injector_ClassifyLinks. */ class HTMLPurifier_Injector_ClassifyLinksTest extends \Codeception\Test\Unit { public function setUp(): void { $config = new Config([ 'CONVERT_IDNA_URL' => false, ]); Config::set($config); } /** * @dataProvider dataProvider */ public function testClassifyLinks($uri, $domains, $in, $out) { # create purifier $config = \HTMLPurifier_Config::createDefault(); $config->set('AutoFormat.Custom', ['ClassifyLinks']); $config->set('Cache.DefinitionImpl', null); $purifier = new \HTMLPurifier($config); # run test fakeServer($uri, $domains); $this->assertEquals($out, $purifier->purify($in)); } /** * Data provider for testClassifyLinks. */ public function dataProvider() { // domains of faked Stud.IP server $domains = [ 'org' => 'example.org/studip', 'home' => 'example.org/~home', 'net' => 'example.net/studip', ]; // return absolute URL for a path on one of the faked domains $url = function ($domainKey, $path) use (&$domains) { return 'http://' . $domains[$domainKey] . '/' . $path; }; $a = function ($url, $className, $content) { $href = ' href="' . $url . '"'; $class = empty($className) ? '' : ' class="' . $className . '"'; return '' . $content . ''; }; // class names for internal and external links $in = 'link-intern'; $ex = 'link-extern'; // return test data return [ [ $url('org', 'index.php'), $domains, $a('http://www.google.de', '', 'Google'), $a('http://www.google.de', $ex, 'Google') ], [ $url('org', 'index.php'), $domains, $a($url('org', 'index.php'), '', 'Main Page'), $a($url('org', 'index.php'), $in, 'Main Page') ], [ $url('org', 'index.php'), $domains, $a($url('home', 'index.php'), '', 'Main Page'), $a($url('home', 'index.php'), $in, 'Main Page') ], [ $url('org', 'index.php'), $domains, $a($url('net', 'index.php'), '', 'Main Page'), $a($url('net', 'index.php'), $in, 'Main Page') ], ]; } public function tearDown(): void { Config::set(null); } }