Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion includes/admin/helpers/class-rop-bluesky-api.php
Original file line number Diff line number Diff line change
Expand Up @@ -504,7 +504,7 @@ private function get_external_post_url( $post ) {
'external' => array(
'uri' => $post['post_url'],
'title' => isset( $post['title'] ) ? $post['title'] : '',
'description' => isset( $post['content'] ) ? $post['content'] : '',
'description' => '',
),
);
}
Expand Down
3 changes: 3 additions & 0 deletions phpunit.xml
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,9 @@
<testsuite name="bluesky-image">
<directory>./tests/test-bluesky-image.php</directory>
</testsuite>
<testsuite name="bluesky-card">
<directory>./tests/test-bluesky-card.php</directory>
</testsuite>
<testsuite name="x-premium-limit">
<directory>./tests/test-x-premium-limit.php</directory>
</testsuite>
Expand Down
78 changes: 78 additions & 0 deletions tests/test-bluesky-card.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
<?php
/**
* ROP Test Bluesky link card embed for PHPUnit.
*
* Reproduces GitHub issue Codeinwp/tweet-old-post-pro#676: the link card
* (app.bsky.embed.external) must not repeat the post caption as its
* description — Bluesky renders cards without a description as title + domain.
*
* @package ROP
* @subpackage Tests
* @license http://opensource.org/licenses/gpl-2.0.php GNU Public License
*/

/**
* Test Bluesky link card. class.
*/
class Test_RopBlueskyCard extends WP_UnitTestCase {

/**
* The link card description must be empty, not a copy of the post body.
*
* @covers Rop_Bluesky_Api::create_post
*/
public function test_link_card_description_is_empty() {
$captured = null;

$interceptor = function ( $preempt, $args, $url ) use ( &$captured ) {
if ( false === strpos( $url, 'com.atproto.repo.createRecord' ) ) {
return $preempt;
}
$captured = json_decode( $args['body'], true );

return array(
'headers' => array(),
'body' => wp_json_encode(
array(
'uri' => 'at://did:plc:test/app.bsky.feed.post/test',
'cid' => 'test-cid',
)
),
'response' => array(
'code' => 200,
'message' => 'OK',
),
'cookies' => array(),
'filename' => null,
);
};
add_filter( 'pre_http_request', $interceptor, 10, 3 );

$api = new Rop_Bluesky_Api( 'test.bsky.social', 'test-app-password' );
$api->create_post(
'did:plc:test',
array(
'content' => 'My caption text for this share.',
'title' => 'My Post Title',
'post_url' => 'https://example.org/my-post/',
),
'link',
'',
'test-access-token'
);

remove_filter( 'pre_http_request', $interceptor, 10 );

$this->assertNotNull( $captured, 'create_post() should have attempted a createRecord request.' );

$embed = $captured['record']['embed'];
$this->assertSame( 'app.bsky.embed.external', $embed['$type'] );
$this->assertSame( 'https://example.org/my-post/', $embed['external']['uri'] );
$this->assertSame( 'My Post Title', $embed['external']['title'] );
$this->assertSame(
'',
$embed['external']['description'],
'Link card description must be empty, not a duplicate of the post caption (issue #676).'
);
}
}
Loading