Skip to content

Commit 73ae7a5

Browse files
committed
fix content creation
and added tests
1 parent b014973 commit 73ae7a5

File tree

5 files changed

+109
-3
lines changed

5 files changed

+109
-3
lines changed

docker-compose-test.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
version: '2'
22
services:
33
test-db:
4+
platform: linux/x86_64
45
image: mysql:5.7
56
environment:
67
MYSQL_DATABASE: activitypub-test

includes/class-shortcodes.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,8 @@ public static function content( $atts, $content, $tag ) {
208208
$content = wp_filter_content_tags( $content );
209209
}
210210

211+
$content = \trim( \preg_replace( '/[\n\r\t]/', '', $content ) );
212+
211213
return $content;
212214
}
213215

includes/model/class-post.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -387,9 +387,7 @@ public function get_content() {
387387
$content = \wpautop( \wp_kses( $content, $this->allowed_tags ) );
388388

389389
$filtered_content = \apply_filters( 'activitypub_the_content', $content, $post );
390-
$decoded_content = \html_entity_decode( $filtered_content, \ENT_QUOTES, 'UTF-8' );
391-
392-
$content = \trim( \preg_replace( '/[\n\r\t]/', '', $content ) );
390+
$content = \html_entity_decode( $filtered_content, \ENT_QUOTES, 'UTF-8' );
393391

394392
$this->content = $content;
395393

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
<?php
2+
class Test_Activitypub_Rest_Inbox extends WP_UnitTestCase {
3+
/**
4+
* @dataProvider the_data_provider
5+
*/
6+
public function test_is_activity_public( $data, $check ) {
7+
8+
$this->assertEquals( $check, Activitypub\Rest\Inbox::is_activity_public( $data ) );
9+
}
10+
11+
public function the_data_provider() {
12+
return array(
13+
array(
14+
array(
15+
'cc' => array(
16+
'https://example.org/@test',
17+
'https://example.com/@test2',
18+
),
19+
'to' => 'https://www.w3.org/ns/activitystreams#Public',
20+
'object' => array(),
21+
),
22+
true,
23+
),
24+
array(
25+
array(
26+
'cc' => array(
27+
'https://example.org/@test',
28+
'https://example.com/@test2',
29+
),
30+
'to' => array(
31+
'https://www.w3.org/ns/activitystreams#Public',
32+
),
33+
'object' => array(),
34+
),
35+
true,
36+
),
37+
array(
38+
array(
39+
'cc' => array(
40+
'https://example.org/@test',
41+
'https://example.com/@test2',
42+
),
43+
'object' => array(),
44+
),
45+
false,
46+
),
47+
array(
48+
array(
49+
'cc' => array(
50+
'https://example.org/@test',
51+
'https://example.com/@test2',
52+
),
53+
'object' => array(
54+
'to' => 'https://www.w3.org/ns/activitystreams#Public',
55+
),
56+
),
57+
true,
58+
),
59+
array(
60+
array(
61+
'cc' => array(
62+
'https://example.org/@test',
63+
'https://example.com/@test2',
64+
),
65+
'object' => array(
66+
'to' => array(
67+
'https://www.w3.org/ns/activitystreams#Public',
68+
),
69+
),
70+
),
71+
true,
72+
),
73+
);
74+
}
75+
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
<?php
2+
class Test_Activitypub_Shortcodes extends WP_UnitTestCase {
3+
public function test_content() {
4+
global $post;
5+
6+
$post_id = -99; // negative ID, to avoid clash with a valid post
7+
$post = new stdClass();
8+
$post->ID = $post_id;
9+
$post->post_author = 1;
10+
$post->post_date = current_time( 'mysql' );
11+
$post->post_date_gmt = current_time( 'mysql', 1 );
12+
$post->post_title = 'Some title or other';
13+
$post->post_content = '<script>test</script>hallo';
14+
$post->post_status = 'publish';
15+
$post->comment_status = 'closed';
16+
$post->ping_status = 'closed';
17+
$post->post_name = 'fake-page-' . rand( 1, 99999 ); // append random number to avoid clash
18+
$post->post_type = 'page';
19+
$post->filter = 'raw'; // important!
20+
21+
$content = '[ap_content]';
22+
23+
// Fill in the shortcodes.
24+
setup_postdata( $post );
25+
$content = do_shortcode( $content );
26+
wp_reset_postdata();
27+
28+
$this->assertEquals( '<p>hallo</p>', $content );
29+
}
30+
}

0 commit comments

Comments
 (0)