fix some method names

and add basic tests
This commit is contained in:
Matthias Pfefferle 2020-05-14 22:33:09 +02:00
parent 74c063b690
commit f9223be5d7
2 changed files with 28 additions and 5 deletions

View file

@ -13,6 +13,7 @@ class Post {
private $summary; private $summary;
private $content; private $content;
private $attachments; private $attachments;
private $tags;
private $object_type; private $object_type;
/** /**
@ -26,7 +27,7 @@ class Post {
public function __construct( $post = null ) { public function __construct( $post = null ) {
$this->post = \get_post( $post ); $this->post = \get_post( $post );
$this->post_author = $this->post->post_author(); $this->post_author = $this->post->post_author;
$this->permalink = $this->generate_permalink(); $this->permalink = $this->generate_permalink();
$this->summary = $this->generate_the_title(); $this->summary = $this->generate_the_title();
$this->content = $this->generate_the_content(); $this->content = $this->generate_the_content();
@ -75,9 +76,8 @@ class Post {
} }
public function generate_permalink() { public function generate_permalink() {
$post = $this->post; $post = $this->post;
$permalink = \get_permalink( $post );
$permalink = \generate_permalink( $post );
// replace 'trashed' for delete activity // replace 'trashed' for delete activity
return \str_replace( '__trashed', '', $permalink ); return \str_replace( '__trashed', '', $permalink );
@ -339,7 +339,7 @@ class Post {
if ( \get_option( 'activitypub_use_shortlink', 0 ) ) { if ( \get_option( 'activitypub_use_shortlink', 0 ) ) {
$link = \esc_url( \wp_get_shortlink( $post->ID ) ); $link = \esc_url( \wp_get_shortlink( $post->ID ) );
} else { } else {
$link = \esc_url( \generate_permalink( $post->ID ) ); $link = \esc_url( \get_permalink( $post->ID ) );
} }
return $content . '<p><a href="' . $link . '">' . $link . '</a></p>'; return $content . '<p><a href="' . $link . '">' . $link . '</a></p>';

View file

@ -0,0 +1,23 @@
<?php
class Test_Activitypub_Post extends WP_UnitTestCase {
public function test_to_array() {
$post = \wp_insert_post(
array(
'post_author' => 1,
'post_content' => 'test',
)
);
$permalink = \get_permalink( $post );
$activitypub_post = new \Activitypub\Model\Post( $post );
$this->assertEquals( $permalink, $activitypub_post->get_permalink() );
\wp_trash_post( $post );
$activitypub_post = new \Activitypub\Model\Post( $post );
$this->assertEquals( $permalink, $activitypub_post->get_permalink() );
}
}