- Ajout de jobs de lint, test, ci - Refactoring de code - montée de version sur laravel 13 uniquement et php8.5
72 lines
2.4 KiB
PHP
72 lines
2.4 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace Uwil\SitemapGenerator\Tests\Feature;
|
|
|
|
use Illuminate\Support\Facades\File;
|
|
use Illuminate\Support\Facades\Route;
|
|
use Uwil\SitemapGenerator\Config\SitemapConfig;
|
|
use Uwil\SitemapGenerator\Console\Commands\GenerateSitemapCommand;
|
|
|
|
covers(GenerateSitemapCommand::class);
|
|
|
|
describe('GenerateSitemapCommand test', function () {
|
|
it('displays the dry-run table without creating the sitemap file', 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
|
|
/** @var \Illuminate\Testing\PendingCommand $command */
|
|
$command = $this->artisan('uwil:sitemap:refresh --dry-run');
|
|
|
|
// THEN
|
|
$command
|
|
->expectsOutput('Generating Sitemap..')
|
|
->assertSuccessful()
|
|
->run();
|
|
expect(File::exists($this->testXmlPath))->toBeFalse();
|
|
});
|
|
|
|
it('generates the sitemap xml file and serves it via the GET route', function () {
|
|
/** @var \Uwil\SitemapGenerator\Tests\TestCase $this */
|
|
// GIVEN
|
|
$url = 'sitemap.xml';
|
|
Route::name('contact')->get('/{locale}/contact', fn () => 'contact');
|
|
config()->set(SitemapConfig::CONFIG_KEY . '.single_pages', ['contact']);
|
|
|
|
// WHEN
|
|
/** @var \Illuminate\Testing\PendingCommand $command */
|
|
$command = $this->artisan('uwil:sitemap:refresh');
|
|
|
|
// THEN
|
|
$command
|
|
->expectsOutput('Generating Sitemap..')
|
|
->expectsOutput('A new sitemap.xml was generated')
|
|
->assertSuccessful()
|
|
->run();
|
|
expect(File::exists($this->testXmlPath))->toBeTrue();
|
|
$content = File::get($this->testXmlPath);
|
|
expect($content)
|
|
->toContain('<urlset')
|
|
->toContain('/fr/contact')
|
|
->toContain('/en/contact');
|
|
$this->get($url)
|
|
->assertOk()
|
|
->assertSee('/fr/contact');
|
|
});
|
|
|
|
it('returns 404 when the sitemap has not been generated yet', function () {
|
|
/** @var \Uwil\SitemapGenerator\Tests\TestCase $this */
|
|
// GIVEN
|
|
$url = 'sitemap.xml';
|
|
|
|
// WHEN
|
|
$result = $this->get($url);
|
|
|
|
// THEN
|
|
$result->assertNotFound();
|
|
});
|
|
});
|