wordpress-activitypub/tests/test-class-activitypub-link.php
Daniel Hüsken 2ac7676359
Replace hashtags, urls and mentions in summary with links (#849)
* replace hashtags, mentions and ulrs in summary

* move faq stuff and auto generate markdown version with grunt

* I would rename it the class to `Link` because it's about linking not about URLs

* fix auto generated readme

* let use not converted links in extra fields our link generation

* consistency

* find new function name, because it is not purely about links

* make `rel` directly filterable to be more flexible in the future

* remove some whitespaces

* it is not needed to check for a link inside a link

* not convert extra field links with additional text

* not convert extra field links with additional text

* simplified code

---------

Co-authored-by: Matthias Pfefferle <pfefferle@users.noreply.github.com>
2024-08-14 15:41:42 +02:00

47 lines
3.5 KiB
PHP

<?php
class Test_Activitypub_Link extends WP_UnitTestCase {
/**
* @dataProvider the_content_provider
*/
public function test_the_content( $content, $content_with_hashtag ) {
$content = \Activitypub\Link::the_content( $content );
$this->assertEquals( $content_with_hashtag, $content );
}
public function the_content_provider() {
$code = '<code>text with some https://test.de and <a> tag inside</code>';
$style = <<<ENDSTYLE
<style type="text/css">
<![CDATA[
color: #ccc;
]]>
</style>
ENDSTYLE;
$pre = <<<ENDPRE
<pre>
Please don't https://test.de
this.
</pre>
ENDPRE;
$textarea = '<textarea name="test" rows="20">color: #ccc</textarea>';
$a_href = '<a href="https://test.de">Text</a>';
return array(
array( 'https://wordpress.org/plugins/activitypub/', '<a href="https://wordpress.org/plugins/activitypub/" target="_blank" rel="nofollow noopener noreferrer" translate="no"><span class="invisible">https://</span><span class="ellipsis">wordpress.org/plugins/activity</span><span class="invisible">pub/</span></a>' ),
array( 'http://wordpress.org/', '<a href="http://wordpress.org/" target="_blank" rel="nofollow noopener noreferrer" translate="no"><span class="invisible">http://</span><span class="">wordpress.org/</span><span class="invisible"></span></a>' ),
array( 'https://test.org/?get=täst', '<a href="https://test.org/?get=täst" target="_blank" rel="nofollow noopener noreferrer" translate="no"><span class="invisible">https://</span><span class="">test.org/?get=täst</span><span class="invisible"></span></a>' ),
array( 'https://täst.org/', '<a href="https://täst.org/" target="_blank" rel="nofollow noopener noreferrer" translate="no"><span class="invisible">https://</span><span class="">täst.org/</span><span class="invisible"></span></a>' ),
array( 'https://wordpress.org/index.html', '<a href="https://wordpress.org/index.html" target="_blank" rel="nofollow noopener noreferrer" translate="no"><span class="invisible">https://</span><span class="">wordpress.org/index.html</span><span class="invisible"></span></a>' ),
array( 'ftp://test.de/', 'ftp://test.de/' ),
array( 'hello https://www.test.de world https://wordpress.org/ test', 'hello <a href="https://www.test.de" target="_blank" rel="nofollow noopener noreferrer" translate="no"><span class="invisible">https://www.</span><span class="">test.de</span><span class="invisible"></span></a> world <a href="https://wordpress.org/" target="_blank" rel="nofollow noopener noreferrer" translate="no"><span class="invisible">https://</span><span class="">wordpress.org/</span><span class="invisible"></span></a> test' ),
array( 'hello https://www.test.de test', 'hello <a href="https://www.test.de" target="_blank" rel="nofollow noopener noreferrer" translate="no"><span class="invisible">https://www.</span><span class="">test.de</span><span class="invisible"></span></a> test' ),
array( 'hello www.test.de test', 'hello <a href="https://www.test.de" target="_blank" rel="nofollow noopener noreferrer" translate="no"><span class="invisible">https://www.</span><span class="">test.de</span><span class="invisible"></span></a> test' ),
array( 'hello https://test:test@test.de test', 'hello <a href="https://test:test@test.de" target="_blank" rel="nofollow noopener noreferrer" translate="no"><span class="invisible">https://test:test@</span><span class="">test.de</span><span class="invisible"></span></a> test' ),
array( $code, $code ),
array( $style, $style ),
array( $textarea, $textarea ),
array( $pre, $pre ),
array( $a_href, $a_href ),
);
}
}