mivita/tests/Feature/Incentive/IncentiveTeaserPageTest.php
Kevin b83b43ef4c Incentive (E1): Teaser und Rangliste zu einer Incentive-Seite zusammengefasst
Eine Seite unter /incentive/{slug}: oben Teilnahme-Block mit Bedingungen
(oder fuer bestaetigte Teilnehmer der Kopf mit Rang, Punkten, Praemie und
Bedingungen zum Aufklappen), darunter Titelbild, Text, Kacheln, "So
funktioniert es", Galerie und das Live-Ranking mit Sprungmarke #ranking.
Die alte URL /incentive/{slug}/ranking leitet dorthin um, Dashboard und
Detailseite verlinken auf die Sprungmarke, show.blade.php entfaellt.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
2026-09-22 13:11:10 +00:00

90 lines
2.6 KiB
PHP

<?php
use App\Http\Controllers\User\IncentiveController;
use App\Models\Incentive;
use App\Models\IncentiveParticipant;
use App\User;
use Illuminate\Foundation\Testing\RefreshDatabase;
uses(RefreshDatabase::class);
it('collectGalleryImages returns an array of image paths excluding the hero image', function () {
$incentive = Incentive::factory()->active()->create([
'image' => 'nikki-beach.jpg',
]);
$controller = new IncentiveController;
$method = new ReflectionMethod($controller, 'collectGalleryImages');
$method->setAccessible(true);
$result = $method->invoke($controller, $incentive);
expect($result)->toBeArray();
expect($result)->not->toContain('img/incentive/nikki-beach.jpg');
foreach ($result as $path) {
expect($path)->toStartWith('img/incentive/');
}
});
it('collectGalleryImages returns empty array when directory does not exist', function () {
$incentive = Incentive::factory()->active()->create([
'image' => 'nonexistent-hero.jpg',
]);
$controller = new IncentiveController;
$method = new ReflectionMethod($controller, 'collectGalleryImages');
$method->setAccessible(true);
$result = $method->invoke($controller, $incentive);
expect($result)->toBeArray();
});
it('collectGalleryImages returns sorted results', function () {
$incentive = Incentive::factory()->active()->create([
'image' => 'nikki-beach.jpg',
]);
$controller = new IncentiveController;
$method = new ReflectionMethod($controller, 'collectGalleryImages');
$method->setAccessible(true);
$result = $method->invoke($controller, $incentive);
$sorted = $result;
sort($sorted);
expect($result)->toBe($sorted);
});
it('teaser view receives galleryImages and participant data', function () {
$incentive = Incentive::factory()->active()->create();
$user = User::forceCreate([
'email' => 'teaser-'.uniqid('', true).'@example.com',
'password' => bcrypt('secret'),
'lang' => 'de',
'active' => 1,
]);
$participant = IncentiveParticipant::factory()->create([
'incentive_id' => $incentive->id,
'user_id' => $user->id,
'accepted_terms_at' => now(),
]);
$this->actingAs($user);
$controller = new IncentiveController;
$response = $controller->teaser($incentive->slug);
$data = $response->getData();
expect($data)->toHaveKeys(['incentive', 'participant', 'galleryImages', 'ranking', 'hasConfirmedParticipation'])
->and($data['incentive']->id)->toBe($incentive->id)
->and($data['participant']->id)->toBe($participant->id)
->and($data['galleryImages'])->toBeArray();
});