1010use phpMyFAQ \System ;
1111use phpMyFAQ \Translation ;
1212use PHPUnit \Framework \TestCase ;
13- use Symfony \Component \HttpFoundation \Exception \SuspiciousOperationException ;
1413
1514class FaqHelperTest extends TestCase
1615{
17- /** @var Configuration */
18- private Configuration $ configuration ;
19-
2016 /** @var FaqHelper*/
2117 private FaqHelper $ faqHelper ;
2218
@@ -34,15 +30,15 @@ protected function setUp(): void
3430
3531 $ dbHandle = new Sqlite3 ();
3632 $ dbHandle ->connect (PMF_TEST_DIR . '/test.db ' , '' , '' );
37- $ this -> configuration = new Configuration ($ dbHandle );
38- $ this -> configuration ->set ('main.currentVersion ' , System::getVersion ());
39- $ this -> configuration ->set ('main.referenceURL ' , 'https://localhost:443/ ' );
40- $ this -> configuration ->set ('records.allowedMediaHosts ' , 'www.youtube.com,example.com,phpmyfaq.de ' );
33+ $ configuration = new Configuration ($ dbHandle );
34+ $ configuration ->set ('main.currentVersion ' , System::getVersion ());
35+ $ configuration ->set ('main.referenceURL ' , 'https://localhost:443/ ' );
36+ $ configuration ->set ('records.allowedMediaHosts ' , 'www.youtube.com,example.com,phpmyfaq.de ' );
4137
42- $ language = new Language ($ this -> configuration );
43- $ this -> configuration ->setLanguage ($ language );
38+ $ language = new Language ($ configuration );
39+ $ configuration ->setLanguage ($ language );
4440
45- $ this ->faqHelper = new FaqHelper ($ this -> configuration );
41+ $ this ->faqHelper = new FaqHelper ($ configuration );
4642 }
4743
4844 public function testRewriteLanguageMarkupClass (): void
@@ -78,7 +74,8 @@ public function testCreateFaqUrl(): void
7874
7975 public function testCleanUpContent (): void
8076 {
81- $ content = '<p>Some text <script>alert("Hello, world!");</script><img src=foo onerror=alert(document.cookie)></p> ' ;
77+ $ content = '<p>Some text <script>alert("Hello, world!"); ' .
78+ '</script><img src=foo onerror=alert(document.cookie)></p> ' ;
8279 $ expectedOutput = '<p>Some text <img src="foo" /></p> ' ;
8380
8481 $ actualOutput = $ this ->faqHelper ->cleanUpContent ($ content );
@@ -151,6 +148,16 @@ public function testCleanUpContentWithDifferentImageSource(): void
151148 $ this ->assertEquals ($ expectedOutput , $ actualOutput );
152149 }
153150
151+ public function testExternalLinks (): void
152+ {
153+ $ content = '<a rel="nofollow" target="_blank" href="https://www.phpmyfaq.de">phpMyFAQ</a> ' ;
154+ $ expectedOutput = '<a rel="nofollow" target="_blank" href="https://www.phpmyfaq.de">phpMyFAQ</a> ' ;
155+
156+ $ actualOutput = $ this ->faqHelper ->cleanUpContent ($ content );
157+
158+ $ this ->assertEquals ($ expectedOutput , $ actualOutput );
159+ }
160+
154161 public function testConvertOldInternalLinks (): void
155162 {
156163 // Test questions for slug generation
0 commit comments