fix content creation

and added tests
This commit is contained in:
Matthias Pfefferle 2023-02-20 18:08:10 +01:00
parent b0149739fa
commit 73ae7a5d75
5 changed files with 109 additions and 3 deletions

View file

@ -1,6 +1,7 @@
version: '2' version: '2'
services: services:
test-db: test-db:
platform: linux/x86_64
image: mysql:5.7 image: mysql:5.7
environment: environment:
MYSQL_DATABASE: activitypub-test MYSQL_DATABASE: activitypub-test

View file

@ -208,6 +208,8 @@ class Shortcodes {
$content = wp_filter_content_tags( $content ); $content = wp_filter_content_tags( $content );
} }
$content = \trim( \preg_replace( '/[\n\r\t]/', '', $content ) );
return $content; return $content;
} }

View file

@ -387,9 +387,7 @@ class Post {
$content = \wpautop( \wp_kses( $content, $this->allowed_tags ) ); $content = \wpautop( \wp_kses( $content, $this->allowed_tags ) );
$filtered_content = \apply_filters( 'activitypub_the_content', $content, $post ); $filtered_content = \apply_filters( 'activitypub_the_content', $content, $post );
$decoded_content = \html_entity_decode( $filtered_content, \ENT_QUOTES, 'UTF-8' ); $content = \html_entity_decode( $filtered_content, \ENT_QUOTES, 'UTF-8' );
$content = \trim( \preg_replace( '/[\n\r\t]/', '', $content ) );
$this->content = $content; $this->content = $content;

View file

@ -0,0 +1,75 @@
<?php
class Test_Activitypub_Rest_Inbox extends WP_UnitTestCase {
/**
* @dataProvider the_data_provider
*/
public function test_is_activity_public( $data, $check ) {
$this->assertEquals( $check, Activitypub\Rest\Inbox::is_activity_public( $data ) );
}
public function the_data_provider() {
return array(
array(
array(
'cc' => array(
'https://example.org/@test',
'https://example.com/@test2',
),
'to' => 'https://www.w3.org/ns/activitystreams#Public',
'object' => array(),
),
true,
),
array(
array(
'cc' => array(
'https://example.org/@test',
'https://example.com/@test2',
),
'to' => array(
'https://www.w3.org/ns/activitystreams#Public',
),
'object' => array(),
),
true,
),
array(
array(
'cc' => array(
'https://example.org/@test',
'https://example.com/@test2',
),
'object' => array(),
),
false,
),
array(
array(
'cc' => array(
'https://example.org/@test',
'https://example.com/@test2',
),
'object' => array(
'to' => 'https://www.w3.org/ns/activitystreams#Public',
),
),
true,
),
array(
array(
'cc' => array(
'https://example.org/@test',
'https://example.com/@test2',
),
'object' => array(
'to' => array(
'https://www.w3.org/ns/activitystreams#Public',
),
),
),
true,
),
);
}
}

View file

@ -0,0 +1,30 @@
<?php
class Test_Activitypub_Shortcodes extends WP_UnitTestCase {
public function test_content() {
global $post;
$post_id = -99; // negative ID, to avoid clash with a valid post
$post = new stdClass();
$post->ID = $post_id;
$post->post_author = 1;
$post->post_date = current_time( 'mysql' );
$post->post_date_gmt = current_time( 'mysql', 1 );
$post->post_title = 'Some title or other';
$post->post_content = '<script>test</script>hallo';
$post->post_status = 'publish';
$post->comment_status = 'closed';
$post->ping_status = 'closed';
$post->post_name = 'fake-page-' . rand( 1, 99999 ); // append random number to avoid clash
$post->post_type = 'page';
$post->filter = 'raw'; // important!
$content = '[ap_content]';
// Fill in the shortcodes.
setup_postdata( $post );
$content = do_shortcode( $content );
wp_reset_postdata();
$this->assertEquals( '<p>hallo</p>', $content );
}
}