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
5 changes: 5 additions & 0 deletions phpstan.neon.dist
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,8 @@ parameters:
message: '#Access to an undefined property Corcel\\Model\\Post[a-zA-Z0-9::a-zA-Z]#'
-
message: '#Function get_field not found.#'
-
identifier: function.impossibleType
path: src/Traits/HasMeta.php
count: 1

2 changes: 1 addition & 1 deletion src/PostData.php
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,7 @@ public function hasThumbnail(): bool

public function url(): string
{
if (null === $this->id) {
if (null === $this->id || ! is_post_publicly_viewable($this->id)) {
return '';
}

Expand Down
19 changes: 19 additions & 0 deletions tests/src/PostDataTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,33 @@
'return' => 'https://example.com/hello-world',
]);

\WP_Mock::userFunction('is_post_publicly_viewable', [
'args' => [1],
'return' => true,
]);

expect($this->postData->url())->toBe('https://example.com/hello-world');
});

it('returns an empty string when post is not publicly viewable', function () {
\WP_Mock::userFunction('is_post_publicly_viewable', [
'args' => [1],
'return' => false,
]);

expect($this->postData->url())->toBe('');
});

it('returns an empty string when url does not exist', function () {
\WP_Mock::userFunction('get_permalink', [
'args' => [1],
'return' => false,
]);

\WP_Mock::userFunction('is_post_publicly_viewable', [
'args' => [1],
'return' => true,
]);

expect($this->postData->url())->toBe('');
});