My favorite sites are https://www.colinodell.com and https://commonmark.thephpleague.com
' . "\n"; + $expected = 'My favorite sites are https://www.colinodell.com and https://commonmark.thephpleague.com
'; $this->assertEquals($expected, $this->parse(self::INPUT)); } public function testCustomConfiguration() { - $expected = 'My favorite sites are https://www.colinodell.com and https://commonmark.thephpleague.com
' . "\n"; + $expected = 'My favorite sites are https://www.colinodell.com and https://commonmark.thephpleague.com
'; $config = [ 'external_link' => [ @@ -47,7 +47,7 @@ public function testWithBadUrls() { $input = 'Report [xss](javascript:alert(0);) vulnerabilities by emailingReport xss vulnerabilities by emailing colinodell@gmail.com
' . "\n"; + $expected = 'Report xss vulnerabilities by emailing colinodell@gmail.com
'; $this->assertEquals($expected, $this->parse($input)); } @@ -59,7 +59,7 @@ private function parse(string $markdown, array $config = []) $c = new CommonMarkConverter($config, $e); - return $c->convertToHtml($markdown); + return \rtrim($c->convertToHtml($markdown)); } /** @@ -91,4 +91,94 @@ public function dataProviderForTestHostMatches() // You can even mix-and-match multiple strings with multiple regexes yield ['www.colinodell.com', ['/colinodell\.com/', 'aol.com'], true]; } + + /** + * @param string $nofollow + * @param string $noopener + * @param string $noreferrer + * @param string $expectedOutput + * + * @dataProvider dataProviderForTestRelOptions + */ + public function testRelOptions(string $nofollow, string $noopener, string $noreferrer, string $expectedOutput): void + { + $config = [ + 'external_link' => [ + 'nofollow' => $nofollow, + 'noopener' => $noopener, + 'noreferrer' => $noreferrer, + 'internal_hosts' => ['commonmark.thephpleague.com'], + ], + ]; + + $this->assertEquals($expectedOutput, $this->parse(self::INPUT, $config)); + } + + public function dataProviderForTestRelOptions(): iterable + { + yield ['', '', '', 'My favorite sites are https://www.colinodell.com and https://commonmark.thephpleague.com
']; + yield ['', '', 'all', 'My favorite sites are https://www.colinodell.com and https://commonmark.thephpleague.com
']; + yield ['', '', 'external', 'My favorite sites are https://www.colinodell.com and https://commonmark.thephpleague.com
']; + yield ['', '', 'internal', 'My favorite sites are https://www.colinodell.com and https://commonmark.thephpleague.com
']; + yield ['', 'all', '', 'My favorite sites are https://www.colinodell.com and https://commonmark.thephpleague.com
']; + yield ['', 'all', 'all', 'My favorite sites are https://www.colinodell.com and https://commonmark.thephpleague.com
']; + yield ['', 'all', 'external', 'My favorite sites are https://www.colinodell.com and https://commonmark.thephpleague.com
']; + yield ['', 'all', 'internal', 'My favorite sites are https://www.colinodell.com and https://commonmark.thephpleague.com
']; + yield ['', 'external', '', 'My favorite sites are https://www.colinodell.com and https://commonmark.thephpleague.com
']; + yield ['', 'external', 'all', 'My favorite sites are https://www.colinodell.com and https://commonmark.thephpleague.com
']; + yield ['', 'external', 'external', 'My favorite sites are https://www.colinodell.com and https://commonmark.thephpleague.com
']; + yield ['', 'external', 'internal', 'My favorite sites are https://www.colinodell.com and https://commonmark.thephpleague.com
']; + yield ['', 'internal', '', 'My favorite sites are https://www.colinodell.com and https://commonmark.thephpleague.com
']; + yield ['', 'internal', 'all', 'My favorite sites are https://www.colinodell.com and https://commonmark.thephpleague.com
']; + yield ['', 'internal', 'external', 'My favorite sites are https://www.colinodell.com and https://commonmark.thephpleague.com
']; + yield ['', 'internal', 'internal', 'My favorite sites are https://www.colinodell.com and https://commonmark.thephpleague.com
']; + yield ['all', '', '', 'My favorite sites are https://www.colinodell.com and https://commonmark.thephpleague.com
']; + yield ['all', '', 'all', 'My favorite sites are https://www.colinodell.com and https://commonmark.thephpleague.com
']; + yield ['all', '', 'external', 'My favorite sites are https://www.colinodell.com and https://commonmark.thephpleague.com
']; + yield ['all', '', 'internal', 'My favorite sites are https://www.colinodell.com and https://commonmark.thephpleague.com
']; + yield ['all', 'all', '', 'My favorite sites are https://www.colinodell.com and https://commonmark.thephpleague.com
']; + yield ['all', 'all', 'all', 'My favorite sites are https://www.colinodell.com and https://commonmark.thephpleague.com
']; + yield ['all', 'all', 'external', 'My favorite sites are https://www.colinodell.com and https://commonmark.thephpleague.com
']; + yield ['all', 'all', 'internal', 'My favorite sites are https://www.colinodell.com and https://commonmark.thephpleague.com
']; + yield ['all', 'external', '', 'My favorite sites are https://www.colinodell.com and https://commonmark.thephpleague.com
']; + yield ['all', 'external', 'all', 'My favorite sites are https://www.colinodell.com and https://commonmark.thephpleague.com
']; + yield ['all', 'external', 'external', 'My favorite sites are https://www.colinodell.com and https://commonmark.thephpleague.com
']; + yield ['all', 'external', 'internal', 'My favorite sites are https://www.colinodell.com and https://commonmark.thephpleague.com
']; + yield ['all', 'internal', '', 'My favorite sites are https://www.colinodell.com and https://commonmark.thephpleague.com
']; + yield ['all', 'internal', 'all', 'My favorite sites are https://www.colinodell.com and https://commonmark.thephpleague.com
']; + yield ['all', 'internal', 'external', 'My favorite sites are https://www.colinodell.com and https://commonmark.thephpleague.com
']; + yield ['all', 'internal', 'internal', 'My favorite sites are https://www.colinodell.com and https://commonmark.thephpleague.com
']; + yield ['external', '', '', 'My favorite sites are https://www.colinodell.com and https://commonmark.thephpleague.com
']; + yield ['external', '', 'all', 'My favorite sites are https://www.colinodell.com and https://commonmark.thephpleague.com
']; + yield ['external', '', 'external', 'My favorite sites are https://www.colinodell.com and https://commonmark.thephpleague.com
']; + yield ['external', '', 'internal', 'My favorite sites are https://www.colinodell.com and https://commonmark.thephpleague.com
']; + yield ['external', 'all', '', 'My favorite sites are https://www.colinodell.com and https://commonmark.thephpleague.com
']; + yield ['external', 'all', 'all', 'My favorite sites are https://www.colinodell.com and https://commonmark.thephpleague.com
']; + yield ['external', 'all', 'external', 'My favorite sites are https://www.colinodell.com and https://commonmark.thephpleague.com
']; + yield ['external', 'all', 'internal', 'My favorite sites are https://www.colinodell.com and https://commonmark.thephpleague.com
']; + yield ['external', 'external', '', 'My favorite sites are https://www.colinodell.com and https://commonmark.thephpleague.com
']; + yield ['external', 'external', 'all', 'My favorite sites are https://www.colinodell.com and https://commonmark.thephpleague.com
']; + yield ['external', 'external', 'external', 'My favorite sites are https://www.colinodell.com and https://commonmark.thephpleague.com
']; + yield ['external', 'external', 'internal', 'My favorite sites are https://www.colinodell.com and https://commonmark.thephpleague.com
']; + yield ['external', 'internal', '', 'My favorite sites are https://www.colinodell.com and https://commonmark.thephpleague.com
']; + yield ['external', 'internal', 'all', 'My favorite sites are https://www.colinodell.com and https://commonmark.thephpleague.com
']; + yield ['external', 'internal', 'external', 'My favorite sites are https://www.colinodell.com and https://commonmark.thephpleague.com
']; + yield ['external', 'internal', 'internal', 'My favorite sites are https://www.colinodell.com and https://commonmark.thephpleague.com
']; + yield ['internal', '', '', 'My favorite sites are https://www.colinodell.com and https://commonmark.thephpleague.com
']; + yield ['internal', '', 'all', 'My favorite sites are https://www.colinodell.com and https://commonmark.thephpleague.com
']; + yield ['internal', '', 'external', 'My favorite sites are https://www.colinodell.com and https://commonmark.thephpleague.com
']; + yield ['internal', '', 'internal', 'My favorite sites are https://www.colinodell.com and https://commonmark.thephpleague.com
']; + yield ['internal', 'all', '', 'My favorite sites are https://www.colinodell.com and https://commonmark.thephpleague.com
']; + yield ['internal', 'all', 'all', 'My favorite sites are https://www.colinodell.com and https://commonmark.thephpleague.com
']; + yield ['internal', 'all', 'external', 'My favorite sites are https://www.colinodell.com and https://commonmark.thephpleague.com
']; + yield ['internal', 'all', 'internal', 'My favorite sites are https://www.colinodell.com and https://commonmark.thephpleague.com
']; + yield ['internal', 'external', '', 'My favorite sites are https://www.colinodell.com and https://commonmark.thephpleague.com
']; + yield ['internal', 'external', 'all', 'My favorite sites are https://www.colinodell.com and https://commonmark.thephpleague.com
']; + yield ['internal', 'external', 'external', 'My favorite sites are https://www.colinodell.com and https://commonmark.thephpleague.com
']; + yield ['internal', 'external', 'internal', 'My favorite sites are https://www.colinodell.com and https://commonmark.thephpleague.com
']; + yield ['internal', 'internal', '', 'My favorite sites are https://www.colinodell.com and https://commonmark.thephpleague.com
']; + yield ['internal', 'internal', 'all', 'My favorite sites are https://www.colinodell.com and https://commonmark.thephpleague.com
']; + yield ['internal', 'internal', 'external', 'My favorite sites are https://www.colinodell.com and https://commonmark.thephpleague.com
']; + yield ['internal', 'internal', 'internal', 'My favorite sites are https://www.colinodell.com and https://commonmark.thephpleague.com
']; + } }