wordpress-activitypub/tests/test-class-activitypub-hashtag.php

55 lines
2.1 KiB
PHP
Raw Normal View History

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 ) {
\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' );
$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 );
$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' ),
array( 'hallo #object test', 'hallo <a rel="tag" class="hashtag u-tag u-category" href="%s">#object</a> test' ),
array( '#object test', '<a rel="tag" class="hashtag u-tag u-category" href="%s">#object</a> test' ),
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' ),
array( '<div>hallo #object test</div>', '<div>hallo <a rel="tag" class="hashtag u-tag u-category" href="%s">#object</a> test</div>' ),
array( '<div>hallo #object</div>', '<div>hallo <a rel="tag" class="hashtag u-tag u-category" href="%s">#object</a></div>' ),
array( '<div>#object</div>', '<div><a rel="tag" class="hashtag u-tag u-category" href="%s">#object</a></div>' ),
array( '<a>#object</a>', '<a>#object</a>' ),
array( '<!-- #object -->', '<!-- #object -->' ),
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
}
}