2019-08-18 22:08:58 +02:00
|
|
|
<?php
|
|
|
|
class Test_Activitypub_Hashtag extends WP_UnitTestCase {
|
|
|
|
/**
|
|
|
|
* @dataProvider the_content_provider
|
|
|
|
*/
|
|
|
|
public function test_the_content( $content, $content_with_hashtag ) {
|
2022-12-09 09:20:25 +01:00
|
|
|
\wp_create_term( 'object', 'post_tag' );
|
2023-01-27 16:55:52 +01:00
|
|
|
\wp_create_term( 'touch', 'post_tag' );
|
2023-01-27 16:50:04 +01:00
|
|
|
\wp_create_term( 'ccc', 'post_tag' );
|
2022-12-09 09:20:25 +01:00
|
|
|
$object = \get_term_by( 'name', 'object', 'post_tag' );
|
|
|
|
$link = \get_term_link( $object, 'post_tag' );
|
|
|
|
|
2019-08-18 22:08:58 +02:00
|
|
|
$content = \Activitypub\Hashtag::the_content( $content );
|
|
|
|
|
2022-12-09 09:20:25 +01:00
|
|
|
$this->assertEquals( sprintf( $content_with_hashtag, $link ), $content );
|
2019-08-18 22:08:58 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public function the_content_provider() {
|
2023-01-27 16:50:04 +01:00
|
|
|
$code = '<code>text with some #object and <a> tag inside</code>';
|
|
|
|
$style = <<<ENDSTYLE
|
|
|
|
<style type="text/css">
|
2023-01-27 16:59:15 +01:00
|
|
|
<![CDATA[
|
2023-01-27 16:50:04 +01:00
|
|
|
color: #ccc;
|
|
|
|
]]>
|
|
|
|
</style>
|
|
|
|
ENDSTYLE;
|
2023-01-27 16:55:52 +01:00
|
|
|
$pre = <<<ENDPRE
|
|
|
|
<pre>
|
|
|
|
Please don't #touch
|
|
|
|
this.
|
|
|
|
</pre>
|
|
|
|
ENDPRE;
|
2023-01-27 16:50:04 +01:00
|
|
|
$textarea = '<textarea name="test" rows="20">color: #ccc</textarea>';
|
2019-08-18 22:24:34 +02:00
|
|
|
return array(
|
|
|
|
array( 'test', 'test' ),
|
|
|
|
array( '#test', '#test' ),
|
|
|
|
array( 'hallo #test test', 'hallo #test test' ),
|
2022-12-09 09:20:25 +01:00
|
|
|
array( 'hallo #object test', 'hallo <a rel="tag" class="u-tag u-category" href="%s">#object</a> test' ),
|
|
|
|
array( '#object test', '<a rel="tag" class="u-tag u-category" href="%s">#object</a> test' ),
|
2019-08-18 23:27:06 +02:00
|
|
|
array( 'hallo <a href="http://test.test/#object">test</a> test', 'hallo <a href="http://test.test/#object">test</a> test' ),
|
|
|
|
array( 'hallo <a href="http://test.test/#object">#test</a> test', 'hallo <a href="http://test.test/#object">#test</a> test' ),
|
2022-12-09 09:20:25 +01:00
|
|
|
array( '<div>hallo #object test</div>', '<div>hallo <a rel="tag" class="u-tag u-category" href="%s">#object</a> test</div>' ),
|
|
|
|
array( '<div>hallo #object</div>', '<div>hallo <a rel="tag" class="u-tag u-category" href="%s">#object</a></div>' ),
|
2019-08-18 23:27:06 +02:00
|
|
|
array( '<div>#object</div>', '<div>#object</div>' ),
|
|
|
|
array( '<a>#object</a>', '<a>#object</a>' ),
|
|
|
|
array( '<div style="color: #ccc;">object</a>', '<div style="color: #ccc;">object</a>' ),
|
2023-01-27 16:50:04 +01:00
|
|
|
array( $code, $code ),
|
|
|
|
array( $style, $style ),
|
|
|
|
array( $textarea, $textarea ),
|
2023-01-27 16:55:52 +01:00
|
|
|
array( $pre, $pre ),
|
2019-08-18 22:24:34 +02:00
|
|
|
);
|
2019-08-18 22:08:58 +02:00
|
|
|
}
|
|
|
|
}
|