Skip to content
Merged
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: 2 additions & 0 deletions src/Data/Comment.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ class Comment extends Dto
{
/**
* @param array<string, string> $author_avatar_urls
* @param array<string, mixed> $meta
*/
public function __construct(
public readonly int $id,
Expand All @@ -31,6 +32,7 @@ public function __construct(
public readonly string $status,
public readonly string $type,
public readonly array $author_avatar_urls = [],
public readonly array $meta = [],
) {
}
}
12 changes: 12 additions & 0 deletions src/Data/PostType.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,27 @@
/**
* @SuppressWarnings("PHPMD.BooleanArgumentFlag")
* @SuppressWarnings("PHPMD.CamelCaseParameterName")
* @SuppressWarnings("PHPMD.CamelCasePropertyName")
* @SuppressWarnings("PHPMD.ExcessiveParameterList")
*/
class PostType extends Dto
{
/**
* @param array<string, mixed> $labels
* @param array<string, mixed> $supports
* @param array<int, string> $taxonomies
*/
public function __construct(
public readonly string $slug,
public readonly string $name,
public readonly string $rest_base = '',
public readonly bool $hierarchical = false,
public readonly bool $viewable = true,
public readonly string $description = '',
public readonly string $rest_namespace = '',
public readonly array $labels = [],
public readonly array $supports = [],
public readonly array $taxonomies = [],
) {
}
}
4 changes: 4 additions & 0 deletions src/Data/Taxonomy.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,17 @@ class Taxonomy extends Dto
{
/**
* @param array<int, string> $types
* @param array<string, mixed> $labels
*/
public function __construct(
public readonly string $slug,
public readonly string $name,
public readonly array $types = [],
public readonly string $rest_base = '',
public readonly bool $hierarchical = false,
public readonly string $description = '',
public readonly string $rest_namespace = '',
public readonly array $labels = [],
) {
}
}
48 changes: 48 additions & 0 deletions tests/Unit/Data/DataModelsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -159,12 +159,15 @@ public function testCommentConstructorPreservesRenderedContentAndAvatarMap(): vo
status: 'approved',
type: 'comment',
author_avatar_urls: ['96' => 'https://example.com/avatar-96.jpg'],
meta: ['source' => 'integration'],
);

$this->assertSame(21, $comment->id);
$this->assertSame($content, $comment->content);
$this->assertSame('SDK Bot', $comment->author_name);
$this->assertSame(['96' => 'https://example.com/avatar-96.jpg'], $comment->author_avatar_urls);
$this->assertSame(['source' => 'integration'], $comment->meta);
$this->assertSame(['source' => 'integration'], $comment->toArray()['meta']);
}

public function testTaxonomyConstructorDefaultsOptionalWordPressSchemaFields(): void
Expand All @@ -179,6 +182,9 @@ public function testTaxonomyConstructorDefaultsOptionalWordPressSchemaFields():
$this->assertSame([], $taxonomy->types);
$this->assertSame('', $taxonomy->rest_base);
$this->assertFalse($taxonomy->hierarchical);
$this->assertSame('', $taxonomy->description);
$this->assertSame('', $taxonomy->rest_namespace);
$this->assertSame([], $taxonomy->labels);
}

public function testPostTypeConstructorPreservesViewabilityFlags(): void
Expand All @@ -197,6 +203,48 @@ public function testPostTypeConstructorPreservesViewabilityFlags(): void
$this->assertFalse($postType->viewable);
}

public function testPostTypeConstructorPreservesAdditionalWordPressSchemaFields(): void
{
$postType = new PostType(
slug: 'book',
name: 'Books',
rest_base: 'books',
hierarchical: false,
viewable: true,
description: 'Book content',
rest_namespace: 'wp/v2',
labels: ['singular_name' => 'Book'],
supports: ['title' => true, 'editor' => true],
taxonomies: ['category', 'post_tag'],
);

$this->assertSame('Book content', $postType->description);
$this->assertSame('wp/v2', $postType->rest_namespace);
$this->assertSame(['singular_name' => 'Book'], $postType->labels);
$this->assertSame(['title' => true, 'editor' => true], $postType->supports);
$this->assertSame(['category', 'post_tag'], $postType->taxonomies);
$this->assertSame('wp/v2', $postType->toArray()['rest_namespace']);
}

public function testTaxonomyConstructorPreservesAdditionalWordPressSchemaFields(): void
{
$taxonomy = new Taxonomy(
slug: 'genre',
name: 'Genres',
types: ['book'],
rest_base: 'genres',
hierarchical: true,
description: 'Book genres',
rest_namespace: 'wp/v2',
labels: ['singular_name' => 'Genre'],
);

$this->assertSame('Book genres', $taxonomy->description);
$this->assertSame('wp/v2', $taxonomy->rest_namespace);
$this->assertSame(['singular_name' => 'Genre'], $taxonomy->labels);
$this->assertSame('Book genres', $taxonomy->toArray()['description']);
}

public function testSearchResultConstructorStoresWordPressSearchShape(): void
{
$result = new SearchResult(
Expand Down
Loading