2026-06-14 21:32:07 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
declare(strict_types=1);
|
|
|
|
|
|
2026-10-29 14:56:35 +01:00
|
|
|
use App\Models\Discount;
|
2026-06-14 21:32:07 +02:00
|
|
|
use App\Models\Page;
|
2026-09-30 16:49:26 +02:00
|
|
|
use App\Models\Product;
|
|
|
|
|
use App\Models\Range;
|
|
|
|
|
use App\Models\Slide;
|
2026-06-14 21:32:07 +02:00
|
|
|
use Database\Seeders\ContentSeeder;
|
2026-10-29 14:56:35 +01:00
|
|
|
use Domain\Enums\DiscountType;
|
2026-09-30 16:49:26 +02:00
|
|
|
use Domain\Enums\ProductBrand;
|
|
|
|
|
use Domain\Enums\SellUnit;
|
|
|
|
|
use Domain\Enums\TaxRate;
|
|
|
|
|
use Domain\Enums\Units\InvoicingUnit;
|
2026-10-29 14:56:35 +01:00
|
|
|
use Domain\Models\ValueObjects\DiscountValue;
|
2026-09-30 16:49:26 +02:00
|
|
|
use Illuminate\Support\Carbon;
|
2026-06-14 21:32:07 +02:00
|
|
|
use Illuminate\Support\Facades\View;
|
2026-09-30 16:49:26 +02:00
|
|
|
use Money\Money;
|
|
|
|
|
use Ramsey\Uuid\Uuid;
|
2026-06-14 21:32:07 +02:00
|
|
|
|
|
|
|
|
describe('HomeController', function () {
|
|
|
|
|
it('can access home page', function () {
|
2026-09-30 16:49:26 +02:00
|
|
|
/** @var \Tests\TestCase $this */
|
2026-06-14 21:32:07 +02:00
|
|
|
// GIVEN
|
|
|
|
|
$this->seed(ContentSeeder::class);
|
|
|
|
|
View::share('PageList', Page::getCached()
|
|
|
|
|
->mapWithKeys(fn ($page) => [
|
|
|
|
|
$page->slug->value() => $page,
|
|
|
|
|
]));
|
|
|
|
|
|
|
|
|
|
// WHEN
|
|
|
|
|
$response = $this->get('/');
|
|
|
|
|
|
|
|
|
|
// THEN
|
|
|
|
|
$response->assertOk();
|
|
|
|
|
});
|
2026-09-30 16:49:26 +02:00
|
|
|
|
|
|
|
|
it('displays star products, slides and ranges', function () {
|
|
|
|
|
/** @var \Tests\TestCase $this */
|
|
|
|
|
// GIVEN
|
|
|
|
|
$this->seed(ContentSeeder::class);
|
|
|
|
|
View::share('PageList', Page::getCached()
|
|
|
|
|
->mapWithKeys(fn ($page) => [
|
|
|
|
|
$page->slug->value() => $page,
|
|
|
|
|
]));
|
|
|
|
|
|
|
|
|
|
$range = new Range();
|
|
|
|
|
$range->name = 'Boucherie';
|
|
|
|
|
$range->slug = 'boucherie';
|
|
|
|
|
$range->picture = 'ranges/boucherie.jpg';
|
|
|
|
|
$range->picture_alt = 'Boucherie';
|
|
|
|
|
$range->picture_title = 'Boucherie';
|
|
|
|
|
$range->status = true;
|
|
|
|
|
$range->order = 1;
|
|
|
|
|
$range->save();
|
|
|
|
|
|
|
|
|
|
$slide = new Slide();
|
|
|
|
|
$slide->title = 'Super Promo';
|
|
|
|
|
$slide->status = true;
|
|
|
|
|
$slide->order = 1;
|
|
|
|
|
$slide->connected = false;
|
|
|
|
|
$slide->link = 'https://example.com';
|
|
|
|
|
$slide->date_start = Carbon::yesterday();
|
|
|
|
|
$slide->date_end = Carbon::tomorrow();
|
|
|
|
|
$slide->save();
|
|
|
|
|
|
|
|
|
|
$product = new Product();
|
|
|
|
|
$product->id = (string) Uuid::uuid7();
|
|
|
|
|
$product->name = 'Poulet Fermier';
|
|
|
|
|
$product->brand = ProductBrand::loue;
|
|
|
|
|
$product->slug = 'poulet-fermier';
|
|
|
|
|
$product->description = 'Délicieux poulet fermier';
|
|
|
|
|
$product->picture_alt = 'Poulet Fermier';
|
|
|
|
|
$product->picture_title = 'Poulet Fermier';
|
|
|
|
|
$product->picture_large_alt = 'Poulet Fermier';
|
|
|
|
|
$product->picture_large_title = 'Poulet Fermier';
|
|
|
|
|
$product->price = Money::EUR(1500);
|
|
|
|
|
$product->invoicing_unit = InvoicingUnit::KGM;
|
|
|
|
|
$product->sell_unit = SellUnit::KGM;
|
|
|
|
|
$product->tax_rate = TaxRate::TVA_5_5;
|
|
|
|
|
$product->stock = 10;
|
|
|
|
|
$product->range_id = $range->id;
|
|
|
|
|
$product->order = 1;
|
|
|
|
|
$product->star = true;
|
|
|
|
|
$product->status = true;
|
|
|
|
|
$product->save();
|
|
|
|
|
|
|
|
|
|
// WHEN
|
|
|
|
|
$response = $this->get('/');
|
|
|
|
|
|
|
|
|
|
// THEN
|
|
|
|
|
$response->assertOk();
|
2026-10-02 19:44:29 +02:00
|
|
|
$response->assertSee('id="hero-carousel"', false);
|
2026-09-30 16:49:26 +02:00
|
|
|
$response->assertSee('Poulet Fermier');
|
|
|
|
|
$response->assertSee('Super Promo');
|
|
|
|
|
$response->assertSee('Boucherie');
|
|
|
|
|
});
|
2026-10-02 19:44:29 +02:00
|
|
|
|
|
|
|
|
it('does not display slider section when no slides are published', function () {
|
|
|
|
|
/** @var \Tests\TestCase $this */
|
|
|
|
|
// GIVEN
|
|
|
|
|
$this->seed(ContentSeeder::class);
|
|
|
|
|
View::share('PageList', Page::getCached()
|
|
|
|
|
->mapWithKeys(fn ($page) => [
|
|
|
|
|
$page->slug->value() => $page,
|
|
|
|
|
]));
|
|
|
|
|
|
|
|
|
|
$expiredSlide = new Slide();
|
|
|
|
|
$expiredSlide->title = 'Expired Promo';
|
|
|
|
|
$expiredSlide->status = true;
|
|
|
|
|
$expiredSlide->order = 1;
|
|
|
|
|
$expiredSlide->connected = false;
|
|
|
|
|
$expiredSlide->link = 'https://example.com';
|
|
|
|
|
$expiredSlide->date_start = Carbon::now()->subDays(5);
|
|
|
|
|
$expiredSlide->date_end = Carbon::now()->subDays(2);
|
|
|
|
|
$expiredSlide->save();
|
|
|
|
|
|
|
|
|
|
// WHEN
|
|
|
|
|
$response = $this->get('/');
|
|
|
|
|
|
|
|
|
|
// THEN
|
|
|
|
|
$response->assertOk();
|
|
|
|
|
$response->assertDontSee('id="hero-carousel"', false);
|
|
|
|
|
$response->assertDontSee('Expired Promo');
|
|
|
|
|
});
|
2026-10-29 14:56:35 +01:00
|
|
|
|
|
|
|
|
it('displays promo prices in red for discounted star products on homepage', function () {
|
|
|
|
|
/** @var \Tests\TestCase $this */
|
|
|
|
|
// GIVEN
|
|
|
|
|
$this->seed(ContentSeeder::class);
|
|
|
|
|
View::share('PageList', Page::getCached()
|
|
|
|
|
->mapWithKeys(fn ($page) => [
|
|
|
|
|
$page->slug->value() => $page,
|
|
|
|
|
]));
|
|
|
|
|
|
|
|
|
|
$range = new Range();
|
|
|
|
|
$range->name = 'Boucherie';
|
|
|
|
|
$range->slug = 'boucherie';
|
|
|
|
|
$range->picture = 'ranges/boucherie.jpg';
|
|
|
|
|
$range->picture_alt = 'Boucherie';
|
|
|
|
|
$range->picture_title = 'Boucherie';
|
|
|
|
|
$range->status = true;
|
|
|
|
|
$range->order = 1;
|
|
|
|
|
$range->save();
|
|
|
|
|
|
|
|
|
|
$discount = new Discount();
|
|
|
|
|
$discount->type = DiscountType::PERCENT;
|
|
|
|
|
$discount->value = DiscountValue::fromPercentage(10);
|
|
|
|
|
$discount->is_old_price_displayed = false;
|
|
|
|
|
$discount->date_start = Carbon::yesterday();
|
|
|
|
|
$discount->date_end = Carbon::tomorrow();
|
|
|
|
|
$discount->save();
|
|
|
|
|
|
|
|
|
|
$promoProduct = new Product();
|
|
|
|
|
$promoProduct->id = (string) Uuid::uuid7();
|
|
|
|
|
$promoProduct->name = 'Foie Gras Promo';
|
|
|
|
|
$promoProduct->brand = ProductBrand::loue;
|
|
|
|
|
$promoProduct->slug = 'foie-gras-promo';
|
|
|
|
|
$promoProduct->description = 'Foie Gras en promo';
|
|
|
|
|
$promoProduct->picture_alt = 'Foie Gras Promo';
|
|
|
|
|
$promoProduct->picture_title = 'Foie Gras Promo';
|
|
|
|
|
$promoProduct->picture_large_alt = 'Foie Gras Promo';
|
|
|
|
|
$promoProduct->picture_large_title = 'Foie Gras Promo';
|
|
|
|
|
$promoProduct->price = Money::EUR(2000);
|
|
|
|
|
$promoProduct->invoicing_unit = InvoicingUnit::PCE;
|
|
|
|
|
$promoProduct->sell_unit = SellUnit::PCE;
|
|
|
|
|
$promoProduct->tax_rate = TaxRate::TVA_5_5;
|
|
|
|
|
$promoProduct->stock = 10;
|
|
|
|
|
$promoProduct->range_id = $range->id;
|
|
|
|
|
$promoProduct->order = 1;
|
|
|
|
|
$promoProduct->star = true;
|
|
|
|
|
$promoProduct->status = true;
|
|
|
|
|
$promoProduct->discount_id = $discount->id;
|
|
|
|
|
$promoProduct->save();
|
|
|
|
|
|
|
|
|
|
$regularProduct = new Product();
|
|
|
|
|
$regularProduct->id = (string) Uuid::uuid7();
|
|
|
|
|
$regularProduct->name = 'Poulet Standard';
|
|
|
|
|
$regularProduct->brand = ProductBrand::loue;
|
|
|
|
|
$regularProduct->slug = 'poulet-standard';
|
|
|
|
|
$regularProduct->description = 'Poulet standard sans promo';
|
|
|
|
|
$regularProduct->picture_alt = 'Poulet Standard';
|
|
|
|
|
$regularProduct->picture_title = 'Poulet Standard';
|
|
|
|
|
$regularProduct->picture_large_alt = 'Poulet Standard';
|
|
|
|
|
$regularProduct->picture_large_title = 'Poulet Standard';
|
|
|
|
|
$regularProduct->price = Money::EUR(1500);
|
|
|
|
|
$regularProduct->invoicing_unit = InvoicingUnit::PCE;
|
|
|
|
|
$regularProduct->sell_unit = SellUnit::PCE;
|
|
|
|
|
$regularProduct->tax_rate = TaxRate::TVA_5_5;
|
|
|
|
|
$regularProduct->stock = 10;
|
|
|
|
|
$regularProduct->range_id = $range->id;
|
|
|
|
|
$regularProduct->order = 2;
|
|
|
|
|
$regularProduct->star = true;
|
|
|
|
|
$regularProduct->status = true;
|
|
|
|
|
$regularProduct->discount_id = null;
|
|
|
|
|
$regularProduct->save();
|
|
|
|
|
|
|
|
|
|
// WHEN
|
|
|
|
|
$response = $this->get('/');
|
|
|
|
|
|
|
|
|
|
// THEN
|
|
|
|
|
$response->assertOk();
|
|
|
|
|
$content = $response->getContent();
|
|
|
|
|
expect($content)->toContain('Foie Gras Promo')
|
|
|
|
|
->and($content)->toContain('Poulet Standard');
|
|
|
|
|
|
|
|
|
|
// Promo product price span has text-danger class
|
|
|
|
|
expect($content)->toMatch('/Foie Gras Promo.*?<span class="fw-semibold h4\s+text-danger\s*">/s')
|
|
|
|
|
// Regular product price span does NOT have text-danger class
|
|
|
|
|
->and($content)->toMatch('/Poulet Standard.*?<span class="fw-semibold h4\s*">/s');
|
|
|
|
|
});
|
2026-11-16 02:50:39 +01:00
|
|
|
|
|
|
|
|
it('escapes decoded HTML payloads in featured product slider description', function (): void {
|
|
|
|
|
/** @var \Tests\TestCase $this */
|
|
|
|
|
// GIVEN
|
|
|
|
|
$this->seed(ContentSeeder::class);
|
|
|
|
|
View::share('PageList', Page::getCached()->mapWithKeys(fn ($page) => [$page->slug->value() => $page]));
|
|
|
|
|
|
|
|
|
|
$range = new Range();
|
|
|
|
|
$range->name = 'Volaille';
|
|
|
|
|
$range->slug = 'volaille';
|
|
|
|
|
$range->picture = 'ranges/volaille.jpg';
|
|
|
|
|
$range->picture_alt = 'Volaille';
|
|
|
|
|
$range->picture_title = 'Volaille';
|
|
|
|
|
$range->status = true;
|
|
|
|
|
$range->order = 1;
|
|
|
|
|
$range->save();
|
|
|
|
|
|
|
|
|
|
$product = new Product();
|
|
|
|
|
$product->id = (string) Uuid::uuid7();
|
|
|
|
|
$product->name = 'Poulet Sûr';
|
|
|
|
|
$product->brand = ProductBrand::loue;
|
|
|
|
|
$product->slug = 'poulet-sur';
|
|
|
|
|
$product->description = '<p>Rôti <img src=x onerror=alert(1)></p>';
|
|
|
|
|
$product->picture_alt = 'alt';
|
|
|
|
|
$product->picture_title = 'title';
|
|
|
|
|
$product->picture_large_alt = 'alt';
|
|
|
|
|
$product->picture_large_title = 'title';
|
|
|
|
|
$product->price = Money::EUR(1500);
|
|
|
|
|
$product->invoicing_unit = InvoicingUnit::PCE;
|
|
|
|
|
$product->sell_unit = SellUnit::PCE;
|
|
|
|
|
$product->tax_rate = TaxRate::TVA_5_5;
|
|
|
|
|
$product->stock = 10;
|
|
|
|
|
$product->range_id = $range->id;
|
|
|
|
|
$product->order = 1;
|
|
|
|
|
$product->star = true;
|
|
|
|
|
$product->status = true;
|
|
|
|
|
$product->save();
|
|
|
|
|
|
|
|
|
|
// WHEN
|
|
|
|
|
$response = $this->get('/');
|
|
|
|
|
|
|
|
|
|
// THEN
|
|
|
|
|
$response->assertOk();
|
|
|
|
|
$response->assertDontSee('<img src=x onerror=alert(1)>', false);
|
|
|
|
|
$response->assertSee('Rôti <img src=x onerror=alert(1)>', false);
|
|
|
|
|
});
|
2026-06-14 21:32:07 +02:00
|
|
|
});
|