diff --git a/composer.json b/composer.json index ec34cd1b..4a04c00d 100644 --- a/composer.json +++ b/composer.json @@ -22,7 +22,7 @@ } }, "require": { - "statamic/cms": "^4.0" + "statamic/cms": "^4.1.3" }, "require-dev": { "orchestra/testbench": "^7.0 || ^8.0", diff --git a/src/Cascade.php b/src/Cascade.php index a3dd7db1..8a5c4216 100644 --- a/src/Cascade.php +++ b/src/Cascade.php @@ -73,7 +73,7 @@ public function get() return $this->getForSitemap(); } - if (array_get($this->current, 'response_code') === 404) { + if (array_get($this->data, 'response_code') === 404) { $this->current['title'] = '404 Page Not Found'; } diff --git a/tests/CascadeTest.php b/tests/CascadeTest.php index 0d1db087..f8401fc6 100644 --- a/tests/CascadeTest.php +++ b/tests/CascadeTest.php @@ -164,4 +164,18 @@ public function it_generates_seo_cascade_without_exception_when_no_home_entry_ex $this->assertArraySubset($expected, $data); } + + /** @test */ + public function it_generates_404_title_with_404_in_response_code_in_context() + { + $data = (new Cascade) + ->with(SiteDefaults::load()->all()) + ->with([ + 'response_code' => 404, + ]) + ->get(); + + $this->assertEquals('404 Page Not Found', $data['title']); + $this->assertEquals('404 Page Not Found | Site Name', $data['compiled_title']); + } } diff --git a/tests/Fixtures/views/antlers/errors/404.antlers.html b/tests/Fixtures/views/antlers/errors/404.antlers.html new file mode 100644 index 00000000..a8eab27f --- /dev/null +++ b/tests/Fixtures/views/antlers/errors/404.antlers.html @@ -0,0 +1,2 @@ +

antlers

+

404!

diff --git a/tests/Fixtures/views/blade-components/errors/404.blade.php b/tests/Fixtures/views/blade-components/errors/404.blade.php new file mode 100644 index 00000000..25f54906 --- /dev/null +++ b/tests/Fixtures/views/blade-components/errors/404.blade.php @@ -0,0 +1,4 @@ + +

blade-components

+

404!

+
diff --git a/tests/Fixtures/views/blade/errors/404.blade.php b/tests/Fixtures/views/blade/errors/404.blade.php new file mode 100644 index 00000000..c783e2fe --- /dev/null +++ b/tests/Fixtures/views/blade/errors/404.blade.php @@ -0,0 +1,3 @@ +@extends('layout') +

blade

+

404!

diff --git a/tests/MetaTagTest.php b/tests/MetaTagTest.php index e0f39a0d..1efae6d9 100644 --- a/tests/MetaTagTest.php +++ b/tests/MetaTagTest.php @@ -657,6 +657,25 @@ public function it_generates_search_engine_verification_codes($viewType) $response->assertSee('', false); } + /** + * @test + * + * @dataProvider viewScenarioProvider + */ + public function it_generates_proper_404_page_title($viewType) + { + $this->prepareViews($viewType); + + $expected = <<<'EOT' +404 Page Not Found | Site Name +EOT; + + $content = $this->get('/non-existent-page')->content(); + $this->assertStringContainsString("

{$viewType}

", $content); + $this->assertStringContainsString('

404!

', $content); + $this->assertStringContainsString($this->normalizeMultilineString($expected), $content); + } + protected function setCustomGlidePresetDimensions($app) { $app->config->set('statamic.seo-pro.assets', [