feat: {{link:ID}} placeholder via Divi's post_link_url dynamic content
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,37 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace LIT\MCP\Tests\Unit\Integrations\Divi\Pages;
|
||||
|
||||
use Brain\Monkey\Functions;
|
||||
use LIT\MCP\Integrations\Divi\Pages\WpLinkTargets;
|
||||
use LIT\MCP\Tests\Unit\TestCase;
|
||||
use WP_Post;
|
||||
|
||||
final class WpLinkTargetsTest extends TestCase
|
||||
{
|
||||
public function testOnlyReadableLivingPostsCanBeLinked(): void
|
||||
{
|
||||
$posts = [
|
||||
839 => new WP_Post(['ID' => 839, 'post_type' => 'page', 'post_status' => 'draft']),
|
||||
841 => new WP_Post(['ID' => 841, 'post_type' => 'page', 'post_status' => 'trash']),
|
||||
842 => new WP_Post(['ID' => 842, 'post_type' => 'page', 'post_status' => 'private']),
|
||||
843 => new WP_Post(['ID' => 843, 'post_type' => 'revision', 'post_status' => 'inherit']),
|
||||
844 => new WP_Post(['ID' => 844, 'post_type' => 'page', 'post_status' => 'auto-draft']),
|
||||
];
|
||||
Functions\when('get_post')->alias(static fn (int $id): ?WP_Post => $posts[$id] ?? null);
|
||||
Functions\when('current_user_can')->alias(
|
||||
static fn (string $cap, int $id): bool => $cap === 'read_post' && $id !== 842
|
||||
);
|
||||
|
||||
$links = new WpLinkTargets();
|
||||
|
||||
self::assertSame('page', $links->postTypeOf(839));
|
||||
self::assertNull($links->postTypeOf(841), 'trashed');
|
||||
self::assertNull($links->postTypeOf(842), 'not readable');
|
||||
self::assertNull($links->postTypeOf(843), 'revision');
|
||||
self::assertNull($links->postTypeOf(844), 'auto-draft');
|
||||
self::assertNull($links->postTypeOf(900), 'missing');
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user