|
| 1 | +<?php |
| 2 | +/** |
| 3 | + * ROP Test Bluesky link card embed for PHPUnit. |
| 4 | + * |
| 5 | + * Reproduces GitHub issue Codeinwp/tweet-old-post-pro#676: the link card |
| 6 | + * (app.bsky.embed.external) must not repeat the post caption as its |
| 7 | + * description — Bluesky renders cards without a description as title + domain. |
| 8 | + * |
| 9 | + * @package ROP |
| 10 | + * @subpackage Tests |
| 11 | + * @license http://opensource.org/licenses/gpl-2.0.php GNU Public License |
| 12 | + */ |
| 13 | + |
| 14 | +/** |
| 15 | + * Test Bluesky link card. class. |
| 16 | + */ |
| 17 | +class Test_RopBlueskyCard extends WP_UnitTestCase { |
| 18 | + |
| 19 | + /** |
| 20 | + * The link card description must be empty, not a copy of the post body. |
| 21 | + * |
| 22 | + * @covers Rop_Bluesky_Api::create_post |
| 23 | + */ |
| 24 | + public function test_link_card_description_is_empty() { |
| 25 | + $captured = null; |
| 26 | + |
| 27 | + $interceptor = function ( $preempt, $args, $url ) use ( &$captured ) { |
| 28 | + if ( false === strpos( $url, 'com.atproto.repo.createRecord' ) ) { |
| 29 | + return $preempt; |
| 30 | + } |
| 31 | + $captured = json_decode( $args['body'], true ); |
| 32 | + |
| 33 | + return array( |
| 34 | + 'headers' => array(), |
| 35 | + 'body' => wp_json_encode( |
| 36 | + array( |
| 37 | + 'uri' => 'at://did:plc:test/app.bsky.feed.post/test', |
| 38 | + 'cid' => 'test-cid', |
| 39 | + ) |
| 40 | + ), |
| 41 | + 'response' => array( |
| 42 | + 'code' => 200, |
| 43 | + 'message' => 'OK', |
| 44 | + ), |
| 45 | + 'cookies' => array(), |
| 46 | + 'filename' => null, |
| 47 | + ); |
| 48 | + }; |
| 49 | + add_filter( 'pre_http_request', $interceptor, 10, 3 ); |
| 50 | + |
| 51 | + $api = new Rop_Bluesky_Api( 'test.bsky.social', 'test-app-password' ); |
| 52 | + $api->create_post( |
| 53 | + 'did:plc:test', |
| 54 | + array( |
| 55 | + 'content' => 'My caption text for this share.', |
| 56 | + 'title' => 'My Post Title', |
| 57 | + 'post_url' => 'https://example.org/my-post/', |
| 58 | + ), |
| 59 | + 'link', |
| 60 | + '', |
| 61 | + 'test-access-token' |
| 62 | + ); |
| 63 | + |
| 64 | + remove_filter( 'pre_http_request', $interceptor, 10 ); |
| 65 | + |
| 66 | + $this->assertNotNull( $captured, 'create_post() should have attempted a createRecord request.' ); |
| 67 | + |
| 68 | + $embed = $captured['record']['embed']; |
| 69 | + $this->assertSame( 'app.bsky.embed.external', $embed['$type'] ); |
| 70 | + $this->assertSame( 'https://example.org/my-post/', $embed['external']['uri'] ); |
| 71 | + $this->assertSame( 'My Post Title', $embed['external']['title'] ); |
| 72 | + $this->assertSame( |
| 73 | + '', |
| 74 | + $embed['external']['description'], |
| 75 | + 'Link card description must be empty, not a duplicate of the post caption (issue #676).' |
| 76 | + ); |
| 77 | + } |
| 78 | +} |
0 commit comments