ldc-sitemap-generator/tests/Unit/Jobs/GenerateSitemapJobTest.php

55 lines
1.6 KiB
PHP
Raw Permalink Normal View History

<?php
declare(strict_types=1);
namespace Uwil\SitemapGenerator\Tests\Unit\Jobs;
use Illuminate\Support\Facades\Queue;
use Illuminate\Support\Facades\Route;
use Illuminate\Support\Facades\Storage;
use Uwil\SitemapGenerator\Config\SitemapConfig;
use Uwil\SitemapGenerator\Jobs\GenerateSitemapJob;
covers(GenerateSitemapJob::class);
describe('GenerateSitemapJob', function () {
beforeEach(function () {
/** @var \Uwil\SitemapGenerator\Tests\TestCase $this */
Storage::disk($this->outputDisk)->delete($this->outputPath);
});
afterEach(function () {
/** @var \Uwil\SitemapGenerator\Tests\TestCase $this */
Storage::disk($this->outputDisk)->delete($this->outputPath);
});
it('generates and writes the sitemap to storage when handled', function () {
/** @var \Uwil\SitemapGenerator\Tests\TestCase $this */
// GIVEN
Route::name('contact')->get('/{locale}/contact', fn () => 'contact');
config()->set(SitemapConfig::CONFIG_KEY . '.single_pages', ['contact']);
// WHEN
GenerateSitemapJob::dispatchSync();
// THEN
expect(Storage::disk($this->outputDisk)->exists($this->outputPath))->toBeTrue();
$content = Storage::disk($this->outputDisk)->get($this->outputPath);
expect($content)
->toContain('<urlset')
->toContain('/fr/contact')
->toContain('/en/contact');
});
it('can be dispatched to queue', function () {
// GIVEN
Queue::fake();
// WHEN
GenerateSitemapJob::dispatch();
// THEN
Queue::assertPushed(GenerateSitemapJob::class);
});
});