From 1bcf579143684f70ad90166550b60ee91c868264 Mon Sep 17 00:00:00 2001 From: sindoring Date: Tue, 20 Oct 2026 19:50:17 +0400 Subject: [PATCH] =?UTF-8?q?=D1=84=D0=B8=D0=BA=D1=81=20=D0=B4=D0=BB=D1=8F?= =?UTF-8?q?=20=D1=81=D0=B5=D0=BE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- resources/views/seo/sitemap.blade.php | 4 +- tests/Feature/SitemapRenderingFeatureTest.php | 55 +++++++++++++++++++ 2 files changed, 58 insertions(+), 1 deletion(-) create mode 100644 tests/Feature/SitemapRenderingFeatureTest.php diff --git a/resources/views/seo/sitemap.blade.php b/resources/views/seo/sitemap.blade.php index a12ad45..88c0d0b 100644 --- a/resources/views/seo/sitemap.blade.php +++ b/resources/views/seo/sitemap.blade.php @@ -1,4 +1,6 @@ -{!! '' !!} +@php + echo ''; +@endphp {{ $seo->routeUrl('landing.index') }} diff --git a/tests/Feature/SitemapRenderingFeatureTest.php b/tests/Feature/SitemapRenderingFeatureTest.php new file mode 100644 index 0000000..034bb0a --- /dev/null +++ b/tests/Feature/SitemapRenderingFeatureTest.php @@ -0,0 +1,55 @@ +loadEnvironmentFrom('.env.example'); + $app->make(Illuminate\Contracts\Console\Kernel::class)->bootstrap(); + $compiledPath = sys_get_temp_dir().'/moonwell-sitemap-'.bin2hex(random_bytes(8)); + mkdir($compiledPath); + config(['app.url' => 'https://moon-well.online', 'view.compiled' => $compiledPath]); + try { + $app['blade.compiler']->compile(resource_path('views/seo/sitemap.blade.php')); + echo view('seo.sitemap', [ + 'seo' => app(App\Services\SeoService::class), + 'articles' => collect([(new App\Models\News)->forceFill([ + 'id' => 42, + 'updated_at' => '2026-10-20 12:00:00', + ])]), + ])->render(); + } finally { + (new Illuminate\Filesystem\Filesystem)->deleteDirectory($compiledPath); + } + PHP; + + $process = new Process([PHP_BINARY, '-d', 'short_open_tag='.$setting, '-r', $script, base_path()]); + $process->run(); + + $this->assertTrue($process->isSuccessful(), $process->getErrorOutput().$process->getOutput()); + $this->assertStringStartsWith('', $process->getOutput()); + $xml = simplexml_load_string($process->getOutput()); + $this->assertNotFalse($xml); + $xml->registerXPathNamespace('s', 'http://www.sitemaps.org/schemas/sitemap/0.9'); + $this->assertSame('https://moon-well.online/news/42', (string) $xml->xpath('//s:url[3]/s:loc')[0]); + $this->assertSame('2026-10-20T12:00:00+00:00', (string) $xml->xpath('//s:lastmod')[0]); + } + + public static function shortOpenTagSettings(): array + { + return [ + 'production: enabled' => ['1'], + 'development: disabled' => ['0'], + ]; + } +}