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
4 changes: 2 additions & 2 deletions src/Cascades/ContentCascade.php
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ public function canonical(): ?string
return null;
}

return match ($this->get('canonical_type')) {
return match ($this->get('canonical_type')?->value()) {
'entry' => $this->get('canonical_entry')?->absoluteUrl() ?? $this->canonicalUrl(),
'custom' => $this->get('canonical_custom') ?? $this->canonicalUrl(),
default => $this->canonicalUrl(),
Expand All @@ -146,7 +146,7 @@ protected function canonicalUrl(): string

public function siteSchema(): ?string
{
$type = $this->get('site_json_ld_type');
$type = $this->get('site_json_ld_type')?->value();

if (! $type || $type === 'none') {
return null;
Expand Down
17 changes: 9 additions & 8 deletions tests/Cascades/ContentCascadeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use Statamic\Facades\Collection;
use Statamic\Facades\Entry;
use Statamic\Facades\Site;
use Statamic\Fields\LabeledValue;
use Statamic\Testing\Concerns\PreventsSavingStacheItemsToDisk;

uses(PreventsSavingStacheItemsToDisk::class);
Expand Down Expand Up @@ -246,7 +247,7 @@
it('returns custom canonical url', function () {
config(['advanced-seo.crawling.environments' => ['testing']]);

$this->cascade->set('canonical_type', 'custom');
$this->cascade->set('canonical_type', new LabeledValue('custom', 'Custom'));
$this->cascade->set('canonical_custom', 'https://other-site.com/page');

expect($this->cascade->canonical())->toBe('https://other-site.com/page');
Expand All @@ -258,7 +259,7 @@
$other = Entry::make()->collection('pages')->locale('english')->slug('original');
$other->save();

$this->cascade->set('canonical_type', 'entry');
$this->cascade->set('canonical_type', new LabeledValue('entry', 'Entry'));
$this->cascade->set('canonical_entry', $other);

expect($this->cascade->canonical())->toBe('https://example.com/original');
Expand All @@ -267,7 +268,7 @@
it('falls back to self-referencing canonical when entry is null', function () {
config(['advanced-seo.crawling.environments' => ['testing']]);

$this->cascade->set('canonical_type', 'entry');
$this->cascade->set('canonical_type', new LabeledValue('entry', 'Entry'));
$this->cascade->set('canonical_entry', null);

expect($this->cascade->canonical())->toBe('https://example.com/about');
Expand All @@ -276,14 +277,14 @@
it('falls back to self-referencing canonical when custom canonical is null', function () {
config(['advanced-seo.crawling.environments' => ['testing']]);

$this->cascade->set('canonical_type', 'custom');
$this->cascade->set('canonical_type', new LabeledValue('custom', 'Custom'));
$this->cascade->set('canonical_custom', null);

expect($this->cascade->canonical())->toBe('https://example.com/about');
});

it('returns null site schema when type is none', function () {
$this->cascade->set('site_json_ld_type', 'none');
$this->cascade->set('site_json_ld_type', new LabeledValue('none', 'None'));

expect($this->cascade->siteSchema())->toBeNull();
});
Expand All @@ -293,14 +294,14 @@
});

it('returns custom site schema json', function () {
$this->cascade->set('site_json_ld_type', 'custom');
$this->cascade->set('site_json_ld_type', new LabeledValue('custom', 'Custom'));
$this->cascade->set('site_json_ld', '{"@type": "Organization"}');

expect($this->cascade->siteSchema())->toBe('{"@type": "Organization"}');
});

it('returns organization schema json', function () {
$this->cascade->set('site_json_ld_type', 'organization');
$this->cascade->set('site_json_ld_type', new LabeledValue('organization', 'Organization'));
$this->cascade->set('organization_name', 'Acme Inc');

$schema = json_decode($this->cascade->siteSchema(), true);
Expand All @@ -311,7 +312,7 @@
});

it('returns person schema json', function () {
$this->cascade->set('site_json_ld_type', 'person');
$this->cascade->set('site_json_ld_type', new LabeledValue('person', 'Person'));
$this->cascade->set('person_name', 'John Doe');

$schema = json_decode($this->cascade->siteSchema(), true);
Expand Down
Loading