fix some method names
and add basic tests
This commit is contained in:
parent
74c063b690
commit
f9223be5d7
2 changed files with 28 additions and 5 deletions
|
@ -13,6 +13,7 @@ class Post {
|
|||
private $summary;
|
||||
private $content;
|
||||
private $attachments;
|
||||
private $tags;
|
||||
private $object_type;
|
||||
|
||||
/**
|
||||
|
@ -26,7 +27,7 @@ class Post {
|
|||
public function __construct( $post = null ) {
|
||||
$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->summary = $this->generate_the_title();
|
||||
$this->content = $this->generate_the_content();
|
||||
|
@ -76,8 +77,7 @@ class Post {
|
|||
|
||||
public function generate_permalink() {
|
||||
$post = $this->post;
|
||||
|
||||
$permalink = \generate_permalink( $post );
|
||||
$permalink = \get_permalink( $post );
|
||||
|
||||
// replace 'trashed' for delete activity
|
||||
return \str_replace( '__trashed', '', $permalink );
|
||||
|
@ -339,7 +339,7 @@ class Post {
|
|||
if ( \get_option( 'activitypub_use_shortlink', 0 ) ) {
|
||||
$link = \esc_url( \wp_get_shortlink( $post->ID ) );
|
||||
} else {
|
||||
$link = \esc_url( \generate_permalink( $post->ID ) );
|
||||
$link = \esc_url( \get_permalink( $post->ID ) );
|
||||
}
|
||||
|
||||
return $content . '<p><a href="' . $link . '">' . $link . '</a></p>';
|
||||
|
|
23
tests/test-class-activitypub-post.php
Normal file
23
tests/test-class-activitypub-post.php
Normal 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() );
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue